HACK for Polkadot old/new DOTs (#3402)
* HACK for Polkadot old/new DOTs * Format M balances
This commit is contained in:
parent
56ac2ab739
commit
7bc5c314c4
@ -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);
|
||||
|
||||
@ -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<string, Record<string, string>> {
|
||||
}
|
||||
|
||||
async function retrieve (api: ApiPromise): Promise<ChainData> {
|
||||
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<ChainData> {
|
||||
]);
|
||||
|
||||
// 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 || '<unknown>').toString(),
|
||||
systemChainType,
|
||||
systemName: systemName.toString(),
|
||||
|
||||
@ -30,8 +30,11 @@ function format (value: Compact<any> | 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}.<span className='ui--FormatBalance-postfix'>{minor}</span>{unit}{labelPost || ''}</>;
|
||||
}
|
||||
|
||||
return <>{`${prefix}${isShort ? '' : '.'}`}{!isShort && (<><span className='ui--FormatBalance-postfix'>{`000${postfix || ''}`.slice(-3)}</span></>)}{`${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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user