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 {