From a9cd43c8f02a35ece97a70a70c8498e4270fd74a Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 20 Sep 2019 12:04:58 +0200 Subject: [PATCH] Some more func component conversions (#1639) --- packages/app-accounts/src/index.tsx | 124 +++++---------- packages/app-accounts/src/modals/Create.tsx | 3 + .../src/modals/CreateConfirmation.tsx | 2 + packages/app-accounts/src/modals/Transfer.tsx | 137 ++++++++--------- packages/app-address-book/src/Address.tsx | 143 ++++++++---------- packages/app-address-book/src/Overview.tsx | 81 ++++------ packages/app-address-book/src/index.tsx | 125 ++++----------- .../app-address-book/src/modals/Create.tsx | 135 +++++++---------- packages/app-dashboard/src/Spacer.tsx | 12 +- packages/app-dashboard/src/index.tsx | 72 ++++----- packages/app-explorer/src/BlockInfo/index.tsx | 66 +++----- packages/app-generic-asset/src/AssetCard.tsx | 68 ++++----- packages/app-generic-asset/src/Assets.tsx | 106 +++++-------- packages/app-generic-asset/src/index.tsx | 72 ++++----- .../Account/InputValidationController.tsx | 46 ++---- .../Account/InputValidationSessionKey.tsx | 49 +++--- .../src/Actions/Account/Nominate.tsx | 115 +++++--------- packages/app-staking/src/Actions/Accounts.tsx | 136 ++++++----------- packages/app-staking/src/index.tsx | 58 +++---- 19 files changed, 585 insertions(+), 965 deletions(-) diff --git a/packages/app-accounts/src/index.tsx b/packages/app-accounts/src/index.tsx index 24149838b4..b4e3ebbef1 100644 --- a/packages/app-accounts/src/index.tsx +++ b/packages/app-accounts/src/index.tsx @@ -6,11 +6,10 @@ import { AppProps, I18nProps } from '@polkadot/react-components/types'; import { ComponentProps, LocationProps } from './types'; import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { Route, Switch } from 'react-router'; import accountObservable from '@polkadot/ui-keyring/observable/accounts'; import { HelpOverlay, Tabs } from '@polkadot/react-components'; -import { TabItem } from '@polkadot/react-components/Tabs'; import { withMulti, withObservable } from '@polkadot/react-api'; import basicMd from './md/basic.md'; @@ -23,92 +22,20 @@ interface Props extends AppProps, I18nProps { location: any; } -interface State { - hidden: string[]; - tabs: TabItem[]; -} +function AccountsApp ({ allAccounts = {}, basePath, location, onStatusChange, t }: Props): React.ReactElement { + const [hidden, setHidden] = useState(['vanity']); -class AccountsApp extends React.PureComponent { - public state: State; - - public constructor (props: Props) { - super(props); - - const { allAccounts = {}, t } = props; - const baseState = Object.keys(allAccounts).length !== 0 - ? AccountsApp.showTabsState() - : AccountsApp.hideTabsState(); - - this.state = { - ...(baseState as State), - tabs: [ - { - isRoot: true, - name: 'overview', - text: t('My accounts') - }, - { - name: 'vanity', - text: t('Vanity address') - } - ] - }; - } - - private static showTabsState (): Partial { - return { - hidden: [] as string[] - }; - } - - private static hideTabsState (): Partial { - // Hide vanity as well - since the route order and matching changes, the - // /create/:seed route become problematic, so don't allow that option - return { - hidden: ['vanity'] - }; - } - - public static getDerivedStateFromProps ({ allAccounts = {} }: Props, { hidden }: State): State | null { - const hasAddresses = Object.keys(allAccounts).length !== 0; - - if (hidden.length === 0) { - return hasAddresses - ? null - : AccountsApp.hideTabsState() as State; - } - - return hasAddresses - ? AccountsApp.showTabsState() as State - : null; - } - - public render (): React.ReactNode { - const { basePath } = this.props; - const { hidden, tabs } = this.state; - - return ( -
- -
-
- - - - -
+ useEffect((): void => { + setHidden( + Object.keys(allAccounts).length !== 0 + ? [] + : ['vanity'] ); - } + }, [allAccounts]); - private renderComponent (Component: React.ComponentType): (props: LocationProps) => React.ReactNode { + const _renderComponent = (Component: React.ComponentType): (props: LocationProps) => React.ReactNode => { + // eslint-disable-next-line react/display-name return ({ match }: LocationProps): React.ReactNode => { - const { basePath, location, onStatusChange } = this.props; - return ( { /> ); }; - } + }; + + return ( +
+ +
+
+ + + + +
+ ); } export default withMulti( diff --git a/packages/app-accounts/src/modals/Create.tsx b/packages/app-accounts/src/modals/Create.tsx index 3efe6b78f9..274bac0678 100644 --- a/packages/app-accounts/src/modals/Create.tsx +++ b/packages/app-accounts/src/modals/Create.tsx @@ -170,7 +170,9 @@ class Create extends React.PureComponent {