Browse Source

Remove unneeded InputBalanceBonded indirection (#2585)

Jaco Greeff 4 years ago
parent
commit
eb6b27750a

+ 1 - 2
packages/apps/src/WarmUp.tsx

@@ -7,7 +7,6 @@ import { useApi, useCall } from '@polkadot/react-hooks';
 
 function WarmUp (): React.ReactElement {
   const { api, isApiReady } = useApi();
-  const fees = useCall<unknown>(isApiReady && api.derive.balances?.fees, []);
   const indexes = useCall<unknown>(isApiReady && api.derive.accounts?.indexes, []);
   const registrars = useCall<unknown>(isApiReady && api.query.identity?.registrars, []);
   const staking = null; // useCall<unknown>(isApiReady && api.derive.staking?.overview, []);
@@ -15,7 +14,7 @@ function WarmUp (): React.ReactElement {
   const [hasValues, setHasValues] = useState(false);
 
   useEffect((): void => {
-    setHasValues(!!fees || !!indexes || !!issuance || !!registrars || !!staking);
+    setHasValues(!!indexes || !!issuance || !!registrars || !!staking);
   // eslint-disable-next-line react-hooks/exhaustive-deps
   }, []);
 

+ 2 - 10
packages/page-staking/src/Actions/NewStake.tsx

@@ -6,7 +6,7 @@ import { SubmittableExtrinsic } from '@polkadot/api/types';
 
 import BN from 'bn.js';
 import React, { useEffect, useState } from 'react';
-import { Button, Dropdown, InputAddress, InputBalanceBonded, Modal, TxButton } from '@polkadot/react-components';
+import { Button, Dropdown, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
 import { useApi, useToggle } from '@polkadot/react-hooks';
 
 import { useTranslation } from '../translate';
@@ -61,14 +61,12 @@ function NewStake ({ className, isInElection }: Props): React.ReactElement<Props
         >
           <Modal.Content className='ui--signer-Signer-Content'>
             <InputAddress
-              className='medium'
               label={t('stash account')}
               onChange={setStashId}
               type='account'
               value={stashId}
             />
             <InputAddress
-              className='medium'
               help={t('The controller is the account that will be used to control any nominating or validating actions. Should not match another stash or controller.')}
               label={t('controller account')}
               onChange={setControllerId}
@@ -80,17 +78,12 @@ function NewStake ({ className, isInElection }: Props): React.ReactElement<Props
               controllerId={controllerId}
               onError={setControllerError}
             />
-            <InputBalanceBonded
+            <InputBalance
               autoFocus
-              className='medium'
-              controllerId={controllerId}
-              destination={destination}
-              extrinsicProp={'staking.bond'}
               help={t('The total amount of the stash balance that will be at stake in any forthcoming rounds (should be less than the total amount available)')}
               isError={!hasValue || !!amountError}
               label={t('value bonded')}
               onChange={setAmount}
-              stashId={stashId}
             />
             <InputValidateAmount
               accountId={stashId}
@@ -98,7 +91,6 @@ function NewStake ({ className, isInElection }: Props): React.ReactElement<Props
               value={amount}
             />
             <Dropdown
-              className='medium'
               defaultValue={0}
               help={t('The destination account for any payments as either a nominator or validator')}
               label={t('payment destination')}

+ 0 - 101
packages/react-components/src/InputBalanceBonded.tsx

@@ -1,101 +0,0 @@
-
-// Copyright 2017-2020 @polkadot/react-components authors & contributors
-// This software may be modified and distributed under the terms
-// of the Apache-2.0 license. See the LICENSE file for details.
-
-import { BareProps, BitLength } from './types';
-import { DeriveFees, DeriveBalancesAll } from '@polkadot/api-derive/types';
-
-import BN from 'bn.js';
-import React from 'react';
-import { ApiProps } from '@polkadot/react-api/types';
-import { BitLengthOption } from '@polkadot/react-components/constants';
-import { InputNumber } from '@polkadot/react-components';
-import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
-import { withCalls, withMulti, withApi } from '@polkadot/react-api/hoc';
-
-interface Props extends BareProps, ApiProps {
-  autoFocus?: boolean;
-  balances_fees?: DeriveFees;
-  balances_all?: DeriveBalancesAll;
-  controllerId: string;
-  defaultValue?: BN | string;
-  destination?: number;
-  extrinsicProp: 'staking.bond' | 'staking.bondExtra' | 'staking.unbond';
-  help?: React.ReactNode;
-  isDisabled?: boolean;
-  isError?: boolean;
-  isFull?: boolean;
-  isZeroable?: boolean;
-  label?: any;
-  onChange?: (value?: BN) => void;
-  onEnter?: () => void;
-  onEscape?: () => void;
-  placeholder?: string;
-  stashId: string;
-  value?: BN | string;
-  withEllipsis?: boolean;
-  withLabel?: boolean;
-  withMax?: boolean;
-}
-
-interface State {
-  maxBalance?: BN;
-  extrinsic: SubmittableExtrinsic | null;
-}
-
-const ZERO = new BN(0);
-const DEFAULT_BITLENGTH = BitLengthOption.CHAIN_SPEC as BitLength;
-
-class InputBalanceBonded extends React.PureComponent<Props, State> {
-  public state: State;
-
-  constructor (props: Props) {
-    super(props);
-
-    this.state = {
-      extrinsic: null,
-      maxBalance: ZERO
-    };
-  }
-
-  public render (): React.ReactNode {
-    const { autoFocus, className, defaultValue, help, isDisabled, isError, isFull, isZeroable, label, onChange, onEnter, onEscape, placeholder, style, value, withEllipsis, withLabel, withMax } = this.props;
-    const { maxBalance } = this.state;
-
-    return (
-      <InputNumber
-        autoFocus={autoFocus}
-        bitLength={DEFAULT_BITLENGTH}
-        className={className}
-        defaultValue={defaultValue}
-        help={help}
-        isDisabled={isDisabled}
-        isError={isError}
-        isFull={isFull}
-        isSi
-        isZeroable={isZeroable}
-        label={label}
-        maxValue={maxBalance}
-        onChange={onChange}
-        onEnter={onEnter}
-        onEscape={onEscape}
-        placeholder={placeholder}
-        style={style}
-        value={value}
-        withEllipsis={withEllipsis}
-        withLabel={withLabel}
-        withMax={withMax}
-      />
-    );
-  }
-}
-
-export default withMulti(
-  InputBalanceBonded,
-  withApi,
-  withCalls<Props>(
-    'derive.balances.fees',
-    ['derive.balances.all', { paramName: 'stashId' }]
-  )
-);

+ 0 - 1
packages/react-components/src/index.tsx

@@ -46,7 +46,6 @@ export { default as InputAddress } from './InputAddress';
 export { default as InputAddressMulti } from './InputAddressMulti';
 export { default as InputAddressSimple } from './InputAddressSimple';
 export { default as InputBalance } from './InputBalance';
-export { default as InputBalanceBonded } from './InputBalanceBonded';
 export { default as InputConsts } from './InputConsts';
 export { default as InputError } from './InputError';
 export { default as InputExtrinsic } from './InputExtrinsic';