From 91bd4bb8420caae65ec5b3a3b4985e11407259fa Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 5 Feb 2021 09:07:39 +0100 Subject: [PATCH] Check nomination amount on intial set (#4603) --- .../src/Actions/Account/InputValidateAmount.tsx | 13 ++++++++++--- packages/page-staking/src/Actions/NewNominator.tsx | 6 +++++- packages/page-staking/src/Actions/partials/Bond.tsx | 6 +++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx b/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx index a3948a96b0..0aed2aa7cd 100644 --- a/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx +++ b/packages/page-staking/src/Actions/Account/InputValidateAmount.tsx @@ -16,6 +16,8 @@ import { useTranslation } from '../../translate'; interface Props { controllerId: string | null; currentAmount?: BN | null; + isNominating?: boolean; + minNomination?: BN; onError: (state: AmountValidateState | null) => void; stashId: string | null; value?: BN | null; @@ -37,7 +39,7 @@ function formatExistential (value: BN): string { return fmt; } -function ValidateAmount ({ currentAmount, onError, stashId, value }: Props): React.ReactElement | null { +function ValidateAmount ({ currentAmount, isNominating, minNomination, onError, stashId, value }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); const stashBalance = useCall(api.derive.balances.all, [stashId]); @@ -50,6 +52,7 @@ function ValidateAmount ({ currentAmount, onError, stashId, value }: Props): Rea const existentialDeposit = api.consts.balances.existentialDeposit; const maxBond = stashBalance.freeBalance.sub(existentialDeposit.divn(2)); let newError: string | null = null; + let newWarning: string | null = null; if (check.gte(maxBond)) { newError = t('The specified value is too large and does not allow funds to pay future transaction fees.'); @@ -57,18 +60,22 @@ function ValidateAmount ({ currentAmount, onError, stashId, value }: Props): Rea newError = t('The bonded amount is less than the minimum bond amount of {{existentialDeposit}}', { replace: { existentialDeposit: formatExistential(existentialDeposit) } }); + } else if (isNominating && minNomination && check.lte(minNomination)) { + newWarning = t('The bonded amount is less than the current active minimum nominated amount of {{minNomination}} and depending on the network state, may not be selected to participate', { + replace: { minNomination: formatBalance(minNomination) } + }); } setResult((state): AmountValidateState => { const error = state.error !== newError ? newError : state.error; - const warning = state.warning; + const warning = state.warning !== newWarning ? newWarning : state.warning; onError((error || warning) ? { error, warning } : null); return { error, warning }; }); } - }, [api, currentAmount, onError, stashBalance, t, value]); + }, [api, currentAmount, isNominating, minNomination, onError, stashBalance, t, value]); if (error) { return ; diff --git a/packages/page-staking/src/Actions/NewNominator.tsx b/packages/page-staking/src/Actions/NewNominator.tsx index 3d981eae93..4bf9122a39 100644 --- a/packages/page-staking/src/Actions/NewNominator.tsx +++ b/packages/page-staking/src/Actions/NewNominator.tsx @@ -72,7 +72,11 @@ function NewNominator ({ isInElection, targets }: Props): React.ReactElement {step === 1 && ( - + )} {controllerId && stashId && step === 2 && ( void; } -function Bond ({ className = '', onChange }: Props): React.ReactElement { +function Bond ({ className = '', isNominating, minNomination, onChange }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); const [amount, setAmount] = useState(); @@ -134,6 +136,8 @@ function Bond ({ className = '', onChange }: Props): React.ReactElement { />