diff --git a/packages/page-accounts/src/modals/Transfer.tsx b/packages/page-accounts/src/modals/Transfer.tsx index 9bbe19171d..33a1b3391d 100644 --- a/packages/page-accounts/src/modals/Transfer.tsx +++ b/packages/page-accounts/src/modals/Transfer.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; -import type { AccountInfo } from '@polkadot/types/interfaces'; +import type { AccountInfoWithProviders, AccountInfoWithRefCount } from '@polkadot/types/interfaces'; import BN from 'bn.js'; import React, { useEffect, useState } from 'react'; @@ -22,6 +22,10 @@ interface Props { senderId?: string; } +function isRefcount (accountInfo: AccountInfoWithProviders | AccountInfoWithRefCount): accountInfo is AccountInfoWithRefCount { + return !!(accountInfo as AccountInfoWithRefCount).refcount; +} + function Transfer ({ className = '', onClose, recipientId: propRecipientId, senderId: propSenderId }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); @@ -33,7 +37,7 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send const [recipientId, setRecipientId] = useState(propRecipientId || null); const [senderId, setSenderId] = useState(propSenderId || null); const balances = useCall(api.derive.balances.all, [senderId]); - const accountInfo = useCall(api.query.system.account, [senderId]); + const accountInfo = useCall(api.query.system.account, [senderId]); useEffect((): void => { if (balances && balances.accountId.eq(senderId) && recipientId && senderId && isFunction(api.rpc.payment?.queryInfo)) { @@ -61,7 +65,12 @@ function Transfer ({ className = '', onClose, recipientId: propRecipientId, send } }, [api, balances, recipientId, senderId]); - const canToggleAll = !isProtected && balances && balances.accountId.eq(senderId) && maxTransfer && (!accountInfo || !accountInfo.refcount || accountInfo.refcount.isZero()); + const noReference = accountInfo + ? isRefcount(accountInfo) + ? accountInfo.refcount.isZero() + : (accountInfo.consumers.isZero() && accountInfo.providers.isZero()) + : true; + const canToggleAll = !isProtected && balances && balances.accountId.eq(senderId) && maxTransfer && noReference; return ( )} - {!isProtected && accountInfo && accountInfo.refcount && !accountInfo.refcount.isZero() && ( + {!isProtected && !noReference && ( ('There is an existing reference count on the sender account. As such the account cannot be reaped from the state.')} /> )}