Show proxy reservation reserve (#5258)

This commit is contained in:
Jaco 2021-05-11 21:27:28 +03:00 committed by GitHub
parent 13cbc21d9c
commit 17e1a41627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,10 +6,10 @@ import type { SubmittableExtrinsic } from '@polkadot/api/types';
import type { AccountId, ProxyDefinition, ProxyType } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import styled from 'styled-components';
import { BatchWarning, Button, Dropdown, InputAddress, MarkError, Modal, TxButton } from '@polkadot/react-components';
import { BatchWarning, Button, Dropdown, InputAddress, InputBalance, MarkError, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useTxBatch } from '@polkadot/react-hooks';
import { BN_ZERO } from '@polkadot/util';
@ -152,12 +152,17 @@ function ProxyOverview ({ className, onClose, previousProxy: [existing] = EMPTY_
const [batchPrevious, setBatchPrevious] = useState<SubmittableExtrinsic<'promise'>[]>([]);
const [batchAdded, setBatchAdded] = useState<SubmittableExtrinsic<'promise'>[]>([]);
const [txs, setTxs] = useState<SubmittableExtrinsic<'promise'>[] | null>(null);
const [previous, setPrevious] = useState<PrevProxy[]>(
existing.map(({ delegate, proxyType }): [AccountId, ProxyType] => [delegate, proxyType])
);
const [previous, setPrevious] = useState<PrevProxy[]>(() => existing.map(({ delegate, proxyType }) => [delegate, proxyType]));
const [added, setAdded] = useState<PrevProxy[]>([]);
const extrinsics = useTxBatch(txs, optTxBatch);
const reservedAmount = useMemo(
() => api.consts.proxy.proxyDepositFactor
.muln(batchPrevious.length + batchAdded.length)
.iadd(api.consts.proxy.proxyDepositBase),
[api, batchPrevious, batchAdded]
);
const typeOpts = useRef(
api.createType('ProxyType').defKeys.map((text, value) => ({ text, value }))
);
@ -269,6 +274,13 @@ function ProxyOverview ({ className, onClose, previousProxy: [existing] = EMPTY_
/>
</Button.Group>
</Modal.Columns>
<Modal.Columns hint={t<string>('The amount that is reserved for the proxy based on the base deposit and number of proxies')}>
<InputBalance
defaultValue={reservedAmount}
isDisabled
label={t<string>('reserved balance')}
/>
</Modal.Columns>
<Modal.Columns>
<BatchWarning />
</Modal.Columns>