ghost-portal/packages/page-staking/src/usePoolAccounts.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

36 lines
1.0 KiB
TypeScript

// Copyright 2017-2022 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiPromise } from '@polkadot/api';
import type { BN } from '@polkadot/util';
import type { PoolAccounts } from './types';
import { useMemo } from 'react';
import { createNamedHook, useApi } from '@polkadot/react-hooks';
import { bnToU8a, stringToU8a, u8aConcat } from '@polkadot/util';
const EMPTY_H256 = new Uint8Array(32);
const ADDR_PREFIX = stringToU8a('modlpy/npols');
export function createAccount (api: ApiPromise, poolId: BN, index: number): string {
return api.registry.createType(
'AccountId32',
u8aConcat(ADDR_PREFIX, new Uint8Array([index]), bnToU8a(poolId, { bitLength: 32 }), EMPTY_H256)
).toString();
}
function usePoolAccountsImpl (poolId: BN): PoolAccounts {
const { api } = useApi();
return useMemo(
() => ({
rewardId: createAccount(api, poolId, 1),
stashId: createAccount(api, poolId, 0)
}),
[api, poolId]
);
}
export default createNamedHook('usePoolAccounts', usePoolAccountsImpl);