From 31796b87f30337e8fcf78dd354c7a663f0124cdf Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 6 Apr 2020 12:28:29 +0200 Subject: [PATCH] ChangePass from TxComponent (#2520) * ChangePass from TxComponent * Import as functional * Cleanups (vanity) * Use bundled node --- .github/workflows/pr-any.yml | 3 - .github/workflows/push-master.yml | 3 - .../src/Accounts/modals/ChangePass.tsx | 195 +++++++--------- .../src/Accounts/modals/Import.tsx | 208 +++++++++--------- packages/page-accounts/src/Vanity/index.tsx | 135 ++++-------- 5 files changed, 219 insertions(+), 325 deletions(-) diff --git a/.github/workflows/pr-any.yml b/.github/workflows/pr-any.yml index 9284f7652a..d3d23417eb 100644 --- a/.github/workflows/pr-any.yml +++ b/.github/workflows/pr-any.yml @@ -10,9 +10,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - name: ${{ matrix.step }} run: | yarn install --immutable | grep -v 'YN0013' diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml index 006a66c74c..74dac8b15b 100644 --- a/.github/workflows/push-master.yml +++ b/.github/workflows/push-master.yml @@ -16,9 +16,6 @@ jobs: - uses: actions/checkout@v1 with: token: ${{ secrets.GH_PAT }} - - uses: actions/setup-node@v1 - with: - node-version: '12.x' - name: ${{ matrix.step }} env: CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} diff --git a/packages/page-accounts/src/Accounts/modals/ChangePass.tsx b/packages/page-accounts/src/Accounts/modals/ChangePass.tsx index 1078d0fa6a..68613009ce 100644 --- a/packages/page-accounts/src/Accounts/modals/ChangePass.tsx +++ b/packages/page-accounts/src/Accounts/modals/ChangePass.tsx @@ -2,71 +2,83 @@ // 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 React from 'react'; -import { AddressRow, Button, Modal, Password, TxComponent } from '@polkadot/react-components'; -import { ActionStatus } from '@polkadot/react-components/Status/types'; +import React, { useCallback, useState } from 'react'; +import { AddressRow, Button, Modal, Password } from '@polkadot/react-components'; import keyring from '@polkadot/ui-keyring'; -import translate from '../../translate'; +import { useTranslation } from '../../translate'; -interface Props extends I18nProps { +interface Props { + className?: string; address: string; onClose: () => void; } -interface State { +interface NewPass { isNewValid: boolean; - isOldValid: boolean; newPass: string; +} + +interface OldPass { + isOldValid: boolean; oldPass: string; } -class ChangePass extends TxComponent { - public state: State = { - isNewValid: false, - isOldValid: false, - newPass: '', - oldPass: '' - }; +function ChangePass ({ address, className, onClose }: Props): React.ReactElement { + const { t } = useTranslation(); + const [{ isNewValid, newPass }, setNewPass] = useState({ isNewValid: false, newPass: '' }); + const [{ isOldValid, oldPass }, setOldPass] = useState({ isOldValid: false, oldPass: '' }); - public render (): React.ReactNode { - const { t } = this.props; + const _onChangeNew = useCallback( + (newPass: string) => + setNewPass({ isNewValid: keyring.isPassValid(newPass), newPass }), + [] + ); - return ( - - {this.renderContent()} - {this.renderButtons()} - - ); - } + const _onChangeOld = useCallback( + (oldPass: string) => + setOldPass({ isOldValid: keyring.isPassValid(oldPass), oldPass }), + [] + ); - private renderButtons (): React.ReactNode { - const { onClose, t } = this.props; - const { isNewValid, isOldValid } = this.state; + const _doChange = useCallback( + (): void => { + const account = address && keyring.getPair(address); - return ( - -