* Expansion to pools logic * Add filtering * Pass through own pools * Allow pool nominate tx * Start with account actions * Asho pool nominees * Nomination operational * Adjust table rows * BondExtra for pools * use availableBalance in calcs (w/ existential) * Re-use isAmountError check * Pass through actual pool info * s/id/poolId/ * Display payout stashes * Display points balance * OCD cleanups * claimPayout * Calculate pool claimable * Unbond * Fix Unbond max * Display remaining witldrawal eras * Stashed/Pooled selection * Withdraw unbonded * StakingRedeemable display * Renames as per metadata * Additional * s/pool/pools/ * PoolInfo display hints * Adjust usePoolInfo hook * Ordering adjustments * Additional dedupes * Combine queries * Combinations & renames * Flatten transform * Non-existent reward * bnMax sub * lint fixes * Bump API
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
// Copyright 2017-2022 @polkadot/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Option } from '@polkadot/types';
|
|
import type { AccountId, StakingLedger } from '@polkadot/types/interfaces';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
import { createNamedHook } from './createNamedHook';
|
|
import { useAccounts } from './useAccounts';
|
|
import { useApi } from './useApi';
|
|
import { useCall } from './useCall';
|
|
|
|
type IsInKeyring = boolean;
|
|
|
|
function getStashes (allAccounts: string[], ownBonded: Option<AccountId>[], ownLedger: Option<StakingLedger>[]): [string, IsInKeyring][] {
|
|
const result: [string, IsInKeyring][] = [];
|
|
|
|
ownBonded.forEach((value, index): void => {
|
|
value.isSome && result.push([allAccounts[index], true]);
|
|
});
|
|
|
|
ownLedger.forEach((ledger): void => {
|
|
if (ledger.isSome) {
|
|
const stashId = ledger.unwrap().stash.toString();
|
|
|
|
!result.some(([accountId]) => accountId === stashId) && result.push([stashId, false]);
|
|
}
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
function useOwnStashesImpl (additional?: string[]): [string, IsInKeyring][] | undefined {
|
|
const { allAccounts } = useAccounts();
|
|
const { api } = useApi();
|
|
|
|
const ids = useMemo(
|
|
() => allAccounts.concat(additional || []),
|
|
[allAccounts, additional]
|
|
);
|
|
|
|
const ownBonded = useCall<Option<AccountId>[]>(ids.length !== 0 && api.query.staking?.bonded.multi, [ids]);
|
|
const ownLedger = useCall<Option<StakingLedger>[]>(ids.length !== 0 && api.query.staking?.ledger.multi, [ids]);
|
|
|
|
return useMemo(
|
|
() => ids.length
|
|
? ownBonded && ownLedger
|
|
? getStashes(ids, ownBonded, ownLedger)
|
|
: undefined
|
|
: [],
|
|
[ids, ownBonded, ownLedger]
|
|
);
|
|
}
|
|
|
|
export const useOwnStashes = createNamedHook('useOwnStashes', useOwnStashesImpl);
|
|
|
|
function useOwnStashIdsImpl (additional?: string[]): string[] | undefined {
|
|
const ownStashes = useOwnStashes(additional);
|
|
|
|
return useMemo(
|
|
() => ownStashes
|
|
? ownStashes.map(([stashId]) => stashId)
|
|
: undefined,
|
|
[ownStashes]
|
|
);
|
|
}
|
|
|
|
export const useOwnStashIds = createNamedHook('useOwnStashIds', useOwnStashIdsImpl);
|