Skip to content

Commit

Permalink
feat: Replace maxElectingVoters const with counterForNominators s…
Browse files Browse the repository at this point in the history
…torage (#2319)
  • Loading branch information
rossbulat authored Nov 7, 2024
1 parent b952ab0 commit f55229f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/contexts/Api/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const defaultConsts: APIConstants = {
sessionsPerEra: new BigNumber(0),
maxExposurePageSize: new BigNumber(0),
historyDepth: new BigNumber(0),
maxElectingVoters: new BigNumber(0),
expectedBlockTime: new BigNumber(0),
epochDuration: new BigNumber(0),
existentialDeposit: new BigNumber(0),
Expand Down Expand Up @@ -77,6 +76,7 @@ export const defaultStakingMetrics: APIStakingMetrics = {
maxValidatorsCount: new BigNumber(0),
minNominatorBond: new BigNumber(0),
totalStaked: new BigNumber(0),
counterForNominators: new BigNumber(0),
};

export const defaultApiContext: APIContextInterface = {
Expand Down
1 change: 0 additions & 1 deletion src/contexts/Api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ export const APIProvider = ({ children, network }: APIProviderProps) => {

setConsts({
maxNominations: new BigNumber(16),
maxElectingVoters: new BigNumber(22500),
bondDuration: new BigNumber(bondingDuration),
sessionsPerEra: new BigNumber(sessionsPerEra),
maxExposurePageSize: new BigNumber(maxExposurePageSize),
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/Api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface APIConstants {
sessionsPerEra: BigNumber;
maxExposurePageSize: BigNumber;
historyDepth: BigNumber;
maxElectingVoters: BigNumber;
expectedBlockTime: BigNumber;
epochDuration: BigNumber;
existentialDeposit: BigNumber;
Expand Down Expand Up @@ -65,6 +64,7 @@ export interface APIStakingMetrics {
maxValidatorsCount: BigNumber;
minNominatorBond: BigNumber;
totalStaked: BigNumber;
counterForNominators: BigNumber;
}

export interface APIContextInterface {
Expand Down
1 change: 0 additions & 1 deletion src/model/Observables/ChainSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class ChainSpec implements ObservableGetSubscription {
// Unsubscribe from class subscription.
unsubscribe = (): void => {
if (typeof this.#unsub === 'function') {
console.log('UNSUBSCRIBING FROM CHAINSPEC');
this.#unsub();
}
};
Expand Down
2 changes: 2 additions & 0 deletions src/model/Query/NetworkMeta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class NetworkMeta {
[api.query.staking.erasTotalStake, previousEra.toString()],
api.query.staking.minNominatorBond,
[api.query.staking.erasTotalStake, activeEra.index.toString()],
api.query.staking.counterForNominators,
]);

// format optional configs to BigNumber or null.
Expand Down Expand Up @@ -90,6 +91,7 @@ export class NetworkMeta {
lastTotalStake: stringToBn(networkMeta[20].toString()),
minNominatorBond: stringToBn(networkMeta[21].toString()),
totalStaked: stringToBn(networkMeta[22].toString()),
counterForNominators: stringToBn(networkMeta[23].toString()),
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/model/Subscribe/StakingMetrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class StakingMetrics implements Unsubscribable {
api.query.staking.erasTotalStake,
this.#activeEra.index.toString(),
],
api.query.staking.counterForNominators,
],
(result) => {
const stakingMetrics = {
Expand All @@ -77,6 +78,7 @@ export class StakingMetrics implements Unsubscribable {
lastTotalStake: stringToBn(result[5].toString()),
minNominatorBond: stringToBn(result[6].toString()),
totalStaked: stringToBn(result[7].toString()),
counterForNominators: stringToBn(result[8].toString()),
};

document.dispatchEvent(
Expand Down
13 changes: 7 additions & 6 deletions src/pages/Nominate/Active/Stats/ActiveNominators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import { Pie } from 'library/StatBoxList/Pie';

export const ActiveNominatorsStat = () => {
const { t } = useTranslation('pages');
const { consts } = useApi();
const { maxElectingVoters } = consts;
const {
stakingMetrics: { counterForNominators },
} = useApi();
const { totalActiveNominators } = useStaking().eraStakers;

// active nominators as percent
let totalNominatorsAsPercent = 0;
if (maxElectingVoters.isGreaterThan(0)) {
if (counterForNominators.isGreaterThan(0)) {
totalNominatorsAsPercent =
totalActiveNominators / maxElectingVoters.dividedBy(100).toNumber();
totalActiveNominators / counterForNominators.dividedBy(100).toNumber();
}

const params = {
label: t('overview.activeNominators'),
stat: {
value: totalActiveNominators,
total: maxElectingVoters.toNumber(),
total: counterForNominators.toNumber(),
unit: '',
},
graph: {
value1: totalActiveNominators,
value2: maxElectingVoters.minus(totalActiveNominators).toNumber(),
value2: counterForNominators.minus(totalActiveNominators).toNumber(),
},
tooltip: `${new BigNumber(totalNominatorsAsPercent)
.decimalPlaces(2)
Expand Down

0 comments on commit f55229f

Please sign in to comment.