From 6ef01c0024a2e314e08a4e00a309c09cdff101af Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 1 Jun 2019 08:36:28 +0200 Subject: [PATCH] Render AddressRow balances from AddressInfo (#1259) * Render AddressRow balances from AddressInfo * Extract BalanceActiveType * Filtering around AddressSummary children --- packages/app-staking/src/Overview/Address.tsx | 7 +- packages/apps/src/Apps.tsx | 7 +- packages/apps/webpack.config.js | 3 + packages/ui-app/src/AddressInfo.tsx | 53 ++++++++-- packages/ui-app/src/AddressRow.tsx | 11 +-- packages/ui-app/src/AddressSummary.tsx | 96 ++++--------------- packages/ui-app/src/styles/components.css | 25 ++--- 7 files changed, 92 insertions(+), 110 deletions(-) diff --git a/packages/app-staking/src/Overview/Address.tsx b/packages/app-staking/src/Overview/Address.tsx index 01f353003c..021737897a 100644 --- a/packages/app-staking/src/Overview/Address.tsx +++ b/packages/app-staking/src/Overview/Address.tsx @@ -79,7 +79,7 @@ class Address extends React.PureComponent { const isAuthor = [address, controllerId, stashId].includes(lastAuthor); const bonded = stakers && !stakers.own.isZero() ? [stakers.own, stakers.total.sub(stakers.own)] - : undefined; + : true; if ((filter === 'hasNominators' && !this.hasNominators()) || (filter === 'noNominators' && this.hasNominators()) @@ -92,15 +92,14 @@ class Address extends React.PureComponent { return (
{this.renderNominators()} - {this.renderOffline()} + {this.renderOffline()} { isAuthor && stashId ?
#{lastBlock}
diff --git a/packages/apps/src/Apps.tsx b/packages/apps/src/Apps.tsx index 11b4ae8c51..e37b515960 100644 --- a/packages/apps/src/Apps.tsx +++ b/packages/apps/src/Apps.tsx @@ -5,8 +5,11 @@ import { BareProps } from '@polkadot/ui-app/types'; import { SideBarTransition, SIDEBAR_TRANSITION_DURATION, SIDEBAR_MENU_THRESHOLD } from './constants'; -import React from 'react'; +// this is disabled, Chrome + WASM memory leak makes it slow & laggy. If enabled +// we also need to export the default as hot(Apps) (last line) // import { hot } from 'react-hot-loader/root'; + +import React from 'react'; import store from 'store'; import { ThemeProvider } from 'styled-components'; import Signer from '@polkadot/ui-signer'; @@ -176,4 +179,4 @@ class Apps extends React.Component { } } -export default Apps; // hot(Apps); +export default Apps; diff --git a/packages/apps/webpack.config.js b/packages/apps/webpack.config.js index 2d76acd48d..26a199708d 100644 --- a/packages/apps/webpack.config.js +++ b/packages/apps/webpack.config.js @@ -187,6 +187,9 @@ function createWebpack ({ alias = {}, context, name = 'index' }) { isProd ? null : new WebpackPluginServe({ + hmr: false, // switch off, Chrome WASM memory leak + liveReload: false, // explict off, overrides hmr + progress: false, // since we have hmr off, disable port: 3000, static: path.join(process.cwd(), '/build') }) diff --git a/packages/ui-app/src/AddressInfo.tsx b/packages/ui-app/src/AddressInfo.tsx index 78f6649d6c..a01864b1bb 100644 --- a/packages/ui-app/src/AddressInfo.tsx +++ b/packages/ui-app/src/AddressInfo.tsx @@ -5,6 +5,7 @@ import { DerivedBalances, DerivedStaking } from '@polkadot/api-derive/types'; import { BareProps, I18nProps } from './types'; +import BN from 'bn.js'; import React from 'react'; import styled from 'styled-components'; import { formatBalance, formatNumber } from '@polkadot/util'; @@ -15,13 +16,27 @@ import translate from './translate'; import CryptoType from './CryptoType'; import Label from './Label'; +// true to display, or (for bonded) provided values [own, ...all extras] +export type BalanceActiveType = { + available?: boolean, + bonded?: boolean | Array, + free?: boolean, + redeemable?: boolean, + unlocking?: boolean +}; + +export type CryptoActiveType = { + crypto?: boolean, + nonce?: boolean +}; + type Props = BareProps & I18nProps & { balances_all?: DerivedBalances, children?: React.ReactNode, staking_info?: DerivedStaking, value: string, - withBalance?: boolean | { available?: boolean, bonded?: boolean, free?: boolean, redeemable?: boolean, unlocking?: boolean }, - withExtended?: boolean | { crypto?: boolean, nonce?: boolean } + withBalance?: boolean | BalanceActiveType, + withExtended?: boolean | CryptoActiveType }; // {
{formatBalance(balances_all.availableBalance)}
)} - {balanceDisplay.bonded && staking_info && staking_info.stakingLedger && staking_info.accountId.eq(staking_info.stashId) && ( - <> - } - params={accountId} - /> +
+ +
); } protected renderChildren () { const { children } = this.props; + // we need children, or when an array, at least 1 non-empty value + const hasChildren = !children + ? false + : Array.isArray(children) + ? children.filter((child) => child).length !== 0 + : true; - if (!children || (Array.isArray(children) && children.length === 0)) { + if (!hasChildren) { return null; } @@ -352,23 +311,6 @@ class AddressSummary extends React.PureComponent { ); } - protected renderNonce () { - const { t, withNonce } = this.props; - const { address } = this.state; - - if (!withNonce || !address) { - return null; - } - - return ( - {t('transactions')}} - params={address} - /> - ); - } - protected renderSaveIcon (callback: () => void) { return (