diff --git a/packages/apps-config/src/api/constants.ts b/packages/apps-config/src/api/constants.ts index b404598a0e..c5820bb970 100644 --- a/packages/apps-config/src/api/constants.ts +++ b/packages/apps-config/src/api/constants.ts @@ -2,7 +2,9 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -export const POLKADOT_GENESIS = '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'; -export const POLKADOT_DENOM_BLOCK = 1248328; +import BN from 'bn.js'; export const KUSAMA_GENESIS = '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe'; + +export const POLKADOT_GENESIS = '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'; +export const POLKADOT_DENOM_BLOCK = new BN(1248328); diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index c58bf81658..ac021353ba 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -11,7 +11,7 @@ import store from 'store'; import ApiPromise from '@polkadot/api/promise'; import { setDeriveCache, deriveMapCache } from '@polkadot/api-derive/util'; import { typesChain, typesSpec } from '@polkadot/apps-config/api'; -// import { POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; +import { POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; import { web3Accounts, web3Enable } from '@polkadot/extension-dapp'; import { WsProvider } from '@polkadot/rpc-provider'; import { StatusContext } from '@polkadot/react-components/Status'; @@ -69,7 +69,7 @@ function getDevTypes (): Record> { } async function retrieve (api: ApiPromise): Promise { - const [, chainProperties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ + const [bestHeader, chainProperties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ api.rpc.chain.getHeader(), api.rpc.system.properties(), api.rpc.system.chain(), @@ -96,16 +96,15 @@ async function retrieve (api: ApiPromise): Promise { ]); // HACK Horrible hack to try and give some window to the DOT denomination - // const bestNumber = bestHeader.number.toBn(); - // const properties = api.genesisHash.eq(POLKADOT_GENESIS) - // ? bestNumber.gten(POLKADOT_DENOM_BLOCK) - // ? registry.createType('ChainProperties', { ...chainProperties, tokenDecimals: 10, tokenSymbol: 'New DOT' }) - // : registry.createType('ChainProperties', { ...chainProperties, tokenDecimals: 12, tokenSymbol: 'DOT (old)' }) - // : chainProperties; + const properties = api.genesisHash.eq(POLKADOT_GENESIS) + ? bestHeader.number.toBn().gte(POLKADOT_DENOM_BLOCK) + ? registry.createType('ChainProperties', { ...chainProperties, tokenDecimals: 10, tokenSymbol: 'New DOT' }) + : registry.createType('ChainProperties', { ...chainProperties, tokenDecimals: 12, tokenSymbol: 'DOT (old)' }) + : chainProperties; return { injectedAccounts, - properties: chainProperties, + properties, systemChain: (systemChain || '').toString(), systemChainType, systemName: systemName.toString(), diff --git a/packages/react-query/src/FormatBalance.tsx b/packages/react-query/src/FormatBalance.tsx index 8dd8641019..506fac38ce 100644 --- a/packages/react-query/src/FormatBalance.tsx +++ b/packages/react-query/src/FormatBalance.tsx @@ -30,8 +30,11 @@ function format (value: Compact | BN | string, currency: string | null, wit const isShort = _isShort || (withSi && prefix.length >= K_LENGTH); if (prefix.length > M_LENGTH) { - // TODO Format with balance-postfix - return `${formatBalance(value, { withUnit: !!currency })}${labelPost || ''}`; + const [major, rest] = formatBalance(value, { withUnit: !!currency }).split('.'); + const minor = rest.substr(0, 3); + const unit = rest.substr(3); + + return <>{major}.{minor}{unit}{labelPost || ''}; } return <>{`${prefix}${isShort ? '' : '.'}`}{!isShort && (<>{`000${postfix || ''}`.slice(-3)})}{`${currency ? ` ${currency}` : ''}${labelPost || ''}`}; @@ -76,7 +79,7 @@ export default React.memo(styled(FormatBalance)` > .ui--FormatBalance-postfix { font-weight: 100; - opacity: 0.75; + opacity: 0.7; vertical-align: baseline; } }