11// Copyright 2017-2025 @polkadot/react-components authors & contributors
22// SPDX-License-Identifier: Apache-2.0
33
4+ import type { ApiPromise } from '@polkadot/api' ;
45import type { DeriveBalancesAccountData , DeriveBalancesAll , DeriveDemocracyLock , DeriveStakingAccount } from '@polkadot/api-derive/types' ;
56import type { Raw } from '@polkadot/types' ;
67import type { BlockNumber , ValidatorPrefsTo145 , Voting } from '@polkadot/types/interfaces' ;
@@ -10,7 +11,7 @@ import type { BN } from '@polkadot/util';
1011import React , { useRef } from 'react' ;
1112
1213import { withCalls , withMulti } from '@polkadot/react-api/hoc' ;
13- import { useBestNumberRelay } from '@polkadot/react-hooks' ;
14+ import { useBestNumberRelay , useStakingAsyncApis } from '@polkadot/react-hooks' ;
1415import { BlockToTime , FormatBalance } from '@polkadot/react-query' ;
1516import { BN_MAX_INTEGER , BN_ZERO , bnMax , formatBalance , formatNumber , isObject } from '@polkadot/util' ;
1617
@@ -50,6 +51,7 @@ export interface ValidatorPrefsType {
5051}
5152
5253interface Props {
54+ apiOverride ?: ApiPromise ;
5355 address : string ;
5456 balancesAll ?: DeriveBalancesAll ;
5557 children ?: React . ReactNode ;
@@ -237,7 +239,7 @@ function renderValidatorPrefs ({ stakingInfo, withValidatorPrefs = false }: Prop
237239 ) ;
238240}
239241
240- function createBalanceItems ( formatIndex : number , lookup : Record < string , string > , t : TFunction , { address, balanceDisplay, balancesAll, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, votingOf, withBalanceToggle, withLabel } : { address : string ; balanceDisplay : BalanceActiveType ; balancesAll ?: DeriveBalancesAll | DeriveBalancesAccountData ; bestNumber ?: BlockNumber ; convictionLocks ?: RefLock [ ] ; democracyLocks ?: DeriveDemocracyLock [ ] ; isAllLocked : boolean ; otherBonded : BN [ ] ; ownBonded : BN ; stakingInfo ?: DeriveStakingAccount ; votingOf ?: Voting ; withBalanceToggle : boolean , withLabel : boolean } ) : React . ReactNode {
242+ function createBalanceItems ( formatIndex : number , lookup : Record < string , string > , t : TFunction , { address, apiOverride , balanceDisplay, balancesAll, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, votingOf, withBalanceToggle, withLabel } : { address : string ; apiOverride : ApiPromise | undefined , balanceDisplay : BalanceActiveType ; balancesAll ?: DeriveBalancesAll | DeriveBalancesAccountData ; bestNumber ?: BlockNumber ; convictionLocks ?: RefLock [ ] ; democracyLocks ?: DeriveDemocracyLock [ ] ; isAllLocked : boolean ; otherBonded : BN [ ] ; ownBonded : BN ; stakingInfo ?: DeriveStakingAccount ; votingOf ?: Voting ; withBalanceToggle : boolean , withLabel : boolean } ) : React . ReactNode {
241243 const allItems : React . ReactNode [ ] = [ ] ;
242244 const deriveBalances = balancesAll as DeriveBalancesAll ;
243245
@@ -293,7 +295,10 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
293295 >
294296 < div >
295297 < p > { formatBalance ( locked , { forceUnit : '-' } ) } { t ( 'fully vested in' ) } </ p >
296- < BlockToTime value = { endBlock . sub ( bestNumber ) } />
298+ < BlockToTime
299+ api = { apiOverride }
300+ value = { endBlock . sub ( bestNumber ) }
301+ />
297302 </ div >
298303 < div className = 'middle' >
299304 (Block { formatNumber ( endBlock ) } @ { formatBalance ( perBlock ) } /block)
@@ -526,7 +531,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
526531 ) ;
527532}
528533
529- function renderBalances ( props : Props , lookup : Record < string , string > , bestNumber : BlockNumber | undefined , t : TFunction ) : React . ReactNode [ ] {
534+ function renderBalances ( props : Props , lookup : Record < string , string > , bestNumber : BlockNumber | undefined , apiOverride : ApiPromise | undefined , t : TFunction ) : React . ReactNode [ ] {
530535 const { address, balancesAll, convictionLocks, democracyLocks, stakingInfo, votingOf, withBalance = true , withBalanceToggle = false , withLabel = false } = props ;
531536 const balanceDisplay = withBalance === true
532537 ? DEFAULT_BALANCES
@@ -538,7 +543,7 @@ function renderBalances (props: Props, lookup: Record<string, string>, bestNumbe
538543
539544 const [ ownBonded , otherBonded ] = calcBonded ( stakingInfo , balanceDisplay . bonded ) ;
540545 const isAllLocked = ! ! balancesAll && balancesAll . lockedBreakdown . some ( ( { amount } ) : boolean => amount ?. isMax ( ) ) ;
541- const baseOpts = { address, balanceDisplay, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, votingOf, withBalanceToggle, withLabel } ;
546+ const baseOpts = { address, apiOverride , balanceDisplay, bestNumber, convictionLocks, democracyLocks, isAllLocked, otherBonded, ownBonded, votingOf, withBalanceToggle, withLabel } ;
542547 const items = [ createBalanceItems ( 0 , lookup , t , { ...baseOpts , balancesAll, stakingInfo } ) ] ;
543548
544549 withBalanceToggle && balancesAll ?. additional . length && balancesAll . additional . forEach ( ( balancesAll , index ) : void => {
@@ -551,6 +556,7 @@ function renderBalances (props: Props, lookup: Record<string, string>, bestNumbe
551556function AddressInfo ( props : Props ) : React . ReactElement < Props > {
552557 const { t } = useTranslation ( ) ;
553558 const bestNumber = useBestNumberRelay ( ) ;
559+ const { isStakingAsync, rcApi } = useStakingAsyncApis ( ) ;
554560 const { children, className = '' , extraInfo, withBalanceToggle, withHexSessionId } = props ;
555561
556562 const lookup = useRef < Record < string , string > > ( {
@@ -564,7 +570,7 @@ function AddressInfo (props: Props): React.ReactElement<Props> {
564570 return (
565571 < div className = { `${ className } ui--AddressInfo ${ withBalanceToggle ? 'ui--AddressInfo-expander' : '' } ` } >
566572 < div className = { `column${ withBalanceToggle ? ' column--expander' : '' } ` } >
567- { renderBalances ( props , lookup . current , bestNumber , t ) }
573+ { renderBalances ( props , lookup . current , bestNumber , isStakingAsync ? rcApi : undefined , t ) }
568574 { withHexSessionId ?. [ 0 ] && (
569575 < >
570576 < Label label = { t ( 'session keys' ) } />
0 commit comments