@subwallet/extension-base 1.1.68-2 → 1.2.2-0
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 +3 -1
- package/background/handlers/State.d.ts +1 -78
- package/background/handlers/State.js +1 -428
- package/background/types.d.ts +1 -0
- package/cjs/background/handlers/State.js +1 -456
- package/cjs/constants/storage.js +3 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -2
- package/cjs/koni/api/nft/acala_nft/index.js +1 -3
- package/cjs/koni/api/nft/assethub_nft/index.js +1 -3
- package/cjs/koni/api/nft/assethub_unique/index.js +1 -3
- package/cjs/koni/api/nft/bit.country/index.js +4 -6
- package/cjs/koni/api/nft/config.js +1 -8
- package/cjs/koni/api/nft/evm_nft/index.js +1 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -3
- package/cjs/koni/api/nft/ordinal_nft/index.js +4 -3
- package/cjs/koni/api/nft/rmrk_nft/index.js +4 -6
- package/cjs/koni/api/nft/unique_network_nft/index.js +1 -3
- package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +1 -3
- package/cjs/koni/api/nft/vara_nft/index.js +1 -3
- package/cjs/koni/api/nft/wasm_nft/index.js +10 -17
- package/cjs/koni/api/staking/bonding/astar.js +2 -4
- package/cjs/koni/api/staking/subsquidStaking.js +9 -12
- package/cjs/koni/api/subquery/subquery.js +1 -3
- package/cjs/koni/background/handlers/Extension.js +39 -15
- package/cjs/koni/background/handlers/Mobile.js +7 -4
- package/cjs/koni/background/handlers/State.js +68 -12
- package/cjs/koni/background/handlers/Tabs.js +7 -3
- package/cjs/koni/background/handlers/index.js +71 -71
- package/cjs/koni/background/subscription.js +7 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/helpers.js +3 -1
- package/cjs/services/chain-service/index.js +36 -27
- package/cjs/services/chain-service/utils/patch.js +1 -3
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -2
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -3
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -3
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -2
- package/cjs/services/earning-service/handlers/native-staking/astar.js +3 -4
- package/cjs/services/event-service/index.js +0 -1
- package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -3
- package/cjs/services/keyring-service/index.js +22 -0
- package/cjs/services/migration-service/scripts/MigrateRemoveGenesisHash.js +28 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +16 -21
- package/cjs/services/notification-service/NotificationService.js +3 -1
- package/cjs/services/price-service/coingecko.js +6 -7
- package/cjs/services/price-service/index.js +7 -3
- package/cjs/services/request-service/handler/PopupHandler.js +14 -15
- package/cjs/services/setting-service/SettingService.js +4 -1
- package/cjs/services/setting-service/constants.js +1 -1
- package/cjs/services/setting-service/i18n/i18n.js +2 -4
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +14 -1
- package/cjs/services/storage-service/db-stores/KeyValue.js +13 -0
- package/cjs/services/subscan-service/index.js +11 -3
- package/cjs/services/transaction-service/index.js +3 -3
- package/cjs/services/wallet-connect-service/constants.js +2 -2
- package/cjs/services/wallet-connect-service/helpers.js +1 -4
- package/cjs/services/wallet-connect-service/index.js +50 -33
- package/cjs/storage/index.js +120 -23
- package/cjs/types/common/index.js +16 -0
- package/cjs/types/common/storage.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/environment.js +1 -1
- package/cjs/utils/eth/parseTransaction/index.js +8 -10
- package/cjs/utils/fetch.js +55 -0
- package/cjs/utils/fetchStaticCache.js +2 -4
- package/cjs/utils/fetchStaticData.js +7 -4
- package/cjs/utils/index.js +24 -0
- package/cjs/utils/reportError.js +1 -3
- package/constants/storage.d.ts +1 -0
- package/constants/storage.js +1 -0
- package/koni/api/dotsama/crowdloan.js +2 -3
- package/koni/api/nft/acala_nft/index.js +0 -1
- package/koni/api/nft/assethub_nft/index.js +0 -1
- package/koni/api/nft/assethub_unique/index.js +0 -1
- package/koni/api/nft/bit.country/index.js +0 -1
- package/koni/api/nft/config.js +1 -7
- package/koni/api/nft/evm_nft/index.js +0 -1
- package/koni/api/nft/karura_nft/index.js +0 -1
- package/koni/api/nft/ordinal_nft/index.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/index.js +4 -3
- package/koni/api/nft/rmrk_nft/index.js +0 -1
- package/koni/api/nft/unique_network_nft/index.js +0 -1
- package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/koni/api/nft/vara_nft/index.js +0 -1
- package/koni/api/nft/wasm_nft/index.js +4 -10
- package/koni/api/staking/bonding/astar.js +0 -1
- package/koni/api/staking/subsquidStaking.js +10 -12
- package/koni/api/subquery/subquery.js +0 -1
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +29 -8
- package/koni/background/handlers/Mobile.js +9 -6
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +68 -12
- package/koni/background/handlers/Tabs.js +7 -3
- package/koni/background/handlers/index.d.ts +13 -7
- package/koni/background/handlers/index.js +67 -62
- package/koni/background/subscription.js +2 -1
- package/package.json +35 -28
- package/packageInfo.js +1 -1
- package/services/campaign-service/helpers.js +3 -1
- package/services/chain-service/index.js +36 -28
- package/services/chain-service/utils/patch.js +0 -1
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +0 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -1
- package/services/earning-service/handlers/native-staking/astar.js +0 -1
- package/services/event-service/index.js +0 -1
- package/services/history-service/subsquid-multi-chain-history.js +0 -1
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +19 -0
- package/services/migration-service/scripts/MigrateRemoveGenesisHash.d.ts +4 -0
- package/services/migration-service/scripts/MigrateRemoveGenesisHash.js +20 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +17 -21
- package/services/notification-service/NotificationService.js +3 -1
- package/services/price-service/coingecko.js +6 -6
- package/services/price-service/index.js +7 -3
- package/services/request-service/handler/PopupHandler.d.ts +1 -1
- package/services/request-service/handler/PopupHandler.js +14 -15
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +4 -1
- package/services/setting-service/constants.js +2 -2
- package/services/setting-service/i18n/i18n.js +2 -4
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.d.ts +8 -0
- package/services/storage-service/databases/index.js +13 -1
- package/services/storage-service/db-stores/KeyValue.d.ts +4 -0
- package/services/storage-service/db-stores/KeyValue.js +5 -0
- package/services/subscan-service/index.d.ts +2 -0
- package/services/subscan-service/index.js +10 -1
- package/services/transaction-service/index.js +4 -4
- package/services/wallet-connect-service/constants.js +3 -3
- package/services/wallet-connect-service/helpers.js +1 -4
- package/services/wallet-connect-service/index.d.ts +2 -0
- package/services/wallet-connect-service/index.js +42 -31
- package/storage/index.d.ts +19 -9
- package/storage/index.js +115 -23
- package/types/common/index.d.ts +1 -0
- package/types/common/index.js +4 -0
- package/types/common/storage.d.ts +4 -0
- package/types/common/storage.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/environment.js +1 -1
- package/utils/eth/parseTransaction/index.js +8 -10
- package/utils/fetch.d.ts +8 -0
- package/utils/fetch.js +44 -0
- package/utils/fetchStaticCache.js +2 -3
- package/utils/fetchStaticData.d.ts +1 -1
- package/utils/fetchStaticData.js +7 -4
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/reportError.js +0 -1
- package/background/handlers/Extension.d.ts +0 -55
- package/background/handlers/Extension.js +0 -601
- package/background/handlers/Tabs.d.ts +0 -24
- package/background/handlers/Tabs.js +0 -194
- package/background/handlers/index.d.ts +0 -3
- package/background/handlers/index.js +0 -45
- package/cjs/background/handlers/Extension.js +0 -642
- package/cjs/background/handlers/Tabs.js +0 -222
- package/cjs/background/handlers/index.js +0 -54
- package/cjs/koni/background/events.js +0 -14
- package/koni/background/events.d.ts +0 -1
- package/koni/background/events.js +0 -7
package/koni/api/nft/config.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { RuntimeInfo } from '@subwallet/extension-base/utils';
|
|
6
|
-
import Bowser from 'bowser';
|
|
4
|
+
import { isFirefox, RuntimeInfo } from '@subwallet/extension-base/utils';
|
|
7
5
|
export const SINGULAR_V1_ENDPOINT = 'https://singular.rmrk-api.xyz/api/account-rmrk1/';
|
|
8
6
|
export const SINGULAR_V2_ENDPOINT = 'https://singular.rmrk-api.xyz/api/account/';
|
|
9
7
|
export const KANARIA_ENDPOINT = 'https://kanaria.rmrk.app/api/rmrk2/';
|
|
@@ -54,10 +52,6 @@ export const IPFS2_RMRK = 'https://ipfs2.rmrk.link/ipfs/'; // ????
|
|
|
54
52
|
export const IPFS_ETH_ARAGON = 'https://ipfs.eth.aragon.network/ipfs/'; // 400
|
|
55
53
|
export const SUBWALLET_IPFS = 'https://ipfs.subwallet.app/ipfs/'; // ???
|
|
56
54
|
|
|
57
|
-
const detectFirefox = () => {
|
|
58
|
-
return (SWStorage.instance.getItem('browserInfo') || Bowser.getParser(window.navigator.userAgent).getBrowserName()).toLowerCase() === 'firefox';
|
|
59
|
-
};
|
|
60
|
-
const isFirefox = detectFirefox();
|
|
61
55
|
export let SUPPORTED_NFT_NETWORKS;
|
|
62
56
|
(function (SUPPORTED_NFT_NETWORKS) {
|
|
63
57
|
SUPPORTED_NFT_NETWORKS["karura"] = "karura";
|
|
@@ -7,7 +7,6 @@ import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
|
7
7
|
import { _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
8
8
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
10
|
-
import fetch from 'cross-fetch';
|
|
11
10
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
12
11
|
export class EvmNftApi extends BaseNftApi {
|
|
13
12
|
evmContracts = [];
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { getRandomIpfsGateway } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
6
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
7
|
-
import fetch from 'cross-fetch';
|
|
8
7
|
export class KaruraNftApi extends BaseNftApi {
|
|
9
8
|
// eslint-disable-next-line no-useless-constructor
|
|
10
9
|
constructor(api, addresses, chain) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
1
2
|
import { BaseNftApi, HandleNftParams } from '../nft';
|
|
2
3
|
export default class OrdinalNftApi extends BaseNftApi {
|
|
3
4
|
subscanChain: string;
|
|
5
|
+
subscanService: SubscanService;
|
|
4
6
|
constructor(addresses: string[], chain: string, subscanChain: string);
|
|
5
7
|
handleNft(address: string, handleNftParams: HandleNftParams): Promise<void>;
|
|
6
8
|
handleNfts(params: HandleNftParams): Promise<void>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { ORDINAL_COLLECTION } from '@subwallet/extension-base/constants';
|
|
5
|
-
import {
|
|
5
|
+
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
6
6
|
import { BaseNftApi } from "../nft.js";
|
|
7
7
|
const parseParamData = (param, event, chain, address) => {
|
|
8
8
|
const ordinalData = JSON.parse(param.value);
|
|
@@ -43,12 +43,13 @@ export default class OrdinalNftApi extends BaseNftApi {
|
|
|
43
43
|
constructor(addresses, chain, subscanChain) {
|
|
44
44
|
super(chain, undefined, addresses);
|
|
45
45
|
this.subscanChain = subscanChain;
|
|
46
|
+
this.subscanService = SubscanService.getInstance();
|
|
46
47
|
}
|
|
47
48
|
async handleNft(address, handleNftParams) {
|
|
48
|
-
const events = await
|
|
49
|
+
const events = await this.subscanService.getAccountRemarkEvents(this.subscanChain, address);
|
|
49
50
|
if (events && events.length) {
|
|
50
51
|
const extrinsicIds = events.map(data => data.extrinsic_index);
|
|
51
|
-
const extrinsicParams = await
|
|
52
|
+
const extrinsicParams = await this.subscanService.getExtrinsicParams(this.subscanChain, extrinsicIds);
|
|
52
53
|
const items = [];
|
|
53
54
|
for (const data of extrinsicParams) {
|
|
54
55
|
const {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { RMRK_VER } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
6
|
import { isUrl, reformatAddress } from '@subwallet/extension-base/utils';
|
|
7
|
-
import fetch from 'cross-fetch';
|
|
8
7
|
import { SINGULAR_V1_COLLECTION_ENDPOINT, SINGULAR_V2_COLLECTION_ENDPOINT, SINGULAR_V2_ENDPOINT } from "../config.js";
|
|
9
8
|
var RMRK_SOURCE;
|
|
10
9
|
(function (RMRK_SOURCE) {
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { OPAL_SCAN_ENDPOINT, QUARTZ_SCAN_ENDPOINT, UNIQUE_IPFS_GATEWAY, UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
6
|
import { baseParseIPFSUrl } from '@subwallet/extension-base/utils';
|
|
7
|
-
import fetch from 'cross-fetch';
|
|
8
7
|
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
|
9
8
|
export class UniqueNftApi extends BaseNftApi {
|
|
10
9
|
constructor(chain, addresses) {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { UNIQUE_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
|
-
import fetch from 'cross-fetch';
|
|
7
6
|
export class UniqueNftApiV2 extends BaseNftApi {
|
|
8
7
|
endpoint = UNIQUE_SCAN_ENDPOINT;
|
|
9
8
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import { VARA_SCAN_ENDPOINT } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
6
|
-
import fetch from 'cross-fetch';
|
|
7
6
|
import { hexAddPrefix, u8aToHex } from '@polkadot/util';
|
|
8
7
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
9
8
|
export class VaraNftApi extends BaseNftApi {
|
|
@@ -9,8 +9,6 @@ import { getPSP34ContractPromise, getTokenUriMethod, isAzeroDomainNft, isPinkRob
|
|
|
9
9
|
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/tokens/wasm/utils';
|
|
10
10
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
11
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
12
|
-
import axios from 'axios';
|
|
13
|
-
import fetch from 'cross-fetch';
|
|
14
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
15
13
|
|
|
16
14
|
// interface CollectionAttributes {
|
|
@@ -95,10 +93,8 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
95
93
|
return undefined;
|
|
96
94
|
}
|
|
97
95
|
const nftItemImageSrc = `${itemImageApiFromArtZero(this.chain)}?input=${parsedTokenUri}&size=500`;
|
|
98
|
-
const collectionImageUrl = await
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
return collectionImageUrl.data;
|
|
96
|
+
const collectionImageUrl = await fetch(nftItemImageSrc);
|
|
97
|
+
return await collectionImageUrl.text();
|
|
102
98
|
}
|
|
103
99
|
async parseFeaturedCollectionImage(smartContract) {
|
|
104
100
|
const urlencoded = new URLSearchParams();
|
|
@@ -123,10 +119,8 @@ export class WasmNftApi extends BaseNftApi {
|
|
|
123
119
|
return;
|
|
124
120
|
}
|
|
125
121
|
const collectionImageSrc = `${itemImageApiFromArtZero(this.chain)}?input=${parsedCollectionImage}&size=500`;
|
|
126
|
-
const collectionImageUrl = await
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
return collectionImageUrl.data;
|
|
122
|
+
const collectionImageUrl = await fetch(collectionImageSrc);
|
|
123
|
+
return await collectionImageUrl.text();
|
|
130
124
|
}
|
|
131
125
|
|
|
132
126
|
// private async getCollectionAttributes (contractPromise: ContractPromise): Promise<CollectionAttributes> {
|
|
@@ -6,7 +6,6 @@ import { getEarningStatusByNominations } from '@subwallet/extension-base/koni/ap
|
|
|
6
6
|
import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
7
7
|
import { EarningStatus, UnstakingStatus } from '@subwallet/extension-base/types';
|
|
8
8
|
import { isUrl, parseRawNumber } from '@subwallet/extension-base/utils';
|
|
9
|
-
import fetch from 'cross-fetch';
|
|
10
9
|
import { BN, BN_ZERO } from '@polkadot/util';
|
|
11
10
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
12
11
|
const convertAddress = address => {
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
import { APIItemState, StakingType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { INDEXER_SUPPORTED_STAKING_CHAINS, SUBSQUID_ENDPOINTS } from '@subwallet/extension-base/koni/api/staking/config';
|
|
6
6
|
import { _getChainSubstrateAddressPrefix, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
-
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
8
|
-
import axios from 'axios';
|
|
7
|
+
import { fetchJson, reformatAddress } from '@subwallet/extension-base/utils';
|
|
9
8
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
10
9
|
const getSubsquidQuery = (account, chain) => {
|
|
11
10
|
if (chain === 'moonbeam' || chain === 'moonriver' || chain === 'astar') {
|
|
@@ -44,16 +43,13 @@ const getSubsquidStaking = async (accounts, chain, chainInfoMap, callback) => {
|
|
|
44
43
|
type: StakingType.NOMINATED,
|
|
45
44
|
address: reformatAddress(account, 42)
|
|
46
45
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (resp.status === 200) {
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
56
|
-
const respData = resp.data.data;
|
|
46
|
+
try {
|
|
47
|
+
const respData = await fetchJson(SUBSQUID_ENDPOINTS[chain], {
|
|
48
|
+
method: 'post',
|
|
49
|
+
data: {
|
|
50
|
+
query: getSubsquidQuery(parsedAccount, chain)
|
|
51
|
+
}
|
|
52
|
+
});
|
|
57
53
|
const rewardItem = respData.stakerById;
|
|
58
54
|
if (rewardItem) {
|
|
59
55
|
const latestReward = rewardItem.rewards[0];
|
|
@@ -67,6 +63,8 @@ const getSubsquidStaking = async (accounts, chain, chainInfoMap, callback) => {
|
|
|
67
63
|
stakingRewardItem.latestReward = latestReward.amount;
|
|
68
64
|
}
|
|
69
65
|
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error(e);
|
|
70
68
|
}
|
|
71
69
|
if (stakingRewardItem.totalReward && parseFloat(stakingRewardItem.totalReward) > 0) {
|
|
72
70
|
callback(stakingRewardItem);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import { MessageTypes, RequestTypes, ResponseAuthorizeList, ResponseType } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
4
|
+
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
|
|
4
5
|
import { Prefix } from '@polkadot/util-crypto/types';
|
|
6
|
+
export declare const SEED_DEFAULT_LENGTH = 12;
|
|
7
|
+
export declare const SEED_LENGTHS: number[];
|
|
8
|
+
export declare function isJsonPayload(value: SignerPayloadJSON | SignerPayloadRaw): value is SignerPayloadJSON;
|
|
5
9
|
export default class KoniExtension {
|
|
6
10
|
#private;
|
|
7
11
|
constructor(state: KoniState);
|
|
@@ -5,7 +5,6 @@ import { Common } from '@ethereumjs/common';
|
|
|
5
5
|
import { LegacyTransaction } from '@ethereumjs/tx';
|
|
6
6
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
7
7
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
8
|
-
import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/extension-base/background/handlers/Extension';
|
|
9
8
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
10
9
|
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
11
10
|
import { AccountExternalErrorCode, BasicTxErrorType, BasicTxWarningCode, CampaignDataType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, MantaPayEnableMessage, StakingTxErrorType, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
@@ -34,7 +33,7 @@ import { isProposalExpired, isSupportWalletConnectChain, isSupportWalletConnectN
|
|
|
34
33
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
35
34
|
import { AccountsStore } from '@subwallet/extension-base/stores';
|
|
36
35
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
37
|
-
import { BN_ZERO, convertSubjectInfoToAddresses, createTransactionFromRLP, isSameAddress, reformatAddress, signatureToHex, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
36
|
+
import { BN_ZERO, convertSubjectInfoToAddresses, createTransactionFromRLP, isSameAddress, MODULE_SUPPORT, reformatAddress, signatureToHex, uniqueStringArray } from '@subwallet/extension-base/utils';
|
|
38
37
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
39
38
|
import { balanceFormatter, formatNumber } from '@subwallet/extension-base/utils/number';
|
|
40
39
|
import { createPair } from '@subwallet/keyring';
|
|
@@ -66,13 +65,18 @@ const ACCOUNT_ALL_JSON = {
|
|
|
66
65
|
address: ALL_ACCOUNT_KEY,
|
|
67
66
|
name: 'All'
|
|
68
67
|
};
|
|
68
|
+
export const SEED_DEFAULT_LENGTH = 12;
|
|
69
|
+
export const SEED_LENGTHS = [12, 15, 18, 21, 24];
|
|
70
|
+
export function isJsonPayload(value) {
|
|
71
|
+
return value.genesisHash !== undefined;
|
|
72
|
+
}
|
|
69
73
|
export default class KoniExtension {
|
|
70
74
|
#lockTimeOut = undefined;
|
|
71
75
|
#koniState;
|
|
72
76
|
#timeAutoLock = DEFAULT_AUTO_LOCK_TIME;
|
|
73
77
|
#skipAutoLock = false;
|
|
74
|
-
#alwaysLock = false;
|
|
75
78
|
#firstTime = true;
|
|
79
|
+
#alwaysLock = false;
|
|
76
80
|
constructor(state) {
|
|
77
81
|
this.#koniState = state;
|
|
78
82
|
const updateTimeAutoLock = rs => {
|
|
@@ -103,7 +107,7 @@ export default class KoniExtension {
|
|
|
103
107
|
SWStorage.instance.setItem(LATEST_SESSION, JSON.stringify({
|
|
104
108
|
remind: true,
|
|
105
109
|
timeCalculate: time
|
|
106
|
-
}));
|
|
110
|
+
})).catch(console.error);
|
|
107
111
|
};
|
|
108
112
|
this.#koniState.settingService.getSettings(updateTimeAutoLock);
|
|
109
113
|
this.#koniState.settingService.getSubject().subscribe({
|
|
@@ -395,7 +399,7 @@ export default class KoniExtension {
|
|
|
395
399
|
}
|
|
396
400
|
}
|
|
397
401
|
}
|
|
398
|
-
const url = `${chrome.
|
|
402
|
+
const url = `${chrome.runtime.getURL('index.html')}#${path}${subPath || ''}${paramString}`;
|
|
399
403
|
if (!ALLOWED_PATH.includes(path)) {
|
|
400
404
|
console.error('Not allowed to open the url:', url);
|
|
401
405
|
return false;
|
|
@@ -1369,7 +1373,16 @@ export default class KoniExtension {
|
|
|
1369
1373
|
if (isPasswordValidated) {
|
|
1370
1374
|
try {
|
|
1371
1375
|
this._saveCurrentAccountAddress(address, () => {
|
|
1372
|
-
|
|
1376
|
+
var _newAccount$meta, _newAccount$meta2;
|
|
1377
|
+
const newAccount = keyring.restoreAccount(file, password, withMasterPassword);
|
|
1378
|
+
|
|
1379
|
+
// genesisHash is not used in SubWallet => reset it to empty string
|
|
1380
|
+
if ((_newAccount$meta = newAccount.meta) !== null && _newAccount$meta !== void 0 && _newAccount$meta.genesisHash && ((_newAccount$meta2 = newAccount.meta) === null || _newAccount$meta2 === void 0 ? void 0 : _newAccount$meta2.genesisHash) !== '') {
|
|
1381
|
+
keyring.saveAccountMeta(newAccount, {
|
|
1382
|
+
...newAccount.meta,
|
|
1383
|
+
genesisHash: ''
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1373
1386
|
this._addAddressToAuthList(address, isAllowed);
|
|
1374
1387
|
});
|
|
1375
1388
|
if (this.#alwaysLock) {
|
|
@@ -1394,6 +1407,7 @@ export default class KoniExtension {
|
|
|
1394
1407
|
try {
|
|
1395
1408
|
this._saveCurrentAccountAddress(ALL_ACCOUNT_KEY, () => {
|
|
1396
1409
|
keyring.restoreAccounts(file, password);
|
|
1410
|
+
this.#koniState.keyringService.removeNoneHardwareGenesisHash();
|
|
1397
1411
|
this._addAddressesToAuthList(addressList, isAllowed);
|
|
1398
1412
|
});
|
|
1399
1413
|
|
|
@@ -2893,7 +2907,8 @@ export default class KoniExtension {
|
|
|
2893
2907
|
}) {
|
|
2894
2908
|
try {
|
|
2895
2909
|
keyring.unlockKeyring(password);
|
|
2896
|
-
this.#koniState.initMantaPay(password)
|
|
2910
|
+
// this.#koniState.initMantaPay(password)
|
|
2911
|
+
// .catch(console.error);
|
|
2897
2912
|
} catch (e) {
|
|
2898
2913
|
return {
|
|
2899
2914
|
errors: [e.message],
|
|
@@ -3580,7 +3595,7 @@ export default class KoniExtension {
|
|
|
3580
3595
|
}
|
|
3581
3596
|
async initSyncMantaPay(address) {
|
|
3582
3597
|
var _this$koniState$chain3, _this$koniState$chain4, _this$koniState$chain5, _this$koniState$chain6;
|
|
3583
|
-
if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing) {
|
|
3598
|
+
if ((_this$koniState$chain3 = this.#koniState.chainService) !== null && _this$koniState$chain3 !== void 0 && (_this$koniState$chain4 = _this$koniState$chain3.mantaPay) !== null && _this$koniState$chain4 !== void 0 && _this$koniState$chain4.getSyncState().isSyncing || !MODULE_SUPPORT.MANTA_ZK) {
|
|
3584
3599
|
return;
|
|
3585
3600
|
}
|
|
3586
3601
|
this.#skipAutoLock = true;
|
|
@@ -4079,6 +4094,8 @@ export default class KoniExtension {
|
|
|
4079
4094
|
}, this.#timeAutoLock * 60 * 1000);
|
|
4080
4095
|
}
|
|
4081
4096
|
switch (type) {
|
|
4097
|
+
case 'pri(ping)':
|
|
4098
|
+
return 'pong';
|
|
4082
4099
|
/// Clone from PolkadotJs
|
|
4083
4100
|
case 'pri(accounts.create.external)':
|
|
4084
4101
|
return this.accountsCreateExternal(request);
|
|
@@ -4599,6 +4616,10 @@ export default class KoniExtension {
|
|
|
4599
4616
|
return this.#koniState.dbService.importDB(request);
|
|
4600
4617
|
case 'pri(database.exportJson)':
|
|
4601
4618
|
return this.#koniState.dbService.getExportJson();
|
|
4619
|
+
case 'pri(database.migrateLocalStorage)':
|
|
4620
|
+
return this.#koniState.migrateMV3LocalStorage(request);
|
|
4621
|
+
case 'pri(database.setLocalStorage)':
|
|
4622
|
+
return this.#koniState.setStorageFromWS(request);
|
|
4602
4623
|
/* Database */
|
|
4603
4624
|
|
|
4604
4625
|
/* Swap service */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { SWHandler } from '@subwallet/extension-base/koni/background/handlers/index';
|
|
5
5
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
6
|
-
import { listMerge } from '@subwallet/extension-base/utils';
|
|
6
|
+
import { isSupportWindow, listMerge } from '@subwallet/extension-base/utils';
|
|
7
7
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
8
8
|
export function isLocalStorageReset() {
|
|
9
9
|
var _window;
|
|
10
|
-
if ((_window = window) !== null && _window !== void 0 && _window.localStorage) {
|
|
10
|
+
if (isSupportWindow && (_window = window) !== null && _window !== void 0 && _window.localStorage) {
|
|
11
11
|
return !window.localStorage.getItem('keyring:subwallet');
|
|
12
12
|
} else {
|
|
13
13
|
return false;
|
|
@@ -15,7 +15,7 @@ export function isLocalStorageReset() {
|
|
|
15
15
|
}
|
|
16
16
|
export async function isIndexedDBReset() {
|
|
17
17
|
try {
|
|
18
|
-
return (await state.dbService.stores.migration.table.count()) < 1;
|
|
18
|
+
return (await SWHandler.instance.state.dbService.stores.migration.table.count()) < 1;
|
|
19
19
|
} catch (e) {
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
@@ -50,7 +50,9 @@ export default class Mobile {
|
|
|
50
50
|
constructor(state) {
|
|
51
51
|
this.state = state;
|
|
52
52
|
if (!isLocalStorageReset()) {
|
|
53
|
-
|
|
53
|
+
swStorage.copy().then(data => {
|
|
54
|
+
this.lastRestoreData.storage = data;
|
|
55
|
+
}).catch(console.error);
|
|
54
56
|
}
|
|
55
57
|
(async () => {
|
|
56
58
|
if (!(await isIndexedDBReset())) {
|
|
@@ -128,6 +130,7 @@ export default class Mobile {
|
|
|
128
130
|
console.log('restartSubscriptionServices');
|
|
129
131
|
}
|
|
130
132
|
async _getLocalStorageExportData() {
|
|
133
|
+
await swStorage.waitReady;
|
|
131
134
|
return Promise.resolve(JSON.stringify(swStorage.copy()));
|
|
132
135
|
}
|
|
133
136
|
async _getDexieExportData() {
|
|
@@ -177,7 +180,7 @@ export default class Mobile {
|
|
|
177
180
|
if (storage) {
|
|
178
181
|
const storageData = JSON.parse(storage);
|
|
179
182
|
for (const key in storageData) {
|
|
180
|
-
swStorage.setItem(key, storageData[key]);
|
|
183
|
+
await swStorage.setItem(key, storageData[key]);
|
|
181
184
|
}
|
|
182
185
|
}
|
|
183
186
|
if (indexedDB) {
|
|
@@ -24,7 +24,7 @@ import { SubscanService } from '@subwallet/extension-base/services/subscan-servi
|
|
|
24
24
|
import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
25
25
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
26
26
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
27
|
-
import { BalanceMap, EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
27
|
+
import { BalanceMap, EvmFeeInfo, StorageDataInterface } from '@subwallet/extension-base/types';
|
|
28
28
|
import { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
|
|
29
29
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
30
30
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -220,7 +220,12 @@ export default class KoniState {
|
|
|
220
220
|
evmSendTransaction(id: string, url: string, networkKey: string, allowedAccounts: string[], transactionParams: EvmSendTransactionParams): Promise<string | undefined>;
|
|
221
221
|
getConfirmationsQueueSubject(): BehaviorSubject<ConfirmationsQueue>;
|
|
222
222
|
completeConfirmation(request: RequestConfirmationComplete): Promise<boolean>;
|
|
223
|
+
private onMV3Update;
|
|
224
|
+
migrateMV3LocalStorage(data: string): Promise<boolean>;
|
|
225
|
+
private onMV3Install;
|
|
226
|
+
onInstallOrUpdate(details: chrome.runtime.InstalledDetails): void;
|
|
223
227
|
private onHandleRemindExportAccount;
|
|
228
|
+
setStorageFromWS({ key, value }: StorageDataInterface): Promise<boolean>;
|
|
224
229
|
onCheckToRemindUser(): void;
|
|
225
230
|
onInstall(): void;
|
|
226
231
|
get activeNetworks(): Record<string, _ChainInfo>;
|
|
@@ -28,13 +28,12 @@ import { openPopup } from '@subwallet/extension-base/services/request-service/ha
|
|
|
28
28
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
29
29
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
30
30
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
31
|
-
import { SUBSCAN_API_CHAIN_MAP } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
|
|
32
31
|
import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
33
32
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
34
33
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
35
34
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
36
35
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
37
|
-
import { isAccountAll, stripUrl,
|
|
36
|
+
import { isAccountAll, stripUrl, targetIsWeb, wait } from '@subwallet/extension-base/utils';
|
|
38
37
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
39
38
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
40
39
|
import { decodePair } from '@subwallet/keyring/pair/decode';
|
|
@@ -44,7 +43,7 @@ import BN from 'bn.js';
|
|
|
44
43
|
import SimpleKeyring from 'eth-simple-keyring';
|
|
45
44
|
import { t } from 'i18next';
|
|
46
45
|
import { Subject } from 'rxjs';
|
|
47
|
-
import { assert, hexStripPrefix, hexToU8a, isHex, logger as createLogger, u8aToHex } from '@polkadot/util';
|
|
46
|
+
import { assert, hexStripPrefix, hexToU8a, isHex, logger as createLogger, noop, u8aToHex } from '@polkadot/util';
|
|
48
47
|
import { base64Decode, isEthereumAddress, keyExtractSuri } from '@polkadot/util-crypto';
|
|
49
48
|
import { KoniCron } from "../cron.js";
|
|
50
49
|
import { KoniSubscription } from "../subscription.js";
|
|
@@ -94,7 +93,7 @@ export default class KoniState {
|
|
|
94
93
|
this.keyringService = new KeyringService(this.eventService);
|
|
95
94
|
this.notificationService = new NotificationService();
|
|
96
95
|
this.chainService = new ChainService(this.dbService, this.eventService);
|
|
97
|
-
this.subscanService =
|
|
96
|
+
this.subscanService = SubscanService.getInstance();
|
|
98
97
|
this.settingService = new SettingService();
|
|
99
98
|
this.requestService = new RequestService(this.chainService, this.settingService, this.keyringService);
|
|
100
99
|
this.priceService = new PriceService(this.dbService, this.eventService, this.chainService);
|
|
@@ -114,7 +113,7 @@ export default class KoniState {
|
|
|
114
113
|
this.logger = createLogger('State');
|
|
115
114
|
|
|
116
115
|
// Init state
|
|
117
|
-
if (
|
|
116
|
+
if (targetIsWeb) {
|
|
118
117
|
this.init().catch(console.error);
|
|
119
118
|
}
|
|
120
119
|
}
|
|
@@ -1343,15 +1342,57 @@ export default class KoniState {
|
|
|
1343
1342
|
async completeConfirmation(request) {
|
|
1344
1343
|
return await this.requestService.completeConfirmation(request);
|
|
1345
1344
|
}
|
|
1346
|
-
|
|
1347
|
-
const
|
|
1345
|
+
async onMV3Update() {
|
|
1346
|
+
const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
|
|
1347
|
+
if (!migrationStatus || migrationStatus !== 'done') {
|
|
1348
|
+
// Open migration tab
|
|
1349
|
+
const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
|
|
1350
|
+
await openPopup(url);
|
|
1351
|
+
|
|
1352
|
+
// migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
async migrateMV3LocalStorage(data) {
|
|
1357
|
+
try {
|
|
1358
|
+
const parsedData = JSON.parse(data);
|
|
1359
|
+
parsedData.mv3_migration = 'done';
|
|
1360
|
+
await SWStorage.instance.setMap(parsedData);
|
|
1361
|
+
|
|
1362
|
+
// Reload some services use SWStorage
|
|
1363
|
+
// wallet connect
|
|
1364
|
+
this.walletConnectService.initClient().catch(console.error);
|
|
1365
|
+
return true;
|
|
1366
|
+
} catch (e) {
|
|
1367
|
+
console.error(e);
|
|
1368
|
+
return false;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
async onMV3Install() {
|
|
1372
|
+
await SWStorage.instance.setItem('mv3_migration', 'done');
|
|
1373
|
+
|
|
1374
|
+
// Open expand page
|
|
1375
|
+
const url = `${chrome.runtime.getURL('index.html')}#/welcome`;
|
|
1376
|
+
withErrorLog(() => chrome.tabs.create({
|
|
1377
|
+
url
|
|
1378
|
+
}));
|
|
1379
|
+
}
|
|
1380
|
+
onInstallOrUpdate(details) {
|
|
1381
|
+
// Open mv3 migration window
|
|
1382
|
+
if (details.reason === 'install') {
|
|
1383
|
+
this.onMV3Install().catch(console.error);
|
|
1384
|
+
} else if (details.reason === 'update') {
|
|
1385
|
+
this.onMV3Update().catch(console.error);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
async onHandleRemindExportAccount() {
|
|
1389
|
+
const remindStatus = await SWStorage.instance.getItem(REMIND_EXPORT_ACCOUNT);
|
|
1348
1390
|
if (!remindStatus || !remindStatus.includes('done')) {
|
|
1349
1391
|
const handleRemind = account => {
|
|
1350
1392
|
if (account.address !== '') {
|
|
1351
1393
|
// Open remind tab
|
|
1352
1394
|
const url = `${chrome.runtime.getURL('index.html')}#/remind-export-account`;
|
|
1353
|
-
openPopup(url);
|
|
1354
|
-
subscription.unsubscribe();
|
|
1395
|
+
openPopup(url).then(noop).catch(console.error).finally(() => subscription.unsubscribe());
|
|
1355
1396
|
} else {
|
|
1356
1397
|
setTimeout(() => {
|
|
1357
1398
|
subscription.unsubscribe();
|
|
@@ -1361,8 +1402,21 @@ export default class KoniState {
|
|
|
1361
1402
|
const subscription = this.keyringService.currentAccountSubject.subscribe(handleRemind);
|
|
1362
1403
|
}
|
|
1363
1404
|
}
|
|
1405
|
+
async setStorageFromWS({
|
|
1406
|
+
key,
|
|
1407
|
+
value
|
|
1408
|
+
}) {
|
|
1409
|
+
try {
|
|
1410
|
+
const jsonData = JSON.stringify(value);
|
|
1411
|
+
await SWStorage.instance.setItem(key, jsonData);
|
|
1412
|
+
return true;
|
|
1413
|
+
} catch (e) {
|
|
1414
|
+
console.error(e);
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1364
1418
|
onCheckToRemindUser() {
|
|
1365
|
-
this.onHandleRemindExportAccount();
|
|
1419
|
+
this.onHandleRemindExportAccount().catch(console.error);
|
|
1366
1420
|
}
|
|
1367
1421
|
onInstall() {
|
|
1368
1422
|
// const singleModes = Object.values(_PREDEFINED_SINGLE_MODES);
|
|
@@ -1448,7 +1502,7 @@ export default class KoniState {
|
|
|
1448
1502
|
this.generalStatus = ServiceStatus.STOPPED;
|
|
1449
1503
|
this.waitSleeping = null;
|
|
1450
1504
|
}
|
|
1451
|
-
async _start(
|
|
1505
|
+
async _start() {
|
|
1452
1506
|
// Wait sleep finish before start to avoid conflict
|
|
1453
1507
|
this.generalStatus === ServiceStatus.STOPPING && this.waitSleeping && (await this.waitSleeping);
|
|
1454
1508
|
|
|
@@ -1462,6 +1516,7 @@ export default class KoniState {
|
|
|
1462
1516
|
await this.waitStarting;
|
|
1463
1517
|
return;
|
|
1464
1518
|
}
|
|
1519
|
+
const isWakeup = this.generalStatus === ServiceStatus.STOPPED;
|
|
1465
1520
|
const starting = createPromiseHandler();
|
|
1466
1521
|
this.generalStatus = ServiceStatus.STARTING;
|
|
1467
1522
|
this.waitStarting = starting.promise;
|
|
@@ -1481,7 +1536,7 @@ export default class KoniState {
|
|
|
1481
1536
|
this.generalStatus = ServiceStatus.STARTED;
|
|
1482
1537
|
}
|
|
1483
1538
|
async wakeup() {
|
|
1484
|
-
await this._start(
|
|
1539
|
+
await this._start();
|
|
1485
1540
|
}
|
|
1486
1541
|
cancelSubscription(id) {
|
|
1487
1542
|
if (isSubscriptionRunning(id)) {
|
|
@@ -1570,6 +1625,7 @@ export default class KoniState {
|
|
|
1570
1625
|
await this.dbService.resetWallet(resetAll);
|
|
1571
1626
|
this.accountRefStore.set('refList', []);
|
|
1572
1627
|
if (resetAll) {
|
|
1628
|
+
await this.priceService.setPriceCurrency(DEFAULT_CURRENCY);
|
|
1573
1629
|
this.settingService.resetWallet();
|
|
1574
1630
|
await this.priceService.setPriceCurrency(DEFAULT_CURRENCY);
|
|
1575
1631
|
}
|
|
@@ -182,7 +182,7 @@ export default class KoniTabs {
|
|
|
182
182
|
redirectPhishingLanding(phishingWebsite) {
|
|
183
183
|
const nonFragment = phishingWebsite.split('#')[0];
|
|
184
184
|
const encodedWebsite = encodeURIComponent(nonFragment);
|
|
185
|
-
const url = `${chrome.
|
|
185
|
+
const url = `${chrome.runtime.getURL('index.html')}#${PHISHING_PAGE_REDIRECT}/${encodedWebsite}`;
|
|
186
186
|
chrome.tabs.query({
|
|
187
187
|
url: nonFragment
|
|
188
188
|
}, tabs => {
|
|
@@ -927,6 +927,12 @@ export default class KoniTabs {
|
|
|
927
927
|
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
928
928
|
return this.redirectIfPhishing(url);
|
|
929
929
|
}
|
|
930
|
+
if (type === 'pub(ping)') {
|
|
931
|
+
return Promise.resolve(true);
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// Wait for account ready and chain ready
|
|
935
|
+
await Promise.all([this.#koniState.eventService.waitAccountReady, this.#koniState.eventService.waitChainReady]);
|
|
930
936
|
if (type !== 'pub(authorize.tabV2)' && !this.isEvmPublicRequest(type, request)) {
|
|
931
937
|
await this.#koniState.ensureUrlAuthorizedV2(url).catch(e => {
|
|
932
938
|
if (type.startsWith('evm')) {
|
|
@@ -946,8 +952,6 @@ export default class KoniTabs {
|
|
|
946
952
|
return this.metadataList(url);
|
|
947
953
|
case 'pub(metadata.provide)':
|
|
948
954
|
return this.metadataProvide(url, request);
|
|
949
|
-
case 'pub(ping)':
|
|
950
|
-
return Promise.resolve(true);
|
|
951
955
|
case 'pub(rpc.listProviders)':
|
|
952
956
|
return this.rpcListProviders();
|
|
953
957
|
case 'pub(rpc.send)':
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
2
|
import { MessageTypes, TransportRequestMessage } from '@subwallet/extension-base/background/types';
|
|
3
|
-
import { NftHandler } from '@subwallet/extension-base/koni/api/nft';
|
|
4
3
|
import KoniExtension from '@subwallet/extension-base/koni/background/handlers/Extension';
|
|
5
4
|
import Mobile from '@subwallet/extension-base/koni/background/handlers/Mobile';
|
|
6
5
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
7
6
|
import KoniTabs from '@subwallet/extension-base/koni/background/handlers/Tabs';
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
export declare class SWHandler {
|
|
8
|
+
_state?: KoniState;
|
|
9
|
+
_extensionHandler?: KoniExtension;
|
|
10
|
+
_tabsHandler?: KoniTabs;
|
|
11
|
+
_mobileHandler?: Mobile;
|
|
12
|
+
get state(): KoniState;
|
|
13
|
+
get extensionHandler(): KoniExtension;
|
|
14
|
+
get tabHandler(): KoniTabs;
|
|
15
|
+
get mobileHandler(): Mobile;
|
|
16
|
+
handle<TMessageType extends MessageTypes>({ id, message, request }: TransportRequestMessage<TMessageType>, port: chrome.runtime.Port): void;
|
|
17
|
+
private static _instance;
|
|
18
|
+
static get instance(): SWHandler;
|
|
19
|
+
}
|