diff --git a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx index 1ed5d79de8..cc17c6b42f 100644 --- a/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx +++ b/packages/page-staking/src/Actions/Account/SetRewardDestination.tsx @@ -1,13 +1,14 @@ // Copyright 2017-2021 @polkadot/app-staking authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { DeriveBalancesAll } from '@polkadot/api-derive/types'; import type { RewardDestination } from '@polkadot/types/interfaces'; import type { DestinationType } from '../types'; import React, { useMemo, useState } from 'react'; -import { Dropdown, InputAddress, Modal, TxButton } from '@polkadot/react-components'; -import { useApi } from '@polkadot/react-hooks'; +import { Dropdown, InputAddress, MarkError, Modal, TxButton } from '@polkadot/react-components'; +import { useApi, useCall } from '@polkadot/react-hooks'; import { useTranslation } from '../../translate'; import { createDestCurr } from '../destOptions'; @@ -24,6 +25,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas const { api } = useApi(); const [destination, setDestination] = useState(() => ((defaultDestination?.isAccount ? 'Account' : defaultDestination?.toString()) || 'Staked') as 'Staked'); const [destAccount, setDestAccount] = useState(() => defaultDestination?.isAccount ? defaultDestination.asAccount.toString() : null); + const destBalance = useCall(api.derive.balances.all, [destAccount]); const options = useMemo( () => createDestCurr(t), @@ -31,6 +33,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas ); const isAccount = destination === 'Account'; + const isDestError = isAccount && destBalance && destBalance.accountId.eq(destAccount) && destBalance.freeBalance.isZero(); return ( )} + {isDestError && ( + ('The selected destination account does not exist and cannot be used to receive rewards')} /> + )} ('Set reward destination')} onStart={onClose} params={[ diff --git a/packages/page-staking/src/Actions/partials/Bond.tsx b/packages/page-staking/src/Actions/partials/Bond.tsx index 3a6d60cc6f..9431d1d631 100644 --- a/packages/page-staking/src/Actions/partials/Bond.tsx +++ b/packages/page-staking/src/Actions/partials/Bond.tsx @@ -8,7 +8,7 @@ import type { BondInfo } from './types'; import BN from 'bn.js'; import React, { useCallback, useEffect, useMemo, useState } from 'react'; -import { Dropdown, InputAddress, InputBalance, Modal, Static } from '@polkadot/react-components'; +import { Dropdown, InputAddress, InputBalance, MarkError, Modal, Static } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; import { BalanceFree, BlockToTime } from '@polkadot/react-query'; import { BN_ZERO } from '@polkadot/util'; @@ -46,6 +46,7 @@ function Bond ({ className = '', isNominating, minNomination, onChange }: Props) const [stashId, setStashId] = useState(null); const [startBalance, setStartBalance] = useState(null); const stashBalance = useCall(api.derive.balances.all, [stashId]); + const destBalance = useCall(api.derive.balances.all, [destAccount]); const bondedBlocks = useUnbondDuration(); const options = useMemo( @@ -90,6 +91,7 @@ function Bond ({ className = '', isNominating, minNomination, onChange }: Props) const hasValue = !!amount?.gtn(0); const isAccount = destination === 'Account'; + const isDestError = isAccount && destBalance && destBalance.accountId.eq(destAccount) && destBalance.freeBalance.isZero(); return (
@@ -175,6 +177,9 @@ function Bond ({ className = '', isNominating, minNomination, onChange }: Props) value={destAccount} /> )} + {isDestError && ( + ('The selected destination account does not exist and cannot be used to receive rewards')} /> + )}
);