Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into feat/add-funding-s…
Browse files Browse the repository at this point in the history
…ection-to-staking-manage
  • Loading branch information
truemiller committed Aug 28, 2024
2 parents de10e16 + 31ac520 commit 5d75760
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ import { UNICODE_SYMBOLS } from '@/constants/symbols';
const { Text } = Typography;

export const AlertInsufficientMigrationFunds = ({
totalOlasBalance,
masterSafeOlasBalance,
stakedOlasBalance,
totalOlasRequiredForStaking,
}: {
totalOlasBalance: number;
}) => (
<CustomAlert
type="warning"
showIcon
message={
<Flex vertical gap={4}>
<Text className="font-weight-600">
Insufficient amount of funds to switch
</Text>
masterSafeOlasBalance: number;
stakedOlasBalance: number;
totalOlasRequiredForStaking: number;
}) => {
const requiredOlasDeposit =
totalOlasRequiredForStaking - (stakedOlasBalance + masterSafeOlasBalance);

<Text>Add funds to your account to meet the program requirements.</Text>
<Text>
Your current OLAS balance:{' '}
<span className="font-weight-600">{totalOlasBalance} OLAS</span>
</Text>
</Flex>
}
/>
);
return (
<CustomAlert
type="warning"
showIcon
message={
<Flex vertical gap={4}>
<Text className="font-weight-600">
An additional {requiredOlasDeposit} OLAS is required to switch
</Text>
<Text>
Add <strong>{requiredOlasDeposit} OLAS</strong> to your account to
meet the contract requirements and switch.
</Text>
</Flex>
}
/>
);
};

export const AlertNoSlots = () => (
<CustomAlert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ export const StakingContractSection = ({
const { setMigrationModalOpen } = useModals();
const { activeStakingProgram, defaultStakingProgram, updateStakingProgram } =
useStakingProgram();
const { stakingContractInfoRecord } = useStakingContractInfo();
const { token } = useToken();
const { totalOlasBalance, isBalanceLoaded } = useBalance();
const { isServiceStakedForMinimumDuration } = useStakingContractInfo();
const { safeBalance, totalOlasStakedBalance, isBalanceLoaded } = useBalance();
const { isServiceStakedForMinimumDuration, stakingContractInfoRecord } =
useStakingContractInfo();
const [isFundingSectionOpen, setIsFundingSectionOpen] = useState(false);

const stakingContractInfoForStakingProgram =
Expand All @@ -93,10 +93,15 @@ export const StakingContractSection = ({
);

const hasEnoughOlasToMigrate = useMemo(() => {
if (totalOlasBalance === undefined) return false;
if (!minimumOlasRequiredToMigrate) return false;
return totalOlasBalance >= minimumOlasRequiredToMigrate;
}, [minimumOlasRequiredToMigrate, totalOlasBalance]);
if (safeBalance?.OLAS === undefined || totalOlasStakedBalance === undefined)
return false;

const balanceForMigration = safeBalance.OLAS + totalOlasStakedBalance;

if (minimumOlasRequiredToMigrate === undefined) return false;

return balanceForMigration >= minimumOlasRequiredToMigrate;
}, [minimumOlasRequiredToMigrate, safeBalance?.OLAS, totalOlasStakedBalance]);

const hasEnoughSlots =
stakingContractInfoForStakingProgram?.maxNumServices &&
Expand Down Expand Up @@ -173,6 +178,7 @@ export const StakingContractSection = ({
isBalanceLoaded,
isSelected,
isServiceStakedForMinimumDuration,
minimumOlasRequiredToMigrate,
serviceStatus,
]);

Expand All @@ -185,9 +191,17 @@ export const StakingContractSection = ({
return <AlertNoSlots />;
}

if (!hasEnoughOlasToMigrate) {
if (
!hasEnoughOlasToMigrate &&
safeBalance?.OLAS !== undefined &&
totalOlasStakedBalance !== undefined
) {
return (
<AlertInsufficientMigrationFunds totalOlasBalance={totalOlasBalance!} />
<AlertInsufficientMigrationFunds
masterSafeOlasBalance={safeBalance.OLAS}
stakedOlasBalance={totalOlasStakedBalance}
totalOlasRequiredForStaking={minimumOlasRequiredToMigrate}
/>
);
}

Expand All @@ -197,10 +211,12 @@ export const StakingContractSection = ({
}, [
isSelected,
isBalanceLoaded,
totalOlasBalance,
hasEnoughSlots,
hasEnoughOlasToMigrate,
isAppVersionCompatible,
safeBalance?.OLAS,
totalOlasStakedBalance,
minimumOlasRequiredToMigrate,
]);

const contractTagStatus = useMemo(() => {
Expand Down

0 comments on commit 5d75760

Please sign in to comment.