Link to extension upgrade, cater for non-existing case (#3401)
This commit is contained in:
parent
a1f4e7b1f7
commit
6a5f37fd07
8
packages/apps-config/src/api/constants.ts
Normal file
8
packages/apps-config/src/api/constants.ts
Normal file
@ -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';
|
||||
@ -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 (
|
||||
<Banner type='warning'>
|
||||
<p><Trans key='dotRenom1'>On approximately August 21st at 13:15 UTC (block number 1,248,328), the DOT token will undergo a <a href='#/poll'>redenomination</a> from its original sale.</Trans></p>
|
||||
<p><Trans key='dotRenom1'>On approximately August 21st at 13:15 UTC (block number {formatNumber(POLKADOT_DENOM_BLOCK)}), the DOT token will undergo a <a href='#/poll'>redenomination</a> from its original sale.</Trans></p>
|
||||
<p><Trans key='dotRenom2'>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.</Trans></p>
|
||||
<p><Trans key='dotRenom3'>See the <a
|
||||
href='https://polkadot.network/the-results-are-in/'
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
import { detect } from 'detect-browser';
|
||||
import React from 'react';
|
||||
import { Trans } from 'react-i18next';
|
||||
import useExtensionCounter from '@polkadot/app-settings/useCounter';
|
||||
import { availableExtensions } from '@polkadot/apps-config/extensions';
|
||||
import { isWeb3Injected } from '@polkadot/extension-dapp';
|
||||
import { stringUpperFirst } from '@polkadot/util';
|
||||
@ -23,6 +25,7 @@ const isSupported = browserName && Object.keys(availableExtensions).includes(bro
|
||||
function BannerExtension (): React.ReactElement | null {
|
||||
const { t } = useTranslation();
|
||||
const { hasInjectedAccounts } = useApi();
|
||||
const upgradableCount = useExtensionCounter();
|
||||
|
||||
if (!isSupported || !browserName) {
|
||||
return null;
|
||||
@ -30,7 +33,16 @@ function BannerExtension (): React.ReactElement | null {
|
||||
|
||||
if (isWeb3Injected) {
|
||||
if (hasInjectedAccounts) {
|
||||
return null;
|
||||
if (!upgradableCount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Banner type='warning'>
|
||||
<p>{t<string>('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 } })}</p>
|
||||
<p><Trans key='extensionUpgrade'>Visit your <a href='#/settings/metadata'>settings page</a> to apply the updates to the injected extensions.</Trans></p>
|
||||
</Banner>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -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<string, number> = {
|
||||
// Polkadot
|
||||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 0.6
|
||||
[POLKADOT_GENESIS]: 0.6
|
||||
};
|
||||
|
||||
const SLASH_THRESHOLDS: Record<string, number> = {
|
||||
// Polkadot
|
||||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 0.75
|
||||
[POLKADOT_GENESIS]: 0.75
|
||||
};
|
||||
|
||||
export function getThreshold (api: ApiPromise): number {
|
||||
|
||||
@ -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;
|
||||
})
|
||||
|
||||
@ -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<string, Record<string, string>> {
|
||||
}
|
||||
|
||||
async function retrieve (api: ApiPromise): Promise<ChainData> {
|
||||
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<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;
|
||||
|
||||
return {
|
||||
injectedAccounts,
|
||||
properties,
|
||||
properties: chainProperties,
|
||||
systemChain: (systemChain || '<unknown>').toString(),
|
||||
systemChainType,
|
||||
systemName: systemName.toString(),
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<string, BN> = {
|
||||
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': new BN(403200)
|
||||
[POLKADOT_GENESIS]: new BN(403200)
|
||||
};
|
||||
|
||||
function AvailableDisplay ({ className = '', help, label, onChange, value }: Props): React.ReactElement<Props> | null {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user