Skip to content

Commit

Permalink
fix(suite): update handling of ethereum unstaking period
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-pvl authored and tomasklim committed Jan 24, 2025
1 parent 53c913f commit b0cb779
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
13 changes: 10 additions & 3 deletions packages/suite/src/utils/suite/ethereumStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit b0cb779

Please sign in to comment.