Add base known chain info to icon/ss58 display (#386)

* Add base known chain info to icon/ss58 display

* comment around ordering

* Adjust backgrounds
This commit is contained in:
Jaco Greeff
2020-07-07 14:30:16 +02:00
committed by GitHub
parent b87dc4d063
commit e983cb5f6d
6 changed files with 76 additions and 23 deletions
+7
View File
@@ -1,5 +1,12 @@
# CHANGELOG
## 0.32.0-beta.x
- Add Kulupu to the chain lock dropdown (Thanks to https://github.com/carumusan)
- Minor README updates (Thanks to https://github.com/marceljay)
- Add base known chain info to icon/ss58 display lookups
- Adjust IdentityIcon backgrounds between dark/light themes
## 0.31.1 Jun 24, 2020
- Indicate password error when account cannot be unlocked on signing
+36
View File
@@ -0,0 +1,36 @@
// Copyright 2019-2020 @polkadot/extension-chains authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { MetadataDefBase } from '@polkadot/extension-inject/types';
const hashes: MetadataDefBase[] = [
// keep at the top (favoritism)
{
chain: 'Polkadot CC1',
genesisHash: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
icon: 'polkadot',
ss58Format: 0
},
{
chain: 'Kusama',
genesisHash: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe',
icon: 'polkadot',
ss58Format: 2
},
// alphabetical to avoid (further) favorites
{
chain: 'Edgeware',
genesisHash: '0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b',
icon: 'substrate',
ss58Format: 7
},
{
chain: 'Kulupu',
genesisHash: '0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba',
icon: 'substrate',
ss58Format: 16
}
];
export default hashes;
+6 -16
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import chains from './chains';
interface Option {
text: string;
value: string;
@@ -12,22 +14,10 @@ const hashes: Option[] = [
text: 'Allow use on any chain',
value: ''
},
{
text: 'Polkadot CC1 (live)',
value: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'
},
{
text: 'Kusama (canary)',
value: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe'
},
{
text: 'Edgeware (live)',
value: '0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b'
},
{
text: 'Kulupu (live)',
value: '0xf7a99d3cb92853d00d5275c971c132c074636256583fee53b3bbe60d7b8769ba'
}
...chains.map(({ chain, genesisHash }) => ({
text: `${chain} (${chain.startsWith('Kusama') ? 'canary' : 'live'})`,
value: genesisHash
}))
];
export default hashes;
+6 -3
View File
@@ -47,13 +47,16 @@ export interface ProviderMeta {
transport: string;
}
export interface MetadataDef {
color?: string;
export interface MetadataDefBase {
chain: string;
genesisHash: string;
icon: string;
specVersion: number;
ss58Format: number;
}
export interface MetadataDef extends MetadataDefBase {
color?: string;
specVersion: number;
tokenDecimals: number;
tokenSymbol: string;
types: Record<string, Record<string, string> | string>;
@@ -32,6 +32,8 @@ function Identicon ({ className, iconTheme, onCopy, prefix, value }: Props): Rea
}
export default styled(Identicon)(({ theme }: ThemeProps) => `
background: rgba(192, 192, 292, 0.25);
border-radius: 50%;
display: flex;
justify-content: center;
+19 -4
View File
@@ -9,8 +9,9 @@ import { MetadataDef } from '@polkadot/extension-inject/types';
import { KeypairType } from '@polkadot/util-crypto/types';
import { PORT_EXTENSION } from '@polkadot/extension-base/defaults';
import chrome from '@polkadot/extension-inject/chrome';
import allChains from '@polkadot/extension-chains/chains';
import { metadataExpand } from '@polkadot/extension-chains';
import chrome from '@polkadot/extension-inject/chrome';
import { KeyringPair$Json } from '@polkadot/keyring/types';
interface Handler {
@@ -135,9 +136,23 @@ export async function getMetadata (genesisHash?: string | null, isPartial = fals
const def = await request;
return def
? metadataExpand(def, isPartial)
: null;
if (def) {
return metadataExpand(def, isPartial);
} else if (isPartial) {
const chain = allChains.find((chain) => chain.genesisHash === genesisHash);
if (chain) {
return metadataExpand({
...chain,
specVersion: 0,
tokenDecimals: 15,
tokenSymbol: 'Unit',
types: {}
}, isPartial);
}
}
return null;
}
export async function rejectAuthRequest (id: string): Promise<boolean> {