From df9c515326ffcd5565fe00f1d1cac527fdd8b11e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 23 Jan 2021 09:23:46 +0100 Subject: [PATCH] Display all balance instances (#4479) --- package.json | 6 +- packages/page-contracts/package.json | 2 +- packages/react-api/package.json | 2 +- packages/react-api/src/Api.tsx | 2 +- packages/react-components/src/AddressInfo.tsx | 90 ++++++----- yarn.lock | 142 +++++++++--------- 6 files changed, 127 insertions(+), 117 deletions(-) diff --git a/package.json b/package.json index a0ac230c8b..7e68e2acb7 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,13 @@ "packages/*" ], "resolutions": { - "@polkadot/api": "^3.5.2-9", - "@polkadot/api-contract": "^3.5.2-9", + "@polkadot/api": "^3.5.2-10", + "@polkadot/api-contract": "^3.5.2-10", "@polkadot/hw-ledger": "^5.3.2-7", "@polkadot/keyring": "^5.3.2-7", "@polkadot/networks": "^5.3.2-7", "@polkadot/phishing": "^0.3.22", - "@polkadot/types": "^3.5.2-9", + "@polkadot/types": "^3.5.2-10", "@polkadot/util": "^5.3.2-7", "@polkadot/util-crypto": "^5.3.2-7", "@polkadot/wasm-crypto": "^3.2.1", diff --git a/packages/page-contracts/package.json b/packages/page-contracts/package.json index cc87621460..6b564d78ef 100644 --- a/packages/page-contracts/package.json +++ b/packages/page-contracts/package.json @@ -10,6 +10,6 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.12.5", - "@polkadot/api-contract": "^3.5.2-9" + "@polkadot/api-contract": "^3.5.2-10" } } diff --git a/packages/react-api/package.json b/packages/react-api/package.json index 0c0da82218..63f6e87f43 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/polkadot-js/apps/tree/master/packages/react-api#readme", "dependencies": { "@babel/runtime": "^7.12.5", - "@polkadot/api": "^3.5.2-9", + "@polkadot/api": "^3.5.2-10", "@polkadot/extension-dapp": "^0.36.2-8", "@polkadot/x-rxjs": "^5.3.2-7", "fflate": "^0.6.0" diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index bc58e8a8fb..20e86077be 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -51,7 +51,7 @@ interface ChainData { systemVersion: string; } -export const DEFAULT_DECIMALS = registry.createType('u32', 15); +export const DEFAULT_DECIMALS = registry.createType('u32', 12); export const DEFAULT_SS58 = registry.createType('u32', addressDefaults.prefix); let api: ApiPromise; diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index e099d47439..1a56ac6fad 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -2,16 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 import type { TFunction } from 'i18next'; -import type { DeriveBalancesAll, DeriveDemocracyLock, DeriveStakingAccount } from '@polkadot/api-derive/types'; +import type { DeriveBalancesAccountData, DeriveBalancesAll, DeriveDemocracyLock, DeriveStakingAccount } from '@polkadot/api-derive/types'; import type { BlockNumber, LockIdentifier, ValidatorPrefsTo145 } from '@polkadot/types/interfaces'; import BN from 'bn.js'; -import React from 'react'; +import React, { useRef } from 'react'; import styled from 'styled-components'; import { withCalls, withMulti } from '@polkadot/react-api/hoc'; import { Expander, Icon, Tooltip } from '@polkadot/react-components'; -import { useAccounts, useApi, useCall } from '@polkadot/react-hooks'; +import { useApi, useCall } from '@polkadot/react-hooks'; import { BlockToTime, FormatBalance } from '@polkadot/react-query'; import { BN_ZERO, formatBalance, formatNumber, hexToString, isObject } from '@polkadot/util'; @@ -216,25 +216,7 @@ function renderValidatorPrefs ({ stakingInfo, withValidatorPrefs = false }: Prop ); } -function renderBalances (props: Props, allAccounts: string[], bestNumber: BlockNumber | undefined, t: TFunction): React.ReactNode { - const { address, balancesAll, democracyLocks, stakingInfo, withBalance = true, withBalanceToggle = false } = props; - const balanceDisplay = withBalance === true - ? DEFAULT_BALANCES - : withBalance || false; - - if (!bestNumber || !balanceDisplay) { - return null; - } - - const [ownBonded, otherBonded] = calcBonded(stakingInfo, balanceDisplay.bonded); - const isAllLocked = !!balancesAll && balancesAll.lockedBreakdown.some(({ amount }): boolean => amount.isMax()); - const lookup = { - democrac: t('via Democracy/Vote'), - phrelect: t('via Council/Vote'), - 'staking ': t('via Staking/Bond'), - 'vesting ': t('via Vesting') - }; - +function createBalanceItems (index: number, lookup: Record, t: TFunction, { address, balanceDisplay, balancesAll, bestNumber, democracyLocks, isAllLocked, otherBonded, ownBonded, stakingInfo, withBalanceToggle }: { address: string; balanceDisplay: BalanceActiveType; balancesAll?: DeriveBalancesAll | DeriveBalancesAccountData; bestNumber: BlockNumber; democracyLocks?: DeriveDemocracyLock[]; isAllLocked: boolean; otherBonded: BN[]; ownBonded: BN; stakingInfo?: DeriveStakingAccount; withBalanceToggle: boolean }): React.ReactNode { const allItems = ( <> {!withBalanceToggle && balancesAll && balanceDisplay.total && ( @@ -246,16 +228,16 @@ function renderBalances (props: Props, allAccounts: string[], bestNumber: BlockN /> )} - {balancesAll && balanceDisplay.available && ( + {balancesAll && balanceDisplay.available && (balancesAll as DeriveBalancesAll).availableBalance && ( <>