Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darwinia staking #8131

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
690bb2a
darwinia staking power is visible on the validators table
isunaslabs Aug 15, 2022
7a12ef8
linted the updated code
isunaslabs Aug 15, 2022
4df928e
code refactoring
isunaslabs Aug 17, 2022
fee827c
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Aug 17, 2022
a976105
after merging with master
isunaslabs Aug 17, 2022
8ebeab3
added Darwinia balance support in the AddressInfo component
isunaslabs Aug 18, 2022
262efcc
accounts->all stashes table completed
isunaslabs Aug 22, 2022
73b5df0
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Aug 22, 2022
aa6ace8
after master branch merge
isunaslabs Aug 22, 2022
408b7df
unbond and rebond funds are working
isunaslabs Aug 23, 2022
de642e0
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Aug 23, 2022
211f1ad
staking->accounts completed
isunaslabs Aug 24, 2022
a98ae45
staking->payouts completed
isunaslabs Aug 26, 2022
570c66e
staking->targets completed
isunaslabs Aug 29, 2022
e6b8c96
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Aug 29, 2022
eee8515
packages minor updates
isunaslabs Aug 29, 2022
0d868b1
Staking->Validator stats done
isunaslabs Aug 30, 2022
37e9ffe
Staking->Target sorting done
isunaslabs Sep 1, 2022
d3970b4
locale string reordering
isunaslabs Sep 1, 2022
d58ff2e
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 1, 2022
7fb1bed
packages update
isunaslabs Sep 1, 2022
d3fdcf3
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 5, 2022
011a9f4
packages update
isunaslabs Sep 5, 2022
b11a1c8
bug fix
isunaslabs Sep 8, 2022
30fe017
elected stake graph bug fix
isunaslabs Sep 10, 2022
58ca5ed
sort button hidden in Darwinia staking
isunaslabs Sep 10, 2022
77dab6a
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 14, 2022
3962450
merged with master branch
isunaslabs Sep 14, 2022
77264ee
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 16, 2022
609884d
merged with master branch
isunaslabs Sep 16, 2022
5d5b03c
Merge branch 'master' into darwinia_staking
isunaslabs Sep 19, 2022
8285952
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 19, 2022
7ea44f3
merged with master branch
isunaslabs Sep 19, 2022
cf04cce
working code
isunaslabs Sep 19, 2022
ecf11c0
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 20, 2022
dd7a422
conflict resolve,working code Sept 20th 09:07 Beijing Time
isunaslabs Sep 20, 2022
f1750e8
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 21, 2022
4c8c367
conflict resolve,working code Sept 21st 09:53 Beijing Time
isunaslabs Sep 21, 2022
538968e
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 21, 2022
aa9bf8c
conflict resolve,working code Sept 21st 14:34 Beijing Time
isunaslabs Sep 21, 2022
e6c624b
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Sep 21, 2022
3738739
conflict resolve,working code Oct 17th 13:31 Beijing Time
isunaslabs Oct 17, 2022
0c3e045
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Oct 17, 2022
cfdbf6e
Removed bignumber JS package
isunaslabs Oct 17, 2022
c51bbba
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Oct 17, 2022
fbad27c
Working code after merging with master Oct 17th 2022 16:12 Beijing time
isunaslabs Oct 17, 2022
b9fc517
removed @darwinia/types in the page-staking package
isunaslabs Oct 19, 2022
03f18cf
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Oct 19, 2022
f9113c2
Merge remote-tracking branch 'origin/master' into darwinia_staking
isunaslabs Feb 13, 2023
22e8abf
-Removed Pangolin from test networks
isunaslabs Feb 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions packages/apps-config/src/endpoints/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import type { EndpointOption } from './types';

import { chains3dpassPNG, chainsAcalaSVG, chainsAlephSVG, chainsBrainstormPNG, chainsCreditcoinTestPNG, chainsDebioSVG, chainsEquilibriumSVG, chainsFerrumPNG, chainsKintsugiPNG, chainsLogionPNG, chainsMyriadPNG, chainsShidenPNG, chainsSkyekiwiPNG, chainsTanglePNG, chainsVaraSVG } from '../ui/logos/chains';
import { nodesAjunaPNG, nodesArcticPNG, nodesAresGladiosSVG, nodesAutomataPNG, nodesBifrostSVG, nodesBitcountryPNG, nodesCessPNG, nodesCloverSVG, nodesCrustMaxwellSVG, nodesDatahighwayPNG, nodesDockPNG, nodesDolphinSVG, nodesDotmogSVG, nodesEdgewareWhitePNG, nodesEncointerBlueSVG, nodesFantourPNG, nodesGalitalLogoPNG, nodesGamepowerSVG, nodesGeekSVG, nodesInterlaySVG, nodesIpsePNG, nodesJazPNG, nodesJupiterSVG, nodesKhalaSVG, nodesKiltPNG, nodesKlugPNG, nodesKylinPNG, nodesLaminarCircleSVG, nodesLitentryPNG, nodesMantaPNG, nodesMathSVG, nodesMinixPNG, nodesMoonbaseAlphaPNG, nodesMybankPNG, nodesNftmartPNG, nodesNodleSVG, nodesOpalLogoPNG, nodesOpportunityPNG, nodesPangolinSVG, nodesPangoroSVG, nodesPhalaSVG, nodesPhoenixPNG, nodesPichiuPNG, nodesPolkadexSVG, nodesPolkafoundrySVG, nodesPolymeshSVG, nodesPontemSVG, nodesPrismPNG, nodesRealisPNG, nodesRiochainSVG, nodesSherpaxPNG, nodesSoonsocialPNG, nodesSoraSubstrateSVG, nodesSubdaoPNG, nodesSubgameSVG, nodesSubspacePNG, nodesTernoaSVG, nodesThebifrostPNG, nodesUniartsPNG, nodesUniqueSVG, nodesUnitnetworkPNG, nodesWeb3gamesSVG, nodesZCloakSVG, nodesZeitgeistPNG } from '../ui/logos/nodes';
import { nodesAjunaPNG, nodesArcticPNG, nodesAresGladiosSVG, nodesAutomataPNG, nodesBifrostSVG, nodesBitcountryPNG, nodesCessPNG, nodesCloverSVG, nodesCrustMaxwellSVG, nodesDatahighwayPNG, nodesDockPNG, nodesDolphinSVG, nodesDotmogSVG, nodesEdgewareWhitePNG, nodesEncointerBlueSVG, nodesFantourPNG, nodesGalitalLogoPNG, nodesGamepowerSVG, nodesGeekSVG, nodesInterlaySVG, nodesIpsePNG, nodesJazPNG, nodesJupiterSVG, nodesKhalaSVG, nodesKiltPNG, nodesKlugPNG, nodesKylinPNG, nodesLaminarCircleSVG, nodesLitentryPNG, nodesMantaPNG, nodesMathSVG, nodesMinixPNG, nodesMoonbaseAlphaPNG, nodesMybankPNG, nodesNftmartPNG, nodesNodleSVG, nodesOpalLogoPNG, nodesOpportunityPNG, nodesPangoroSVG, nodesPhalaSVG, nodesPhoenixPNG, nodesPichiuPNG, nodesPolkadexSVG, nodesPolkafoundrySVG, nodesPolymeshSVG, nodesPontemSVG, nodesPrismPNG, nodesRealisPNG, nodesRiochainSVG, nodesSherpaxPNG, nodesSoonsocialPNG, nodesSoraSubstrateSVG, nodesSubdaoPNG, nodesSubgameSVG, nodesSubspacePNG, nodesTernoaSVG, nodesThebifrostPNG, nodesUniartsPNG, nodesUniqueSVG, nodesUnitnetworkPNG, nodesWeb3gamesSVG, nodesZCloakSVG, nodesZeitgeistPNG } from '../ui/logos/nodes';

export * from './testingRelayRococo';
export * from './testingRelayWestend';
Expand Down Expand Up @@ -593,17 +593,6 @@ export const testChains: EndpointOption[] = [
logo: nodesOpportunityPNG
}
},
{
info: 'pangolin',
providers: {
'Darwinia Network': 'wss://pangolin-rpc.darwinia.network'
},
text: 'Pangolin',
ui: {
color: '#4B30DD',
logo: nodesPangolinSVG
}
},
{
info: 'pangoro',
providers: {
Expand Down
4 changes: 2 additions & 2 deletions packages/apps-config/src/endpoints/testingRelayRococo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ export const testParasRococo: EndpointOption[] = [
info: 'rococoPangolin',
paraId: 2105,
providers: {
// 'Darwinia Network': 'wss://pangolin-parachain-rpc.darwinia.network' // https://github.com/polkadot-js/apps/issues/9005
'Darwinia Network': 'wss://pangolin-rpc.darwinia.network'
},
text: 'Pangolin',
text: 'Pangolin 2',
ui: {
color: '#4B30DD',
logo: nodesPangolinSVG
Expand Down
16 changes: 16 additions & 0 deletions packages/apps-routing/src/staking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017-2023 @polkadot/apps-routing authors & contributors
// SPDX-License-Identifier: Apache-2.0

import type { ExposureT as DarwiniaStakingStructsExposure } from '@darwinia/types/interfaces/darwiniaInject';
import type { TFunction } from 'i18next';
import type { ApiPromise } from '@polkadot/api';
import type { PalletStakingExposure } from '@polkadot/types/lookup';
Expand All @@ -14,6 +15,21 @@ import { assert, BN_ONE } from '@polkadot/util';
function needsApiCheck (api: ApiPromise): boolean {
try {
// we need a known Exposure type
const storageType = unwrapStorageType(api.registry, api.query.staking.erasStakers.creator.meta.type);

if (storageType.toString() === 'DarwiniaStakingStructsExposure') {
const { others: [{ ktonBalance, power, ringBalance, who }], ownRingBalance, ownKtonBalance, ownPower, totalPower } = api.registry.createType<DarwiniaStakingStructsExposure>(
storageType,
{ others: [{ ktonBalance: BN_ONE, power: BN_ONE, ringBalance: BN_ONE, who: TEST_ADDR }], ownKtonBalance: BN_ONE, ownPower: BN_ONE, ownRingBalance: BN_ONE, totalPower: BN_ONE }
);

assert(ownRingBalance.eq(BN_ONE) && ownKtonBalance.eq(BN_ONE) && ownPower.eq(BN_ONE) &&
totalPower.eq(BN_ONE) && who.eq(TEST_ADDR) && ringBalance.eq(BN_ONE) &&
ktonBalance.eq(BN_ONE) && power.eq(BN_ONE), 'Exposure type may have been changed');

return true;
}

const { others: [{ value, who }], own, total } = api.registry.createType<PalletStakingExposure>(
unwrapStorageType(api.registry, api.query.staking.erasStakers.creator.meta.type),
{ others: [{ value: BN_ONE, who: ZERO_ACCOUNT }], own: BN_ONE, total: BN_ONE }
Expand Down
1 change: 1 addition & 0 deletions packages/apps/public/locales/en/app-staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
"points": "points",
"pool id": "pool id",
"pools": "pools",
"power": "power",
"prev": "prev",
"rebag from account": "rebag from account",
"rebonded amount": "rebonded amount",
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/public/locales/en/react-query.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Unknown": "Unknown",
"everything": "everything"
"everything": "everything",
"power": "power"
}
1 change: 1 addition & 0 deletions packages/apps/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@
"points": "得分",
"poll on token decimals": "投票代币小数点",
"pot": "池",
"power": "power",
"preimage hash": "预像哈希",
"preimage {{hash}}": "预像{{hash}}",
"prev": "上一步",
Expand Down
30 changes: 25 additions & 5 deletions packages/page-staking/src/Actions/Account/BondExtra.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { AmountValidateState } from '../types';
import React, { useMemo, useState } from 'react';

import { ApiPromise } from '@polkadot/api';
import { rpcNetwork } from '@polkadot/react-api/util/getEnvironment';
import { InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { BalanceFree } from '@polkadot/react-query';
Expand All @@ -22,11 +23,17 @@ interface Props {
stashId: string;
}

function calcBalance (api: ApiPromise, stakingInfo?: DeriveStakingAccount, stashBalance?: DeriveBalancesAll): BN | null {
function calcBalance (api: ApiPromise, stakingInfo?: DeriveStakingAccount, stashBalance?: DeriveBalancesAll, isDarwinia?: boolean): BN | null {
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() || BN_ZERO).sub(sumUnlocking).sub(redeemable);
let available;

if (isDarwinia) {
available = stashBalance.freeBalance.sub(stashBalance.lockedBalance);
} else {
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)
Expand All @@ -46,12 +53,25 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
() => stakingInfo && stakingInfo.stakingLedger?.active?.unwrap(),
[stakingInfo]
);
const isDarwinia = rpcNetwork.isDarwinia();

const startBalance = useMemo(
() => calcBalance(api, stakingInfo, stashBalance),
[api, stakingInfo, stashBalance]
() => calcBalance(api, stakingInfo, stashBalance, isDarwinia),
[api, isDarwinia, stakingInfo, stashBalance]
);

const getDarwiniaQueryParams = () => {
/* Default promise months to zero since the user has no option to change the number of
* months that he wants to freeze his tokens like the way it is for the Darwinia Apps website */
const promiseMonths = 0;

if (!maxAdditional) {
return [{ ringbalance: '0' }, promiseMonths];
}

return [{ ringbalance: maxAdditional?.toString() }, promiseMonths];
};

return (
<Modal
header= {t<string>('Bond more funds')}
Expand Down Expand Up @@ -98,7 +118,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
isDisabled={!maxAdditional?.gt(BN_ZERO) || !!amountError?.error}
label={t<string>('Bond more')}
onStart={onClose}
params={[maxAdditional]}
params={isDarwinia ? getDarwiniaQueryParams() : [maxAdditional]}
tx={api.tx.staking.bondExtra}
/>
</Modal.Actions>
Expand Down
39 changes: 33 additions & 6 deletions packages/page-staking/src/Actions/Account/Rebond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import type { DeriveStakingAccount } from '@polkadot/api-derive/types';

import React, { useMemo, useState } from 'react';

import { rpcNetwork } from '@polkadot/react-api/util/getEnvironment';
import { InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { DarwiniaStakingStructsStakingLedger } from '@polkadot/react-components/types';
import { useApi, useBestNumber } from '@polkadot/react-hooks';
import { BN, BN_ZERO } from '@polkadot/util';

import { useTranslation } from '../../translate';
Expand All @@ -24,14 +26,39 @@ function Rebond ({ controllerId, onClose, stakingInfo, stashId }: Props): React.
const { t } = useTranslation();
const { api } = useApi();
const [maxAdditional, setMaxAdditional] = useState<BN | undefined>();
const currentBlock = useBestNumber();
const isDarwinia = rpcNetwork.isDarwinia();

const startBalance = useMemo(
() => stakingInfo && stakingInfo.unlocking
? stakingInfo.unlocking.reduce((total, { value }) => total.iadd(value), new BN(0))
: BN_ZERO,
[stakingInfo]
() => {
if (isDarwinia) {
if (!stakingInfo || !stakingInfo.stakingLedger || !currentBlock) {
return BN_ZERO;
}

const darwiniaStakingLedger = stakingInfo.stakingLedger as unknown as DarwiniaStakingStructsStakingLedger;
const unbondings = darwiniaStakingLedger.ringStakingLock.unbondings.filter((item) => item.until.gt(currentBlock));

return unbondings.reduce((accumulator, item) => accumulator.add(item.amount), BN_ZERO);
}

return stakingInfo && stakingInfo.unlocking
? stakingInfo.unlocking.reduce((total, { value }) => total.iadd(value), new BN(0))
: BN_ZERO;
},
[currentBlock, isDarwinia, stakingInfo]
);

const getDarwiniaQueryParams = () => {
const ktonBalance = BN_ZERO;

if (!maxAdditional) {
return [BN_ZERO, ktonBalance];
}

return [maxAdditional, ktonBalance];
};

return (
<Modal
header= {t<string>('Bond more funds')}
Expand Down Expand Up @@ -62,7 +89,7 @@ function Rebond ({ controllerId, onClose, stakingInfo, stashId }: Props): React.
isDisabled={!maxAdditional || maxAdditional.isZero() || !startBalance || maxAdditional.gt(startBalance)}
label={t<string>('Rebond')}
onStart={onClose}
params={[maxAdditional]}
params={isDarwinia ? getDarwiniaQueryParams() : [maxAdditional]}
tx={api.tx.staking.rebond}
/>
</Modal.Actions>
Expand Down
55 changes: 39 additions & 16 deletions packages/page-staking/src/Actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import type { SortedTargets } from '../types';

import React, { useMemo, useRef, useState } from 'react';

import { rpcNetwork } from '@polkadot/react-api/util/getEnvironment';
import { Button, ToggleGroup } from '@polkadot/react-components';
import { DarwiniaStakingStructsStakingLedger } from '@polkadot/react-components/types';
import { useApi, useAvailableSlashes } from '@polkadot/react-hooks';
import { FormatBalance } from '@polkadot/react-query';
import { BN, BN_ZERO } from '@polkadot/util';
Expand Down Expand Up @@ -53,7 +55,7 @@ function sortStashes (a: StakerState, b: StakerState): number {
return assignValue(a) - assignValue(b);
}

function extractState (ownStashes?: StakerState[]): State {
function extractState (ownStashes?: StakerState[], isDarwinia?: boolean): State {
if (!ownStashes) {
return {};
}
Expand All @@ -64,9 +66,23 @@ function extractState (ownStashes?: StakerState[]): State {
const bondedTotal = new BN(0);

ownStashes.forEach(({ isStashNominating, isStashValidating, stakingLedger }): void => {
const value = stakingLedger && stakingLedger.total
? stakingLedger.total.unwrap()
: BN_ZERO;
let value;

if (isDarwinia && stakingLedger) {
const darwiniaStakingLedger = stakingLedger as unknown as DarwiniaStakingStructsStakingLedger;
/* calculate total bonded RING */
const allStakingRing = (darwiniaStakingLedger.active || darwiniaStakingLedger.activeRing || BN_ZERO).toBn();
const lockedRing = (darwiniaStakingLedger.activeDepositRing?.unwrap() || BN_ZERO);
const bondedRing = allStakingRing.sub(lockedRing);

const unbondingAndUnbonded = darwiniaStakingLedger.ringStakingLock.unbondings.reduce((accumulator, item) => accumulator.add(item.amount), new BN(0));

value = unbondingAndUnbonded.add(bondedRing);
} else {
value = stakingLedger && stakingLedger.total
? stakingLedger.total.unwrap()
: BN_ZERO;
}

bondedTotal.iadd(value);

Expand Down Expand Up @@ -121,6 +137,7 @@ function Actions ({ className = '', isInElection, minCommission, ownPools, ownSt
const allSlashes = useAvailableSlashes();
const [accTypeIndex, setAccTypeIndex] = useState(0);
const [stashTypeIndex, setStashTypeIndex] = useState(0);
const isDarwinia = rpcNetwork.isDarwinia();

const accTypes = useRef([
{ text: t<string>('Stashed'), value: 'stash' },
Expand All @@ -135,8 +152,8 @@ function Actions ({ className = '', isInElection, minCommission, ownPools, ownSt
]);

const state = useMemo(
() => extractState(ownStashes),
[ownStashes]
() => extractState(ownStashes, isDarwinia),
[isDarwinia, ownStashes]
);

const [filtered, footer] = useMemo(
Expand Down Expand Up @@ -170,16 +187,22 @@ function Actions ({ className = '', isInElection, minCommission, ownPools, ownSt
options={stashTypes.current}
value={stashTypeIndex}
/>
<NewNominator
isInElection={isInElection}
targets={targets}
/>
<NewValidator
isInElection={isInElection}
minCommission={minCommission}
targets={targets}
/>
<NewStash />
{
!isDarwinia && (
<>
<NewNominator
isInElection={isInElection}
targets={targets}
/>
<NewValidator
isInElection={isInElection}
minCommission={minCommission}
targets={targets}
/>
<NewStash />
</>
)
}
</>
)}
</Button.Group>
Expand Down
15 changes: 11 additions & 4 deletions packages/page-staking/src/Actions/useUnbondDuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
// SPDX-License-Identifier: Apache-2.0

import type { DeriveSessionInfo } from '@polkadot/api-derive/types';
import type { BN } from '@polkadot/util';

import { useMemo } from 'react';

import { rpcNetwork } from '@polkadot/react-api/util/getEnvironment';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
import { BN_ONE } from '@polkadot/util';
import { BN, BN_ONE } from '@polkadot/util';

function useUnbondDurationImpl (): BN | undefined {
const { api } = useApi();
const sessionInfo = useCall<DeriveSessionInfo>(api.derive.session.info);
const isDarwinia = rpcNetwork.isDarwinia();

return useMemo(
() => (sessionInfo && sessionInfo.sessionLength.gt(BN_ONE))
? sessionInfo.eraLength.mul(api.consts.staking.bondingDuration)
? (() => {
if (isDarwinia) {
return new BN(api.consts.staking.bondingDurationInBlockNumber.toString());
}

return sessionInfo.eraLength.mul(api.consts.staking.bondingDuration);
})()
: undefined,
[api, sessionInfo]
[api, sessionInfo, isDarwinia]
);
}

Expand Down
15 changes: 15 additions & 0 deletions packages/page-staking/src/Query/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ export function balanceToNumber (amount: BN | ToBN = BN_ZERO, divisor: BN): numb

return value.mul(BN_THOUSAND).div(divisor).toNumber() / 1000;
}

export const formatDarwiniaPower = (power: BN| undefined, unit?: string): string => {
if (!power) {
return '';
}

console.log();

const powerUnit = unit || '';
const firstLetter = powerUnit.substring(0, 1).toUpperCase();
const capitalizedUnit = `${firstLetter}${powerUnit.substring(1, powerUnit.length)}`;
const formattedPower = power.toNumber().toLocaleString("en-US",{maximumFractionDigits: 0})

return `${formattedPower} ${capitalizedUnit}`;
};
4 changes: 3 additions & 1 deletion packages/page-staking/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Inflation } from '@polkadot/react-hooks/types';
import type { AccountId, Balance, BlockNumber, EraIndex, Exposure, Hash, SessionIndex, ValidatorPrefs, ValidatorPrefsTo196 } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';

import { Exposure as DarwiniaExposure } from '@darwinia/types';

export type Nominators = Record<string, string[]>;

export type AccountFilter = 'all' | 'controller' | 'session' | 'stash' | 'unbonded';
Expand Down Expand Up @@ -51,7 +53,7 @@ export interface ValidatorInfo extends ValidatorInfoRank {
bondShare: number;
bondTotal: BN;
commissionPer: number;
exposure: Exposure;
exposure: Exposure | DarwiniaExposure;
isActive: boolean;
isBlocking: boolean;
isElected: boolean;
Expand Down
Loading