diff --git a/packages/apps/src/SideBar/NodeInfo.tsx b/packages/apps/src/SideBar/NodeInfo.tsx index 914bfc2077..2cce89069e 100644 --- a/packages/apps/src/SideBar/NodeInfo.tsx +++ b/packages/apps/src/SideBar/NodeInfo.tsx @@ -15,34 +15,31 @@ interface Props extends ApiProps, BareProps {} // eslint-disable-next-line @typescript-eslint/no-var-requires const pkgJson = require('../../package.json'); -class NodeInfo extends React.PureComponent { - public render (): React.ReactNode { - const { api, className } = this.props; - const uiInfo = `apps v${pkgJson.version}`; +const uiInfo = `apps v${pkgJson.version}`; - return ( -
- {this.renderNode()} -
{api.libraryInfo.replace('@polkadot/', '')}
-
{uiInfo}
-
- ); +function renderNode ({ isApiReady }: Props): React.ReactNode { + if (!isApiReady) { + return null; } - private renderNode (): React.ReactNode { - const { isApiReady } = this.props; + return ( +
+   + +
+ ); +} - if (!isApiReady) { - return null; - } +function NodeInfo (props: Props): React.ReactElement { + const { api, className } = props; - return ( -
-   - -
- ); - } + return ( +
+ {renderNode(props)} +
{api.libraryInfo.replace('@polkadot/', '')}
+
{uiInfo}
+
+ ); } export default withApi( diff --git a/packages/apps/src/TopBar.tsx b/packages/apps/src/TopBar.tsx index 8dfefd879a..df277eafef 100644 --- a/packages/apps/src/TopBar.tsx +++ b/packages/apps/src/TopBar.tsx @@ -12,23 +12,19 @@ interface Props { className?: string; } -class TopBar extends React.PureComponent { - public render (): React.ReactNode { - const { className } = this.props; - - return ( -
-
-   - -
-
-   - -
+function TopBar ({ className }: Props): React.ReactElement { + return ( +
+
+   +
- ); - } +
+   + +
+
+ ); } export default styled(TopBar)` diff --git a/packages/apps/src/overlays/Connecting.tsx b/packages/apps/src/overlays/Connecting.tsx index 741ff1af89..0c3a2ac7ef 100644 --- a/packages/apps/src/overlays/Connecting.tsx +++ b/packages/apps/src/overlays/Connecting.tsx @@ -16,60 +16,57 @@ import BaseOverlay from './Base'; type Props = I18nProps & ApiProps; const isFirefox = typeof (window as any).InstallTrigger !== 'undefined'; +const wsUrl = settings.apiUrl; +const isWs = wsUrl.startsWith('ws://'); +const isWsRemote = wsUrl.includes('127.0.0.1'); +const isHttps = window.location.protocol.startsWith('https:'); -class Connecting extends React.PureComponent { - public render (): React.ReactNode { - return this.renderExtension() || this.renderConnecting(); +function renderExtension ({ className, isWaitingInjected, t }: Props): React.ReactNode { + if (!isWaitingInjected) { + return null; } - private renderExtension (): React.ReactNode { - const { className, isWaitingInjected, t } = this.props; + return ( + +
{t('Waiting for authorization from the extension. Please open the installed extension and approve or reject access.')}
+
+ ); +} - if (!isWaitingInjected) { - return null; - } - - return ( - -
{t('Waiting for authorization from the extension. Please open the installed extension and approve or reject access.')}
-
- ); +function renderConnecting ({ className, isApiConnected, t }: Props): React.ReactNode { + if (isApiConnected) { + return null; } - private renderConnecting (): React.ReactNode { - const { className, isApiConnected, t } = this.props; + return ( + +
{t('You are not connected to a node. Ensure that your node is running and that the Websocket endpoint is reachable.')}
+ { + isFirefox && isWs + ?
{t('With the Firefox browser connecting to insecure WebSockets ({{wsUrl}}) will fail due to the browser not allowing localhost access from a secure site.', { replace: { wsUrl } })}
+ : undefined + } + { + isWs && isWsRemote && isHttps + ?
{t('You are connecting from a secure location to an insecure WebSocket ({{wsUrl}}). Due to browser mixed-content security policies this connection type is not allowed. Change the RPC service to a secure \'wss\' endpoint.', { replace: { wsUrl } })}
+ : undefined + } +
+ ); +} - if (isApiConnected) { - return null; - } - - const wsUrl = settings.apiUrl; - const isWs = wsUrl.startsWith('ws://'); - const isWsRemote = wsUrl.includes('127.0.0.1'); - const isHttps = window.location.protocol.startsWith('https:'); - - return ( - -
{t('You are not connected to a node. Ensure that your node is running and that the Websocket endpoint is reachable.')}
- { - isFirefox && isWs - ?
{t('With the Firefox browser connecting to insecure WebSockets ({{wsUrl}}) will fail due to the browser not allowing localhost access from a secure site.', { replace: { wsUrl } })}
- : undefined - } - { - isWs && isWsRemote && isHttps - ?
{t('You are connecting from a secure location to an insecure WebSocket ({{wsUrl}}). Due to browser mixed-content security policies this connection type is not allowed. Change the RPC service to a secure \'wss\' endpoint.', { replace: { wsUrl } })}
- : undefined - } -
- ); - } +function Connecting (props: Props): React.ReactElement { + return ( + <> + {renderExtension(props) || renderConnecting(props)} + + ); } export default withMulti( diff --git a/packages/react-components/src/ActionItem.tsx b/packages/react-components/src/ActionItem.tsx index 574b04ba7b..5d952fcf1d 100644 --- a/packages/react-components/src/ActionItem.tsx +++ b/packages/react-components/src/ActionItem.tsx @@ -28,37 +28,25 @@ export const styles = ` ${proposedActionStyles} `; -class ActionItem extends React.PureComponent { - public render (): React.ReactNode { - const { className, children, accessory } = this.props; - - return ( - -
-
-
- {this.renderProposal()} -
- {accessory} +function ActionItem ({ className, children, accessory, idNumber, proposal, expandNested }: Props): React.ReactElement { + return ( + +
+
+
+
- {children} + {accessory}
- - ); - } - - private renderProposal (): React.ReactNode { - const { idNumber, proposal, expandNested } = this.props; - - return ( - - ); - } + {children} +
+
+ ); } -export default withRouter(styled(ActionItem as React.ComponentClass)`${styles}`); +export default withRouter(styled(ActionItem)`${styles}`); diff --git a/packages/react-components/src/AddressCard.tsx b/packages/react-components/src/AddressCard.tsx index c77e0fb564..73409a2399 100644 --- a/packages/react-components/src/AddressCard.tsx +++ b/packages/react-components/src/AddressCard.tsx @@ -20,30 +20,27 @@ interface Props extends AddressProps { withExplorer?: boolean; } -class AddressCard extends React.PureComponent { - public render (): React.ReactNode { - const { className, value, withExplorer } = this.props; - - return ( - - - {withExplorer && ( -
- -
- )} -
- ); - } +function AddressCard (props: Props): React.ReactElement { + const { className, value, withExplorer } = props; + return ( + + + {withExplorer && ( +
+ +
+ )} +
+ ); } -export default translate(styled(AddressCard as React.ComponentClass)` +export default translate(styled(AddressCard)` display: flex; flex-direction: column; justify-content: space-between; diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 7d5a57d5a3..ac202876ab 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -49,239 +49,225 @@ type Props = BareProps & I18nProps & { withValidatorPrefs?: boolean | ValidatorPrefsType; }; -class AddressInfo extends React.PureComponent { - public render (): React.ReactNode { - const { children, className } = this.props; +// either true (filtered above already) or [own, ...all extras bonded funds from nominators] +function renderBonded ({ staking_info, t }: Props, bonded: true | BN[]): React.ReactNode { + let value; - return ( -
-
- {this.renderBalances()} - {this.renderHexSessionId()} - {this.renderValidatorPrefs()} - {this.renderRewardDestination()} -
+ if (Array.isArray(bonded)) { + // Get the sum of funds bonded by any nominator (if available) + const extras = bonded.filter((_, index): boolean => index !== 0); + const extra = extras.reduce((total, value): BN => total.add(value), new BN(0)).gtn(0) + ? `(+${extras.map((bonded): string => formatBalance(bonded)).join(', ')})` + : ''; - {this.renderExtended()} - {children && ( -
- {children} -
- )} -
- ); + value = `${formatBalance(bonded[0])} ${extra}`; + } else if (staking_info && staking_info.stakingLedger && staking_info.accountId.eq(staking_info.stashId)) { + value = formatBalance(staking_info.stakingLedger.active); } - private renderBalances (): React.ReactNode { - const { balances_all, staking_info, t, withBalance = true } = this.props; - const balanceDisplay = withBalance === true - ? { available: true, bonded: true, free: true, redeemable: true, unlocking: true } - : withBalance || undefined; - - if (!balanceDisplay || !balances_all) { - return null; - } - - return ( + return value + ? ( <> - {balanceDisplay.free && ( - <> -