Pool param query updates (#7433)
This commit is contained in:
parent
e5d3d074f0
commit
f96d483252
@ -7,8 +7,8 @@ import type { Params } from './types';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { Button, Input, InputAddress, InputBalance, InputNumber, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { useApi, useCall, useToggle } from '@polkadot/react-hooks';
|
||||
import { BN_ONE, bnMax } from '@polkadot/util';
|
||||
import { useApi, useToggle } from '@polkadot/react-hooks';
|
||||
import { BN_ZERO, bnMax } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
@ -18,13 +18,12 @@ interface Props {
|
||||
params: Params;
|
||||
}
|
||||
|
||||
function Create ({ className, isDisabled, params: { minCreateBond, minNominatorBond } }: Props): React.ReactElement<Props> {
|
||||
function Create ({ className, isDisabled, params: { minCreateBond, minNominatorBond, nextPoolId } }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const lastPoolId = useCall<BN>(api.query.nominationPools.lastPoolId);
|
||||
const [isOpen, toggleOpen] = useToggle();
|
||||
const [accountId, setAccount] = useState<string | null>(null);
|
||||
const [amount, setAmount] = useState<BN | undefined>();
|
||||
const [amount, setAmount] = useState<BN>(BN_ZERO);
|
||||
const [metadata, setMetadata] = useState('');
|
||||
|
||||
const minValue = useMemo(
|
||||
@ -33,11 +32,6 @@ function Create ({ className, isDisabled, params: { minCreateBond, minNominatorB
|
||||
[api, minCreateBond, minNominatorBond]
|
||||
);
|
||||
|
||||
const nextPoolId = useMemo(
|
||||
() => lastPoolId && lastPoolId.add(BN_ONE),
|
||||
[lastPoolId]
|
||||
);
|
||||
|
||||
const isAmountError = useMemo(
|
||||
() => !amount || !minValue || amount.lt(minValue),
|
||||
[amount, minValue]
|
||||
|
||||
@ -6,12 +6,14 @@ import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
export interface Params {
|
||||
lastPoolId: BN;
|
||||
maxDelegators: number;
|
||||
maxDelegatorsPool: number;
|
||||
maxPools: number;
|
||||
minCreateBond?: BN;
|
||||
minJoinBond?: BN;
|
||||
minNominatorBond?: BN;
|
||||
nextPoolId: BN;
|
||||
}
|
||||
|
||||
// FIXME Once available, use types from lookup
|
||||
|
||||
@ -6,21 +6,25 @@ import type { BN } from '@polkadot/util';
|
||||
import type { Params } from './types';
|
||||
|
||||
import { createNamedHook, useApi, useCallMulti } from '@polkadot/react-hooks';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
import { BN_ONE, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
const queryOptions = {
|
||||
defaultValue: {
|
||||
lastPoolId: BN_ZERO,
|
||||
maxDelegators: 0,
|
||||
maxDelegatorsPool: 0,
|
||||
maxPools: 0
|
||||
maxPools: 0,
|
||||
nextPoolId: BN_ONE
|
||||
},
|
||||
transform: ([maxDelegators, maxDelegatorsPerPool, maxPools, minCreateBond, minJoinBond, minNominatorBond]: [Option<u32>, Option<u32>, Option<u32>, BN, BN, BN]): Params => ({
|
||||
transform: ([lastPoolId, maxDelegators, maxDelegatorsPerPool, maxPools, minCreateBond, minJoinBond, minNominatorBond]: [BN, Option<u32>, Option<u32>, Option<u32>, BN, BN, BN]): Params => ({
|
||||
lastPoolId,
|
||||
maxDelegators: maxDelegators.unwrapOr(BN_ZERO).toNumber(),
|
||||
maxDelegatorsPool: maxDelegatorsPerPool.unwrapOr(BN_ZERO).toNumber(),
|
||||
maxPools: maxPools.unwrapOr(BN_ZERO).toNumber(),
|
||||
minCreateBond,
|
||||
minJoinBond,
|
||||
minNominatorBond
|
||||
minNominatorBond,
|
||||
nextPoolId: lastPoolId.add(BN_ONE)
|
||||
})
|
||||
};
|
||||
|
||||
@ -28,8 +32,9 @@ function useParamsImpl (): Params {
|
||||
const { api } = useApi();
|
||||
|
||||
return useCallMulti<Params>([
|
||||
api.query.nominationPools.maxDelegators,
|
||||
api.query.nominationPools.maxDelegatorsPerPool,
|
||||
api.query.nominationPools.lastPoolId,
|
||||
api.query.nominationPools.maxPoolMembers,
|
||||
api.query.nominationPools.maxPoolMembersPerPool,
|
||||
api.query.nominationPools.maxPools,
|
||||
api.query.nominationPools.minCreateBond,
|
||||
api.query.nominationPools.minJoinBond,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user