Check refcount on max transfer (#3990)

This commit is contained in:
Jaco Greeff 2020-11-06 21:47:14 +01:00 committed by GitHub
parent f8182b601a
commit d7d28533b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { DeriveBalancesAll } from '@polkadot/api-derive/types';
import { AccountInfo } from '@polkadot/types/interfaces';
import BN from 'bn.js';
import React, { useEffect, useState } from 'react';
@ -31,6 +32,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send
const [recipientId, setRecipientId] = useState<string | null>(propRecipientId || null);
const [senderId, setSenderId] = useState<string | null>(propSenderId || null);
const balances = useCall<DeriveBalancesAll>(api.derive.balances.all, [senderId]);
const accountInfo = useCall<AccountInfo>(api.query.system.account, [senderId]);
useEffect((): void => {
if (balances && balances.accountId.eq(senderId) && recipientId && senderId && isFunction(api.rpc.payment?.queryInfo)) {
@ -59,7 +61,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send
}, [api, balances, recipientId, senderId]);
const transferrable = <span className='label'>{t<string>('transferrable')}</span>;
const canToggleAll = !isProtected && balances && balances.accountId.eq(senderId) && maxTransfer;
const canToggleAll = !isProtected && balances && balances.accountId.eq(senderId) && maxTransfer && (!accountInfo || !accountInfo.refcount || accountInfo.refcount.isZero());
return (
<Modal