mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-07-20 14:15:40 +00:00
971df8edba
- Remove all 3rd party parachain configurations from endpoints: - productionRelayPolkadot.ts: Keep only system parachains - productionRelayDicle.ts: Keep only system parachains - testingRelayZagros.ts: Keep only system parachains - testingRelayTeyrChain.ts: Keep only system parachains - Update domain references: - polkadot.js.org → pezkuwichain.app - wiki.polkadot.network → wiki.pezkuwichain.io - dotapps.io → pezkuwichain.app - statement.polkadot.network → docs.pezkuwichain.io/statement - support.polkadot.network → docs.pezkuwichain.io - Update repository references: - github.com/pezkuwi-js/apps → github.com/pezkuwichain/pwap - Rename system parachains to Pezkuwi ecosystem: - PolkadotAssetHub → PezkuwiAssetHub - polkadotBridgeHub → pezkuwiBridgeHub - polkadotCollectives → pezkuwiCollectives - polkadotCoretime → pezkuwiCoretime - polkadotPeople → pezkuwiPeople - Update network name in claims utility: - Polkadot → Pezkuwi
102 lines
2.8 KiB
TypeScript
102 lines
2.8 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/app-staking authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { u32 } from '@pezkuwi/types';
|
|
import type { NominatorValue } from './types.js';
|
|
|
|
import React, { useMemo } from 'react';
|
|
|
|
import { AddressMini, ExpanderScroll } from '@pezkuwi/react-components';
|
|
import { useApi } from '@pezkuwi/react-hooks';
|
|
import { FormatBalance } from '@pezkuwi/react-query';
|
|
import { BN, BN_ZERO } from '@pezkuwi/util';
|
|
|
|
interface Props {
|
|
stakeOther?: BN;
|
|
nominators?: NominatorValue[];
|
|
}
|
|
|
|
function extractFunction (all: NominatorValue[]): null | [number, () => React.ReactNode[]] {
|
|
return [
|
|
all.length,
|
|
() => all.map(({ nominatorId, value }): React.ReactNode =>
|
|
<AddressMini
|
|
bonded={value}
|
|
key={nominatorId}
|
|
value={nominatorId}
|
|
withBonded
|
|
/>
|
|
)
|
|
];
|
|
}
|
|
|
|
function sumValue (all: { value: BN }[]): BN {
|
|
const total = new BN(0);
|
|
|
|
for (let i = 0, count = all.length; i < count; i++) {
|
|
total.iadd(all[i].value);
|
|
}
|
|
|
|
return total;
|
|
}
|
|
|
|
function extractTotals (maxPaid: BN | undefined, nominators?: NominatorValue[], stakeOther?: BN): [null | [number, () => React.ReactNode[]], BN, null | [number, () => React.ReactNode[]], BN] {
|
|
if (!nominators) {
|
|
return [null, BN_ZERO, null, BN_ZERO];
|
|
}
|
|
|
|
const sorted = nominators.sort((a, b) => b.value.cmp(a.value));
|
|
|
|
if (!maxPaid || maxPaid.gtn(sorted.length)) {
|
|
return [extractFunction(sorted), stakeOther || BN_ZERO, null, BN_ZERO];
|
|
}
|
|
|
|
const max = maxPaid.toNumber();
|
|
const rewarded = sorted.slice(0, max);
|
|
const rewardedTotal = sumValue(rewarded);
|
|
const unrewarded = sorted.slice(max);
|
|
const unrewardedTotal = sumValue(unrewarded);
|
|
|
|
return [extractFunction(rewarded), rewardedTotal, extractFunction(unrewarded), unrewardedTotal];
|
|
}
|
|
|
|
function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Props> {
|
|
const { api } = useApi();
|
|
|
|
const [rewarded, rewardedTotal, unrewarded, unrewardedTotal] = useMemo(
|
|
() => extractTotals(api.consts.staking?.maxNominatorRewardedPerValidator as u32, nominators, stakeOther),
|
|
[api, nominators, stakeOther]
|
|
);
|
|
|
|
return (
|
|
<td className='expand all'>
|
|
{(!rewarded || rewarded[0] !== 0) && (
|
|
<ExpanderScroll
|
|
className={rewarded ? '' : '--tmp'}
|
|
renderChildren={rewarded?.[1]}
|
|
summary={
|
|
<FormatBalance
|
|
labelPost={` (${rewarded ? rewarded[0] : '0'})`}
|
|
value={rewardedTotal}
|
|
/>
|
|
}
|
|
/>
|
|
)}
|
|
{unrewarded && (
|
|
<ExpanderScroll
|
|
className='stakeOver'
|
|
renderChildren={unrewarded[1]}
|
|
summary={
|
|
<FormatBalance
|
|
labelPost={` (${unrewarded[0]})`}
|
|
value={unrewardedTotal}
|
|
/>
|
|
}
|
|
/>
|
|
)}
|
|
</td>
|
|
);
|
|
}
|
|
|
|
export default React.memo(StakeOther);
|