@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
@@ -1,7 +1,10 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, CRON_REFRESH_CHAIN_NOMINATOR_METADATA, CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL } from '@subwallet/extension-base/constants';
4
+ import { CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, CRON_GET_API_MAP_STATUS, CRON_REFRESH_CHAIN_NOMINATOR_METADATA, CRON_REFRESH_CHAIN_STAKING_METADATA, CRON_REFRESH_NFT_INTERVAL, CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL, CRON_REFRESH_STAKING_REWARD_INTERVAL } from '@subwallet/extension-base/constants';
5
+ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
6
+ import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportSubstrateStaking, _isChainSupportWasmNft } from '@subwallet/extension-base/services/chain-service/utils';
7
+ import { waitTimeout } from '@subwallet/extension-base/utils';
5
8
  import { Subject } from 'rxjs';
6
9
  import { logger as createLogger } from '@polkadot/util';
7
10
  export class KoniCron {
@@ -47,80 +50,115 @@ export class KoniCron {
47
50
  delete this.cronMap[key];
48
51
  });
49
52
  };
50
- init = () => {
51
- this.state.getCurrentAccount(currentAccountInfo => {
52
- if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
53
- return;
54
- }
55
- if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
56
- this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
57
- this.refreshStakingReward(currentAccountInfo.address);
58
- this.refreshStakingRewardFastInterval(currentAccountInfo.address);
59
- this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
60
- this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
61
- } else {
62
- this.setStakingRewardReady();
63
- }
64
- });
65
- };
53
+
54
+ // init = () => {
55
+ // const currentAccountInfo = this.state.keyringService.currentAccount;
56
+ //
57
+ // if (!currentAccountInfo?.address) {
58
+ // return;
59
+ // }
60
+ //
61
+ // if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
62
+ // this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap());
63
+ // this.updateApiMapStatus();
64
+ // this.refreshStakingReward(currentAccountInfo.address);
65
+ // this.refreshStakingRewardFastInterval(currentAccountInfo.address);
66
+ // // this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
67
+ // this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap());
68
+ // } else {
69
+ // this.setStakingRewardReady();
70
+ // }
71
+ // };
72
+
66
73
  start = () => {
67
74
  if (this.status === 'running') {
68
75
  return;
69
76
  }
70
77
  this.logger.log('Starting cron jobs');
71
- this.state.getCurrentAccount(currentAccountInfo => {
72
- if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
78
+ const currentAccountInfo = this.state.keyringService.currentAccount;
79
+ if (!(currentAccountInfo !== null && currentAccountInfo !== void 0 && currentAccountInfo.address)) {
80
+ return;
81
+ }
82
+ if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
83
+ this.resetNft(currentAccountInfo.address);
84
+ this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
85
+ this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS);
86
+ this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
87
+ this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
88
+ this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
89
+ this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
90
+ this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
91
+ } else {
92
+ this.setStakingRewardReady();
93
+ }
94
+ const commonReloadEvents = ['account.add', 'account.remove', 'account.updateCurrent', 'chain.add', 'asset.updateState'];
95
+ this.eventHandler = (events, eventTypes) => {
96
+ var _serviceInfo$currentA;
97
+ const serviceInfo = this.state.getServiceInfo();
98
+ const commonReload = eventTypes.some(eventType => commonReloadEvents.includes(eventType));
99
+ const chainUpdated = eventTypes.includes('chain.updateState');
100
+ const stakingSubmitted = eventTypes.includes('transaction.submitStaking');
101
+ const updatedChains = [];
102
+ if (chainUpdated) {
103
+ events.forEach(event => {
104
+ if (event.type === 'chain.updateState') {
105
+ const updatedData = event.data;
106
+ updatedChains.push(updatedData[0]);
107
+ }
108
+ });
109
+ }
110
+ if (!commonReload && !chainUpdated && !stakingSubmitted) {
111
+ return;
112
+ }
113
+ this.logger.log('ServiceInfo updated, Cron restarting...', eventTypes);
114
+ const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
115
+ if (!address) {
73
116
  return;
74
117
  }
75
- if (Object.keys(this.state.getSubstrateApiMap()).length !== 0 || Object.keys(this.state.getEvmApiMap()).length !== 0) {
76
- this.resetNft(currentAccountInfo.address);
77
- this.addCron('refreshNft', this.refreshNft(currentAccountInfo.address, this.state.getApiMap(), this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
78
- this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
79
- this.addCron('refreshStakingReward', this.refreshStakingReward(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
80
- this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(currentAccountInfo.address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
81
- this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_STAKING_METADATA);
82
- this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(currentAccountInfo.address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
118
+ const chainInfoMap = serviceInfo.chainInfoMap;
119
+ const needUpdateNft = this.needUpdateNft(chainInfoMap, updatedChains);
120
+ const needUpdateStaking = this.needUpdateStaking(chainInfoMap, updatedChains);
121
+
122
+ // NFT
123
+ (commonReload || needUpdateNft) && this.resetNft(address);
124
+ (commonReload || needUpdateNft) && this.removeCron('refreshNft');
125
+
126
+ // Staking
127
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.resetStakingReward();
128
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshStakingReward');
129
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('refreshPoolingStakingReward');
130
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.removeCron('updateNominatorMetadata');
131
+ needUpdateStaking && this.removeCron('updateChainStakingMetadata');
132
+
133
+ // Chains
134
+ chainUpdated && this.removeCron('checkStatusApiMap');
135
+ chainUpdated && this.removeCron('recoverApiMap');
136
+ if (this.checkNetworkAvailable(serviceInfo)) {
137
+ // only add cron job if there's at least 1 active network
138
+ (commonReload || needUpdateNft) && this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
139
+ chainUpdated && this.addCron('checkStatusApiMap', this.updateApiMapStatus, CRON_GET_API_MAP_STATUS);
140
+ chainUpdated && this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
141
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
142
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
143
+ (commonReload || needUpdateStaking || stakingSubmitted) && this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
144
+ needUpdateStaking && this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
83
145
  } else {
84
146
  this.setStakingRewardReady();
85
147
  }
86
- });
87
- this.serviceSubscription = this.state.subscribeServiceInfo().subscribe({
88
- next: serviceInfo => {
89
- var _serviceInfo$currentA;
90
- this.logger.log('ServiceInfo updated, restarting...');
91
- const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
92
- if (!address) {
93
- return;
94
- }
95
- this.resetStakingReward();
96
- this.resetNft(address);
97
- this.removeCron('refreshNft');
98
- this.removeCron('refreshStakingReward');
99
- this.removeCron('refreshPoolingStakingReward');
100
- this.removeCron('refreshPrice');
101
- this.removeCron('checkStatusApiMap');
102
- this.removeCron('recoverApiMap');
103
- this.removeCron('updateChainStakingMetadata');
104
- this.removeCron('updateNominatorMetadata');
105
- if (this.checkNetworkAvailable(serviceInfo)) {
106
- // only add cron job if there's at least 1 active network
107
- this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
108
- this.addCron('recoverApiMap', this.recoverApiMap, CRON_AUTO_RECOVER_DOTSAMA_INTERVAL, false);
109
- this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
110
- this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
111
- this.addCron('updateChainStakingMetadata', this.updateChainStakingMetadata(serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_STAKING_METADATA);
112
- this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, serviceInfo.chainInfoMap, serviceInfo.chainStateMap, serviceInfo.chainApiMap.substrate), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
113
- } else {
114
- this.setStakingRewardReady();
115
- }
116
- }
117
- });
148
+ };
149
+ this.state.eventService.onLazy(this.eventHandler);
118
150
  this.status = 'running';
119
151
  };
120
152
  stop = () => {
121
153
  if (this.status === 'stopped') {
122
154
  return;
123
155
  }
156
+
157
+ // Unsubscribe events
158
+ if (this.eventHandler) {
159
+ this.state.eventService.offLazy(this.eventHandler);
160
+ this.eventHandler = undefined;
161
+ }
124
162
  if (this.serviceSubscription) {
125
163
  this.serviceSubscription.unsubscribe();
126
164
  this.serviceSubscription = undefined;
@@ -129,7 +167,38 @@ export class KoniCron {
129
167
  this.removeAllCrons();
130
168
  this.status = 'stopped';
131
169
  };
170
+ updateApiMapStatus = () => {
171
+ const apiMap = this.state.getApiMap();
172
+ const networkMap = this.state.getChainStateMap();
173
+ for (const [key, substrateApi] of Object.entries(apiMap.substrate)) {
174
+ let status = _ChainConnectionStatus.CONNECTING;
175
+ if (substrateApi.isApiConnected) {
176
+ status = _ChainConnectionStatus.CONNECTED;
177
+ }
178
+ if (!networkMap[key].connectionStatus) {
179
+ this.state.updateChainConnectionStatus(key, status);
180
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== status) {
181
+ this.state.updateChainConnectionStatus(key, status);
182
+ }
183
+ }
184
+ for (const [key, evmApi] of Object.entries(apiMap.evm)) {
185
+ evmApi.api.eth.net.isListening().then(() => {
186
+ if (!networkMap[key].connectionStatus) {
187
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
188
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTED) {
189
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTED);
190
+ }
191
+ }).catch(() => {
192
+ if (!networkMap[key].connectionStatus) {
193
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
194
+ } else if (networkMap[key].connectionStatus && networkMap[key].connectionStatus !== _ChainConnectionStatus.CONNECTING) {
195
+ this.state.updateChainConnectionStatus(key, _ChainConnectionStatus.CONNECTING);
196
+ }
197
+ });
198
+ }
199
+ };
132
200
  recoverApiMap = () => {
201
+ var _this$subscriptions;
133
202
  const apiMap = this.state.getApiMap();
134
203
  for (const [networkKey, apiProp] of Object.entries(apiMap.substrate)) {
135
204
  if (!apiProp.isApiConnected) {
@@ -141,37 +210,33 @@ export class KoniCron {
141
210
  this.state.refreshWeb3Api(key);
142
211
  });
143
212
  }
144
- this.state.getCurrentAccount(({
213
+ const {
145
214
  address
146
- }) => {
147
- var _this$subscriptions;
148
- ((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
149
- });
215
+ } = this.state.keyringService.currentAccount;
216
+ ((_this$subscriptions = this.subscriptions) === null || _this$subscriptions === void 0 ? void 0 : _this$subscriptions.subscribeBalancesAndCrowdloans) && this.subscriptions.subscribeBalancesAndCrowdloans(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
150
217
  };
151
218
  refreshNft = (address, apiMap, smartContractNfts, chainInfoMap) => {
152
219
  return () => {
153
- this.logger.log('Refresh Nft state');
220
+ console.debug('Refresh NFT state');
154
221
  this.subscriptions.subscribeNft(address, apiMap.substrate, apiMap.evm, smartContractNfts, chainInfoMap);
155
222
  };
156
223
  };
157
224
  resetNft = newAddress => {
158
- this.logger.log('Reset Nft state');
159
- this.state.resetNft(newAddress).catch(e => this.logger.warn(e));
225
+ this.state.resetNft(newAddress);
160
226
  };
161
227
  resetStakingReward = () => {
162
- this.logger.log('Reset Staking Reward State');
163
228
  this.state.resetStakingReward();
164
229
  };
165
230
  refreshStakingReward = address => {
166
231
  return () => {
167
- this.logger.log('Fetching staking reward data');
168
- this.subscriptions.subscribeStakingReward(address).then(() => this.logger.log('Refresh staking reward state')).catch(this.logger.error);
232
+ console.debug('Refresh staking reward state');
233
+ this.subscriptions.subscribeStakingReward(address).catch(this.logger.error);
169
234
  };
170
235
  };
171
236
  refreshStakingRewardFastInterval = address => {
172
237
  return () => {
173
- this.logger.log('Fetching staking reward data with fast interval');
174
- this.subscriptions.subscribeStakingRewardFastInterval(address).then(() => this.logger.log('Refresh staking reward state with fast interval')).catch(this.logger.error);
238
+ console.debug('Refresh staking reward data with fast interval');
239
+ this.subscriptions.subscribeStakingRewardFastInterval(address).catch(this.logger.error);
175
240
  };
176
241
  };
177
242
  setStakingRewardReady = () => {
@@ -182,14 +247,52 @@ export class KoniCron {
182
247
  };
183
248
  updateChainStakingMetadata = (chainInfoMap, chainStateMap, substrateApiMap) => {
184
249
  return () => {
185
- this.logger.log('Fetching chain staking metadata');
186
- this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated chain staking metadata')).catch(this.logger.error);
250
+ console.debug('Fetching chain staking metadata');
251
+ this.subscriptions.fetchChainStakingMetadata(chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
187
252
  };
188
253
  };
189
254
  updateNominatorMetadata = (address, chainInfoMap, chainStateMap, substrateApiMap) => {
190
255
  return () => {
191
- this.logger.log('Fetching nominator data', address);
192
- this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).then(() => this.logger.log('Updated nominator data', address)).catch(this.logger.error);
256
+ console.debug('Fetching nominator data for', address);
257
+ this.subscriptions.fetchNominatorMetadata(address, chainInfoMap, chainStateMap, substrateApiMap).catch(this.logger.error);
193
258
  };
194
259
  };
260
+ async reloadNft() {
261
+ const address = this.state.keyringService.currentAccount.address;
262
+ const serviceInfo = this.state.getServiceInfo();
263
+ console.debug('Hard refresh NFT for', address);
264
+ this.resetNft(address);
265
+ this.removeCron('refreshNft');
266
+ this.addCron('refreshNft', this.refreshNft(address, serviceInfo.chainApiMap, this.state.getSmartContractNfts(), this.state.getActiveChainInfoMap()), CRON_REFRESH_NFT_INTERVAL);
267
+ await waitTimeout(1800);
268
+ return true;
269
+ }
270
+ async reloadStaking() {
271
+ const address = this.state.keyringService.currentAccount.address;
272
+ console.debug('Hard refresh staking meta for', address);
273
+ this.resetStakingReward();
274
+ this.removeCron('refreshStakingReward');
275
+ this.removeCron('refreshPoolingStakingReward');
276
+ this.removeCron('updateNominatorMetadata');
277
+ this.addCron('refreshStakingReward', this.refreshStakingReward(address), CRON_REFRESH_STAKING_REWARD_INTERVAL);
278
+ this.addCron('refreshPoolingStakingReward', this.refreshStakingRewardFastInterval(address), CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL);
279
+ this.addCron('updateNominatorMetadata', this.updateNominatorMetadata(address, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap()), CRON_REFRESH_CHAIN_NOMINATOR_METADATA);
280
+ await waitTimeout(1800);
281
+ return true;
282
+ }
283
+ needUpdateNft(chainInfoMap, updatedChains) {
284
+ if (updatedChains && updatedChains.length > 0) {
285
+ return updatedChains.some(updatedChain => {
286
+ const chainInfo = chainInfoMap[updatedChain];
287
+ return _isChainSupportNativeNft(chainInfo) || _isChainSupportEvmNft(chainInfo) || _isChainSupportWasmNft(chainInfo);
288
+ });
289
+ }
290
+ return false;
291
+ }
292
+ needUpdateStaking(chainInfoMap, updatedChains) {
293
+ if (updatedChains && updatedChains.length > 0) {
294
+ return updatedChains.some(updatedChain => _isChainSupportSubstrateStaking(chainInfoMap[updatedChain]));
295
+ }
296
+ return false;
297
+ }
195
298
  }
@@ -40,7 +40,6 @@ export default class KoniExtension {
40
40
  private accountsGetAllWithCurrentAddress;
41
41
  private accountsGetAll;
42
42
  private saveRecentAccountId;
43
- private triggerAccountsSubscription;
44
43
  private _getAuthListV2;
45
44
  private authorizeSubscribeV2;
46
45
  private getAuthListV2;
@@ -154,7 +153,7 @@ export default class KoniExtension {
154
153
  private submitStakeWithdrawal;
155
154
  private submitStakeClaimReward;
156
155
  private submitCancelStakeWithdrawal;
157
- private submitPoolingBonding;
156
+ private submitPoolBonding;
158
157
  private submitPoolingUnbonding;
159
158
  private parseContractInput;
160
159
  private submitTuringStakeCompounding;
@@ -179,5 +178,6 @@ export default class KoniExtension {
179
178
  private getTransaction;
180
179
  private subscribeTransactions;
181
180
  private subscribeNotifications;
181
+ private reloadCron;
182
182
  handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
183
183
  }