diff --git a/packages/apps-routing/src/staking.ts b/packages/apps-routing/src/staking.ts index dc616bdb88..6ab59897c1 100644 --- a/packages/apps-routing/src/staking.ts +++ b/packages/apps-routing/src/staking.ts @@ -4,8 +4,7 @@ import { Route } from './types'; -// import Staking from '@polkadot/app-staking'; -import Staking, { useCounter } from '@polkadot/app-staking'; +import Staking from '@polkadot/app-staking'; const route: Route = { Component: Staking, @@ -18,8 +17,7 @@ const route: Route = { defaultValue: 'Staking' }, icon: 'certificate', - name: 'staking', - useCounter + name: 'staking' }; export default route; diff --git a/packages/page-extrinsics/src/Selection.tsx b/packages/page-extrinsics/src/Selection.tsx index b064f76aff..7fc0ca4da5 100644 --- a/packages/page-extrinsics/src/Selection.tsx +++ b/packages/page-extrinsics/src/Selection.tsx @@ -2,128 +2,67 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { I18nProps } from '@polkadot/react-components/types'; -import { QueueTxExtrinsicAdd } from '@polkadot/react-components/Status/types'; -import { ApiProps } from '@polkadot/react-api/types'; import { SubmittableExtrinsic } from '@polkadot/api/types'; -import React from 'react'; -import { Button, Extrinsic, InputAddress, TxButton, TxComponent } from '@polkadot/react-components'; -import { withApi, withMulti } from '@polkadot/react-api/hoc'; +import React, { useCallback, useState } from 'react'; +import { Button, Extrinsic, InputAddress, TxButton } from '@polkadot/react-components'; +import { useApi } from '@polkadot/react-hooks'; import { BalanceFree } from '@polkadot/react-query'; -import translate from './translate'; +import { useTranslation } from './translate'; -interface Props extends ApiProps, I18nProps { - queueExtrinsic: QueueTxExtrinsicAdd; -} +function Selection (): React.ReactElement { + const { t } = useTranslation(); + const { apiDefaultTxSudo } = useApi(); + const [accountId, setAccountId] = useState(null); + const [extrinsic, setExtrinsic] = useState | null>(null); -interface State { - isValid: boolean; - isValidUnsigned: boolean; - method: SubmittableExtrinsic<'promise'> | null; - accountId?: string | null; -} + const _onExtrinsicChange = useCallback( + (method?: SubmittableExtrinsic<'promise'>) => + setExtrinsic(() => method || null), + [] + ); -class Selection extends TxComponent { - public state: State = { - isValid: false, - isValidUnsigned: false, - method: null - }; - - public render (): React.ReactNode { - const { apiDefaultTxSudo, t } = this.props; - const { accountId, isValid, isValidUnsigned } = this.state; - const extrinsic = this.getExtrinsic() || apiDefaultTxSudo('0x00'); - - return ( -
- {t('free balance')}} - params={accountId} - /> - } - onChange={this.onChangeSender} - type='account' - /> - - - + {t('free balance')}} + params={accountId} /> - - - -
- ); - } - - private nextState (newState: Partial): void { - this.setState( - (prevState: State): State => { - const { method = prevState.method, accountId = prevState.accountId } = newState; - const isValid = !!( - accountId && - accountId.length && - method - ); - - return { - accountId, - isValid, - isValidUnsigned: !!method, - method - }; - } - ); - } - - private onChangeExtrinsic = (method: SubmittableExtrinsic<'promise'> | null = null): void => { - this.nextState({ method }); - } - - private onChangeSender = (accountId: string | null): void => { - this.nextState({ accountId }); - } - - private getExtrinsic (): SubmittableExtrinsic<'promise'> | null { - const { api } = this.props; - const { method } = this.state; - - if (!method) { - return null; - } - - const fn = api.findCall(method.callIndex); - - return api.tx[fn.section][fn.method](...method.args); - } + } + onChange={setAccountId} + type='account' + /> + + + + + + + + ); } -export default withMulti( - Selection, - translate, - withApi -); +export default React.memo(Selection); diff --git a/packages/page-toolbox/src/Unlock.tsx b/packages/page-toolbox/src/Unlock.tsx index eef54f6ccb..14cb586fc1 100644 --- a/packages/page-toolbox/src/Unlock.tsx +++ b/packages/page-toolbox/src/Unlock.tsx @@ -2,78 +2,59 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { I18nProps } from '@polkadot/react-components/types'; import { KeyringPair } from '@polkadot/keyring/types'; -import React from 'react'; -import { AddressRow, Button, Modal, Password, TxComponent } from '@polkadot/react-components'; +import React, { useCallback, useEffect, useState } from 'react'; +import { AddressRow, Button, Modal, Password } from '@polkadot/react-components'; -import translate from './translate'; +import { useTranslation } from './translate'; -interface Props extends I18nProps { +interface Props { onClose: () => void; onUnlock: () => void; pair: KeyringPair | null; } -interface State { - address: string; - password: string; - unlockError: string | null; -} +function Unlock ({ onClose, onUnlock, pair }: Props): React.ReactElement | null { + const { t } = useTranslation(); + const [address, setAddress] = useState(''); + const [password, setPassword] = useState(''); + const [unlockError, setUnlockError] = useState(null); -class Unlock extends TxComponent { - public state: State = { - address: '', - password: '', - unlockError: null - }; + useEffect((): void => { + setAddress(pair?.address || ''); + }, [pair]); - public static getDerivedStateFromProps ({ pair }: Props): Pick { - return { - address: (pair && pair.address) || '' - }; + useEffect((): void => { + setUnlockError(null); + }, [password]); + + const _onUnlock = useCallback( + (): void => { + if (!pair || !pair.isLocked) { + return; + } + + try { + pair.decodePkcs8(password); + } catch (error) { + return setUnlockError(error.message); + } + + onUnlock(); + }, + [onUnlock, pair, password] + ); + + if (!pair) { + return null; } - public render (): React.ReactNode { - const { pair, t } = this.props; - - if (!pair) { - return null; - } - - return ( - - {this.renderContent()} - {this.renderActions()} - - ); - } - - private renderActions (): React.ReactNode { - const { t } = this.props; - - return ( - -