@@ -5,9 +5,10 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
5
5
import { NominationInfo , NominatorMetadata , StakingType , UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes' ;
6
6
import { getAstarWithdrawable } from '@subwallet/extension-base/koni/api/staking/bonding/astar' ;
7
7
import { _KNOWN_CHAIN_INFLATION_PARAMS , _SUBSTRATE_DEFAULT_INFLATION_PARAMS , _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants' ;
8
+ import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types' ;
8
9
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils' ;
9
10
import { _STAKING_CHAIN_GROUP } from '@subwallet/extension-base/services/earning-service/constants' ;
10
- import { EarningStatus , PalletStakingEraRewardPoints , UnstakingStatus , YieldPoolInfo , YieldPoolType , YieldPositionInfo } from '@subwallet/extension-base/types' ;
11
+ import { EarningStatus , PalletStakingEraRewardPoints , PalletStakingValidatorPrefs , UnstakingStatus , YieldPoolInfo , YieldPoolType , YieldPositionInfo } from '@subwallet/extension-base/types' ;
11
12
import { detectTranslate , parseRawNumber , reformatAddress } from '@subwallet/extension-base/utils' ;
12
13
import { balanceFormatter , formatNumber } from '@subwallet/extension-base/utils/number' ;
13
14
import BigNumber from 'bignumber.js' ;
@@ -581,16 +582,14 @@ export function getSupportedDaysByHistoryDepth (erasPerDay: number, maxSupported
581
582
}
582
583
}
583
584
584
- export function getValidatorPointsMap ( eraRewardMap : Record < string , PalletStakingEraRewardPoints > ) {
585
+ export function getRelayValidatorPointsMap ( eraRewardMap : Record < string , PalletStakingEraRewardPoints > ) {
585
586
// mapping store validator and totalPoints
586
587
const validatorTotalPointsMap : Record < string , BigNumber > = { } ;
587
588
588
589
Object . values ( eraRewardMap ) . forEach ( ( info ) => {
589
590
const individual = info . individual ;
590
591
591
- Object . entries ( individual ) . forEach ( ( [ validator , rawPoints ] ) => {
592
- const points = rawPoints . replaceAll ( ',' , '' ) ;
593
-
592
+ Object . entries ( individual ) . forEach ( ( [ validator , points ] ) => {
594
593
if ( ! validatorTotalPointsMap [ validator ] ) {
595
594
validatorTotalPointsMap [ validator ] = new BigNumber ( points ) ;
596
595
} else {
@@ -602,7 +601,7 @@ export function getValidatorPointsMap (eraRewardMap: Record<string, PalletStakin
602
601
return validatorTotalPointsMap ;
603
602
}
604
603
605
- export function getTopValidatorByPoints ( validatorPointsList : Record < string , BigNumber > ) {
604
+ export function getRelayTopValidatorByPoints ( validatorPointsList : Record < string , BigNumber > ) {
606
605
const sortValidatorPointsList = Object . fromEntries (
607
606
Object . entries ( validatorPointsList )
608
607
. sort (
@@ -623,6 +622,45 @@ export function getTopValidatorByPoints (validatorPointsList: Record<string, Big
623
622
return Object . keys ( top50PercentRecord ) ;
624
623
}
625
624
625
+ export function getRelayBlockedValidatorList ( validators : any [ ] ) {
626
+ const blockValidatorList : string [ ] = [ ] ;
627
+
628
+ for ( const validator of validators ) {
629
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
630
+ const validatorAddress = validator [ 0 ] . toHuman ( ) [ 0 ] as string ;
631
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
632
+ const validatorPrefs = validator [ 1 ] . toHuman ( ) as unknown as PalletStakingValidatorPrefs ;
633
+
634
+ const isBlocked = validatorPrefs . blocked ;
635
+
636
+ if ( isBlocked ) {
637
+ blockValidatorList . push ( validatorAddress ) ;
638
+ }
639
+ }
640
+
641
+ return blockValidatorList ;
642
+ }
643
+
644
+ export function getRelayEraRewardMap ( eraRewardPointArray : Codec [ ] , startEraForPoints : number ) {
645
+ const eraRewardMap : Record < string , PalletStakingEraRewardPoints > = { } ;
646
+
647
+ for ( const item of eraRewardPointArray ) {
648
+ eraRewardMap [ startEraForPoints ] = item . toPrimitive ( ) as unknown as PalletStakingEraRewardPoints ;
649
+ startEraForPoints ++ ;
650
+ }
651
+
652
+ return eraRewardMap ;
653
+ }
654
+
655
+ export async function getRelayMaxNominations ( substrateApi : _SubstrateApi ) {
656
+ await substrateApi . isReady ;
657
+ const maxNominations = substrateApi . api . consts . staking ?. maxNominations ?. toString ( ) || '16' ;
658
+ const _maxNominationsByNominationQuota = await substrateApi . api . call . stakingApi ?. nominationsQuota ( 0 ) ; // todo: review param. Currently return constant for all param.
659
+ const maxNominationsByNominationQuota = _maxNominationsByNominationQuota ?. toString ( ) ;
660
+
661
+ return maxNominationsByNominationQuota || maxNominations ;
662
+ }
663
+
626
664
export const getMinStakeErrorMessage = ( chainInfo : _ChainInfo , bnMinStake : BN ) : string => {
627
665
const tokenInfo = _getChainNativeTokenBasicInfo ( chainInfo ) ;
628
666
const number = formatNumber ( bnMinStake . toString ( ) , tokenInfo . decimals || 0 , balanceFormatter ) ;
0 commit comments