diff --git a/packages/page-staking/src/Actions/Account/InputValidationController.tsx b/packages/page-staking/src/Actions/Account/InputValidationController.tsx index ec0844286e..53178492d3 100644 --- a/packages/page-staking/src/Actions/Account/InputValidationController.tsx +++ b/packages/page-staking/src/Actions/Account/InputValidationController.tsx @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { DeriveBalancesAll } from '@polkadot/api-derive/types'; import { AccountId, StakingLedger } from '@polkadot/types/interfaces'; import React, { useEffect, useState } from 'react'; @@ -26,7 +27,7 @@ interface ErrorState { function ValidateController ({ accountId, controllerId, defaultController, onError }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); - const bondedId = useCall(api.query.staking.bonded, [controllerId], { + const bondedId = useCall(controllerId ? api.query.staking.bonded : null, [controllerId], { transform: (value: Option): string | null => value.isSome ? value.unwrap().toString() @@ -38,6 +39,7 @@ function ValidateController ({ accountId, controllerId, defaultController, onErr ? value.unwrap().stash.toString() : null }); + const allBalances = useCall(controllerId ? api.derive.balances.all : null, [controllerId]); const [{ error, isFatal }, setError] = useState({ error: null, isFatal: false }); useEffect((): void => { @@ -49,18 +51,21 @@ function ValidateController ({ accountId, controllerId, defaultController, onErr if (bondedId) { isFatal = true; - newError = t('A controller account should not map to another stash. This selected controller is a stash, controlled by {{bondedId}}', { replace: { bondedId } }); + newError = t('A controller account should not map to another stash. This selected controller is a stash, controlled by {{bondedId}}', { replace: { bondedId } }); } else if (stashId) { isFatal = true; - newError = t('A controller account should not be set to manages multiple stashes. The selected controller is already controlling {{stashId}}', { replace: { stashId } }); + newError = t('A controller account should not be set to manage multiple stashes. The selected controller is already controlling {{stashId}}', { replace: { stashId } }); + } else if (allBalances?.freeBalance.isZero()) { + isFatal = true; + newError = t('The controller does no have sufficient funds available to cover transaction fees. Ensure that a funded controller is used.'); } else if (controllerId === accountId) { - newError = t('Distinct stash and controller accounts are recommended to ensure fund security. You will be allowed to make the transaction, but take care to not tie up all funds, only use a portion of the available funds during this period.'); + newError = t('Distinct stash and controller accounts are recommended to ensure fund security. You will be allowed to make the transaction, but take care to not tie up all funds, only use a portion of the available funds during this period.'); } onError(newError, isFatal); setError((state) => state.error !== newError ? { error: newError, isFatal } : state); } - }, [accountId, bondedId, controllerId, defaultController, onError, stashId, t]); + }, [accountId, allBalances, bondedId, controllerId, defaultController, onError, stashId, t]); if (!error || !accountId) { return null;