-
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.
Merge branch 'develop' into devx/constants-file-for-urls
- Loading branch information
Showing
49 changed files
with
2,615 additions
and
972 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.