diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx index 28611e2c4d..affc3f11de 100644 --- a/packages/page-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx @@ -2,80 +2,32 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -/* eslint-disable @typescript-eslint/camelcase */ - -import { I18nProps } from '@polkadot/react-components/types'; -import { ApiProps } from '@polkadot/react-api/types'; -import { CalculateBalanceProps } from '../../types'; - import BN from 'bn.js'; -import React from 'react'; -import { Available, InputAddress, InputBalance, Modal, TxButton, TxComponent } from '@polkadot/react-components'; -import { SubmittableExtrinsic } from '@polkadot/api/promise/types'; -import { withCalls, withApi, withMulti } from '@polkadot/react-api/hoc'; +import React, { useState } from 'react'; +import { Available, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components'; -import translate from '../../translate'; +import { useTranslation } from '../../translate'; import ValidateAmount from './InputValidateAmount'; -interface Props extends I18nProps, ApiProps, CalculateBalanceProps { - controllerId: string; - isOpen: boolean; +interface Props { onClose: () => void; stashId: string; } -interface State { - amountError: string | null; - extrinsic: SubmittableExtrinsic | null; - maxAdditional?: BN; - maxBalance?: BN; -} - const ZERO = new BN(0); -class BondExtra extends TxComponent { - public state: State = { - amountError: null, - extrinsic: null - }; +function BondExtra ({ onClose, stashId }: Props): React.ReactElement { + const { t } = useTranslation(); + const [amountError, setAmountError] = useState(null); + const [maxAdditional, setMaxAdditional] = useState(); + const [maxBalance] = useState(); - public render (): React.ReactNode { - const { isOpen, onClose, stashId, t } = this.props; - const { extrinsic, maxAdditional } = this.state; - const canSubmit = !!maxAdditional && maxAdditional.gtn(0); - - if (!isOpen) { - return null; - } - - return ( - - {this.renderContent()} - - - - - ); - } - - private renderContent (): React.ReactNode { - const { stashId, t } = this.props; - const { amountError, maxAdditional, maxBalance } = this.state; - - return ( + return ( + { isError={!!amountError || !maxAdditional || maxAdditional.eqn(0)} label={t('additional bonded funds')} maxValue={maxBalance} - onChange={this.onChangeValue} - onEnter={this.sendTx} + onChange={setMaxAdditional} /> - ); - } - - private nextState (newState: Partial): void { - this.setState((prevState: State): State => { - const { api } = this.props; - const { amountError = prevState.amountError, maxAdditional = prevState.maxAdditional, maxBalance = prevState.maxBalance } = newState; - const extrinsic: any = (maxAdditional && maxAdditional.gte(ZERO)) - ? api.tx.staking.bondExtra(maxAdditional) - : null; - - return { - amountError, - extrinsic, - maxAdditional, - maxBalance - }; - }); - } - - private onChangeValue = (maxAdditional?: BN): void => { - this.nextState({ maxAdditional }); - } - - private setAmountError = (amountError: string | null): void => { - this.setState({ amountError }); - } + + + + + ); } -export default withMulti( - BondExtra, - translate, - withApi, - withCalls( - 'derive.balances.fees' - ) -); +export default React.memo(BondExtra); diff --git a/packages/page-staking/src/Actions/Account/index.tsx b/packages/page-staking/src/Actions/Account/index.tsx index cba05790a4..99fd629ae0 100644 --- a/packages/page-staking/src/Actions/Account/index.tsx +++ b/packages/page-staking/src/Actions/Account/index.tsx @@ -135,12 +135,6 @@ function Account ({ allStashes, className, isInElection, isOwnStash, next, onUpd return ( - {controllerId && ( + {isBondExtraOpen && ( + + )} {isInjectOpen && ( )} diff --git a/packages/page-staking/src/types.ts b/packages/page-staking/src/types.ts index 46166e50f1..20e7d15759 100644 --- a/packages/page-staking/src/types.ts +++ b/packages/page-staking/src/types.ts @@ -2,16 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { DeriveFees, DeriveBalancesAll } from '@polkadot/api-derive/types'; import { AccountId, Balance, BlockNumber, Hash, SessionIndex } from '@polkadot/types/interfaces'; export type Nominators = Record; -export interface CalculateBalanceProps { - balances_fees?: DeriveFees; - balances_all?: DeriveBalancesAll; -} - export type AccountFilter = 'all' | 'controller' | 'session' | 'stash' | 'unbonded'; export type ValidatorFilter = 'all' | 'hasNominators' | 'noNominators' | 'hasWarnings' | 'noWarnings' | 'iNominated' | 'nextSet';