-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wallet-dashboard): add staking confirmation screen #4034
Changes from 44 commits
c925a99
1d8887e
a852fab
8325b36
388058c
d8d03ac
1ff40ea
2c1adc9
4d93394
8c17341
7f66cd0
5932ed5
1507c81
9bdb887
499e4a6
14a2786
c1341dc
c4329f4
3a4ebb7
3818f2c
54b1b1f
4777432
b13ac91
8242185
cc8b8c6
d5ee9a1
47cbd98
371b2fd
be3b938
80049ac
24144b3
0cfd637
dc99beb
8b2df8f
873a5aa
a6e664b
2afa4d8
796bf46
bcbdebd
b964e75
c8bbc90
af7f7dc
69bcf98
ce38b84
24ea08c
8c14776
9f7fe1d
026ee47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { | ||
useGetTimeBeforeEpochNumber, | ||
useTimeAgo, | ||
TimeUnit, | ||
NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE, | ||
NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_STARTS, | ||
} from '../../index'; | ||
|
||
export function useStakeTxnInfo(startEpoch?: string | number) { | ||
const startEarningRewardsEpoch = | ||
Number(startEpoch || 0) + NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_STARTS; | ||
|
||
const redeemableRewardsEpoch = | ||
Number(startEpoch || 0) + NUM_OF_EPOCH_BEFORE_STAKING_REWARDS_REDEEMABLE; | ||
|
||
const { data: timeBeforeStakeRewardsStarts } = | ||
useGetTimeBeforeEpochNumber(startEarningRewardsEpoch); | ||
const timeBeforeStakeRewardsStartsAgo = useTimeAgo({ | ||
timeFrom: timeBeforeStakeRewardsStarts, | ||
shortedTimeLabel: false, | ||
shouldEnd: true, | ||
maxTimeUnit: TimeUnit.ONE_HOUR, | ||
}); | ||
const stakedRewardsStartEpoch = | ||
timeBeforeStakeRewardsStarts > 0 | ||
? `in ${timeBeforeStakeRewardsStartsAgo}` | ||
: startEpoch | ||
? `Epoch #${Number(startEarningRewardsEpoch)}` | ||
: '--'; | ||
|
||
const { data: timeBeforeStakeRewardsRedeemable } = | ||
useGetTimeBeforeEpochNumber(redeemableRewardsEpoch); | ||
const timeBeforeStakeRewardsRedeemableAgo = useTimeAgo({ | ||
timeFrom: timeBeforeStakeRewardsRedeemable, | ||
shortedTimeLabel: false, | ||
shouldEnd: true, | ||
maxTimeUnit: TimeUnit.ONE_HOUR, | ||
}); | ||
const timeBeforeStakeRewardsRedeemableAgoDisplay = | ||
timeBeforeStakeRewardsRedeemable > 0 | ||
? `in ${timeBeforeStakeRewardsRedeemableAgo}` | ||
: startEpoch | ||
? `Epoch #${Number(redeemableRewardsEpoch)}` | ||
: '--'; | ||
|
||
return { | ||
stakedRewardsStartEpoch, | ||
timeBeforeStakeRewardsRedeemableAgoDisplay, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { useIotaClientQuery } from '@iota/dapp-kit'; | ||
import { useGetValidatorsApy } from '../'; | ||
import { getTotalValidatorStake } from '../../utils'; | ||
|
||
export function useValidatorInfo({ validatorAddress }: { validatorAddress: string }) { | ||
const { | ||
data: system, | ||
isPending: isPendingValidators, | ||
isError: errorValidators, | ||
} = useIotaClientQuery('getLatestIotaSystemState'); | ||
const { data: rollingAverageApys } = useGetValidatorsApy(); | ||
|
||
const validatorSummary = | ||
system?.activeValidators.find((validator) => validator.iotaAddress === validatorAddress) || | ||
null; | ||
|
||
const currentEpoch = Number(system?.epoch || 0); | ||
|
||
const totalValidatorStake = getTotalValidatorStake(validatorSummary); | ||
|
||
const stakingPoolActivationEpoch = Number(validatorSummary?.stakingPoolActivationEpoch || 0); | ||
|
||
// flag as new validator if the validator was activated in the last epoch | ||
// for genesis validators, this will be false | ||
const newValidator = currentEpoch - stakingPoolActivationEpoch <= 1 && currentEpoch !== 0; | ||
|
||
// flag if the validator is at risk of being removed from the active set | ||
const isAtRisk = system?.atRiskValidators.some((item) => item[0] === validatorAddress); | ||
|
||
const { apy, isApyApproxZero } = rollingAverageApys?.[validatorAddress] ?? { | ||
apy: null, | ||
}; | ||
|
||
const commission = validatorSummary ? Number(validatorSummary.commissionRate) / 100 : 0; | ||
|
||
return { | ||
system, | ||
isPendingValidators, | ||
errorValidators, | ||
|
||
currentEpoch, | ||
validatorSummary, | ||
name: validatorSummary?.name || '', | ||
stakingPoolActivationEpoch, | ||
commission, | ||
newValidator, | ||
isAtRisk, | ||
apy, | ||
isApyApproxZero, | ||
totalValidatorStake, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export function formatApy(apy: number, isApyApproxZero: boolean = false): string { | ||
return isApyApproxZero ? '~0%' : `${apy}%`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IotaValidatorSummary } from '@iota/iota-sdk/client'; | ||
|
||
//TODO: verify this is the correct validator stake balance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment unnecessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was in the code previously, are you sure we should delete it? |
||
export function getTotalValidatorStake(validatorSummary: IotaValidatorSummary | null) { | ||
return validatorSummary?.stakingPoolIotaBalance || 0; | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.