-
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): select validator.
- Loading branch information
1 parent
a852fab
commit 7d16bd2
Showing
5 changed files
with
150 additions
and
78 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
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,46 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { useMemo } from 'react'; | ||
import { useIotaClientQuery } from '@iota/dapp-kit'; | ||
import { useGetValidatorsApy } from '@iota/core'; | ||
|
||
export function useValidatorInfo(validatorAddress: string) { | ||
const { data: system } = useIotaClientQuery('getLatestIotaSystemState'); | ||
const { data: rollingAverageApys } = useGetValidatorsApy(); | ||
|
||
const currentEpoch = Number(system?.epoch || 0); | ||
|
||
const validatorSummary = useMemo(() => { | ||
if (!system) return null; | ||
|
||
return ( | ||
system.activeValidators.find( | ||
(validator) => validator.iotaAddress === validatorAddress, | ||
) || null | ||
); | ||
}, [validatorAddress, system]); | ||
|
||
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, | ||
}; | ||
|
||
return { | ||
validatorSummary, | ||
name: validatorSummary?.name || '', | ||
stakingPoolActivationEpoch, | ||
commission: validatorSummary ? Number(validatorSummary.commissionRate) / 100 : 0, | ||
newValidator, | ||
isAtRisk, | ||
apy, | ||
isApyApproxZero, | ||
}; | ||
} |