From 73eb4e284ce1eec5fa3bfc869aaca956972573a3 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 12 Apr 2020 15:07:32 +0200 Subject: [PATCH] Address info expander (#2560) * AddressInfo expander cleanups * Mapping of BalanceLock reasons --- packages/react-components/src/AddressInfo.tsx | 37 +++++++++++-------- packages/react-components/src/Expander.tsx | 4 ++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 2b81324776..679f5aac2e 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { DeriveBalancesAll, DeriveStakingAccount } from '@polkadot/api-derive/types'; -import { ValidatorPrefsTo145 } from '@polkadot/types/interfaces'; +import { LockIdentifier, ValidatorPrefsTo145 } from '@polkadot/types/interfaces'; import { BareProps } from './types'; import BN from 'bn.js'; @@ -77,6 +77,18 @@ const DEFAULT_PREFS = { validatorPayment: true }; +function lookupLock (lookup: Record, lockId: LockIdentifier): string { + const lockHex = lockId.toHex(); + + try { + const lockName = hexToString(lockHex); + + return lookup[lockName] || lockName; + } catch (error) { + return lockHex; + } +} + // skip balances retrieval of none of this matches function skipBalancesIf ({ withBalance = true, withExtended = false }: Props): boolean { if (withBalance === true || withExtended === true) { @@ -213,10 +225,16 @@ function renderBalances (props: Props, allAccounts: string[], t: (key: string) = 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') + }; const allItems = ( <> - {balancesAll && balanceDisplay.total && ( + {!withBalanceToggle && balancesAll && balanceDisplay.total && ( <>