From 525657ee01b6f69b8ef60e2e11b4b39cc97d2f4c Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 28 Feb 2022 13:34:34 +0100 Subject: [PATCH] Min commission check (#7068) --- .../src/Actions/partials/Validate.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/page-staking/src/Actions/partials/Validate.tsx b/packages/page-staking/src/Actions/partials/Validate.tsx index ab7ffaa099..a7d1fd5a83 100644 --- a/packages/page-staking/src/Actions/partials/Validate.tsx +++ b/packages/page-staking/src/Actions/partials/Validate.tsx @@ -5,9 +5,9 @@ import type { ValidateInfo } from './types'; import React, { useCallback, useEffect, useRef, useState } from 'react'; -import { Dropdown, InputAddress, InputNumber, Modal } from '@polkadot/react-components'; -import { useApi } from '@polkadot/react-hooks'; -import { BN, BN_HUNDRED as MAX_COMM, isFunction } from '@polkadot/util'; +import { Dropdown, InputAddress, InputNumber, MarkError, Modal } from '@polkadot/react-components'; +import { useApi, useCall } from '@polkadot/react-hooks'; +import { BN, BN_HUNDRED as MAX_COMM, BN_ONE, isFunction } from '@polkadot/util'; import { useTranslation } from '../../translate'; @@ -25,7 +25,8 @@ const COMM_MUL = new BN(1e7); function Validate ({ className = '', controllerId, onChange, stashId, withFocus, withSenders }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const [commission, setCommission] = useState(1); + const minComm = useCall(api.query.staking.minCommission); + const [commission, setCommission] = useState(BN_ONE); const [allowNoms, setAllowNoms] = useState(true); const blockedOptions = useRef([ @@ -49,12 +50,14 @@ function Validate ({ className = '', controllerId, onChange, stashId, withFocus, const _setCommission = useCallback( (value?: BN) => value && setCommission( value.isZero() - ? 1 // small non-zero set to avoid isEmpty + ? BN_ONE // small non-zero set to avoid isEmpty : value.mul(COMM_MUL) ), [] ); + const commErr = !!minComm && commission.lt(minComm); + return (
{withSenders && ( @@ -75,11 +78,15 @@ function Validate ({ className = '', controllerId, onChange, stashId, withFocus, ('The percentage reward (0-100) that should be applied for the validator')} + isError={commErr} isZeroable label={t('reward commission percentage')} maxValue={MAX_COMM} onChange={_setCommission} /> + {commErr && ( + ('The commission is below the on-chain minimum of {{p}}%', { replace: { p: (minComm.mul(MAX_COMM).div(COMM_MUL).toNumber() / 100).toFixed(2) } })} /> + )} {isFunction(api.tx.staking.kick) && ( ('The validator can block any new nominations. By default it is set to allow all nominations.')}>