From 6a5f37fd0733f24427fcc0b6bba78598026878c9 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 12 Aug 2020 12:49:45 +0200 Subject: [PATCH] Link to extension upgrade, cater for non-existing case (#3401) --- packages/apps-config/src/api/constants.ts | 8 ++++++++ packages/page-accounts/src/Accounts/BannerDOT.tsx | 6 ++++-- .../page-accounts/src/Accounts/BannerExtension.tsx | 14 +++++++++++++- packages/page-council/src/Motions/thresholds.ts | 5 +++-- packages/page-settings/src/useExtensions.ts | 3 ++- packages/react-api/src/Api.tsx | 14 ++++++++++++-- packages/react-api/src/ledger.ts | 5 +++-- .../react-components/src/ConvictionDropdown.tsx | 3 ++- 8 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 packages/apps-config/src/api/constants.ts diff --git a/packages/apps-config/src/api/constants.ts b/packages/apps-config/src/api/constants.ts new file mode 100644 index 0000000000..b404598a0e --- /dev/null +++ b/packages/apps-config/src/api/constants.ts @@ -0,0 +1,8 @@ +// Copyright 2017-2020 @polkadot/app-accounts authors & contributors +// 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; + +export const KUSAMA_GENESIS = '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe'; diff --git a/packages/page-accounts/src/Accounts/BannerDOT.tsx b/packages/page-accounts/src/Accounts/BannerDOT.tsx index b688595070..173baeff55 100644 --- a/packages/page-accounts/src/Accounts/BannerDOT.tsx +++ b/packages/page-accounts/src/Accounts/BannerDOT.tsx @@ -4,13 +4,15 @@ import React, { useState } from 'react'; import { Trans } from 'react-i18next'; +import { POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; import { useApi } from '@polkadot/react-hooks'; +import { formatNumber } from '@polkadot/util'; import Banner from './Banner'; function BannerDOT (): React.ReactElement | null { const { api } = useApi(); - const [isPolkadot] = useState(api.genesisHash.eq('0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3')); + const [isPolkadot] = useState(api.genesisHash.eq(POLKADOT_GENESIS)); if (!isPolkadot) { return null; @@ -18,7 +20,7 @@ function BannerDOT (): React.ReactElement | null { return ( -

On approximately August 21st at 13:15 UTC (block number 1,248,328), the DOT token will undergo a redenomination from its original sale.

+

On approximately August 21st at 13:15 UTC (block number {formatNumber(POLKADOT_DENOM_BLOCK)}), the DOT token will undergo a redenomination from its original sale.

New DOTs will be 100x smaller than DOTs (old). Therefore, your DOT balance will be 100x higher and the price per DOT will be 100x lower. The percentage of the DOTs you own relative to total supply will be unchanged. This will not affect the total value of your position.

See the +

{t('You have {{upgradableCount}} extensions that need to be updated with the latest chain properties in order to display the correct information for the chain you are connected to. This update includes chain metadata and chain properties.', { replace: { upgradableCount } })}

+

Visit your settings page to apply the updates to the injected extensions.

+
+ ); } return ( diff --git a/packages/page-council/src/Motions/thresholds.ts b/packages/page-council/src/Motions/thresholds.ts index c2cc6ef4f1..b252e3750f 100644 --- a/packages/page-council/src/Motions/thresholds.ts +++ b/packages/page-council/src/Motions/thresholds.ts @@ -3,15 +3,16 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { ApiPromise } from '@polkadot/api'; +import { POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; const PROPOSE_THRESHOLDS: Record = { // Polkadot - '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 0.6 + [POLKADOT_GENESIS]: 0.6 }; const SLASH_THRESHOLDS: Record = { // Polkadot - '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 0.75 + [POLKADOT_GENESIS]: 0.75 }; export function getThreshold (api: ApiPromise): number { diff --git a/packages/page-settings/src/useExtensions.ts b/packages/page-settings/src/useExtensions.ts index c907cb479c..12b8acc781 100644 --- a/packages/page-settings/src/useExtensions.ts +++ b/packages/page-settings/src/useExtensions.ts @@ -84,7 +84,8 @@ function filterAll (api: ApiPromise, all: ExtensionKnown[]): Extensions { .map((info): ExtensionInfo | null => { const current = info.known.find(({ genesisHash }) => api.genesisHash.eq(genesisHash)) || null; - return current && (api.runtimeVersion.specVersion.gtn(current.specVersion) || !hasCurrentProperties(api, info)) + // if we cannot find it as known, or either the specVersion or properties mismatches, mark it as upgradable + return !current || api.runtimeVersion.specVersion.gtn(current.specVersion) || !hasCurrentProperties(api, info) ? { ...info, current } : null; }) diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 590f1b3a0d..c58bf81658 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -11,6 +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 { web3Accounts, web3Enable } from '@polkadot/extension-dapp'; import { WsProvider } from '@polkadot/rpc-provider'; import { StatusContext } from '@polkadot/react-components/Status'; @@ -68,7 +69,8 @@ function getDevTypes (): Record> { } async function retrieve (api: ApiPromise): Promise { - const [properties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ + const [, chainProperties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ + api.rpc.chain.getHeader(), api.rpc.system.properties(), api.rpc.system.chain(), api.rpc.system.chainType @@ -93,9 +95,17 @@ 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; + return { injectedAccounts, - properties, + properties: chainProperties, systemChain: (systemChain || '').toString(), systemChainType, systemName: systemName.toString(), diff --git a/packages/react-api/src/ledger.ts b/packages/react-api/src/ledger.ts index f68b056c15..5347ad6f5d 100644 --- a/packages/react-api/src/ledger.ts +++ b/packages/react-api/src/ledger.ts @@ -2,6 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { KUSAMA_GENESIS, POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; import { Ledger } from '@polkadot/ui-keyring'; import uiSettings from '@polkadot/ui-settings'; import { assert } from '@polkadot/util'; @@ -9,8 +10,8 @@ import { assert } from '@polkadot/util'; import { api } from './Api'; const ALLOWED_CHAINS: [string, 'kusama' | 'polkadot'][] = [ - ['0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', 'kusama'], - ['0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3', 'polkadot'] + [KUSAMA_GENESIS, 'kusama'], + [POLKADOT_GENESIS, 'polkadot'] ]; let ledger: Ledger | null = null; diff --git a/packages/react-components/src/ConvictionDropdown.tsx b/packages/react-components/src/ConvictionDropdown.tsx index 9a2f31b787..af6ecd9d74 100644 --- a/packages/react-components/src/ConvictionDropdown.tsx +++ b/packages/react-components/src/ConvictionDropdown.tsx @@ -4,6 +4,7 @@ import BN from 'bn.js'; import React, { useState, useMemo } from 'react'; +import { POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; import { useApi } from '@polkadot/react-hooks'; import Dropdown from './Dropdown'; @@ -22,7 +23,7 @@ const SEC_DAY = 60 * 60 * 24; // REMOVE once Polkadot is upgraded with the correct conviction const PERIODS: Record = { - '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': new BN(403200) + [POLKADOT_GENESIS]: new BN(403200) }; function AvailableDisplay ({ className = '', help, label, onChange, value }: Props): React.ReactElement | null {