From 7415befba200f14ab2f4e62876acfdaa6891b789 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 4 Oct 2019 17:45:10 +0200 Subject: [PATCH] Some more additional func conversions (#1692) * Some more additional func conversions * Create Address functional * Minor cleanups * Adapt ExtrinsicDisplay * Linting updates --- packages/app-123code/src/Transfer.tsx | 80 +++---- .../app-address-book/src/modals/Create.tsx | 220 +++++++----------- packages/app-council/src/Motions/Propose.tsx | 2 +- packages/app-democracy/src/Propose.tsx | 2 +- packages/app-sudo/src/Sudo.tsx | 2 +- packages/react-components/src/Extrinsic.tsx | 144 +++++------- .../react-components/src/Params/Extrinsic.tsx | 4 +- 7 files changed, 174 insertions(+), 280 deletions(-) diff --git a/packages/app-123code/src/Transfer.tsx b/packages/app-123code/src/Transfer.tsx index 44b818c9e6..35ccce6f8b 100644 --- a/packages/app-123code/src/Transfer.tsx +++ b/packages/app-123code/src/Transfer.tsx @@ -3,63 +3,45 @@ // of the Apache-2.0 license. See the LICENSE file for details. import BN from 'bn.js'; -import React from 'react'; -import { Button, InputAddress, InputBalance, TxButton, TxComponent } from '@polkadot/react-components'; +import React, { useState } from 'react'; +import { Button, InputAddress, InputBalance, TxButton } from '@polkadot/react-components'; import Summary from './Summary'; interface Props { accountId?: string | null; } -interface State { - amount?: BN; - recipientId?: string | null; -} -export default class Transfer extends TxComponent { - public state: State = {}; +export default function Transfer ({ accountId }: Props): React.ReactElement { + const [amount, setAmount] = useState(null); + const [recipientId, setRecipientId] = useState(null); - public render (): React.ReactNode { - const { accountId } = this.props; - const { amount, recipientId } = this.state; - - return ( -
-

transfer

-
-
- +

transfer

+
+
+ + + + - - - - -
- Make a transfer from any account you control to another account. Transfer fees and per-transaction fees apply and will be calculated upon submission. +
-
- ); - } - - private onChangeAmount = (amount?: BN): void => { - this.setState({ amount }); - } - - private onChangeRecipient = (recipientId?: string | null): void => { - this.setState({ recipientId }); - } + Make a transfer from any account you control to another account. Transfer fees and per-transaction fees apply and will be calculated upon submission. + + + ); } diff --git a/packages/app-address-book/src/modals/Create.tsx b/packages/app-address-book/src/modals/Create.tsx index 439de94590..e97c4be89a 100644 --- a/packages/app-address-book/src/modals/Create.tsx +++ b/packages/app-address-book/src/modals/Create.tsx @@ -6,7 +6,7 @@ import { I18nProps } from '@polkadot/react-components/types'; import { ActionStatus } from '@polkadot/react-components/Status/types'; import { ModalProps } from '../types'; -import React from 'react'; +import React, { useState } from 'react'; import { AddressRow, Button, Input, InputAddress, Modal } from '@polkadot/react-components'; import keyring from '@polkadot/ui-keyring'; @@ -15,149 +15,50 @@ import translate from '../translate'; interface Props extends ModalProps, I18nProps {} -interface State { - address: string; - isAddressExisting: boolean; - isAddressValid: boolean; - isNameValid: boolean; - isValid: boolean; - name: string; - tags: string[]; -} +function Create ({ onClose, onStatusChange, t }: Props): React.ReactElement { + const [{ isNameValid, name }, setName] = useState<{ isNameValid: boolean; name: string }>({ isNameValid: true, name: 'new address' }); + const [{ address, isAddressExisting, isAddressValid }, setAddress] = useState<{ address: string; isAddressExisting: boolean; isAddressValid: boolean }>({ address: '', isAddressExisting: false, isAddressValid: false }); + const isValid = isAddressValid && isNameValid; -class Create extends React.PureComponent { - public state: State = { - address: '', - isAddressExisting: false, - isAddressValid: false, - isNameValid: true, - isValid: false, - name: 'new address', - tags: [] - }; + const _onChangeAddress = (input: string): void => { + let address = ''; + let isAddressValid = true; + let isAddressExisting = false; - public render (): React.ReactNode { - const { t } = this.props; - const { address, isAddressValid, isNameValid, isValid, name } = this.state; + try { + address = keyring.encodeAddress( + keyring.decodeAddress(input) + ); + isAddressValid = keyring.isAvailable(address); - return ( - - {t('Add an address')} - - - - - - - - -