ghost-portal/packages/page-staking/src/Pools/usePoolInfo.ts
Jaco 2a7af81d16
Staking pools (#7089)
* Staking pools

* Fly-by comment fix

* Some infrastructure

* multi

* Create value

* Retrieve singular params instance

* defaultValue for multi query

* Retrieve list of pool ids

* Drive-by param formatting

* Pool list retrieval

* Retrieve pool info

* Adjust trigger placement

* Dump info

* Join modal

* Fix build

* Allow creation & joining

* caveman typing

* Adjust disabled state

* Adjust

* cowboy types

* Some basic stats

* Created/Destoyed events

* Adjust for latest

* Set metadata on creation

* Basic pools
2022-03-28 21:34:08 +03:00

30 lines
959 B
TypeScript

// Copyright 2017-2022 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Option } from '@polkadot/types';
import type { Codec } from '@polkadot/types/types';
import type { BN } from '@polkadot/util';
import type { PoolInfo } from './types';
import { createNamedHook, useApi, useCallMulti } from '@polkadot/react-hooks';
const options = {
transform: ([bonded, metadata, reward]: [Option<PoolInfo['bonded'] & Codec>, PoolInfo['metadata'], Option<PoolInfo['reward'] & Codec>]): PoolInfo => ({
bonded: bonded.unwrapOr(null),
metadata,
reward: reward.unwrapOr(null)
})
};
function usePoolInfoImpl (id: BN): PoolInfo {
const { api } = useApi();
return useCallMulti([
[api.query.nominationPools.bondedPools, id],
[api.query.nominationPools.metadata, id],
[api.query.nominationPools.rewardPools, id]
], options);
}
export default createNamedHook('usePoolInfo', usePoolInfoImpl);