Protect against empty exposure (#3804)
This commit is contained in:
parent
06ae00f7a8
commit
beccc911d5
@ -7,6 +7,7 @@ import { SortedTargets, TargetSortBy, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { registry } from '@polkadot/react-api';
|
||||
import { useAccounts, useApi, useCall, useDebounce } from '@polkadot/react-hooks';
|
||||
import { Option } from '@polkadot/types';
|
||||
import { BN_ONE, BN_ZERO, formatBalance } from '@polkadot/util';
|
||||
@ -64,7 +65,8 @@ 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 => {
|
||||
const emptyExposure = registry.createType('Exposure');
|
||||
const list = info.map(({ accountId, exposure = emptyExposure, stakingLedger, validatorPrefs }): ValidatorInfo => {
|
||||
// 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;
|
||||
@ -82,7 +84,7 @@ function extractSingle (allAccounts: string[], amount: BN = baseBalance(), { inf
|
||||
const rewardPayout = amount.isZero() || rewardSplit.isZero()
|
||||
? BN_ZERO
|
||||
: amount.mul(rewardSplit).div(amount.add(bondTotal));
|
||||
const isNominating = exposure.others.reduce((isNominating, indv): boolean => {
|
||||
const isNominating = (exposure.others || []).reduce((isNominating, indv): boolean => {
|
||||
const nominator = indv.who.toString();
|
||||
|
||||
nominators[nominator] = true;
|
||||
@ -105,7 +107,7 @@ function extractSingle (allAccounts: string[], amount: BN = baseBalance(), { inf
|
||||
isFavorite: favorites.includes(key),
|
||||
isNominating,
|
||||
key,
|
||||
numNominators: exposure.others.length,
|
||||
numNominators: (exposure.others || []).length,
|
||||
rankBondOther: 0,
|
||||
rankBondOwn: 0,
|
||||
rankBondTotal: 0,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user