Adapt Darwinia, Crab Network types (#5218)
This commit is contained in:
parent
ba2d633c0c
commit
07af3f6279
@ -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",
|
||||
|
||||
@ -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<BN | undefined>();
|
||||
const stashBalance = useCall<DeriveBalancesAll>(api.derive.balances?.all, [stashId]);
|
||||
const currentAmount = useMemo(
|
||||
() => stakingInfo && stakingInfo.stakingLedger?.active.unwrap(),
|
||||
() => stakingInfo && stakingInfo.stakingLedger?.active?.unwrap(),
|
||||
[stakingInfo]
|
||||
);
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const bondedBlocks = useUnbondDuration();
|
||||
const [maxBalance] = useState<BN | null>(() => stakingLedger?.active.unwrap() || null);
|
||||
const [maxBalance] = useState<BN | null>(() => stakingLedger?.active?.unwrap() || null);
|
||||
const [maxUnbond, setMaxUnbond] = useState<BN | null>(null);
|
||||
const [withMax, setWithMax] = useState(false);
|
||||
|
||||
|
||||
@ -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 (
|
||||
<tr className={className}>
|
||||
@ -292,7 +292,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio
|
||||
{t<string>('Bond more funds')}
|
||||
</Menu.Item>
|
||||
<Menu.Item
|
||||
disabled={!isOwnController || !stakingAccount || !stakingAccount.stakingLedger || stakingAccount.stakingLedger.active.isEmpty}
|
||||
disabled={!isOwnController || !stakingAccount || !stakingAccount.stakingLedger || stakingAccount.stakingLedger.active?.isEmpty}
|
||||
onClick={toggleUnbond}
|
||||
>
|
||||
{t<string>('Unbond funds')}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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<Slashin
|
||||
|
||||
// all nominations that are oversubscribed
|
||||
const nomsOver = exposures
|
||||
.map(({ others }) => 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<Slashin
|
||||
// waiting if validator is inactive or we have not submitted long enough ago
|
||||
const nomsWaiting = exposures
|
||||
.map((exposure, index) =>
|
||||
exposure.total.unwrap().isZero() || (
|
||||
exposure.total?.unwrap().isZero() || (
|
||||
nomsInactive.includes(nominees[index]) &&
|
||||
// it could be activeEra + 1 (currentEra for last session)
|
||||
submittedIn.gte(activeEra)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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)),
|
||||
|
||||
@ -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<string, string>
|
||||
<Tooltip
|
||||
text={(balancesAll as DeriveBalancesAll).lockedBreakdown.map(({ amount, id, reasons }, index): React.ReactNode => (
|
||||
<div key={index}>
|
||||
{amount.isMax()
|
||||
{amount?.isMax()
|
||||
? t<string>('everything')
|
||||
: formatBalance(amount, { forceUnit: '-' })
|
||||
}{id && <div className='faded'>{lookupLock(lookup, id)}</div>}<div className='faded'>{reasons.toString()}</div>
|
||||
@ -418,7 +418,7 @@ function renderBalances (props: Props, lookup: Record<string, string>, 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 })];
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ interface Props {
|
||||
}
|
||||
|
||||
function StakingBonded ({ className = '', stakingInfo }: Props): React.ReactElement<Props> | null {
|
||||
const balance = stakingInfo?.stakingLedger?.active.unwrap();
|
||||
const balance = stakingInfo?.stakingLedger?.active?.unwrap();
|
||||
|
||||
if (!balance?.gtn(0)) {
|
||||
return null;
|
||||
|
||||
20
yarn.lock
20
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user