diff --git a/packages/apps-config/package.json b/packages/apps-config/package.json index 94d23f9321..9311d69320 100644 --- a/packages/apps-config/package.json +++ b/packages/apps-config/package.json @@ -10,7 +10,7 @@ "@acala-network/type-definitions": "^0.7.3", "@babel/runtime": "^7.14.0", "@crustio/type-definitions": "0.0.6", - "@darwinia/types": "^1.1.0-alpha.11", + "@darwinia/types": "^1.1.0-alpha.13", "@edgeware/node-types": "^3.3.4", "@equilab/definitions": "1.0.4", "@interlay/polkabtc-types": "^0.6.2", diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index b9aac55a9c..bf66506fd2 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -27,7 +27,7 @@ function calcBalance (api: ApiPromise, stakingInfo?: DeriveStakingAccount, stash if (stakingInfo && stakingInfo.stakingLedger && stashBalance) { const sumUnlocking = (stakingInfo.unlocking || []).reduce((acc, { value }) => acc.iadd(value), new BN(0)); const redeemable = stakingInfo.redeemable || BN_ZERO; - const available = stashBalance.freeBalance.sub(stakingInfo.stakingLedger.active.unwrap()).sub(sumUnlocking).sub(redeemable); + const available = stashBalance.freeBalance.sub(stakingInfo.stakingLedger.active?.unwrap() || BN_ZERO).sub(sumUnlocking).sub(redeemable); return available.gt(api.consts.balances.existentialDeposit) ? available.sub(api.consts.balances.existentialDeposit) @@ -44,7 +44,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea const [maxAdditional, setMaxAdditional] = useState(); const stashBalance = useCall(api.derive.balances?.all, [stashId]); const currentAmount = useMemo( - () => stakingInfo && stakingInfo.stakingLedger?.active.unwrap(), + () => stakingInfo && stakingInfo.stakingLedger?.active?.unwrap(), [stakingInfo] ); diff --git a/packages/page-staking/src/Actions/Account/Unbond.tsx b/packages/page-staking/src/Actions/Account/Unbond.tsx index 701669aa0f..ab7990eb6b 100644 --- a/packages/page-staking/src/Actions/Account/Unbond.tsx +++ b/packages/page-staking/src/Actions/Account/Unbond.tsx @@ -26,7 +26,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId const { t } = useTranslation(); const { api } = useApi(); const bondedBlocks = useUnbondDuration(); - const [maxBalance] = useState(() => stakingLedger?.active.unwrap() || null); + const [maxBalance] = useState(() => stakingLedger?.active?.unwrap() || null); const [maxUnbond, setMaxUnbond] = useState(null); const [withMax, setWithMax] = useState(false); diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index e23cc49300..b044840897 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -102,7 +102,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio [api, controllerId, queueExtrinsic, spanCount] ); - const hasBonded = !!stakingAccount?.stakingLedger && !stakingAccount.stakingLedger.active.isEmpty; + const hasBonded = !!stakingAccount?.stakingLedger && !stakingAccount.stakingLedger.active?.isEmpty; return ( @@ -292,7 +292,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio {t('Bond more funds')} {t('Unbond funds')} diff --git a/packages/page-staking/src/Actions/index.tsx b/packages/page-staking/src/Actions/index.tsx index e9c429e7a4..5f0ac3596e 100644 --- a/packages/page-staking/src/Actions/index.tsx +++ b/packages/page-staking/src/Actions/index.tsx @@ -59,7 +59,7 @@ function extractState (ownStashes?: StakerState[]): State { const bondedTotal = new BN(0); ownStashes.forEach(({ isStashNominating, isStashValidating, stakingLedger }): void => { - const value = stakingLedger + const value = stakingLedger && stakingLedger.total ? stakingLedger.total.unwrap() : BN_ZERO; diff --git a/packages/page-staking/src/Actions/useInactives.ts b/packages/page-staking/src/Actions/useInactives.ts index e645991b4d..4a8b4d16b7 100644 --- a/packages/page-staking/src/Actions/useInactives.ts +++ b/packages/page-staking/src/Actions/useInactives.ts @@ -9,6 +9,7 @@ import { useEffect, useState } from 'react'; import { ApiPromise } from '@polkadot/api'; import { useApi, useCall, useIsMountedRef } from '@polkadot/react-hooks'; +import { BN_ZERO } from '@polkadot/util'; interface Inactives { nomsActive?: string[]; @@ -34,7 +35,7 @@ function extractState (api: ApiPromise, stashId: string, slashes: Option others.sort((a, b) => b.value.unwrap().cmp(a.value.unwrap()))) + .map(({ others }) => others.sort((a, b) => (b.value?.unwrap() || BN_ZERO).cmp(a.value?.unwrap() || BN_ZERO))) .map((others, index) => !max || max.gtn(others.map(({ who }) => who.toString()).indexOf(stashId)) ? null @@ -54,7 +55,7 @@ function extractState (api: ApiPromise, stashId: string, slashes: Option - exposure.total.unwrap().isZero() || ( + exposure.total?.unwrap().isZero() || ( nomsInactive.includes(nominees[index]) && // it could be activeEra + 1 (currentEra for last session) submittedIn.gte(activeEra) diff --git a/packages/page-staking/src/Overview/Address/index.tsx b/packages/page-staking/src/Overview/Address/index.tsx index 4824e0428c..4d6ac41da0 100644 --- a/packages/page-staking/src/Overview/Address/index.tsx +++ b/packages/page-staking/src/Overview/Address/index.tsx @@ -15,6 +15,7 @@ import { AddressSmall, Icon, LinkExternal } from '@polkadot/react-components'; import { checkVisibility } from '@polkadot/react-components/util'; import { useApi, useCall } from '@polkadot/react-hooks'; import { FormatBalance } from '@polkadot/react-query'; +import { BN_ZERO } from '@polkadot/util'; import Favorite from './Favorite'; import NominatedBy from './NominatedBy'; @@ -54,7 +55,7 @@ function expandInfo ({ exposure, validatorPrefs }: ValidatorInfo): StakingState if (exposure && exposure.total) { nominators = exposure.others.map(({ value, who }) => ({ nominatorId: who.toString(), value: value.unwrap() })); - stakeTotal = exposure.total.unwrap(); + stakeTotal = exposure.total?.unwrap() || BN_ZERO; stakeOwn = exposure.own.unwrap(); stakeOther = stakeTotal.sub(stakeOwn); } diff --git a/packages/page-staking/src/useSortedTargets.ts b/packages/page-staking/src/useSortedTargets.ts index a52d4a094e..f759f547ce 100644 --- a/packages/page-staking/src/useSortedTargets.ts +++ b/packages/page-staking/src/useSortedTargets.ts @@ -99,7 +99,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt }, BN_ZERO); if (bondTotal.isZero()) { - bondTotal = bondOwn = stakingLedger.total.unwrap(); + bondTotal = bondOwn = stakingLedger.total?.unwrap() || BN_ZERO; } const key = accountId.toString(); @@ -131,7 +131,7 @@ function extractSingle (api: ApiPromise, allAccounts: string[], derive: DeriveSt isNominating: (exposure.others || []).reduce((isNominating, indv): boolean => { const nominator = indv.who.toString(); - nominators[nominator] = (nominators[nominator] || BN_ZERO).add(indv.value.toBn()); + nominators[nominator] = (nominators[nominator] || BN_ZERO).add(indv.value?.toBn() || BN_ZERO); return isNominating || allAccounts.includes(nominator); }, allAccounts.includes(key)), diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 80fd0d81b5..d643f56729 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -138,7 +138,7 @@ function calcBonded (stakingInfo?: DeriveStakingAccount, bonded?: boolean | BN[] .filter((value): boolean => value.gtn(0)); own = bonded[0]; - } else if (stakingInfo && stakingInfo.stakingLedger && stakingInfo.accountId.eq(stakingInfo.stashId)) { + } else if (stakingInfo && stakingInfo.stakingLedger && stakingInfo.stakingLedger.active && stakingInfo.accountId.eq(stakingInfo.stashId)) { own = stakingInfo.stakingLedger.active.unwrap(); } @@ -297,7 +297,7 @@ function createBalanceItems (formatIndex: number, lookup: Record (
- {amount.isMax() + {amount?.isMax() ? t('everything') : formatBalance(amount, { forceUnit: '-' }) }{id &&
{lookupLock(lookup, id)}
}
{reasons.toString()}
@@ -418,7 +418,7 @@ function renderBalances (props: Props, lookup: Record, bestNumbe } const [ownBonded, otherBonded] = calcBonded(stakingInfo, balanceDisplay.bonded); - const isAllLocked = !!balancesAll && balancesAll.lockedBreakdown.some(({ amount }): boolean => amount.isMax()); + const isAllLocked = !!balancesAll && balancesAll.lockedBreakdown.some(({ amount }): boolean => amount?.isMax()); const baseOpts = { address, balanceDisplay, bestNumber, democracyLocks, isAllLocked, otherBonded, ownBonded, votingOf, withBalanceToggle }; const items = [createBalanceItems(0, lookup, t, { ...baseOpts, balancesAll, stakingInfo })]; diff --git a/packages/react-components/src/StakingBonded.tsx b/packages/react-components/src/StakingBonded.tsx index 59c8ec8422..a04551dd70 100644 --- a/packages/react-components/src/StakingBonded.tsx +++ b/packages/react-components/src/StakingBonded.tsx @@ -13,7 +13,7 @@ interface Props { } function StakingBonded ({ className = '', stakingInfo }: Props): React.ReactElement | null { - const balance = stakingInfo?.stakingLedger?.active.unwrap(); + const balance = stakingInfo?.stakingLedger?.active?.unwrap(); if (!balance?.gtn(0)) { return null; diff --git a/yarn.lock b/yarn.lock index aeb784f6b0..6b12cd67f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1489,24 +1489,24 @@ __metadata: languageName: node linkType: hard -"@darwinia/types-known@npm:^1.1.0-alpha.11": - version: 1.1.0-alpha.11 - resolution: "@darwinia/types-known@npm:1.1.0-alpha.11" +"@darwinia/types-known@npm:^1.1.0-alpha.13": + version: 1.1.0-alpha.13 + resolution: "@darwinia/types-known@npm:1.1.0-alpha.13" dependencies: "@babel/runtime": ^7.9.6 "@polkadot/types": 4.0.4-5 "@polkadot/util": 6.0.5 bn.js: ^5.1.2 - checksum: b11c20453703ee56b7bb722bbf0298e7c57a544e22865c69957b05c42e149336d2290a7dc9daf908484045cc506f52a870f97d42178a4dce5c622e030310a4e6 + checksum: 4aa9d72b86266cfa69db07aeceb0f9c56796b375112701a66670245584a05638116bd4905b10edddd63aa1b0333685059c9eb7a71cfbc97c377be5b099eac1f5 languageName: node linkType: hard -"@darwinia/types@npm:^1.1.0-alpha.11": - version: 1.1.0-alpha.11 - resolution: "@darwinia/types@npm:1.1.0-alpha.11" +"@darwinia/types@npm:^1.1.0-alpha.13": + version: 1.1.0-alpha.13 + resolution: "@darwinia/types@npm:1.1.0-alpha.13" dependencies: - "@darwinia/types-known": ^1.1.0-alpha.11 - checksum: 54015bed406c650751a3827328eb681f2bdcfc8fc9466a68470efd2aabc4b9874fec76ca1f1f0460275fc47a30bcafbc388139c263a7ace6c28f7f33d4f3f208 + "@darwinia/types-known": ^1.1.0-alpha.13 + checksum: 48534c3588a0f715b1fab13440384d9d9ab22fbbcdf11fb6ce443848910d6b2eabee398ee90fe88b8718ebf27ad54655ec722bccc46e354d5db25d8e48cfbbfd languageName: node linkType: hard @@ -2505,7 +2505,7 @@ __metadata: "@acala-network/type-definitions": ^0.7.3 "@babel/runtime": ^7.14.0 "@crustio/type-definitions": 0.0.6 - "@darwinia/types": ^1.1.0-alpha.11 + "@darwinia/types": ^1.1.0-alpha.13 "@edgeware/node-types": ^3.3.4 "@equilab/definitions": 1.0.4 "@interlay/polkabtc-types": ^0.6.2