Update Darwinia Crab IndividualExposure types (#3719)
* Update Darwininia Crab IndividualExposure types * own comment * Charts
This commit is contained in:
parent
e893eb1a8d
commit
158ab2ee19
@ -96,8 +96,9 @@ export default {
|
||||
who: 'AccountId',
|
||||
ring_balance: 'Compact<Balance>',
|
||||
kton_balance: 'Compact<Balance>',
|
||||
power: 'Power',
|
||||
value: 'Compact<Balance>'
|
||||
power: 'Power'
|
||||
// not in https://github.com/darwinia-network/darwinia-common/blob/master/frame/staking/src/lib.rs
|
||||
// value: 'Compact<Balance>'
|
||||
},
|
||||
ElectionResultT: {
|
||||
elected_stashes: 'Vec<AccountId>',
|
||||
|
||||
@ -24,8 +24,9 @@ function extractStake (exposures: DeriveOwnExposure[] = [], divisor: BN): ChartI
|
||||
let total = 0;
|
||||
|
||||
exposures.forEach(({ clipped, era, exposure }): void => {
|
||||
const cli = balanceToNumber(clipped.total.unwrap(), divisor);
|
||||
const exp = balanceToNumber(exposure.total.unwrap(), divisor);
|
||||
// Darwinia Crab doesn't have the total field
|
||||
const cli = balanceToNumber(clipped.total?.unwrap(), divisor);
|
||||
const exp = balanceToNumber(exposure.total?.unwrap(), divisor);
|
||||
|
||||
total += cli;
|
||||
|
||||
|
||||
@ -2,7 +2,18 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BN_ZERO, isBn, isFunction } from '@polkadot/util';
|
||||
|
||||
export function balanceToNumber (amount: BN, divisor: BN): number {
|
||||
return amount.muln(1000).div(divisor).toNumber() / 1000;
|
||||
interface ToBN {
|
||||
toBn: () => BN;
|
||||
}
|
||||
|
||||
export function balanceToNumber (amount: BN | ToBN = BN_ZERO, divisor: BN): number {
|
||||
const value = isBn(amount)
|
||||
? amount
|
||||
: isFunction(amount.toBn)
|
||||
? amount.toBn()
|
||||
: BN_ZERO;
|
||||
|
||||
return value.muln(1000).div(divisor).toNumber() / 1000;
|
||||
}
|
||||
|
||||
@ -65,8 +65,9 @@ function sortValidators (list: ValidatorInfo[]): ValidatorInfo[] {
|
||||
function extractSingle (allAccounts: string[], amount: BN = baseBalance(), { info }: DeriveStakingElected | DeriveStakingWaiting, favorites: string[], perValidatorReward: BN, isElected: boolean): [ValidatorInfo[], string[]] {
|
||||
const nominators: Record<string, boolean> = {};
|
||||
const list = info.map(({ accountId, exposure, stakingLedger, validatorPrefs }): ValidatorInfo => {
|
||||
let bondOwn = exposure.own.unwrap();
|
||||
let bondTotal = exposure.total.unwrap();
|
||||
// some overrides (e.g. Darwinia Crab) does not have the own field in Exposure
|
||||
let bondOwn = exposure.own?.unwrap() || BN_ZERO;
|
||||
let bondTotal = exposure.total?.unwrap() || BN_ZERO;
|
||||
const skipRewards = bondTotal.isZero();
|
||||
|
||||
if (bondTotal.isZero()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user