-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-dashboard): style staked vesting overview (#4303)
* feat(dashboard): style vesting * feat(dashboard): show properly data * fix(wallet-dashboard): wrong buttonType for dist * feat(dashboard): update UI after resolve conflicts. * feat(dashboard): add earned amount * feat(wallet-dashboard): implement StakedTimelockObject component and refactor vesting page * feat(dashboard): add Stake button to Staked Vesting title and simplify StakeDialog prop * feat(dashboard): add useStakeRewardStatus hook and integrate into StakedTimelockObject component * feat(vesting): update vesting interface and calculations to use bigint for improved precision * feat(dashboard): add loader, change style, fix BigInt round issue. * refactor(dashboard): move StakeState and STATUS_COPY to useStakeRewardStatus hook * feat(dashboard): implement bigInt to tests. * fix(dashboard): adjust padding for sidebar overlap on small screens and improve flex layout in vesting page * feat(dashboard): update estimatedReward and principal to use BigInt for improved precision
- Loading branch information
1 parent
55c14e8
commit d2c04ac
Showing
11 changed files
with
426 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; | ||
import { NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE } from '../constants'; | ||
import { useFormatCoin, useGetTimeBeforeEpochNumber, useTimeAgo, TimeUnit } from '.'; | ||
import { determineCountDownText } from '../utils'; | ||
|
||
export function useStakeRewardStatus({ | ||
stakeRequestEpoch, | ||
currentEpoch, | ||
inactiveValidator, | ||
estimatedReward, | ||
}: { | ||
stakeRequestEpoch: string; | ||
currentEpoch: number; | ||
inactiveValidator: boolean; | ||
estimatedReward?: string | number | bigint; | ||
}) { | ||
// TODO: Once two step withdraw is available, add cool down and withdraw now logic | ||
// For cool down epoch, show Available to withdraw add rewards to principal | ||
// Reward earning epoch is 2 epochs after stake request epoch | ||
const earningRewardsEpoch = | ||
Number(stakeRequestEpoch) + NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE; | ||
|
||
const isEarnedRewards = currentEpoch >= Number(earningRewardsEpoch); | ||
|
||
const delegationState = inactiveValidator | ||
? StakeState.InActive | ||
: isEarnedRewards | ||
? StakeState.Earning | ||
: StakeState.WarmUp; | ||
|
||
const rewards = isEarnedRewards && estimatedReward ? BigInt(estimatedReward) : 0n; | ||
|
||
const [rewardsStaked, symbol] = useFormatCoin(rewards, IOTA_TYPE_ARG); | ||
|
||
// Applicable only for warm up | ||
const epochBeforeRewards = delegationState === StakeState.WarmUp ? earningRewardsEpoch : null; | ||
|
||
const statusText = { | ||
// Epoch time before earning | ||
[StakeState.WarmUp]: `Epoch #${earningRewardsEpoch}`, | ||
[StakeState.Earning]: `${rewardsStaked} ${symbol}`, | ||
// Epoch time before redrawing | ||
[StakeState.CoolDown]: `Epoch #`, | ||
[StakeState.Withdraw]: 'Now', | ||
[StakeState.InActive]: 'Not earning rewards', | ||
}; | ||
|
||
const { data: rewardEpochTime } = useGetTimeBeforeEpochNumber(Number(epochBeforeRewards) || 0); | ||
|
||
const timeAgo = useTimeAgo({ | ||
timeFrom: rewardEpochTime || null, | ||
shortedTimeLabel: false, | ||
shouldEnd: true, | ||
maxTimeUnit: TimeUnit.ONE_HOUR, | ||
}); | ||
|
||
const rewardTime = () => { | ||
if (Number(epochBeforeRewards) && rewardEpochTime > 0) { | ||
return determineCountDownText({ | ||
timeAgo, | ||
label: 'in', | ||
}); | ||
} | ||
|
||
return statusText[delegationState]; | ||
}; | ||
|
||
return { | ||
rewards, | ||
title: rewardTime(), | ||
subtitle: STATUS_COPY[delegationState], | ||
}; | ||
} | ||
export enum StakeState { | ||
WarmUp = 'WARM_UP', | ||
Earning = 'EARNING', | ||
CoolDown = 'COOL_DOWN', | ||
Withdraw = 'WITHDRAW', | ||
InActive = 'IN_ACTIVE', | ||
} | ||
export const STATUS_COPY: { | ||
[key in StakeState]: string; | ||
} = { | ||
[StakeState.WarmUp]: 'Starts Earning', | ||
[StakeState.Earning]: 'Staking Rewards', | ||
[StakeState.CoolDown]: 'Available to withdraw', | ||
[StakeState.Withdraw]: 'Withdraw', | ||
[StakeState.InActive]: 'Inactive', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.