Unverified Commit 9e8d39e6 authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

feat: add Polkadot support (#555)



* Add Edgeware

* fix path

* merge master branch

* build: update polkadot dependencies and remove redundant packages

* update kusama metadata to latest

* fix tests

* prepare polkadot network

* add edgeware network

* add kulupu network

* update title

* compatible with network without genesisHash

* add edgeware logo

* order network list

* give each network a order field

* rephrase

* fix order
Co-authored-by: default avatarcarumusan <879525+carumusan@users.noreply.github.com>
parent f2fd84d6
Pipeline #82835 failed with stages
in 3 minutes and 54 seconds
This diff is collapsed.
......@@ -57,11 +57,15 @@ export const EthereumNetworkKeys: {
export const SubstrateNetworkKeys: {
[key: string]: string;
} = Object.freeze({
EDGEWARE:
'0x742a2ca70c2fda6cee4f8df98d64c4c670a052d9568058982dad9d5a7a135c5b', // https://polkascan.io/pre/edgeware/block/0
KULUPU: '0x37e1f8125397a98630013a4dff89b54cb758ff8eed894419e65a6dcf27a6fb8a',
KUSAMA: '0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe', // https://polkascan.io/pre/kusama-cc3/block/0
KUSAMA_CC2:
'0xe3777fa922cafbff200cadeaea1a76bd7898ad5b89f7848999058b50e715f636',
KUSAMA_DEV:
'0x5e9679182f658e148f33d3f760f11179977398bb3da8d1f0bf7b267fe6b3ebb0',
POLKADOT: 'polkadot_reserved',
SUBSTRATE_DEV:
'0x0d667fd278ec412cd9fccdb066f09ed5b4cfd9c9afa9eb747213acb02b1e70bc', // substrate --dev commit ac6a2a783f0e1f4a814cf2add40275730cd41be1 hosted on wss://dev-node.substrate.dev .
WESTEND: '0x4a31f96525a77959d97e267c8fc3066ca333d9ade161720e1b7de8d35ccc6bd2'
......@@ -70,6 +74,7 @@ export const SubstrateNetworkKeys: {
const unknownNetworkBase: { [key: string]: UnknownNetworkParams } = {
[UnknownNetworkKeys.UNKNOWN]: {
color: colors.bg_alert,
order: 0,
pathId: '',
prefix: 2,
protocol: NetworkProtocols.UNKNOWN,
......@@ -81,11 +86,33 @@ const unknownNetworkBase: { [key: string]: UnknownNetworkParams } = {
const substrateNetworkBase: {
[key: string]: Partial<SubstrateNetworkParams>;
} = {
[SubstrateNetworkKeys.EDGEWARE]: {
color: '#0a95df',
decimals: 18,
genesisHash: SubstrateNetworkKeys.EDGEWARE,
logo: require('res/img/logos/edgeware.png'),
order: 4,
pathId: 'edgeware',
prefix: 7,
title: 'Edgeware',
unit: 'EDG'
},
[SubstrateNetworkKeys.KULUPU]: {
color: '#0effee',
decimals: 18,
genesisHash: SubstrateNetworkKeys.KULUPU,
order: 5,
pathId: 'kulupu',
prefix: 16,
title: 'Kulupu',
unit: 'KULU'
},
[SubstrateNetworkKeys.KUSAMA]: {
color: '#e6007a',
decimals: 12,
genesisHash: SubstrateNetworkKeys.KUSAMA,
logo: require('res/img/logos/kusama.png'),
order: 2,
pathId: 'kusama',
prefix: 2,
title: 'Kusama',
......@@ -96,6 +123,7 @@ const substrateNetworkBase: {
decimals: 12,
genesisHash: SubstrateNetworkKeys.KUSAMA,
logo: require('res/img/logos/kusama.png'),
order: 2,
pathId: 'kusama_CC2',
prefix: 2,
title: 'Kusama',
......@@ -105,15 +133,30 @@ const substrateNetworkBase: {
color: '#A60037',
decimals: 12,
genesisHash: SubstrateNetworkKeys.KUSAMA_DEV,
order: 99,
pathId: 'kusama_dev',
prefix: 2,
title: 'Kusama Development',
unit: 'KSM'
},
//TODO genesisHash and Metadata need to be added
[SubstrateNetworkKeys.POLKADOT]: {
color: '#e7007a',
decimals: 12,
//TODO genesisHash to be added after launch
genesisHash: null,
logo: require('res/img/logos/polkadot.png'),
order: 1,
pathId: 'polkadot',
prefix: 0,
title: 'Polkadot',
unit: 'DOT'
},
[SubstrateNetworkKeys.SUBSTRATE_DEV]: {
color: '#ff8c00',
decimals: 12,
genesisHash: SubstrateNetworkKeys.SUBSTRATE_DEV,
order: 100,
pathId: 'substrate_dev',
prefix: 42,
title: 'Substrate Development',
......@@ -124,25 +167,19 @@ const substrateNetworkBase: {
decimals: 12,
genesisHash: SubstrateNetworkKeys.WESTEND,
logo: require('res/img/logos/westend.png'),
order: 3,
pathId: 'westend',
prefix: 42,
title: 'Westend',
unit: 'WND'
}
// [SubstrateNetworkKeys.POLKADOT]: {
// color: '#e6007a',
// decimals: 12,
// genesisHash: SubstrateNetworkKeys.POLKADOT,
// prefix: 0,
// title: 'Polkadot mainnet',
// unit: 'DOT'
// }
};
const ethereumNetworkBase: { [key: string]: Partial<EthereumNetworkParams> } = {
[EthereumNetworkKeys.FRONTIER]: {
color: '#64A2F4',
ethereumChainId: EthereumNetworkKeys.FRONTIER,
order: 101,
secondaryColor: colors.card_bgSolid,
title: 'Ethereum'
},
......@@ -150,19 +187,23 @@ const ethereumNetworkBase: { [key: string]: Partial<EthereumNetworkParams> } = {
color: '#319C7C',
ethereumChainId: EthereumNetworkKeys.CLASSIC,
logo: require('res/img/logos/eth-classic.png'),
order: 102,
secondaryColor: colors.card_bgSolid,
title: 'Ethereum Classic'
},
[EthereumNetworkKeys.ROPSTEN]: {
ethereumChainId: EthereumNetworkKeys.ROPSTEN,
order: 104,
title: 'Ropsten Testnet'
},
[EthereumNetworkKeys.GOERLI]: {
ethereumChainId: EthereumNetworkKeys.GOERLI,
order: 105,
title: 'Görli Testnet'
},
[EthereumNetworkKeys.KOVAN]: {
ethereumChainId: EthereumNetworkKeys.KOVAN,
order: 103,
title: 'Kovan Testnet'
}
};
......
......@@ -50,7 +50,8 @@ import {
NetworkParams,
SubstrateNetworkParams,
isSubstrateNetworkParams,
isEthereumNetworkParams
isEthereumNetworkParams,
isUnknownNetworkParams
} from 'types/networkSpecsTypes';
import { NavigationAccountProps } from 'types/props';
......@@ -126,8 +127,18 @@ function AccountNetworkChooser({
</ScrollView>
);
const sortNetworkKeys = ([, networkParams]: [any, NetworkParams]): number =>
networkParams.protocol !== NetworkProtocols.SUBSTRATE ? 1 : -1;
const sortNetworkKeys = (
[, params1]: [any, NetworkParams],
[, params2]: [any, NetworkParams]
): number => {
if (params1.order > params2.order) {
return 1;
} else if (params1.order < params2.order) {
return -1;
} else {
return 0;
}
};
const filterNetworkKeys = ([networkKey]: [string, any]): boolean => {
const shouldExclude = excludedNetworks.includes(networkKey);
......
......@@ -162,7 +162,7 @@ function PathsList({
)}
<ButtonNewDerivation
testID={testIDs.PathsList.deriveButton}
title="Create New Derivation"
title="Derive New Account"
onPress={(): boolean =>
navigation.navigate('PathDerivation', {
parentPath: isUnknownNetworkPath ? '' : rootPath
......
......@@ -271,6 +271,7 @@ export default class AccountsStore extends Container<AccountsStoreState> {
if (networkKey !== UnknownNetworkKeys.UNKNOWN) {
derivedAccount = this.getAccountFromIdentity(accountId);
} else {
//TODO remove this function when we enable networkSpecs update and remove KUSAMA_CC2 network.
derivedAccount = this.getAccountFromIdentity(address);
}
......
......@@ -10,8 +10,9 @@ export type NetworkParams =
export type SubstrateNetworkParams = {
color: string;
decimals: number;
genesisHash: string;
genesisHash: string | null;
logo: number;
order: number;
pathId: string;
protocol: NetworkProtocol;
prefix: number;
......@@ -24,6 +25,7 @@ export type EthereumNetworkParams = {
color: string;
ethereumChainId: string;
logo: number;
order: number;
protocol: NetworkProtocol;
secondaryColor: string;
title: string;
......@@ -31,6 +33,7 @@ export type EthereumNetworkParams = {
export type UnknownNetworkParams = {
color: string;
order: number;
pathId: string;
prefix: number;
protocol: NetworkProtocol;
......
......@@ -49,7 +49,7 @@ export function generateAccountId({
if (isSubstrateNetworkParams(networkParams)) {
const { genesisHash } = networkParams;
return `${protocol}:${address}:${genesisHash}`;
return `${protocol}:${address}:${genesisHash ?? ''}`;
} else if (protocol === NetworkProtocols.UNKNOWN) {
return `substrate:${address}`;
} else {
......
......@@ -17,8 +17,6 @@
import { AsyncStorage } from 'react-native';
import SecureStorage from 'react-native-secure-storage';
console.log('secure storage is', SecureStorage);
import { generateAccountId } from './account';
import { deserializeIdentities, serializeIdentities } from './identitiesUtils';
......
......@@ -68,7 +68,7 @@ const raw = [
address: 'address5',
expectName: 'default',
name: '',
path: '//polkadot//default'
path: '//polkadot_test//default'
},
{
address: 'address6',
......@@ -111,7 +111,13 @@ const raw = [
address: 'softAddress2',
expectName: '1',
name: '',
path: '/polkadot/1'
path: '/polkadot_test/1'
},
{
address: 'polkadotReservedAddress',
expectName: 'reserved',
name: '',
path: '//polkadot//reserved'
}
];
const expectNames = raw.map(v => v.expectName);
......@@ -184,12 +190,12 @@ describe('IdentitiesUtils', () => {
it('regroup the unknown paths', () => {
const unKnownPaths = [
'//polkadot//default',
'//polkadot_test//default',
'',
'//custom',
'/kusama',
'/kusama/1',
'/polkadot/1'
'/polkadot_test/1'
];
const groupResult = groupPaths(unKnownPaths);
expect(groupResult).toEqual([
......@@ -202,12 +208,12 @@ describe('IdentitiesUtils', () => {
title: '//custom'
},
{
paths: ['/polkadot/1'],
title: '/polkadot'
paths: ['/polkadot_test/1'],
title: '/polkadot_test'
},
{
paths: ['//polkadot//default'],
title: '//polkadot'
paths: ['//polkadot_test//default'],
title: '//polkadot_test'
},
{
paths: ['/kusama', '/kusama/1'],
......@@ -228,7 +234,8 @@ describe('IdentitiesUtils', () => {
expect(networkKeys).toEqual([
EthereumNetworkKeys.FRONTIER,
SubstrateNetworkKeys.KUSAMA,
UnknownNetworkKeys.UNKNOWN
UnknownNetworkKeys.UNKNOWN,
SubstrateNetworkKeys.POLKADOT
]);
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment