diff --git a/packages/app-123code/src/AccountSelector.tsx b/packages/app-123code/src/AccountSelector.tsx index 3f4f2b5a02..d8af701408 100644 --- a/packages/app-123code/src/AccountSelector.tsx +++ b/packages/app-123code/src/AccountSelector.tsx @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import React from 'react'; +import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { Bubble, InputAddress } from '@polkadot/react-components'; import { AccountIndex, Balance, Nonce } from '@polkadot/react-query'; @@ -12,47 +12,32 @@ interface Props { onChange: (accountId?: string) => void; } -interface State { - accountId?: string; -} +function AccountSelector ({ className, onChange }: Props): React.ReactElement { + const [accountId, setAccountId] = useState(); -class AccountSelector extends React.PureComponent { - public state: State = {}; + useEffect((): void => onChange(accountId), [accountId]); - public render (): React.ReactNode { - const { className } = this.props; - const { accountId } = this.state; - - return ( -
- -
- - - - - - - - - -
-
- ); - } - - private onChange = (accountId?: string): void => { - const { onChange } = this.props; - - this.setState({ accountId }, (): void => - onChange(accountId) - ); - } + return ( +
+ +
+ + + + + + + + + +
+
+ ); } export default styled(AccountSelector)` diff --git a/packages/app-123code/src/SummaryBar.tsx b/packages/app-123code/src/SummaryBar.tsx index 4cbd7a8fed..8fbb0544cc 100644 --- a/packages/app-123code/src/SummaryBar.tsx +++ b/packages/app-123code/src/SummaryBar.tsx @@ -8,7 +8,7 @@ import { ApiProps } from '@polkadot/react-api/types'; import { BareProps, I18nProps } from '@polkadot/react-components/types'; import BN from 'bn.js'; -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { withCalls } from '@polkadot/react-api/with'; import { Bubble, IdentityIcon } from '@polkadot/react-components'; import { formatBalance, formatNumber } from '@polkadot/util'; @@ -27,66 +27,51 @@ interface Props extends ApiProps, BareProps, I18nProps { system_version?: string; } -interface State { - nextUp: AccountId[]; -} +function SummaryBar ({ balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, staking_intentions = [], session_validators = [], state_getRuntimeVersion, system_chain, system_name, system_version }: Props): React.ReactElement { + const [nextUp, setNextUp] = useState([]); -class SummaryBar extends React.PureComponent { - public state: State = { - nextUp: [] - }; - - public static getDerivedStateFromProps ({ staking_intentions, session_validators }: Props): State | null { - if (!staking_intentions || !session_validators) { - return null; - } - - return { - nextUp: staking_intentions.filter((accountId): boolean => + useEffect((): void => { + if (staking_intentions && session_validators) { + setNextUp(staking_intentions.filter((accountId): boolean => !session_validators.find((validatorId): boolean => validatorId.eq(accountId) ) - ) - }; - } + )); + } + }, [staking_intentions, session_validators]); - public render (): React.ReactNode { - const { balances_totalIssuance, chain_bestNumber, chain_bestNumberLag, session_validators = [], state_getRuntimeVersion, system_chain, system_name, system_version } = this.props; - const { nextUp } = this.state; - - return ( - -
- - {system_name} v{system_version} - - - {system_chain} - - { - state_getRuntimeVersion && - `${state_getRuntimeVersion.implName} v${state_getRuntimeVersion.implVersion}` - } - - {formatNumber(chain_bestNumber)} ({formatNumber(chain_bestNumberLag)} lag) - - { - session_validators.map((accountId, index): React.ReactNode => ( - - )) - } - { - nextUp.map((accountId, index): React.ReactNode => ( - - )) - } - - {formatBalance(balances_totalIssuance)} - -
-
- ); - } + return ( + +
+ + {system_name} v{system_version} + + + {system_chain} + + { + state_getRuntimeVersion && + `${state_getRuntimeVersion.implName} v${state_getRuntimeVersion.implVersion}` + } + + {formatNumber(chain_bestNumber)} ({formatNumber(chain_bestNumberLag)} lag) + + { + session_validators.map((accountId, index): React.ReactNode => ( + + )) + } + { + nextUp.map((accountId, index): React.ReactNode => ( + + )) + } + + {formatBalance(balances_totalIssuance)} + +
+
+ ); } // inject the actual API calls automatically into props diff --git a/packages/app-123code/src/index.tsx b/packages/app-123code/src/index.tsx index 7048a5888e..199a95be3d 100644 --- a/packages/app-123code/src/index.tsx +++ b/packages/app-123code/src/index.tsx @@ -10,7 +10,7 @@ import { AppProps, I18nProps } from '@polkadot/react-components/types'; // external imports (including those found in the packages/* // of this repo) -import React from 'react'; +import React, { useState } from 'react'; // local imports and components import AccountSelector from './AccountSelector'; @@ -18,33 +18,21 @@ import SummaryBar from './SummaryBar'; import Transfer from './Transfer'; import translate from './translate'; -// define out internal types +// define our internal types interface Props extends AppProps, I18nProps {} -interface State { - accountId?: string; -} +function App ({ className }: Props): React.ReactElement { + const [accountId, setAccountId] = useState(); -class App extends React.PureComponent { - public state: State = {}; - - public render (): React.ReactNode { - const { accountId } = this.state; - - return ( - // in all apps, the main wrapper is setup to allow the padding - // and margins inside the application. (Just from a consistent pov) -
- - - -
- ); - } - - private onAccountChange = (accountId?: string): void => { - this.setState({ accountId }); - } + return ( + // in all apps, the main wrapper is setup to allow the padding + // and margins inside the application. (Just from a consistent pov) +
+ + + +
+ ); } export default translate(App); diff --git a/packages/react-signer/src/PasswordCheck.tsx b/packages/react-signer/src/PasswordCheck.tsx index 2b83396609..ac6e8c5822 100644 --- a/packages/react-signer/src/PasswordCheck.tsx +++ b/packages/react-signer/src/PasswordCheck.tsx @@ -6,7 +6,6 @@ import { I18nProps } from '@polkadot/react-components/types'; import React from 'react'; import styled from 'styled-components'; -import { withMulti } from '@polkadot/react-api'; import translate from './translate'; @@ -15,18 +14,15 @@ interface Props extends I18nProps { unlockError?: string | null; } -function PasswordCheck (props: Props): React.ReactElement | null { - const { className, unlockError, t } = props; - +function PasswordCheck ({ className, unlockError, t }: Props): React.ReactElement | null { return unlockError ?
{t('wrong password')}
: null; } -export default withMulti( +export default translate( styled(PasswordCheck)` margin-left: 15em; color: #9f3a38; - `, - translate + ` );