ghost-portal/packages/page-staking/src/useOwnPools.ts
Jaco 47913892cd
Expansion to pools logic (#7384)
* 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
2022-04-26 18:21:38 +03:00

51 lines
1.5 KiB
TypeScript

// Copyright 2017-2022 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@polkadot/types';
import type { PalletNominationPoolsPoolMember } from '@polkadot/types/lookup';
import type { OwnPool, OwnPoolBase } from './types';
import { useMemo } from 'react';
import { createNamedHook, useAccounts, useApi, useCall } from '@polkadot/react-hooks';
import { createAccount } from './usePoolAccounts';
const OPT_MULTI = {
transform: ([[ids], opts]: [[string[]], Option<PalletNominationPoolsPoolMember>[]]): OwnPoolBase[] =>
ids.reduce((pools: OwnPoolBase[], accountId, index): OwnPoolBase[] => {
if (opts[index].isSome) {
const member = opts[index].unwrap();
let entry = pools.find(({ poolId }) => poolId.eq(member.poolId));
if (!entry) {
entry = { members: {}, poolId: member.poolId };
pools.push(entry);
}
entry.members[accountId] = member;
}
return pools;
}, []),
withParamsTransform: true
};
function useOwnPoolsImpl (): OwnPool[] | undefined {
const { api } = useApi();
const { allAccounts } = useAccounts();
const base = useCall(api.query.nominationPools?.poolMembers.multi, [allAccounts], OPT_MULTI);
return useMemo(
() => base && base.map((base) => ({
...base,
rewardId: createAccount(api, base.poolId, 1),
stashId: createAccount(api, base.poolId, 0)
})),
[api, base]
);
}
export default createNamedHook('useOwnPools', useOwnPoolsImpl);