@subwallet/extension-base 1.0.3-0 → 1.0.4-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +25 -15
- package/background/KoniTypes.js +1 -0
- package/cjs/background/KoniTypes.js +1 -0
- package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
- package/cjs/koni/api/staking/bonding/astar.js +9 -1
- package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
- package/cjs/koni/background/handlers/Extension.js +61 -19
- package/cjs/koni/background/handlers/State.js +12 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +17 -2
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +1 -1
- package/cjs/services/chain-service/index.js +96 -18
- package/cjs/services/keyring-service/index.js +9 -0
- package/cjs/services/migration-service/index.js +7 -4
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/price-service/index.js +0 -1
- package/cjs/services/request-service/handler/AuthRequestHandler.js +7 -0
- package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/cjs/services/request-service/index.js +6 -0
- package/cjs/services/setting-service/SettingService.js +4 -9
- package/cjs/services/setting-service/constants.js +12 -2
- package/cjs/services/storage-service/DatabaseService.js +14 -0
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
- package/cjs/services/transaction-service/index.js +3 -0
- package/koni/api/staking/bonding/amplitude.js +9 -2
- package/koni/api/staking/bonding/astar.js +9 -1
- package/koni/api/staking/bonding/paraChain.js +10 -2
- package/koni/api/staking/bonding/relayChain.js +21 -4
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +42 -1
- package/koni/background/handlers/State.d.ts +1 -0
- package/koni/background/handlers/State.js +12 -0
- package/package.json +21 -16
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +6 -0
- package/services/chain-service/constants.js +10 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +1 -1
- package/services/chain-service/index.d.ts +3 -1
- package/services/chain-service/index.js +97 -19
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +9 -0
- package/services/migration-service/index.js +7 -4
- package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
- package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/price-service/index.js +0 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
- package/services/request-service/handler/AuthRequestHandler.js +7 -0
- package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
- package/services/request-service/handler/EvmRequestHandler.js +21 -0
- package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
- package/services/request-service/handler/MetadataRequestHandler.js +6 -0
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
- package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
- package/services/request-service/index.d.ts +1 -0
- package/services/request-service/index.js +6 -0
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +5 -10
- package/services/setting-service/constants.d.ts +2 -1
- package/services/setting-service/constants.js +10 -1
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +14 -0
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
- package/services/storage-service/db-stores/BaseStore.js +3 -0
- package/services/transaction-service/index.d.ts +1 -0
- package/services/transaction-service/index.js +3 -0
- /package/cjs/services/chain-service/{heath-check → health-check}/index.js +0 -0
- /package/services/chain-service/{heath-check → health-check}/index.d.ts +0 -0
- /package/services/chain-service/{heath-check → health-check}/index.js +0 -0
|
@@ -894,7 +894,7 @@ export default class KoniExtension {
|
|
|
894
894
|
}
|
|
895
895
|
async updateAssetSetting(params) {
|
|
896
896
|
try {
|
|
897
|
-
await this.#koniState.chainService.updateAssetSetting(params.tokenSlug, params.assetSetting);
|
|
897
|
+
await this.#koniState.chainService.updateAssetSetting(params.tokenSlug, params.assetSetting, params.autoEnableNativeToken);
|
|
898
898
|
this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
|
|
899
899
|
return true;
|
|
900
900
|
} catch (e) {
|
|
@@ -2386,6 +2386,11 @@ export default class KoniExtension {
|
|
|
2386
2386
|
chainType: ChainType.SUBSTRATE
|
|
2387
2387
|
});
|
|
2388
2388
|
}
|
|
2389
|
+
|
|
2390
|
+
/// Keyring state
|
|
2391
|
+
|
|
2392
|
+
// Subscribe keyring state
|
|
2393
|
+
|
|
2389
2394
|
keyringStateSubscribe(id, port) {
|
|
2390
2395
|
const cb = createSubscription(id, port);
|
|
2391
2396
|
const keyringStateSubject = this.#koniState.keyringService.keyringStateSubject;
|
|
@@ -2396,6 +2401,9 @@ export default class KoniExtension {
|
|
|
2396
2401
|
});
|
|
2397
2402
|
return this.#koniState.keyringService.keyringState;
|
|
2398
2403
|
}
|
|
2404
|
+
|
|
2405
|
+
// Change master password
|
|
2406
|
+
|
|
2399
2407
|
keyringChangeMasterPassword({
|
|
2400
2408
|
createNew,
|
|
2401
2409
|
newPassword,
|
|
@@ -2431,6 +2439,9 @@ export default class KoniExtension {
|
|
|
2431
2439
|
errors: []
|
|
2432
2440
|
};
|
|
2433
2441
|
}
|
|
2442
|
+
|
|
2443
|
+
// Migrate password
|
|
2444
|
+
|
|
2434
2445
|
keyringMigrateMasterPassword({
|
|
2435
2446
|
address,
|
|
2436
2447
|
password
|
|
@@ -2449,6 +2460,9 @@ export default class KoniExtension {
|
|
|
2449
2460
|
errors: []
|
|
2450
2461
|
};
|
|
2451
2462
|
}
|
|
2463
|
+
|
|
2464
|
+
// Unlock wallet
|
|
2465
|
+
|
|
2452
2466
|
keyringUnlock({
|
|
2453
2467
|
password
|
|
2454
2468
|
}) {
|
|
@@ -2466,11 +2480,17 @@ export default class KoniExtension {
|
|
|
2466
2480
|
errors: []
|
|
2467
2481
|
};
|
|
2468
2482
|
}
|
|
2483
|
+
|
|
2484
|
+
// Lock wallet
|
|
2485
|
+
|
|
2469
2486
|
keyringLock() {
|
|
2470
2487
|
keyring.lockAll();
|
|
2471
2488
|
this.#koniState.updateKeyringState();
|
|
2472
2489
|
clearTimeout(this.#lockTimeOut);
|
|
2473
2490
|
}
|
|
2491
|
+
|
|
2492
|
+
// Export mnemonic
|
|
2493
|
+
|
|
2474
2494
|
keyringExportMnemonic({
|
|
2475
2495
|
address,
|
|
2476
2496
|
password
|
|
@@ -2482,6 +2502,25 @@ export default class KoniExtension {
|
|
|
2482
2502
|
};
|
|
2483
2503
|
}
|
|
2484
2504
|
|
|
2505
|
+
// Reset wallet
|
|
2506
|
+
|
|
2507
|
+
async resetWallet({
|
|
2508
|
+
resetAll
|
|
2509
|
+
}) {
|
|
2510
|
+
try {
|
|
2511
|
+
await this.#koniState.resetWallet(resetAll);
|
|
2512
|
+
return {
|
|
2513
|
+
errors: [],
|
|
2514
|
+
status: true
|
|
2515
|
+
};
|
|
2516
|
+
} catch (e) {
|
|
2517
|
+
return {
|
|
2518
|
+
errors: [e.message],
|
|
2519
|
+
status: false
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2485
2524
|
/// Signing external request
|
|
2486
2525
|
signingApprovePasswordV2({
|
|
2487
2526
|
id
|
|
@@ -3154,6 +3193,8 @@ export default class KoniExtension {
|
|
|
3154
3193
|
return this.keyringLock();
|
|
3155
3194
|
case 'pri(keyring.export.mnemonic)':
|
|
3156
3195
|
return this.keyringExportMnemonic(request);
|
|
3196
|
+
case 'pri(keyring.reset)':
|
|
3197
|
+
return await this.resetWallet(request);
|
|
3157
3198
|
|
|
3158
3199
|
/// Signing external
|
|
3159
3200
|
case 'pri(signing.approve.passwordV2)':
|
|
@@ -1426,4 +1426,16 @@ export default class KoniState {
|
|
|
1426
1426
|
async reloadStaking() {
|
|
1427
1427
|
return await this.cron.reloadStaking();
|
|
1428
1428
|
}
|
|
1429
|
+
async resetWallet(resetAll) {
|
|
1430
|
+
this.keyringService.resetWallet(resetAll);
|
|
1431
|
+
this.requestService.resetWallet();
|
|
1432
|
+
this.transactionService.resetWallet();
|
|
1433
|
+
await this.dbService.resetWallet(resetAll);
|
|
1434
|
+
this.accountRefStore.set('refList', []);
|
|
1435
|
+
if (resetAll) {
|
|
1436
|
+
this.settingService.resetWallet();
|
|
1437
|
+
}
|
|
1438
|
+
this.chainService.resetWallet(resetAll);
|
|
1439
|
+
await this.chainService.init();
|
|
1440
|
+
}
|
|
1429
1441
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.0.
|
|
20
|
+
"version": "1.0.4-1",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -530,10 +530,10 @@
|
|
|
530
530
|
"require": "./cjs/services/chain-service/handler/types.js",
|
|
531
531
|
"default": "./services/chain-service/handler/types.js"
|
|
532
532
|
},
|
|
533
|
-
"./services/chain-service/
|
|
534
|
-
"types": "./services/chain-service/
|
|
535
|
-
"require": "./cjs/services/chain-service/
|
|
536
|
-
"default": "./services/chain-service/
|
|
533
|
+
"./services/chain-service/health-check": {
|
|
534
|
+
"types": "./services/chain-service/health-check/index.d.ts",
|
|
535
|
+
"require": "./cjs/services/chain-service/health-check/index.js",
|
|
536
|
+
"default": "./services/chain-service/health-check/index.js"
|
|
537
537
|
},
|
|
538
538
|
"./services/chain-service/helper": {
|
|
539
539
|
"types": "./services/chain-service/helper/index.d.ts",
|
|
@@ -1225,6 +1225,11 @@
|
|
|
1225
1225
|
"require": "./cjs/services/migration-service/scripts/ClearOldStorage.js",
|
|
1226
1226
|
"default": "./services/migration-service/scripts/ClearOldStorage.js"
|
|
1227
1227
|
},
|
|
1228
|
+
"./services/migration-service/scripts/MigrateAuthUrls": {
|
|
1229
|
+
"types": "./services/migration-service/scripts/MigrateAuthUrls.d.ts",
|
|
1230
|
+
"require": "./cjs/services/migration-service/scripts/MigrateAuthUrls.js",
|
|
1231
|
+
"default": "./services/migration-service/scripts/MigrateAuthUrls.js"
|
|
1232
|
+
},
|
|
1228
1233
|
"./services/migration-service/scripts/MigrateImportedToken": {
|
|
1229
1234
|
"types": "./services/migration-service/scripts/MigrateImportedToken.d.ts",
|
|
1230
1235
|
"require": "./cjs/services/migration-service/scripts/MigrateImportedToken.js",
|
|
@@ -1649,7 +1654,7 @@
|
|
|
1649
1654
|
"@polkadot/hw-ledger": "^10.1.9",
|
|
1650
1655
|
"@polkadot/keyring": "^10.2.1",
|
|
1651
1656
|
"@polkadot/networks": "^10.2.1",
|
|
1652
|
-
"@polkadot/phishing": "^0.21.
|
|
1657
|
+
"@polkadot/phishing": "^0.21.2",
|
|
1653
1658
|
"@polkadot/react-identicon": "^2.9.14",
|
|
1654
1659
|
"@polkadot/react-qr": "^2.9.14",
|
|
1655
1660
|
"@polkadot/rpc-provider": "^9.10.3",
|
|
@@ -1667,12 +1672,12 @@
|
|
|
1667
1672
|
"@subsocial/types": "^0.6.8",
|
|
1668
1673
|
"@substrate/connect": "^0.7.18",
|
|
1669
1674
|
"@subwallet/chain-list": "^0.1.2",
|
|
1670
|
-
"@subwallet/extension-base": "^1.0.
|
|
1671
|
-
"@subwallet/extension-chains": "^1.0.
|
|
1672
|
-
"@subwallet/extension-dapp": "^1.0.
|
|
1673
|
-
"@subwallet/extension-inject": "^1.0.
|
|
1675
|
+
"@subwallet/extension-base": "^1.0.4-1",
|
|
1676
|
+
"@subwallet/extension-chains": "^1.0.4-1",
|
|
1677
|
+
"@subwallet/extension-dapp": "^1.0.4-1",
|
|
1678
|
+
"@subwallet/extension-inject": "^1.0.4-1",
|
|
1674
1679
|
"@subwallet/keyring": "^0.0.5",
|
|
1675
|
-
"@subwallet/ui-keyring": "^0.0.
|
|
1680
|
+
"@subwallet/ui-keyring": "^0.0.7",
|
|
1676
1681
|
"@unique-nft/types": "^0.6.0-4",
|
|
1677
1682
|
"@zeitgeistpm/type-defs": "^0.10.0",
|
|
1678
1683
|
"@zeroio/type-definitions": "^0.0.14",
|
|
@@ -1702,10 +1707,10 @@
|
|
|
1702
1707
|
"protobufjs": "^7.1.2",
|
|
1703
1708
|
"rlp": "^3.0.0",
|
|
1704
1709
|
"rxjs": "^7.8.0",
|
|
1705
|
-
"web3": "^1.
|
|
1706
|
-
"web3-core": "^1.
|
|
1707
|
-
"web3-core-helpers": "^1.
|
|
1708
|
-
"web3-eth-contract": "^1.
|
|
1709
|
-
"web3-utils": "^1.
|
|
1710
|
+
"web3": "^1.10.0",
|
|
1711
|
+
"web3-core": "^1.10.0",
|
|
1712
|
+
"web3-core-helpers": "^1.10.0",
|
|
1713
|
+
"web3-eth-contract": "^1.10.0",
|
|
1714
|
+
"web3-utils": "^1.10.0"
|
|
1710
1715
|
}
|
|
1711
1716
|
}
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.0.
|
|
10
|
+
version: '1.0.4-1'
|
|
11
11
|
};
|
|
@@ -75,3 +75,9 @@ export declare const _XCM_TYPE: {
|
|
|
75
75
|
PR: string;
|
|
76
76
|
};
|
|
77
77
|
export declare const _DEFAULT_ACTIVE_CHAINS: string[];
|
|
78
|
+
export declare const _CHAIN_INFO_SRC: string;
|
|
79
|
+
export declare const _CHAIN_ASSET_SRC: string;
|
|
80
|
+
export declare const _ASSET_REF_SRC: string;
|
|
81
|
+
export declare const _MULTI_CHAIN_ASSET_SRC: string;
|
|
82
|
+
export declare const _CHAIN_LOGO_MAP_SRC: string;
|
|
83
|
+
export declare const _ASSET_LOGO_MAP_SRC: string;
|
|
@@ -201,4 +201,13 @@ export const _XCM_TYPE = {
|
|
|
201
201
|
PR: `${_SubstrateChainType.PARACHAIN}-${_SubstrateChainType.RELAYCHAIN}` // UMP
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS];
|
|
204
|
+
export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS];
|
|
205
|
+
|
|
206
|
+
// TODO: review
|
|
207
|
+
const TARGET_BRANCH = process.env.NODE_ENV !== 'production' ? 'koni-dev' : 'master';
|
|
208
|
+
export const _CHAIN_INFO_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainInfo.json`;
|
|
209
|
+
export const _CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainAsset.json`;
|
|
210
|
+
export const _ASSET_REF_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetRef.json`;
|
|
211
|
+
export const _MULTI_CHAIN_ASSET_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/MultiChainAsset.json`;
|
|
212
|
+
export const _CHAIN_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/ChainLogoMap.json`;
|
|
213
|
+
export const _ASSET_LOGO_MAP_SRC = `https://raw.githubusercontent.com/Koniverse/SubWallet-Chain/${TARGET_BRANCH}/packages/chain-list/src/data/AssetLogoMap.json`;
|
|
@@ -112,7 +112,7 @@ export class SubstrateChainHandler {
|
|
|
112
112
|
name = nameResp.output ? nameObj.Ok || nameObj.ok : '';
|
|
113
113
|
decimals = decimalsResp.output ? new BN(decimalsObj.Ok || decimalsObj.ok).toNumber() : 0;
|
|
114
114
|
symbol = decimalsResp.output ? symbolObj.Ok || symbolObj.ok : '';
|
|
115
|
-
if (name === '' || symbol === '') {
|
|
115
|
+
if (!name || !symbol || typeof name === 'object' || typeof symbol === 'object') {
|
|
116
116
|
contractError = true;
|
|
117
117
|
}
|
|
118
118
|
console.log('validate PSP22', name, symbol, decimals);
|
|
@@ -71,6 +71,7 @@ export declare class ChainService {
|
|
|
71
71
|
enableChains(chainSlugs: string[]): boolean;
|
|
72
72
|
disableChain(chainSlug: string): boolean;
|
|
73
73
|
private checkExistedPredefinedChain;
|
|
74
|
+
private fetchLatestData;
|
|
74
75
|
private initChains;
|
|
75
76
|
private initAssetRegistry;
|
|
76
77
|
private updateChainStateMapSubscription;
|
|
@@ -99,9 +100,10 @@ export declare class ChainService {
|
|
|
99
100
|
setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
|
|
100
101
|
getStoreAssetSettings(): Promise<Record<string, AssetSetting>>;
|
|
101
102
|
getAssetSettings(): Promise<Record<string, AssetSetting>>;
|
|
102
|
-
updateAssetSetting(assetSlug: string, assetSetting: AssetSetting): Promise<boolean | undefined>;
|
|
103
|
+
updateAssetSetting(assetSlug: string, assetSetting: AssetSetting, autoEnableNativeToken?: boolean): Promise<boolean | undefined>;
|
|
103
104
|
updateAssetSettingByChain(chainSlug: string, visible: boolean): Promise<void>;
|
|
104
105
|
subscribeAssetSettings(): BehaviorSubject<Record<string, AssetSetting>>;
|
|
105
106
|
getChainLogoMap(): Promise<Record<string, string>>;
|
|
106
107
|
getAssetLogoMap(): Promise<Record<string, string>>;
|
|
108
|
+
resetWallet(resetAll: boolean): void;
|
|
107
109
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { AssetLogoMap, AssetRefMap, ChainAssetMap, ChainInfoMap, ChainLogoMap, MultiChainAssetMap } from '@subwallet/chain-list';
|
|
5
5
|
import { _AssetRefPath, _AssetType, _ChainStatus, _SubstrateChainType } from '@subwallet/chain-list/types';
|
|
6
|
-
import { _DEFAULT_ACTIVE_CHAINS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { _ASSET_LOGO_MAP_SRC, _ASSET_REF_SRC, _CHAIN_ASSET_SRC, _CHAIN_INFO_SRC, _CHAIN_LOGO_MAP_SRC, _DEFAULT_ACTIVE_CHAINS, _MULTI_CHAIN_ASSET_SRC } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { EvmChainHandler } from '@subwallet/extension-base/services/chain-service/handler/EvmChainHandler';
|
|
8
8
|
import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler';
|
|
9
9
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
@@ -40,7 +40,6 @@ export class ChainService {
|
|
|
40
40
|
this.chainInfoMapSubject.next(this.dataMap.chainInfoMap);
|
|
41
41
|
this.chainStateMapSubject.next(this.dataMap.chainStateMap);
|
|
42
42
|
this.assetRegistrySubject.next(this.dataMap.assetRegistry);
|
|
43
|
-
this.multiChainAssetMapSubject.next(MultiChainAssetMap);
|
|
44
43
|
this.xcmRefMapSubject.next(this.getXcmRefMap());
|
|
45
44
|
this.logger = createLogger('chain-service');
|
|
46
45
|
this.refreshChainStateInterval(3000, 6);
|
|
@@ -350,7 +349,9 @@ export class ChainService {
|
|
|
350
349
|
// Business logic
|
|
351
350
|
async init() {
|
|
352
351
|
// TODO: reconsider the flow of initiation
|
|
353
|
-
this.
|
|
352
|
+
const [latestAssetRefMap, latestMultiChainAssetMap] = await Promise.all([this.fetchLatestData(_ASSET_REF_SRC, AssetRefMap), this.fetchLatestData(_MULTI_CHAIN_ASSET_SRC, MultiChainAssetMap)]);
|
|
353
|
+
this.multiChainAssetMapSubject.next(latestMultiChainAssetMap);
|
|
354
|
+
this.dataMap.assetRefMap = latestAssetRefMap;
|
|
354
355
|
await this.initChains();
|
|
355
356
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
356
357
|
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
@@ -452,16 +453,16 @@ export class ChainService {
|
|
|
452
453
|
this.eventService.emit('chain.updateState', chainSlug);
|
|
453
454
|
return true;
|
|
454
455
|
}
|
|
455
|
-
checkExistedPredefinedChain(genesisHash, evmChainId) {
|
|
456
|
+
checkExistedPredefinedChain(latestChainInfoMap, genesisHash, evmChainId) {
|
|
456
457
|
let duplicatedSlug = '';
|
|
457
458
|
if (genesisHash) {
|
|
458
|
-
Object.values(
|
|
459
|
+
Object.values(latestChainInfoMap).forEach(chainInfo => {
|
|
459
460
|
if (chainInfo.substrateInfo && chainInfo.substrateInfo.genesisHash === genesisHash) {
|
|
460
461
|
duplicatedSlug = chainInfo.slug;
|
|
461
462
|
}
|
|
462
463
|
});
|
|
463
464
|
} else if (evmChainId) {
|
|
464
|
-
Object.values(
|
|
465
|
+
Object.values(latestChainInfoMap).forEach(chainInfo => {
|
|
465
466
|
if (chainInfo.evmInfo && chainInfo.evmInfo.evmChainId === evmChainId) {
|
|
466
467
|
duplicatedSlug = chainInfo.slug;
|
|
467
468
|
}
|
|
@@ -469,8 +470,47 @@ export class ChainService {
|
|
|
469
470
|
}
|
|
470
471
|
return duplicatedSlug;
|
|
471
472
|
}
|
|
473
|
+
async fetchLatestData(src, defaultValue) {
|
|
474
|
+
return Promise.resolve(defaultValue);
|
|
475
|
+
// try {
|
|
476
|
+
// const timeout = new Promise((resolve) => {
|
|
477
|
+
// const id = setTimeout(() => {
|
|
478
|
+
// clearTimeout(id);
|
|
479
|
+
// resolve(null);
|
|
480
|
+
// }, 1500);
|
|
481
|
+
// });
|
|
482
|
+
// let result = defaultValue;
|
|
483
|
+
// const resp = await Promise.race([
|
|
484
|
+
// timeout,
|
|
485
|
+
// fetch(src)
|
|
486
|
+
// ]) as Response || null;
|
|
487
|
+
//
|
|
488
|
+
// if (!resp) {
|
|
489
|
+
// console.warn('Error fetching latest data', src);
|
|
490
|
+
//
|
|
491
|
+
// return result;
|
|
492
|
+
// }
|
|
493
|
+
//
|
|
494
|
+
// if (resp.ok) {
|
|
495
|
+
// try {
|
|
496
|
+
// result = await resp.json();
|
|
497
|
+
// console.log('Fetched latest data', src);
|
|
498
|
+
// } catch (err) {
|
|
499
|
+
// console.warn('Error parsing latest data', src, err);
|
|
500
|
+
// }
|
|
501
|
+
// }
|
|
502
|
+
//
|
|
503
|
+
// return result;
|
|
504
|
+
// } catch (e) {
|
|
505
|
+
// console.warn('Error fetching latest data', src, e);
|
|
506
|
+
//
|
|
507
|
+
// return defaultValue;
|
|
508
|
+
// }
|
|
509
|
+
}
|
|
510
|
+
|
|
472
511
|
async initChains() {
|
|
473
512
|
const storedChainSettings = await this.dbService.getAllChainStore();
|
|
513
|
+
const latestChainInfoMap = await this.fetchLatestData(_CHAIN_INFO_SRC, ChainInfoMap);
|
|
474
514
|
const storedChainSettingMap = {};
|
|
475
515
|
storedChainSettings.forEach(chainStoredSetting => {
|
|
476
516
|
storedChainSettingMap[chainStoredSetting.slug] = chainStoredSetting;
|
|
@@ -479,8 +519,8 @@ export class ChainService {
|
|
|
479
519
|
const deprecatedChains = [];
|
|
480
520
|
const deprecatedChainMap = {};
|
|
481
521
|
if (storedChainSettings.length === 0) {
|
|
482
|
-
this.dataMap.chainInfoMap =
|
|
483
|
-
Object.values(
|
|
522
|
+
this.dataMap.chainInfoMap = latestChainInfoMap;
|
|
523
|
+
Object.values(latestChainInfoMap).forEach(chainInfo => {
|
|
484
524
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
485
525
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
486
526
|
slug: chainInfo.slug,
|
|
@@ -496,10 +536,10 @@ export class ChainService {
|
|
|
496
536
|
});
|
|
497
537
|
});
|
|
498
538
|
} else {
|
|
499
|
-
const mergedChainInfoMap =
|
|
539
|
+
const mergedChainInfoMap = latestChainInfoMap;
|
|
500
540
|
for (const [storedSlug, storedChainInfo] of Object.entries(storedChainSettingMap)) {
|
|
501
|
-
if (storedSlug in
|
|
502
|
-
// check predefined chains first,
|
|
541
|
+
if (storedSlug in latestChainInfoMap) {
|
|
542
|
+
// check predefined chains first, keep setting for providers and currentProvider
|
|
503
543
|
mergedChainInfoMap[storedSlug].providers = {
|
|
504
544
|
...storedChainInfo.providers,
|
|
505
545
|
...mergedChainInfoMap[storedSlug].providers
|
|
@@ -519,7 +559,7 @@ export class ChainService {
|
|
|
519
559
|
var _storedChainInfo$subs, _storedChainInfo$evmI;
|
|
520
560
|
// only custom chains are left
|
|
521
561
|
// check custom chain duplicated with predefined chain => merge into predefined chain
|
|
522
|
-
const duplicatedDefaultSlug = this.checkExistedPredefinedChain((_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
|
|
562
|
+
const duplicatedDefaultSlug = this.checkExistedPredefinedChain(latestChainInfoMap, (_storedChainInfo$subs = storedChainInfo.substrateInfo) === null || _storedChainInfo$subs === void 0 ? void 0 : _storedChainInfo$subs.genesisHash, (_storedChainInfo$evmI = storedChainInfo.evmInfo) === null || _storedChainInfo$evmI === void 0 ? void 0 : _storedChainInfo$evmI.evmChainId);
|
|
523
563
|
if (duplicatedDefaultSlug.length > 0) {
|
|
524
564
|
// merge custom chain with existed chain
|
|
525
565
|
mergedChainInfoMap[duplicatedDefaultSlug].providers = {
|
|
@@ -589,10 +629,11 @@ export class ChainService {
|
|
|
589
629
|
}
|
|
590
630
|
async initAssetRegistry(deprecatedCustomChainMap) {
|
|
591
631
|
const storedAssetRegistry = await this.dbService.getAllAssetStore();
|
|
632
|
+
const latestAssetRegistry = await this.fetchLatestData(_CHAIN_ASSET_SRC, ChainAssetMap);
|
|
592
633
|
if (storedAssetRegistry.length === 0) {
|
|
593
|
-
this.dataMap.assetRegistry =
|
|
634
|
+
this.dataMap.assetRegistry = latestAssetRegistry;
|
|
594
635
|
} else {
|
|
595
|
-
const mergedAssetRegistry =
|
|
636
|
+
const mergedAssetRegistry = latestAssetRegistry;
|
|
596
637
|
const parsedStoredAssetRegistry = {};
|
|
597
638
|
const deprecatedAssets = [];
|
|
598
639
|
|
|
@@ -614,7 +655,7 @@ export class ChainService {
|
|
|
614
655
|
});
|
|
615
656
|
for (const assetInfo of Object.values(parsedStoredAssetRegistry)) {
|
|
616
657
|
let duplicated = false;
|
|
617
|
-
for (const defaultChainAsset of Object.values(
|
|
658
|
+
for (const defaultChainAsset of Object.values(latestAssetRegistry)) {
|
|
618
659
|
// case merge custom asset with default asset
|
|
619
660
|
if (_isEqualSmartContractAsset(assetInfo, defaultChainAsset)) {
|
|
620
661
|
duplicated = true;
|
|
@@ -1152,13 +1193,12 @@ export class ChainService {
|
|
|
1152
1193
|
}
|
|
1153
1194
|
return this.assetSettingSubject.value;
|
|
1154
1195
|
}
|
|
1155
|
-
async updateAssetSetting(assetSlug, assetSetting) {
|
|
1196
|
+
async updateAssetSetting(assetSlug, assetSetting, autoEnableNativeToken) {
|
|
1156
1197
|
const currentAssetSettings = await this.getAssetSettings();
|
|
1157
1198
|
let needUpdateSubject;
|
|
1158
1199
|
|
|
1159
1200
|
// Update settings
|
|
1160
1201
|
currentAssetSettings[assetSlug] = assetSetting;
|
|
1161
|
-
this.setAssetSettings(currentAssetSettings);
|
|
1162
1202
|
if (assetSetting.visible) {
|
|
1163
1203
|
const assetInfo = this.getAssetBySlug(assetSlug);
|
|
1164
1204
|
const chainState = this.getChainStateByKey(assetInfo.originChain);
|
|
@@ -1167,8 +1207,15 @@ export class ChainService {
|
|
|
1167
1207
|
if (chainState && !chainState.active) {
|
|
1168
1208
|
this.enableChain(chainState.slug);
|
|
1169
1209
|
needUpdateSubject = true;
|
|
1210
|
+
if (autoEnableNativeToken) {
|
|
1211
|
+
const nativeAsset = this.getNativeTokenInfo(assetInfo.originChain);
|
|
1212
|
+
currentAssetSettings[nativeAsset.slug] = {
|
|
1213
|
+
visible: true
|
|
1214
|
+
};
|
|
1215
|
+
}
|
|
1170
1216
|
}
|
|
1171
1217
|
}
|
|
1218
|
+
this.setAssetSettings(currentAssetSettings);
|
|
1172
1219
|
return needUpdateSubject;
|
|
1173
1220
|
}
|
|
1174
1221
|
async updateAssetSettingByChain(chainSlug, visible) {
|
|
@@ -1186,9 +1233,40 @@ export class ChainService {
|
|
|
1186
1233
|
return this.assetSettingSubject;
|
|
1187
1234
|
}
|
|
1188
1235
|
async getChainLogoMap() {
|
|
1189
|
-
return
|
|
1236
|
+
return await this.fetchLatestData(_CHAIN_LOGO_MAP_SRC, ChainLogoMap);
|
|
1190
1237
|
}
|
|
1191
1238
|
async getAssetLogoMap() {
|
|
1192
|
-
return
|
|
1239
|
+
return await this.fetchLatestData(_ASSET_LOGO_MAP_SRC, AssetLogoMap);
|
|
1240
|
+
}
|
|
1241
|
+
resetWallet(resetAll) {
|
|
1242
|
+
if (resetAll) {
|
|
1243
|
+
this.setAssetSettings({});
|
|
1244
|
+
|
|
1245
|
+
// Disconnect chain
|
|
1246
|
+
const activeChains = this.getActiveChainInfos();
|
|
1247
|
+
for (const chain of Object.keys(activeChains)) {
|
|
1248
|
+
if (!_DEFAULT_ACTIVE_CHAINS.includes(chain)) {
|
|
1249
|
+
this.disableChain(chain);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// Remove custom chain
|
|
1254
|
+
const allChains = this.getChainInfoMap();
|
|
1255
|
+
for (const chain of Object.keys(allChains)) {
|
|
1256
|
+
if (_isCustomChain(chain)) {
|
|
1257
|
+
this.removeCustomChain(chain);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
// Remove custom asset
|
|
1262
|
+
const assetSettings = this.getAssetSettings();
|
|
1263
|
+
const customToken = [];
|
|
1264
|
+
for (const asset of Object.keys(assetSettings)) {
|
|
1265
|
+
if (_isCustomAsset(asset)) {
|
|
1266
|
+
customToken.push(asset);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
this.deleteCustomAssets(customToken);
|
|
1270
|
+
}
|
|
1193
1271
|
}
|
|
1194
1272
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
4
5
|
import { CurrentAccountStore } from '@subwallet/extension-base/stores';
|
|
5
6
|
import { keyring } from '@subwallet/ui-keyring';
|
|
6
7
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -88,4 +89,12 @@ export class KeyringService {
|
|
|
88
89
|
this.eventService.emit('account.updateCurrent', currentAccountData);
|
|
89
90
|
this.currentAccountStore.set('CurrentAccountInfo', currentAccountData);
|
|
90
91
|
}
|
|
92
|
+
resetWallet(resetAll) {
|
|
93
|
+
keyring.resetWallet(resetAll);
|
|
94
|
+
this.updateKeyringState();
|
|
95
|
+
this.currentAccountSubject.next({
|
|
96
|
+
address: ALL_ACCOUNT_KEY,
|
|
97
|
+
currentGenesisHash: null
|
|
98
|
+
});
|
|
99
|
+
}
|
|
91
100
|
}
|
|
@@ -11,8 +11,11 @@ export default class MigrationService {
|
|
|
11
11
|
async run() {
|
|
12
12
|
this.logger.log('Migrating...');
|
|
13
13
|
const keys = Object.keys(MigrationScripts).sort((a, b) => a.localeCompare(b));
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
// Await timeout 2s
|
|
16
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
17
|
+
for (let i = 0; i < keys.length; i++) {
|
|
18
|
+
try {
|
|
16
19
|
const JobClass = MigrationScripts[keys[i]];
|
|
17
20
|
const key = keys[i];
|
|
18
21
|
const name = JobClass.name;
|
|
@@ -30,9 +33,9 @@ export default class MigrationService {
|
|
|
30
33
|
timestamp: new Date().getTime()
|
|
31
34
|
});
|
|
32
35
|
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
this.logger.error('Migration error: ', MigrationScripts[keys[i]].name, error);
|
|
33
38
|
}
|
|
34
|
-
} catch (error) {
|
|
35
|
-
this.logger.error('Migration error: ', error);
|
|
36
39
|
}
|
|
37
40
|
this.logger.log('Migration done.');
|
|
38
41
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class MigrateSettings extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
return new Promise(resolve => {
|
|
9
|
+
this.state.getAuthorize(value => {
|
|
10
|
+
if (value) {
|
|
11
|
+
const key = 'app.stellaswap.com';
|
|
12
|
+
const stellaSwap = value[key];
|
|
13
|
+
if (stellaSwap) {
|
|
14
|
+
stellaSwap.currentEvmNetworkKey = 'moonbeam';
|
|
15
|
+
value[key] = stellaSwap;
|
|
16
|
+
this.state.setAuthorize(value, () => {
|
|
17
|
+
resolve();
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
resolve();
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
resolve();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import AutoEnableChainsTokens from '@subwallet/extension-base/services/migration-service/scripts/AutoEnableChainsTokens';
|
|
5
|
+
import MigrateAuthUrls from '@subwallet/extension-base/services/migration-service/scripts/MigrateAuthUrls';
|
|
5
6
|
import MigrateImportedToken from '@subwallet/extension-base/services/migration-service/scripts/MigrateImportedToken';
|
|
6
7
|
import MigrateNetworkSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateNetworkSettings';
|
|
7
8
|
import MigrateSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateSettings';
|
|
@@ -12,6 +13,7 @@ export default {
|
|
|
12
13
|
'1.0.1-20': MigrateImportedToken,
|
|
13
14
|
'1.0.1-30': MigrateTransactionHistory,
|
|
14
15
|
'1.0.1-40': AutoEnableChainsTokens,
|
|
15
|
-
'1.0.1-50': MigrateSettings
|
|
16
|
+
'1.0.1-50': MigrateSettings,
|
|
17
|
+
'1.0.1-60': MigrateAuthUrls
|
|
16
18
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
17
19
|
};
|
|
@@ -63,7 +63,6 @@ export class PriceService {
|
|
|
63
63
|
await this.eventService.waitAssetReady;
|
|
64
64
|
this.status = ServiceStatus.INITIALIZED;
|
|
65
65
|
this.eventService.on('asset.updateState', eventHandler);
|
|
66
|
-
this.eventService.on('asset.updateState', eventHandler);
|
|
67
66
|
}
|
|
68
67
|
async loadData() {
|
|
69
68
|
const data = await this.dbService.getPriceStore();
|
|
@@ -283,4 +283,11 @@ export default class AuthRequestHandler {
|
|
|
283
283
|
});
|
|
284
284
|
});
|
|
285
285
|
}
|
|
286
|
+
resetWallet() {
|
|
287
|
+
for (const request of Object.values(this.#authRequestsV2)) {
|
|
288
|
+
request.reject(new Error('Reset wallet'));
|
|
289
|
+
}
|
|
290
|
+
this.authSubjectV2.next([]);
|
|
291
|
+
this.setAuthorize({});
|
|
292
|
+
}
|
|
286
293
|
}
|