@subwallet/extension-base 1.0.1 → 1.0.2-1b
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 -36
- package/background/KoniTypes.js +12 -7
- package/background/errors/TransactionError.js +21 -1
- package/cjs/background/KoniTypes.js +14 -8
- package/cjs/background/errors/TransactionError.js +20 -0
- package/cjs/constants/index.js +13 -28
- package/cjs/koni/api/dotsama/balance.js +60 -224
- package/cjs/koni/api/dotsama/transfer.js +30 -29
- package/cjs/koni/api/nft/acala_nft/index.js +4 -1
- package/cjs/koni/api/nft/bit.country/index.js +4 -1
- package/cjs/koni/api/nft/evm_nft/index.js +7 -3
- package/cjs/koni/api/nft/index.js +3 -6
- package/cjs/koni/api/nft/karura_nft/index.js +4 -1
- package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
- package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
- package/cjs/koni/api/nft/unique_nft/index.js +6 -1
- package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
- package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
- package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
- package/cjs/koni/api/staking/bonding/astar.js +37 -238
- package/cjs/koni/api/staking/bonding/index.js +26 -14
- package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
- package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
- package/cjs/koni/api/staking/bonding/utils.js +55 -10
- package/cjs/koni/api/tokens/wasm/index.js +5 -4
- package/cjs/koni/api/tokens/wasm/utils.js +63 -0
- package/cjs/koni/api/xcm/index.js +0 -111
- package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
- package/cjs/koni/api/xcm/utils.js +18 -13
- package/cjs/koni/api/xcm/xTokens.js +3 -5
- package/cjs/koni/api/xcm/xcmPallet.js +9 -6
- package/cjs/koni/background/cron.js +179 -77
- package/cjs/koni/background/handlers/Extension.js +231 -195
- package/cjs/koni/background/handlers/State.js +147 -111
- package/cjs/koni/background/handlers/Tabs.js +48 -39
- package/cjs/koni/background/subscription.js +64 -56
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +5 -0
- package/cjs/services/chain-service/constants.js +1 -11
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
- package/cjs/services/chain-service/handler/light-client/index.js +2 -0
- package/cjs/services/chain-service/index.js +39 -6
- package/cjs/services/chain-service/utils.js +4 -0
- package/cjs/services/event-service/index.js +75 -0
- package/cjs/services/event-service/types.js +11 -0
- package/cjs/services/history-service/index.js +46 -21
- package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
- package/cjs/services/keyring-service/index.js +101 -0
- package/cjs/services/migration-service/index.js +13 -10
- package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
- package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
- package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
- package/cjs/services/migration-service/scripts/index.js +13 -4
- package/cjs/services/price-service/coingecko.js +15 -3
- package/cjs/services/price-service/index.js +15 -18
- package/cjs/services/request-service/constants.js +8 -2
- package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
- package/cjs/services/request-service/index.js +3 -0
- package/cjs/services/storage-service/DatabaseService.js +53 -34
- package/cjs/services/storage-service/databases/index.js +1 -1
- package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/cjs/services/storage-service/db-stores/Nft.js +8 -18
- package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
- package/cjs/services/subscan-service/index.js +107 -0
- package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
- package/cjs/services/subscan-service/types.js +1 -0
- package/cjs/services/transaction-service/event-parser/index.js +20 -48
- package/cjs/services/transaction-service/index.js +66 -22
- package/cjs/services/transaction-service/utils.js +4 -6
- package/cjs/utils/address.js +9 -1
- package/cjs/utils/index.js +30 -26
- package/constants/index.d.ts +8 -13
- package/constants/index.js +8 -13
- package/koni/api/dotsama/balance.d.ts +0 -1
- package/koni/api/dotsama/balance.js +33 -197
- package/koni/api/dotsama/transfer.js +5 -4
- package/koni/api/nft/acala_nft/index.js +3 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/evm_nft/index.js +6 -3
- package/koni/api/nft/index.d.ts +1 -2
- package/koni/api/nft/index.js +3 -6
- package/koni/api/nft/karura_nft/index.js +3 -1
- package/koni/api/nft/nft.d.ts +1 -0
- package/koni/api/nft/rmrk_nft/index.js +8 -1
- package/koni/api/nft/statemine_nft/index.js +3 -1
- package/koni/api/nft/unique_nft/index.js +5 -1
- package/koni/api/nft/wasm_nft/index.d.ts +0 -2
- package/koni/api/nft/wasm_nft/index.js +167 -109
- package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
- package/koni/api/nft/wasm_nft/utils.js +7 -5
- package/koni/api/staking/bonding/amplitude.d.ts +1 -2
- package/koni/api/staking/bonding/amplitude.js +22 -13
- package/koni/api/staking/bonding/astar.d.ts +2 -11
- package/koni/api/staking/bonding/astar.js +39 -231
- package/koni/api/staking/bonding/index.d.ts +5 -2
- package/koni/api/staking/bonding/index.js +27 -17
- package/koni/api/staking/bonding/paraChain.d.ts +4 -1
- package/koni/api/staking/bonding/paraChain.js +101 -14
- package/koni/api/staking/bonding/relayChain.d.ts +6 -2
- package/koni/api/staking/bonding/relayChain.js +172 -17
- package/koni/api/staking/bonding/utils.d.ts +15 -2
- package/koni/api/staking/bonding/utils.js +53 -11
- package/koni/api/tokens/wasm/index.js +5 -4
- package/koni/api/tokens/wasm/utils.d.ts +6 -0
- package/koni/api/tokens/wasm/utils.js +54 -0
- package/koni/api/xcm/index.js +1 -112
- package/koni/api/xcm/polkadotXcm.js +3 -3
- package/koni/api/xcm/utils.d.ts +5 -6
- package/koni/api/xcm/utils.js +15 -10
- package/koni/api/xcm/xTokens.js +5 -7
- package/koni/api/xcm/xcmPallet.js +10 -9
- package/koni/background/cron.d.ts +6 -1
- package/koni/background/cron.js +179 -76
- package/koni/background/handlers/Extension.d.ts +2 -2
- package/koni/background/handlers/Extension.js +161 -125
- package/koni/background/handlers/State.d.ts +21 -20
- package/koni/background/handlers/State.js +144 -111
- package/koni/background/handlers/Tabs.js +30 -20
- package/koni/background/subscription.d.ts +1 -1
- package/koni/background/subscription.js +64 -58
- package/package.json +63 -18
- package/packageInfo.js +1 -1
- package/page/index.d.ts +2 -0
- package/page/index.js +4 -0
- package/services/chain-service/constants.d.ts +0 -1
- package/services/chain-service/constants.js +0 -9
- package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
- package/services/chain-service/handler/light-client/index.d.ts +17 -1
- package/services/chain-service/handler/light-client/index.js +1 -1
- package/services/chain-service/helper/psp22_abi.json +1041 -881
- package/services/chain-service/helper/psp34_abi.json +2963 -1807
- package/services/chain-service/index.d.ts +6 -4
- package/services/chain-service/index.js +40 -9
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +3 -0
- package/services/event-service/index.d.ts +22 -0
- package/services/event-service/index.js +63 -0
- package/services/event-service/types.d.ts +28 -0
- package/services/event-service/types.js +4 -0
- package/services/history-service/index.d.ts +5 -3
- package/services/history-service/index.js +46 -21
- package/services/history-service/subsquid-multi-chain-history.js +22 -13
- package/services/keyring-service/index.d.ts +19 -0
- package/services/keyring-service/index.js +93 -0
- package/services/migration-service/index.js +11 -9
- package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
- package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
- package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
- package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
- package/services/migration-service/scripts/MigrateSettings.js +23 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
- package/services/migration-service/scripts/index.d.ts +1 -0
- package/services/migration-service/scripts/index.js +10 -3
- package/services/price-service/coingecko.js +15 -3
- package/services/price-service/index.d.ts +5 -3
- package/services/price-service/index.js +15 -18
- package/services/request-service/constants.d.ts +1 -0
- package/services/request-service/constants.js +6 -1
- package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
- package/services/request-service/handler/AuthRequestHandler.js +44 -13
- package/services/request-service/index.d.ts +7 -1
- package/services/request-service/index.js +3 -0
- package/services/storage-service/DatabaseService.d.ts +1 -0
- package/services/storage-service/DatabaseService.js +53 -34
- package/services/storage-service/databases/index.js +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
- package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
- package/services/storage-service/db-stores/Nft.d.ts +3 -3
- package/services/storage-service/db-stores/Nft.js +8 -17
- package/services/storage-service/db-stores/Transaction.js +10 -7
- package/services/subscan-service/index.d.ts +20 -0
- package/services/subscan-service/index.js +99 -0
- package/services/subscan-service/subscan-chain-map.d.ts +5 -0
- package/services/subscan-service/subscan-chain-map.js +63 -0
- package/services/subscan-service/types.d.ts +27 -0
- package/services/subscan-service/types.js +1 -0
- package/services/transaction-service/event-parser/index.d.ts +2 -2
- package/services/transaction-service/event-parser/index.js +21 -49
- package/services/transaction-service/index.d.ts +4 -2
- package/services/transaction-service/index.js +66 -22
- package/services/transaction-service/utils.js +5 -6
- package/utils/address.d.ts +1 -0
- package/utils/address.js +9 -2
- package/utils/index.d.ts +2 -1
- package/utils/index.js +26 -23
- package/cjs/background/errors/EvmRpcError.js +0 -21
- package/cjs/background/errors/SubWalletProviderError.js +0 -17
- package/cjs/constants/ethereum.js +0 -19
- package/cjs/errors/SubWalletProviderError.js +0 -17
- package/cjs/koni/api/xcm/astar.js +0 -160
- package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
- package/cjs/koni/api/xcm/statemintXcm.js +0 -197
- package/cjs/koni/api/xcm/substrateXcm.js +0 -213
- package/cjs/koni/migration/Base.js +0 -20
- package/cjs/koni/migration/index.js +0 -45
- package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
- package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
- package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
- package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
- package/cjs/koni/migration/scripts/index.js +0 -22
- package/cjs/koni/page/index.js +0 -16
- package/cjs/services/asset-service/index.js +0 -91
- package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
- package/cjs/stores/Balance.js +0 -18
- package/cjs/stores/Crowdloan.js +0 -18
- package/cjs/stores/CustomEvmToken.js +0 -18
- package/cjs/stores/NetworkMap.js +0 -18
- package/cjs/stores/Nft.js +0 -18
- package/cjs/stores/NftCollection.js +0 -18
- package/cjs/stores/Price.js +0 -18
- package/cjs/stores/Staking.js +0 -18
- package/cjs/stores/StakingReward.js +0 -18
- package/cjs/utils/eth/parseTransactionData.js +0 -284
- package/koni/page/index.d.ts +0 -2
- package/koni/page/index.js +0 -9
- /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
- /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { logger as createLogger } from '@polkadot/util';
|
|
5
|
-
import MigrationScripts from "./scripts/index.js";
|
|
5
|
+
import MigrationScripts, { EVERYTIME } from "./scripts/index.js";
|
|
6
6
|
export default class MigrationService {
|
|
7
7
|
constructor(state) {
|
|
8
8
|
this.state = state;
|
|
@@ -14,23 +14,25 @@ export default class MigrationService {
|
|
|
14
14
|
try {
|
|
15
15
|
for (let i = 0; i < keys.length; i++) {
|
|
16
16
|
const JobClass = MigrationScripts[keys[i]];
|
|
17
|
+
const key = keys[i];
|
|
18
|
+
const name = JobClass.name;
|
|
17
19
|
const check = await this.state.dbService.stores.migration.table.where({
|
|
18
|
-
name
|
|
19
|
-
key
|
|
20
|
+
name,
|
|
21
|
+
key
|
|
20
22
|
}).first();
|
|
21
|
-
if (!check) {
|
|
22
|
-
const job = new JobClass(this.state);
|
|
23
|
+
if (!check || key.startsWith(EVERYTIME)) {
|
|
23
24
|
this.logger.log('Running script: ', JobClass.name);
|
|
25
|
+
const job = new JobClass(this.state);
|
|
24
26
|
await job.run();
|
|
25
27
|
await this.state.dbService.stores.migration.table.put({
|
|
26
|
-
key
|
|
27
|
-
name
|
|
28
|
-
timestamp:
|
|
28
|
+
key,
|
|
29
|
+
name,
|
|
30
|
+
timestamp: new Date().getTime()
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
} catch (error) {
|
|
33
|
-
this.logger.
|
|
35
|
+
this.logger.error('Migration error: ', error);
|
|
34
36
|
}
|
|
35
37
|
this.logger.log('Migration done.');
|
|
36
38
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
import { keyring } from '@subwallet/ui-keyring';
|
|
6
|
+
export default class AutoEnableChainsTokens extends BaseMigrationJob {
|
|
7
|
+
async run() {
|
|
8
|
+
const accounts = keyring.getAccounts();
|
|
9
|
+
await this.state.autoEnableChains(accounts.map(({
|
|
10
|
+
address
|
|
11
|
+
}) => address));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { _AssetType } from '@subwallet/chain-list/types';
|
|
4
5
|
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
6
|
export default class MigrateNetworkSettings extends BaseMigrationJob {
|
|
6
7
|
async run() {
|
|
7
8
|
const state = this.state;
|
|
8
|
-
|
|
9
|
-
chrome.storage.local.get('NetworkMap',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const items = await new Promise(resolve => {
|
|
10
|
+
chrome.storage.local.get('NetworkMap', items => {
|
|
11
|
+
resolve(items);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
const oldNetworkMap = items.NetworkMap;
|
|
15
|
+
const enableList = [];
|
|
16
|
+
const stateMap = state.getChainStateMap();
|
|
17
|
+
if (!oldNetworkMap) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
Object.entries(oldNetworkMap).forEach(([slug, chain]) => {
|
|
21
|
+
if (chain.active) {
|
|
22
|
+
const currentState = stateMap[slug];
|
|
23
|
+
|
|
24
|
+
// Ensure chain in the list and is not active
|
|
25
|
+
currentState && enableList.push(slug);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (enableList.length > 0) {
|
|
29
|
+
state.chainService.enableChains(enableList);
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
// Enable native token of these chains
|
|
32
|
+
const currentAssetSettings = await state.chainService.getAssetSettings();
|
|
33
|
+
const assetInfoMap = state.chainService.getAssetRegistry();
|
|
34
|
+
Object.entries(assetInfoMap).forEach(([slug, assetInfo]) => {
|
|
35
|
+
const assetSetting = currentAssetSettings[slug] || {};
|
|
36
|
+
|
|
37
|
+
// Enable native token of these chains
|
|
38
|
+
if (assetInfo.name && assetInfo.assetType === _AssetType.NATIVE && enableList.includes(assetInfo.originChain) && !assetSetting.visible) {
|
|
39
|
+
currentAssetSettings[slug] = {
|
|
40
|
+
visible: true
|
|
41
|
+
};
|
|
25
42
|
}
|
|
26
|
-
resolve();
|
|
27
43
|
});
|
|
28
|
-
|
|
44
|
+
state.chainService.setAssetSettings({
|
|
45
|
+
...currentAssetSettings
|
|
46
|
+
});
|
|
47
|
+
}
|
|
29
48
|
}
|
|
30
49
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import uiSettings from '@polkadot/ui-settings';
|
|
6
|
+
export default class MigrateSettings extends BaseMigrationJob {
|
|
7
|
+
async run() {
|
|
8
|
+
try {
|
|
9
|
+
return new Promise(resolve => {
|
|
10
|
+
this.state.settingService.getSettings(currentSettings => {
|
|
11
|
+
const isAccessCamera = uiSettings.camera === 'on';
|
|
12
|
+
this.state.settingService.setSettings({
|
|
13
|
+
...currentSettings,
|
|
14
|
+
camera: isAccessCamera
|
|
15
|
+
});
|
|
16
|
+
resolve();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.error(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChainType, ExtrinsicStatus, ExtrinsicType, TransactionDirection } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
7
|
+
import Dexie from 'dexie';
|
|
8
|
+
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
9
|
+
export default class MigrateTransactionHistory extends BaseMigrationJob {
|
|
10
|
+
async run() {
|
|
11
|
+
const state = this.state;
|
|
12
|
+
const chainInfoMap = state.getChainInfoMap();
|
|
13
|
+
const assetList = Object.values(state.getAssetRegistry());
|
|
14
|
+
try {
|
|
15
|
+
const db = new Dexie('SubWalletDB');
|
|
16
|
+
const dexieDB = await db.open();
|
|
17
|
+
const transactionTable = dexieDB.table('transactions');
|
|
18
|
+
const oldTransactionData = await transactionTable.toArray();
|
|
19
|
+
const newTransactionItems = [];
|
|
20
|
+
oldTransactionData.forEach(item => {
|
|
21
|
+
const chainInfo = chainInfoMap[item.networkKey];
|
|
22
|
+
if (!chainInfo) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const direction = item.action === 'send' ? TransactionDirection.SEND : TransactionDirection.RECEIVED;
|
|
26
|
+
const extrinsicType = item.changeSymbol === item.feeSymbol ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.TRANSFER_TOKEN;
|
|
27
|
+
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
28
|
+
const transferAsset = assetList.find(a => a.originChain === item.networkKey && a.symbol === item.changeSymbol) || nativeAsset;
|
|
29
|
+
const newItem = {
|
|
30
|
+
chain: item.networkKey,
|
|
31
|
+
origin: 'migration',
|
|
32
|
+
type: extrinsicType,
|
|
33
|
+
address: item.address,
|
|
34
|
+
extrinsicHash: item.extrinsicHash,
|
|
35
|
+
time: item.time,
|
|
36
|
+
status: item.isSuccess ? ExtrinsicStatus.SUCCESS : ExtrinsicStatus.FAIL,
|
|
37
|
+
from: direction === TransactionDirection.SEND ? item.address : '',
|
|
38
|
+
to: direction === TransactionDirection.RECEIVED ? item.address : '',
|
|
39
|
+
amount: {
|
|
40
|
+
value: item.change,
|
|
41
|
+
decimals: transferAsset.decimals || 18,
|
|
42
|
+
symbol: transferAsset.symbol
|
|
43
|
+
},
|
|
44
|
+
fee: {
|
|
45
|
+
value: item.fee,
|
|
46
|
+
decimals: nativeAsset.decimals,
|
|
47
|
+
symbol: nativeAsset.symbol
|
|
48
|
+
},
|
|
49
|
+
direction: direction,
|
|
50
|
+
chainType: isEthereumAddress(item.address) ? ChainType.EVM : ChainType.SUBSTRATE,
|
|
51
|
+
chainName: chainInfo.name,
|
|
52
|
+
blockNumber: 0,
|
|
53
|
+
blockHash: '',
|
|
54
|
+
data: '',
|
|
55
|
+
signature: ''
|
|
56
|
+
};
|
|
57
|
+
newTransactionItems.push(newItem);
|
|
58
|
+
});
|
|
59
|
+
await state.historyService.addHistoryItems(newTransactionItems);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
this.logger.error(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import AutoEnableChainsTokens from '@subwallet/extension-base/services/migration-service/scripts/AutoEnableChainsTokens';
|
|
4
5
|
import MigrateImportedToken from '@subwallet/extension-base/services/migration-service/scripts/MigrateImportedToken';
|
|
5
6
|
import MigrateNetworkSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateNetworkSettings';
|
|
7
|
+
import MigrateSettings from '@subwallet/extension-base/services/migration-service/scripts/MigrateSettings';
|
|
8
|
+
import MigrateTransactionHistory from '@subwallet/extension-base/services/migration-service/scripts/MigrateTransactionHistory';
|
|
9
|
+
export const EVERYTIME = '__everytime__';
|
|
6
10
|
export default {
|
|
7
|
-
'1.0.1-
|
|
8
|
-
'1.0.1-
|
|
9
|
-
|
|
11
|
+
'1.0.1-11': MigrateNetworkSettings,
|
|
12
|
+
'1.0.1-20': MigrateImportedToken,
|
|
13
|
+
'1.0.1-30': MigrateTransactionHistory,
|
|
14
|
+
'1.0.1-40': AutoEnableChainsTokens,
|
|
15
|
+
'1.0.1-50': MigrateSettings
|
|
16
|
+
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
10
17
|
};
|
|
@@ -2,15 +2,27 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import axios from 'axios';
|
|
5
|
+
let useBackupApi = false;
|
|
5
6
|
export const getTokenPrice = async (priceIds, currency = 'usd') => {
|
|
6
7
|
try {
|
|
8
|
+
var _res;
|
|
7
9
|
const idStr = Array.from(priceIds).join(',');
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
let res;
|
|
11
|
+
if (!useBackupApi) {
|
|
12
|
+
try {
|
|
13
|
+
res = await axios.get(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency}&per_page=250&ids=${idStr}`);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
useBackupApi = true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (useBackupApi || ((_res = res) === null || _res === void 0 ? void 0 : _res.status) !== 200) {
|
|
19
|
+
useBackupApi = true;
|
|
20
|
+
res = await axios.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
|
|
21
|
+
}
|
|
10
22
|
if (res.status !== 200) {
|
|
11
23
|
console.warn('Failed to get token price');
|
|
12
24
|
}
|
|
13
|
-
const responseData = res.data;
|
|
25
|
+
const responseData = res.data || [];
|
|
14
26
|
const priceMap = {};
|
|
15
27
|
const price24hMap = {};
|
|
16
28
|
responseData.forEach(val => {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { PriceJson
|
|
1
|
+
import { PriceJson } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
3
|
+
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
3
4
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
4
|
-
import { BehaviorSubject
|
|
5
|
+
import { BehaviorSubject } from 'rxjs';
|
|
5
6
|
export declare class PriceService {
|
|
6
7
|
private dbService;
|
|
8
|
+
private eventService;
|
|
7
9
|
private chainService;
|
|
8
10
|
private priceSubject;
|
|
9
11
|
private refreshTimeout;
|
|
10
12
|
private priceIds;
|
|
11
|
-
constructor(
|
|
13
|
+
constructor(dbService: DatabaseService, eventService: EventService, chainService: ChainService);
|
|
12
14
|
getPrice(): Promise<PriceJson>;
|
|
13
15
|
getPriceSubject(): BehaviorSubject<PriceJson>;
|
|
14
16
|
getPriceIds(): Set<string>;
|
|
@@ -13,27 +13,27 @@ const DEFAULT_PRICE_SUBJECT = {
|
|
|
13
13
|
export class PriceService {
|
|
14
14
|
priceSubject = new BehaviorSubject(DEFAULT_PRICE_SUBJECT);
|
|
15
15
|
priceIds = new Set();
|
|
16
|
-
constructor(
|
|
16
|
+
constructor(dbService, eventService, chainService) {
|
|
17
17
|
this.dbService = dbService;
|
|
18
|
+
this.eventService = eventService;
|
|
18
19
|
this.chainService = chainService;
|
|
19
20
|
|
|
20
21
|
// Fetch data from storage
|
|
21
22
|
this.getPrice().catch(console.error);
|
|
23
|
+
const eventHandler = () => {
|
|
24
|
+
const newPriceIds = this.getPriceIds();
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
// Compare two set newPriceIds and this.priceIds
|
|
27
|
+
if (newPriceIds.size !== this.priceIds.size || !Array.from(newPriceIds).every(v => this.priceIds.has(v))) {
|
|
28
|
+
this.priceIds = newPriceIds;
|
|
29
|
+
this.refreshPriceData(this.priceIds);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
this.eventService.waitAssetReady.then(() => {
|
|
26
33
|
this.refreshPriceData();
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Compare two set newPriceIds and this.priceIds
|
|
31
|
-
if (newPriceIds.size !== this.priceIds.size || !Array.from(newPriceIds).every(v => this.priceIds.has(v))) {
|
|
32
|
-
this.priceIds = newPriceIds;
|
|
33
|
-
this.refreshPriceData(this.priceIds);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}, 3000);
|
|
34
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
35
|
+
this.eventService.on('asset.updateState', eventHandler);
|
|
36
|
+
}).catch(console.error);
|
|
37
37
|
}
|
|
38
38
|
async getPrice() {
|
|
39
39
|
const isReady = this.priceSubject.value.ready;
|
|
@@ -62,10 +62,7 @@ export class PriceService {
|
|
|
62
62
|
ready: true
|
|
63
63
|
});
|
|
64
64
|
this.dbService.updatePriceStore(rs).catch(console.error);
|
|
65
|
-
|
|
66
|
-
}).catch(e => {
|
|
67
|
-
// Pass
|
|
68
|
-
});
|
|
65
|
+
}).catch(console.error);
|
|
69
66
|
this.refreshTimeout = setTimeout(this.refreshPriceData.bind(this), CRON_REFRESH_PRICE_INTERVAL);
|
|
70
67
|
}
|
|
71
68
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
export const EXTENSION_REQUEST_URL = 'extension';
|
|
4
|
+
export const EXTENSION_REQUEST_URL = 'extension';
|
|
5
|
+
export const PREDEFINED_CHAIN_DAPP_CHAIN_MAP = {
|
|
6
|
+
'portal.astar.network': ['astar', 'astarEvm'],
|
|
7
|
+
'apps.moonbeam.network': ['moonbeam', 'moonriver'],
|
|
8
|
+
'app.stellaswap.com': ['moonbeam']
|
|
9
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
1
2
|
import { AuthRequestV2 } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
import { AuthorizeRequest, RequestAuthorizeTab } from '@subwallet/extension-base/background/types';
|
|
3
|
+
import { AccountAuthType, AuthorizeRequest, RequestAuthorizeTab } from '@subwallet/extension-base/background/types';
|
|
3
4
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
5
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
5
6
|
import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
|
|
@@ -20,6 +21,12 @@ export default class AuthRequestHandler {
|
|
|
20
21
|
setAuthorize(data: AuthUrls, callback?: () => void): void;
|
|
21
22
|
getAuthorize(update: (value: AuthUrls) => void): void;
|
|
22
23
|
getAuthList(): Promise<AuthUrls>;
|
|
24
|
+
getDAppChainInfo(options: {
|
|
25
|
+
accessType: AccountAuthType;
|
|
26
|
+
autoActive?: boolean;
|
|
27
|
+
defaultChain?: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
}): _ChainInfo | undefined;
|
|
23
30
|
private authCompleteV2;
|
|
24
31
|
authorizeUrlV2(url: string, request: RequestAuthorizeTab): Promise<boolean>;
|
|
25
32
|
getAuthRequestV2(id: string): AuthRequestV2;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
+
import { PREDEFINED_CHAIN_DAPP_CHAIN_MAP } from '@subwallet/extension-base/services/request-service/constants';
|
|
5
6
|
import AuthorizeStore from '@subwallet/extension-base/stores/Authorize';
|
|
7
|
+
import { getDomainFromUrl } from '@subwallet/extension-base/utils';
|
|
6
8
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
7
9
|
import { accounts } from '@subwallet/ui-keyring/observable/accounts';
|
|
8
10
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
@@ -78,9 +80,43 @@ export default class AuthRequestHandler {
|
|
|
78
80
|
});
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
getDAppChainInfo(options) {
|
|
84
|
+
const chainInfoMaps = this.#chainService.getChainInfoMap();
|
|
85
|
+
const chainStateMap = this.#chainService.getChainStateMap();
|
|
86
|
+
let defaultChain = options.defaultChain;
|
|
87
|
+
let needEnableChains = [];
|
|
88
|
+
if (options.url) {
|
|
89
|
+
const domain = getDomainFromUrl(options.url);
|
|
90
|
+
const predefinedSupportChains = PREDEFINED_CHAIN_DAPP_CHAIN_MAP[domain];
|
|
91
|
+
if (!defaultChain && predefinedSupportChains) {
|
|
92
|
+
defaultChain = predefinedSupportChains[0];
|
|
93
|
+
options.autoActive && needEnableChains.push(...predefinedSupportChains);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
let chainInfo;
|
|
97
|
+
if (['both', 'evm'].includes(options.accessType)) {
|
|
98
|
+
const evmChains = Object.values(chainInfoMaps).filter(_isChainEvmCompatible);
|
|
99
|
+
chainInfo = (defaultChain ? chainInfoMaps[defaultChain] : evmChains.find(chain => {
|
|
100
|
+
var _chainStateMap$chain$;
|
|
101
|
+
return (_chainStateMap$chain$ = chainStateMap[chain.slug]) === null || _chainStateMap$chain$ === void 0 ? void 0 : _chainStateMap$chain$.active;
|
|
102
|
+
})) || evmChains[0];
|
|
103
|
+
if (options.autoActive) {
|
|
104
|
+
if (!needEnableChains.includes(chainInfo.slug)) {
|
|
105
|
+
needEnableChains.push(chainInfo.slug);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
needEnableChains = needEnableChains.filter(slug => {
|
|
110
|
+
var _chainStateMap$slug;
|
|
111
|
+
return !((_chainStateMap$slug = chainStateMap[slug]) !== null && _chainStateMap$slug !== void 0 && _chainStateMap$slug.active);
|
|
112
|
+
});
|
|
113
|
+
needEnableChains.length > 0 && this.#chainService.enableChains(needEnableChains);
|
|
114
|
+
return chainInfo;
|
|
115
|
+
}
|
|
116
|
+
authCompleteV2 = (id, url, resolve, reject) => {
|
|
82
117
|
const isAllowedMap = this.getAddressList();
|
|
83
118
|
const complete = (result, cb, accounts) => {
|
|
119
|
+
var _this$getDAppChainInf;
|
|
84
120
|
const isAllowed = result === true;
|
|
85
121
|
let isCancelled = false;
|
|
86
122
|
if (!isAllowed && typeof result === 'object' && result.message === 'Cancelled') {
|
|
@@ -113,16 +149,11 @@ export default class AuthRequestHandler {
|
|
|
113
149
|
isAllowedMap[acc] = true;
|
|
114
150
|
});
|
|
115
151
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
});
|
|
122
|
-
if (defaultChain) {
|
|
123
|
-
defaultEvmNetworkKey = defaultChain.slug;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
152
|
+
const defaultEvmNetworkKey = (_this$getDAppChainInf = this.getDAppChainInfo({
|
|
153
|
+
accessType: accountAuthType,
|
|
154
|
+
url,
|
|
155
|
+
autoActive: !isCancelled && isAllowed
|
|
156
|
+
})) === null || _this$getDAppChainInf === void 0 ? void 0 : _this$getDAppChainInf.slug;
|
|
126
157
|
this.getAuthorize(value => {
|
|
127
158
|
let authorizeList = {};
|
|
128
159
|
if (value) {
|
|
@@ -209,7 +240,7 @@ export default class AuthRequestHandler {
|
|
|
209
240
|
return new Promise((resolve, reject) => {
|
|
210
241
|
const id = getId();
|
|
211
242
|
this.#authRequestsV2[id] = {
|
|
212
|
-
...this.authCompleteV2(id, resolve, reject),
|
|
243
|
+
...this.authCompleteV2(id, url, resolve, reject),
|
|
213
244
|
id,
|
|
214
245
|
idStr,
|
|
215
246
|
request,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
import { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
2
|
+
import { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
4
|
import { AuthUrls, MetaRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
5
5
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
@@ -29,6 +29,12 @@ export default class RequestService {
|
|
|
29
29
|
getAuthList(): Promise<AuthUrls>;
|
|
30
30
|
authorizeUrlV2(url: string, request: RequestAuthorizeTab): Promise<boolean>;
|
|
31
31
|
getAuthRequestV2(id: string): AuthRequestV2;
|
|
32
|
+
getDAppChainInfo(options: {
|
|
33
|
+
accessType: AccountAuthType;
|
|
34
|
+
autoActive?: boolean;
|
|
35
|
+
defaultChain?: string;
|
|
36
|
+
url?: string;
|
|
37
|
+
}): import("@subwallet/chain-list/types")._ChainInfo | undefined;
|
|
32
38
|
get subscribeEvmChainChange(): Subject<AuthUrls>;
|
|
33
39
|
get subscribeAuthorizeUrlSubject(): Subject<AuthUrls>;
|
|
34
40
|
ensureUrlAuthorizedV2(url: string): Promise<boolean>;
|
|
@@ -96,6 +96,9 @@ export default class RequestService {
|
|
|
96
96
|
getAuthRequestV2(id) {
|
|
97
97
|
return this.#authRequestHandler.getAuthRequestV2(id);
|
|
98
98
|
}
|
|
99
|
+
getDAppChainInfo(options) {
|
|
100
|
+
return this.#authRequestHandler.getDAppChainInfo(options);
|
|
101
|
+
}
|
|
99
102
|
get subscribeEvmChainChange() {
|
|
100
103
|
return this.#authRequestHandler.subscribeEvmChainChange;
|
|
101
104
|
}
|
|
@@ -45,6 +45,7 @@ export default class DatabaseService {
|
|
|
45
45
|
deleteNftCollection(chain: string, collectionId: string): Promise<void>;
|
|
46
46
|
getAllNftCollection(chainHashes?: string[]): import("dexie").PromiseExtended<NftCollection[]>;
|
|
47
47
|
subscribeNft(addresses: string[], chainHashes?: string[], callback?: (nfts: INft[]) => void): Subscription;
|
|
48
|
+
cleanUpNft(chain: string, owner: string, collectionId: string, nftIds: string[]): Promise<number>;
|
|
48
49
|
getNft(addresses: string[], chainHashes?: string[]): Promise<INft[]>;
|
|
49
50
|
addNft(address: string, nft: NftItem): Promise<unknown>;
|
|
50
51
|
handleNftTransfer(chain: string, addresses: string[], nftItem: NftItem): import("dexie").PromiseExtended<number>;
|