Pass through minComm to validate (#7343)
This commit is contained in:
parent
47b69df838
commit
e27058540f
@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ValidateInfo } from '../partials/types';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
@ -12,11 +13,12 @@ import ValidatePartial from '../partials/Validate';
|
||||
|
||||
interface Props {
|
||||
controllerId: string;
|
||||
minCommission?: BN;
|
||||
onClose: () => void;
|
||||
stashId: string;
|
||||
}
|
||||
|
||||
function Validate ({ controllerId, onClose, stashId }: Props): React.ReactElement<Props> {
|
||||
function Validate ({ controllerId, minCommission, onClose, stashId }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [{ validateTx }, setTx] = useState<ValidateInfo>({});
|
||||
|
||||
@ -29,6 +31,7 @@ function Validate ({ controllerId, onClose, stashId }: Props): React.ReactElemen
|
||||
<Modal.Content>
|
||||
<ValidatePartial
|
||||
controllerId={controllerId}
|
||||
minCommission={minCommission}
|
||||
onChange={setTx}
|
||||
stashId={stashId}
|
||||
withFocus
|
||||
|
||||
@ -36,6 +36,7 @@ interface Props {
|
||||
isDisabled?: boolean;
|
||||
isSelectable: boolean;
|
||||
info: StakerState;
|
||||
minCommission?: BN;
|
||||
next?: string[];
|
||||
onSelect: (stashId: string, controllerId: string, isSelected: boolean) => void;
|
||||
stashId: string;
|
||||
@ -70,7 +71,7 @@ function useStashCalls (api: ApiPromise, stashId: string) {
|
||||
return { balancesAll, spanCount, stakingAccount };
|
||||
}
|
||||
|
||||
function Account ({ allSlashes, className = '', info: { controllerId, destination, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, isSelectable, onSelect, targets }: Props): React.ReactElement<Props> {
|
||||
function Account ({ allSlashes, className = '', info: { controllerId, destination, hexSessionIdNext, hexSessionIdQueue, isLoading, isOwnController, isOwnStash, isStashNominating, isStashValidating, nominating, sessionIds, stakingLedger, stashId }, isDisabled, isSelectable, minCommission, onSelect, targets }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { queueExtrinsic } = useContext(StatusContext);
|
||||
@ -199,6 +200,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio
|
||||
{isValidateOpen && controllerId && (
|
||||
<Validate
|
||||
controllerId={controllerId}
|
||||
minCommission={minCommission}
|
||||
onClose={toggleValidate}
|
||||
stashId={stashId}
|
||||
/>
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2022 @polkadot/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { SortedTargets } from '../types';
|
||||
import type { BondInfo, SessionInfo, ValidateInfo } from './partials/types';
|
||||
|
||||
@ -17,12 +18,13 @@ import ValidatePartial from './partials/Validate';
|
||||
|
||||
interface Props {
|
||||
isInElection?: boolean;
|
||||
minCommission?: BN;
|
||||
targets: SortedTargets;
|
||||
}
|
||||
|
||||
const NUM_STEPS = 2;
|
||||
|
||||
function NewValidator ({ isInElection, targets }: Props): React.ReactElement<Props> {
|
||||
function NewValidator ({ isInElection, minCommission, targets }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [isVisible, toggleVisible] = useToggle();
|
||||
@ -90,6 +92,7 @@ function NewValidator ({ isInElection, targets }: Props): React.ReactElement<Pro
|
||||
/>
|
||||
<ValidatePartial
|
||||
controllerId={controllerId}
|
||||
minCommission={minCommission}
|
||||
onChange={setValidateInfo}
|
||||
stashId={stashId}
|
||||
/>
|
||||
|
||||
@ -23,6 +23,7 @@ import NewValidator from './NewValidator';
|
||||
interface Props {
|
||||
className?: string;
|
||||
isInElection?: boolean;
|
||||
minCommission?: BN;
|
||||
ownStashes?: StakerState[];
|
||||
next?: string[];
|
||||
validators?: string[];
|
||||
@ -111,7 +112,7 @@ function formatTotal (typeIndex: number, state: State): React.ReactNode {
|
||||
return value && <FormatBalance value={value} />;
|
||||
}
|
||||
|
||||
function Actions ({ className = '', isInElection, ownStashes, targets }: Props): React.ReactElement<Props> {
|
||||
function Actions ({ className = '', isInElection, minCommission, ownStashes, targets }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const allSlashes = useAvailableSlashes();
|
||||
const [typeIndex, setTypeIndex] = useState(0);
|
||||
@ -181,6 +182,7 @@ function Actions ({ className = '', isInElection, ownStashes, targets }: Props):
|
||||
/>
|
||||
<NewValidator
|
||||
isInElection={isInElection}
|
||||
minCommission={minCommission}
|
||||
targets={targets}
|
||||
/>
|
||||
<NewStash />
|
||||
@ -198,6 +200,7 @@ function Actions ({ className = '', isInElection, ownStashes, targets }: Props):
|
||||
isDisabled={isInElection}
|
||||
isSelectable={isSelectable}
|
||||
key={info.stashId}
|
||||
minCommission={minCommission}
|
||||
onSelect={onSelectStash}
|
||||
targets={targets}
|
||||
/>
|
||||
|
||||
@ -3,17 +3,18 @@
|
||||
|
||||
import type { ValidateInfo } from './types';
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
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 { useApi } from '@polkadot/react-hooks';
|
||||
import { BN, BN_HUNDRED as MAX_COMM, BN_ONE, bnMax, isFunction } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../../translate';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
controllerId: string;
|
||||
minCommission?: BN;
|
||||
onChange: (info: ValidateInfo) => void;
|
||||
stashId: string;
|
||||
withFocus?: boolean;
|
||||
@ -22,12 +23,17 @@ interface Props {
|
||||
|
||||
const COMM_MUL = new BN(1e7);
|
||||
|
||||
function Validate ({ className = '', controllerId, onChange, stashId, withFocus, withSenders }: Props): React.ReactElement<Props> {
|
||||
function Validate ({ className = '', controllerId, minCommission, onChange, stashId, withFocus, withSenders }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const minComm = useCall<BN>(api.query.staking.minCommission);
|
||||
const [commission, setCommission] = useState(BN_ONE);
|
||||
const [allowNoms, setAllowNoms] = useState(true);
|
||||
const defaultComm = useMemo(
|
||||
() => minCommission
|
||||
? bnMax(minCommission.div(COMM_MUL), BN_ONE)
|
||||
: BN_ONE,
|
||||
[minCommission]
|
||||
);
|
||||
|
||||
const blockedOptions = useRef([
|
||||
{ text: t('Yes, allow nominations'), value: true },
|
||||
@ -56,7 +62,7 @@ function Validate ({ className = '', controllerId, onChange, stashId, withFocus,
|
||||
[]
|
||||
);
|
||||
|
||||
const commErr = !!minComm && commission.lt(minComm);
|
||||
const commErr = !!minCommission && commission.lt(minCommission);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@ -77,6 +83,7 @@ function Validate ({ className = '', controllerId, onChange, stashId, withFocus,
|
||||
<Modal.Columns hint={t<string>('The commission is deducted from all rewards before the remainder is split with nominators.')}>
|
||||
<InputNumber
|
||||
autoFocus={withFocus}
|
||||
defaultValue={defaultComm}
|
||||
help={t<string>('The percentage reward (0-100) that should be applied for the validator')}
|
||||
isError={commErr}
|
||||
isZeroable
|
||||
@ -85,7 +92,7 @@ function Validate ({ className = '', controllerId, onChange, stashId, withFocus,
|
||||
onChange={_setCommission}
|
||||
/>
|
||||
{commErr && (
|
||||
<MarkError content={t<string>('The commission is below the on-chain minimum of {{p}}%', { replace: { p: (minComm.mul(MAX_COMM).div(COMM_MUL).toNumber() / 100).toFixed(2) } })} />
|
||||
<MarkError content={t<string>('The commission is below the on-chain minimum of {{p}}%', { replace: { p: (minCommission.mul(MAX_COMM).div(COMM_MUL).toNumber() / 100).toFixed(2) } })} />
|
||||
)}
|
||||
</Modal.Columns>
|
||||
{isFunction(api.tx.staking.kick) && (
|
||||
|
||||
@ -190,6 +190,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement<Pr
|
||||
<Actions
|
||||
className={pathname === `${basePath}/actions` ? '' : 'staking--hidden'}
|
||||
isInElection={isInElection}
|
||||
minCommission={minCommission}
|
||||
ownStashes={ownStashes}
|
||||
targets={targets}
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user