@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.
Files changed (220) hide show
  1. package/background/KoniTypes.d.ts +25 -36
  2. package/background/KoniTypes.js +12 -7
  3. package/background/errors/TransactionError.js +21 -1
  4. package/cjs/background/KoniTypes.js +14 -8
  5. package/cjs/background/errors/TransactionError.js +20 -0
  6. package/cjs/constants/index.js +13 -28
  7. package/cjs/koni/api/dotsama/balance.js +60 -224
  8. package/cjs/koni/api/dotsama/transfer.js +30 -29
  9. package/cjs/koni/api/nft/acala_nft/index.js +4 -1
  10. package/cjs/koni/api/nft/bit.country/index.js +4 -1
  11. package/cjs/koni/api/nft/evm_nft/index.js +7 -3
  12. package/cjs/koni/api/nft/index.js +3 -6
  13. package/cjs/koni/api/nft/karura_nft/index.js +4 -1
  14. package/cjs/koni/api/nft/rmrk_nft/index.js +8 -1
  15. package/cjs/koni/api/nft/statemine_nft/index.js +4 -1
  16. package/cjs/koni/api/nft/unique_nft/index.js +6 -1
  17. package/cjs/koni/api/nft/wasm_nft/index.js +169 -111
  18. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  19. package/cjs/koni/api/staking/bonding/amplitude.js +18 -10
  20. package/cjs/koni/api/staking/bonding/astar.js +37 -238
  21. package/cjs/koni/api/staking/bonding/index.js +26 -14
  22. package/cjs/koni/api/staking/bonding/paraChain.js +100 -11
  23. package/cjs/koni/api/staking/bonding/relayChain.js +174 -16
  24. package/cjs/koni/api/staking/bonding/utils.js +55 -10
  25. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  26. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  27. package/cjs/koni/api/xcm/index.js +0 -111
  28. package/cjs/koni/api/xcm/polkadotXcm.js +2 -2
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +3 -5
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +179 -77
  33. package/cjs/koni/background/handlers/Extension.js +231 -195
  34. package/cjs/koni/background/handlers/State.js +147 -111
  35. package/cjs/koni/background/handlers/Tabs.js +48 -39
  36. package/cjs/koni/background/subscription.js +64 -56
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/page/index.js +5 -0
  39. package/cjs/services/chain-service/constants.js +1 -11
  40. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  41. package/cjs/services/chain-service/handler/light-client/index.js +2 -0
  42. package/cjs/services/chain-service/index.js +39 -6
  43. package/cjs/services/chain-service/utils.js +4 -0
  44. package/cjs/services/event-service/index.js +75 -0
  45. package/cjs/services/event-service/types.js +11 -0
  46. package/cjs/services/history-service/index.js +46 -21
  47. package/cjs/services/history-service/subsquid-multi-chain-history.js +19 -11
  48. package/cjs/services/keyring-service/index.js +101 -0
  49. package/cjs/services/migration-service/index.js +13 -10
  50. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  51. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  52. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  53. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  54. package/cjs/services/migration-service/scripts/index.js +13 -4
  55. package/cjs/services/price-service/coingecko.js +15 -3
  56. package/cjs/services/price-service/index.js +15 -18
  57. package/cjs/services/request-service/constants.js +8 -2
  58. package/cjs/services/request-service/handler/AuthRequestHandler.js +43 -12
  59. package/cjs/services/request-service/index.js +3 -0
  60. package/cjs/services/storage-service/DatabaseService.js +53 -34
  61. package/cjs/services/storage-service/databases/index.js +1 -1
  62. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  63. package/cjs/services/storage-service/db-stores/Nft.js +8 -18
  64. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  65. package/cjs/services/subscan-service/index.js +107 -0
  66. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  67. package/cjs/services/subscan-service/types.js +1 -0
  68. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  69. package/cjs/services/transaction-service/index.js +66 -22
  70. package/cjs/services/transaction-service/utils.js +4 -6
  71. package/cjs/utils/address.js +9 -1
  72. package/cjs/utils/index.js +30 -26
  73. package/constants/index.d.ts +8 -13
  74. package/constants/index.js +8 -13
  75. package/koni/api/dotsama/balance.d.ts +0 -1
  76. package/koni/api/dotsama/balance.js +33 -197
  77. package/koni/api/dotsama/transfer.js +5 -4
  78. package/koni/api/nft/acala_nft/index.js +3 -1
  79. package/koni/api/nft/bit.country/index.js +3 -1
  80. package/koni/api/nft/evm_nft/index.js +6 -3
  81. package/koni/api/nft/index.d.ts +1 -2
  82. package/koni/api/nft/index.js +3 -6
  83. package/koni/api/nft/karura_nft/index.js +3 -1
  84. package/koni/api/nft/nft.d.ts +1 -0
  85. package/koni/api/nft/rmrk_nft/index.js +8 -1
  86. package/koni/api/nft/statemine_nft/index.js +3 -1
  87. package/koni/api/nft/unique_nft/index.js +5 -1
  88. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  89. package/koni/api/nft/wasm_nft/index.js +167 -109
  90. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  91. package/koni/api/nft/wasm_nft/utils.js +7 -5
  92. package/koni/api/staking/bonding/amplitude.d.ts +1 -2
  93. package/koni/api/staking/bonding/amplitude.js +22 -13
  94. package/koni/api/staking/bonding/astar.d.ts +2 -11
  95. package/koni/api/staking/bonding/astar.js +39 -231
  96. package/koni/api/staking/bonding/index.d.ts +5 -2
  97. package/koni/api/staking/bonding/index.js +27 -17
  98. package/koni/api/staking/bonding/paraChain.d.ts +4 -1
  99. package/koni/api/staking/bonding/paraChain.js +101 -14
  100. package/koni/api/staking/bonding/relayChain.d.ts +6 -2
  101. package/koni/api/staking/bonding/relayChain.js +172 -17
  102. package/koni/api/staking/bonding/utils.d.ts +15 -2
  103. package/koni/api/staking/bonding/utils.js +53 -11
  104. package/koni/api/tokens/wasm/index.js +5 -4
  105. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  106. package/koni/api/tokens/wasm/utils.js +54 -0
  107. package/koni/api/xcm/index.js +1 -112
  108. package/koni/api/xcm/polkadotXcm.js +3 -3
  109. package/koni/api/xcm/utils.d.ts +5 -6
  110. package/koni/api/xcm/utils.js +15 -10
  111. package/koni/api/xcm/xTokens.js +5 -7
  112. package/koni/api/xcm/xcmPallet.js +10 -9
  113. package/koni/background/cron.d.ts +6 -1
  114. package/koni/background/cron.js +179 -76
  115. package/koni/background/handlers/Extension.d.ts +2 -2
  116. package/koni/background/handlers/Extension.js +161 -125
  117. package/koni/background/handlers/State.d.ts +21 -20
  118. package/koni/background/handlers/State.js +144 -111
  119. package/koni/background/handlers/Tabs.js +30 -20
  120. package/koni/background/subscription.d.ts +1 -1
  121. package/koni/background/subscription.js +64 -58
  122. package/package.json +63 -18
  123. package/packageInfo.js +1 -1
  124. package/page/index.d.ts +2 -0
  125. package/page/index.js +4 -0
  126. package/services/chain-service/constants.d.ts +0 -1
  127. package/services/chain-service/constants.js +0 -9
  128. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  129. package/services/chain-service/handler/light-client/index.d.ts +17 -1
  130. package/services/chain-service/handler/light-client/index.js +1 -1
  131. package/services/chain-service/helper/psp22_abi.json +1041 -881
  132. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  133. package/services/chain-service/index.d.ts +6 -4
  134. package/services/chain-service/index.js +40 -9
  135. package/services/chain-service/utils.d.ts +1 -0
  136. package/services/chain-service/utils.js +3 -0
  137. package/services/event-service/index.d.ts +22 -0
  138. package/services/event-service/index.js +63 -0
  139. package/services/event-service/types.d.ts +28 -0
  140. package/services/event-service/types.js +4 -0
  141. package/services/history-service/index.d.ts +5 -3
  142. package/services/history-service/index.js +46 -21
  143. package/services/history-service/subsquid-multi-chain-history.js +22 -13
  144. package/services/keyring-service/index.d.ts +19 -0
  145. package/services/keyring-service/index.js +93 -0
  146. package/services/migration-service/index.js +11 -9
  147. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  148. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  149. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  150. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  151. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  152. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  153. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  154. package/services/migration-service/scripts/index.d.ts +1 -0
  155. package/services/migration-service/scripts/index.js +10 -3
  156. package/services/price-service/coingecko.js +15 -3
  157. package/services/price-service/index.d.ts +5 -3
  158. package/services/price-service/index.js +15 -18
  159. package/services/request-service/constants.d.ts +1 -0
  160. package/services/request-service/constants.js +6 -1
  161. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +44 -13
  163. package/services/request-service/index.d.ts +7 -1
  164. package/services/request-service/index.js +3 -0
  165. package/services/storage-service/DatabaseService.d.ts +1 -0
  166. package/services/storage-service/DatabaseService.js +53 -34
  167. package/services/storage-service/databases/index.js +1 -1
  168. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  169. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  170. package/services/storage-service/db-stores/Nft.d.ts +3 -3
  171. package/services/storage-service/db-stores/Nft.js +8 -17
  172. package/services/storage-service/db-stores/Transaction.js +10 -7
  173. package/services/subscan-service/index.d.ts +20 -0
  174. package/services/subscan-service/index.js +99 -0
  175. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  176. package/services/subscan-service/subscan-chain-map.js +63 -0
  177. package/services/subscan-service/types.d.ts +27 -0
  178. package/services/subscan-service/types.js +1 -0
  179. package/services/transaction-service/event-parser/index.d.ts +2 -2
  180. package/services/transaction-service/event-parser/index.js +21 -49
  181. package/services/transaction-service/index.d.ts +4 -2
  182. package/services/transaction-service/index.js +66 -22
  183. package/services/transaction-service/utils.js +5 -6
  184. package/utils/address.d.ts +1 -0
  185. package/utils/address.js +9 -2
  186. package/utils/index.d.ts +2 -1
  187. package/utils/index.js +26 -23
  188. package/cjs/background/errors/EvmRpcError.js +0 -21
  189. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  190. package/cjs/constants/ethereum.js +0 -19
  191. package/cjs/errors/SubWalletProviderError.js +0 -17
  192. package/cjs/koni/api/xcm/astar.js +0 -160
  193. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  194. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  195. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  196. package/cjs/koni/migration/Base.js +0 -20
  197. package/cjs/koni/migration/index.js +0 -45
  198. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  199. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  200. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  201. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  202. package/cjs/koni/migration/scripts/index.js +0 -22
  203. package/cjs/koni/page/index.js +0 -16
  204. package/cjs/services/asset-service/index.js +0 -91
  205. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  206. package/cjs/stores/Balance.js +0 -18
  207. package/cjs/stores/Crowdloan.js +0 -18
  208. package/cjs/stores/CustomEvmToken.js +0 -18
  209. package/cjs/stores/NetworkMap.js +0 -18
  210. package/cjs/stores/Nft.js +0 -18
  211. package/cjs/stores/NftCollection.js +0 -18
  212. package/cjs/stores/Price.js +0 -18
  213. package/cjs/stores/Staking.js +0 -18
  214. package/cjs/stores/StakingReward.js +0 -18
  215. package/cjs/utils/eth/parseTransactionData.js +0 -284
  216. package/koni/page/index.d.ts +0 -2
  217. package/koni/page/index.js +0 -9
  218. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  219. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  220. /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: JobClass.name,
19
- key: keys[i]
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: keys[i],
27
- name: JobClass.name,
28
- timestamp: +new Date()
28
+ key,
29
+ name,
30
+ timestamp: new Date().getTime()
29
31
  });
30
32
  }
31
33
  }
32
34
  } catch (error) {
33
- this.logger.warn('Migration error: ', error);
35
+ this.logger.error('Migration error: ', error);
34
36
  }
35
37
  this.logger.log('Migration done.');
36
38
  }
@@ -0,0 +1,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class AutoEnableChainsTokens extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -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
- return new Promise((resolve, reject) => {
9
- chrome.storage.local.get('NetworkMap', function (items) {
10
- if (items && items.NetworkMap) {
11
- const networkMap = items.NetworkMap;
12
- const enableList = [];
13
- const stateMap = state.getChainStateMap();
14
- Object.entries(networkMap).forEach(([slug, chain]) => {
15
- if (chain.active) {
16
- const currentState = stateMap[slug];
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
- // Ensure chain in the list and is not active
19
- currentState && !currentState.active && enableList.push(slug);
20
- }
21
- });
22
- if (enableList.length > 0) {
23
- state.chainService.enableChains(enableList);
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,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateSettings extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -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,4 @@
1
+ import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
2
+ export default class MigrateTransactionHistory extends BaseMigrationJob {
3
+ run(): Promise<void>;
4
+ }
@@ -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,3 +1,4 @@
1
1
  import BaseMigrationJob from '../Base';
2
+ export declare const EVERYTIME = "__everytime__";
2
3
  declare const _default: Record<string, typeof BaseMigrationJob>;
3
4
  export default _default;
@@ -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-1': MigrateNetworkSettings,
8
- '1.0.1-2': MigrateImportedToken
9
- // '1.0.1-0': ClearOldStorage
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
- // const res = await axios.get(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency}&per_page=250&ids=${idStr}`);
9
- const res = await axios.get(`https://chain-data.subwallet.app/api/price/get?ids=${idStr}`);
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, ServiceInfo } from '@subwallet/extension-base/background/KoniTypes';
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, Subject } from 'rxjs';
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(serviceInfoSubject: Subject<ServiceInfo>, dbService: DatabaseService, chainService: ChainService);
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(serviceInfoSubject, dbService, chainService) {
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
- // Add some delay to avoid fetching many times when start extension background
24
- // Subscribe service info to update price list
25
- setTimeout(() => {
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
- serviceInfoSubject.subscribe(serviceInfo => {
28
- const newPriceIds = this.getPriceIds();
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
- console.log('Get Token Price From CoinGecko');
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 +1,2 @@
1
1
  export declare const EXTENSION_REQUEST_URL = "extension";
2
+ export declare const PREDEFINED_CHAIN_DAPP_CHAIN_MAP: Record<string, string[]>;
@@ -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 { _isChainEnabled, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
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
- authCompleteV2 = (id, resolve, reject) => {
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
- let defaultEvmNetworkKey;
117
- if (accountAuthType === 'both' || accountAuthType === 'evm') {
118
- const defaultChain = Object.values(this.#chainService.getChainInfoMap()).find(chainInfo => {
119
- const chainState = this.#chainService.getChainStateByKey(chainInfo.slug);
120
- return _isChainEvmCompatible(chainInfo) && _isChainEnabled(chainState);
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>;