From 7d1459f80535578dc6460951be53389616c54100 Mon Sep 17 00:00:00 2001 From: Pavlo Syrotyna Date: Fri, 24 Jan 2025 18:28:53 +0200 Subject: [PATCH] fix(suite): update handling of ethereum unstaking period --- .../suite/StakingProcess/UnstakingInfo.tsx | 20 +++++++------------ .../StakeInANutshellModal.tsx | 4 ++-- .../suite/__fixtures__/ethereumStaking.ts | 3 ++- .../suite/__tests__/ethereumStaking.test.ts | 5 ++++- .../suite/src/utils/suite/ethereumStaking.ts | 13 +++++++++--- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/suite/src/components/suite/StakingProcess/UnstakingInfo.tsx b/packages/suite/src/components/suite/StakingProcess/UnstakingInfo.tsx index 9e1fa675e7c..d4b3d1e7870 100644 --- a/packages/suite/src/components/suite/StakingProcess/UnstakingInfo.tsx +++ b/packages/suite/src/components/suite/StakingProcess/UnstakingInfo.tsx @@ -3,18 +3,12 @@ import { useSelector } from 'react-redux'; import { BulletList } from '@trezor/components'; import { spacings } from '@trezor/theme'; -import { - selectAccountUnstakeTransactions, - selectValidatorsQueue, - TransactionsRootState, - StakeRootState, - AccountsRootState, -} from '@suite-common/wallet-core'; +import { selectValidatorsQueue, StakeRootState } from '@suite-common/wallet-core'; import { getNetworkDisplaySymbol, NetworkSymbol, NetworkType } from '@suite-common/wallet-config'; import { SOLANA_EPOCH_DAYS } from '@suite-common/wallet-constants'; import { Translation } from 'src/components/suite'; -import { getDaysToUnstake } from 'src/utils/suite/ethereumStaking'; +import { getUnstakingPeriodInDays } from 'src/utils/suite/ethereumStaking'; import { CoinjoinRootState } from 'src/reducers/wallet/coinjoinReducer'; import { InfoRow } from './InfoRow'; @@ -67,13 +61,13 @@ export const UnstakingInfo = ({ isExpanded }: UnstakingInfoProps) => { const { data } = useSelector((state: StakeRootState) => selectValidatorsQueue(state, account?.symbol)) || {}; - const unstakeTxs = useSelector((state: TransactionsRootState & AccountsRootState) => - selectAccountUnstakeTransactions(state, account?.key ?? ''), - ); - if (!account) return null; - const daysToUnstake = getDaysToUnstake(unstakeTxs, data); + const daysToUnstake = getUnstakingPeriodInDays( + data?.validatorWithdrawTime, + data?.validatorExitTime, + ); + const displaySymbol = getNetworkDisplaySymbol(account.symbol); const infoRowsData = getInfoRowsData(account.networkType, account.symbol, daysToUnstake); diff --git a/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeInANutshellModal/StakeInANutshellModal.tsx b/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeInANutshellModal/StakeInANutshellModal.tsx index 86f2a047841..8d61270ecdf 100644 --- a/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeInANutshellModal/StakeInANutshellModal.tsx +++ b/packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeInANutshellModal/StakeInANutshellModal.tsx @@ -57,11 +57,11 @@ interface StakeInANutshellModalProps { export const StakeInANutshellModal = ({ onCancel }: StakeInANutshellModalProps) => { const account = useSelector(selectSelectedAccount); const dispatch = useDispatch(); - const { validatorWithdrawTime } = useSelector(state => + const { validatorWithdrawTime, validatorExitTime } = useSelector(state => selectValidatorsQueueData(state, account?.symbol), ); - const unstakingPeriod = getUnstakingPeriodInDays(validatorWithdrawTime); + const unstakingPeriod = getUnstakingPeriodInDays(validatorWithdrawTime, validatorExitTime); const proceedToEverstakeModal = () => { onCancel(); diff --git a/packages/suite/src/utils/suite/__fixtures__/ethereumStaking.ts b/packages/suite/src/utils/suite/__fixtures__/ethereumStaking.ts index 9e41a200270..42759a96bf2 100644 --- a/packages/suite/src/utils/suite/__fixtures__/ethereumStaking.ts +++ b/packages/suite/src/utils/suite/__fixtures__/ethereumStaking.ts @@ -529,8 +529,9 @@ export const getUnstakingPeriodInDaysFixture = [ description: 'should return correct unstaking period in days', args: { validatorWithdrawTimeInSeconds: 604800, // 7 days + validatorExitTimeInSeconds: 259200, // 3 days }, - result: 7, + result: 10, // 7 + 3 }, { description: diff --git a/packages/suite/src/utils/suite/__tests__/ethereumStaking.test.ts b/packages/suite/src/utils/suite/__tests__/ethereumStaking.test.ts index e3cc1ffc9df..c83600cb302 100644 --- a/packages/suite/src/utils/suite/__tests__/ethereumStaking.test.ts +++ b/packages/suite/src/utils/suite/__tests__/ethereumStaking.test.ts @@ -166,7 +166,10 @@ describe('getStakeTxGasLimit', () => { describe('getUnstakingPeriodInDays', () => { getUnstakingPeriodInDaysFixture.forEach(test => { it(test.description, async () => { - const result = await getUnstakingPeriodInDays(test.args.validatorWithdrawTimeInSeconds); + const result = await getUnstakingPeriodInDays( + test.args.validatorWithdrawTimeInSeconds, + test.args.validatorExitTimeInSeconds, + ); expect(result).toEqual(test.result); }); }); diff --git a/packages/suite/src/utils/suite/ethereumStaking.ts b/packages/suite/src/utils/suite/ethereumStaking.ts index 7799398a83d..e4c3235fa50 100644 --- a/packages/suite/src/utils/suite/ethereumStaking.ts +++ b/packages/suite/src/utils/suite/ethereumStaking.ts @@ -512,12 +512,19 @@ export const getStakeTxGasLimit = async ({ } }; -export const getUnstakingPeriodInDays = (validatorWithdrawTimeInSeconds?: number) => { - if (validatorWithdrawTimeInSeconds === undefined) { +export const getUnstakingPeriodInDays = ( + validatorWithdrawTimeInSeconds?: number, + validatorExitTime?: number, +) => { + if (validatorWithdrawTimeInSeconds === undefined || validatorExitTime === undefined) { return UNSTAKING_ETH_PERIOD; } - return secondsToDays(validatorWithdrawTimeInSeconds); + const unstakingPeriodInSeconds = new BigNumber(validatorWithdrawTimeInSeconds) + .plus(validatorExitTime) + .toNumber(); + + return secondsToDays(unstakingPeriodInSeconds); }; export const getDaysToAddToPool = (