@subwallet/extension-base 1.0.4-0 → 1.0.5-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/background/KoniTypes.d.ts +37 -16
  2. package/background/KoniTypes.js +2 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +2 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/amplitude.js +9 -2
  30. package/cjs/koni/api/staking/bonding/astar.js +37 -13
  31. package/cjs/koni/api/staking/bonding/paraChain.js +10 -2
  32. package/cjs/koni/api/staking/bonding/relayChain.js +21 -4
  33. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  34. package/cjs/koni/api/staking/relayChain.js +0 -1
  35. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  36. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  37. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  38. package/cjs/koni/api/xcm/index.js +0 -1
  39. package/cjs/koni/background/cron.js +0 -45
  40. package/cjs/koni/background/handlers/Extension.js +204 -132
  41. package/cjs/koni/background/handlers/State.js +30 -3
  42. package/cjs/koni/background/handlers/Tabs.js +34 -2
  43. package/cjs/koni/background/handlers/index.js +3 -2
  44. package/cjs/koni/background/subscription.js +0 -26
  45. package/cjs/packageInfo.js +1 -1
  46. package/cjs/services/chain-service/constants.js +1 -1
  47. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  48. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  49. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  50. package/cjs/services/chain-service/index.js +75 -28
  51. package/cjs/services/chain-service/utils.js +3 -0
  52. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
  53. package/cjs/services/history-service/index.js +60 -5
  54. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  55. package/cjs/services/history-service/testChainMap.js +724 -0
  56. package/cjs/services/keyring-service/index.js +9 -2
  57. package/cjs/services/migration-service/index.js +7 -7
  58. package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +39 -0
  59. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  60. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  61. package/cjs/services/migration-service/scripts/index.js +7 -1
  62. package/cjs/services/price-service/coingecko.js +1 -1
  63. package/cjs/services/price-service/index.js +0 -4
  64. package/cjs/services/request-service/handler/AuthRequestHandler.js +8 -1
  65. package/cjs/services/request-service/handler/EvmRequestHandler.js +21 -0
  66. package/cjs/services/request-service/handler/MetadataRequestHandler.js +6 -0
  67. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  68. package/cjs/services/request-service/index.js +6 -0
  69. package/cjs/services/setting-service/SettingService.js +4 -9
  70. package/cjs/services/setting-service/constants.js +18 -2
  71. package/cjs/services/storage-service/DatabaseService.js +16 -44
  72. package/cjs/services/storage-service/databases/index.js +1 -1
  73. package/cjs/services/storage-service/db-stores/BaseStore.js +3 -0
  74. package/cjs/services/transaction-service/constants.js +11 -0
  75. package/cjs/services/transaction-service/index.js +31 -9
  76. package/cjs/services/transaction-service/utils.js +25 -14
  77. package/constants/index.d.ts +1 -1
  78. package/constants/index.js +1 -1
  79. package/koni/api/coingecko.js +1 -4
  80. package/koni/api/dotsama/balance.js +7 -5
  81. package/koni/api/dotsama/crowdloan.js +0 -4
  82. package/koni/api/dotsama/transfer.js +0 -4
  83. package/koni/api/nft/acala_nft/index.js +1 -1
  84. package/koni/api/nft/bit.country/index.js +1 -1
  85. package/koni/api/nft/evm_nft/index.js +2 -3
  86. package/koni/api/nft/index.js +1 -2
  87. package/koni/api/nft/karura_nft/index.js +1 -1
  88. package/koni/api/nft/quartz_nft/index.js +1 -1
  89. package/koni/api/nft/rmrk_nft/index.js +2 -3
  90. package/koni/api/nft/statemine_nft/index.js +1 -1
  91. package/koni/api/nft/transfer.js +5 -5
  92. package/koni/api/nft/unique_nft/index.js +1 -1
  93. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  94. package/koni/api/nft/wasm_nft/index.js +1 -2
  95. package/koni/api/staking/bonding/amplitude.js +9 -2
  96. package/koni/api/staking/bonding/astar.d.ts +2 -1
  97. package/koni/api/staking/bonding/astar.js +36 -13
  98. package/koni/api/staking/bonding/paraChain.js +10 -2
  99. package/koni/api/staking/bonding/relayChain.js +21 -4
  100. package/koni/api/staking/bonding/utils.js +4 -0
  101. package/koni/api/staking/relayChain.js +0 -1
  102. package/koni/api/staking/subsquidStaking.js +0 -2
  103. package/koni/api/tokens/wasm/index.js +0 -1
  104. package/koni/api/tokens/wasm/utils.js +0 -1
  105. package/koni/api/xcm/index.js +0 -1
  106. package/koni/background/cron.js +0 -45
  107. package/koni/background/handlers/Extension.d.ts +3 -0
  108. package/koni/background/handlers/Extension.js +120 -51
  109. package/koni/background/handlers/State.d.ts +4 -1
  110. package/koni/background/handlers/State.js +30 -3
  111. package/koni/background/handlers/Tabs.d.ts +1 -0
  112. package/koni/background/handlers/Tabs.js +32 -1
  113. package/koni/background/handlers/index.js +3 -2
  114. package/koni/background/subscription.d.ts +0 -1
  115. package/koni/background/subscription.js +0 -26
  116. package/package.json +65 -39
  117. package/packageInfo.js +1 -1
  118. package/services/chain-service/constants.js +1 -1
  119. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  120. package/services/chain-service/handler/SubstrateChainHandler.js +3 -10
  121. package/services/chain-service/handler/light-client/index.js +8 -6
  122. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  123. package/services/chain-service/index.d.ts +2 -1
  124. package/services/chain-service/index.js +75 -28
  125. package/services/chain-service/utils.js +3 -0
  126. package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
  127. package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
  128. package/services/history-service/index.d.ts +6 -0
  129. package/services/history-service/index.js +61 -6
  130. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  131. package/services/history-service/testChainMap.d.ts +3 -0
  132. package/services/history-service/testChainMap.js +716 -0
  133. package/services/keyring-service/index.d.ts +1 -0
  134. package/services/keyring-service/index.js +9 -2
  135. package/services/migration-service/index.js +7 -7
  136. package/services/migration-service/scripts/MigrateAuthUrls.d.ts +4 -0
  137. package/services/migration-service/scripts/MigrateAuthUrls.js +31 -0
  138. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  139. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  140. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  141. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  142. package/services/migration-service/scripts/index.js +7 -1
  143. package/services/price-service/coingecko.js +1 -1
  144. package/services/price-service/index.js +0 -4
  145. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  146. package/services/request-service/handler/AuthRequestHandler.js +8 -1
  147. package/services/request-service/handler/EvmRequestHandler.d.ts +1 -0
  148. package/services/request-service/handler/EvmRequestHandler.js +21 -0
  149. package/services/request-service/handler/MetadataRequestHandler.d.ts +1 -0
  150. package/services/request-service/handler/MetadataRequestHandler.js +6 -0
  151. package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -0
  152. package/services/request-service/handler/SubstrateRequestHandler.js +6 -0
  153. package/services/request-service/index.d.ts +1 -0
  154. package/services/request-service/index.js +6 -0
  155. package/services/setting-service/SettingService.d.ts +1 -0
  156. package/services/setting-service/SettingService.js +5 -10
  157. package/services/setting-service/constants.d.ts +4 -1
  158. package/services/setting-service/constants.js +14 -1
  159. package/services/storage-service/DatabaseService.d.ts +1 -0
  160. package/services/storage-service/DatabaseService.js +16 -44
  161. package/services/storage-service/databases/index.js +1 -1
  162. package/services/storage-service/db-stores/BaseStore.d.ts +1 -0
  163. package/services/storage-service/db-stores/BaseStore.js +3 -0
  164. package/services/transaction-service/constants.d.ts +1 -0
  165. package/services/transaction-service/constants.js +4 -0
  166. package/services/transaction-service/index.d.ts +2 -0
  167. package/services/transaction-service/index.js +32 -10
  168. package/services/transaction-service/utils.d.ts +1 -1
  169. package/services/transaction-service/utils.js +24 -13
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.HistoryService = void 0;
7
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
7
8
  var _constants = require("@subwallet/extension-base/constants");
8
9
  var _types = require("@subwallet/extension-base/services/base/types");
10
+ var _recoverHistoryStatus = require("@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus");
9
11
  var _promise = require("@subwallet/extension-base/utils/promise");
10
12
  var _uiKeyring = require("@subwallet/ui-keyring");
11
13
  var _rxjs = require("rxjs");
@@ -15,6 +17,7 @@ var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
15
17
 
16
18
  class HistoryService {
17
19
  historySubject = new _rxjs.BehaviorSubject([]);
20
+ #processingHistories = {};
18
21
  constructor(dbService, chainService, eventService, keyringService) {
19
22
  this.dbService = dbService;
20
23
  this.chainService = chainService;
@@ -24,6 +27,7 @@ class HistoryService {
24
27
  }
25
28
  fetchPromise = null;
26
29
  interval = undefined;
30
+ recoverInterval = undefined;
27
31
  async fetchAndLoadHistories(addresses) {
28
32
  if (!addresses || addresses.length === 0) {
29
33
  return [];
@@ -95,9 +99,6 @@ class HistoryService {
95
99
  });
96
100
  const updateRecords = historyItems.filter(item => {
97
101
  const key = `${item.chain}-${item.extrinsicHash}`;
98
-
99
- // !excludeKeys.includes(key) && console.log('Cancel update', key);
100
-
101
102
  return item.origin === 'app' || !excludeKeys.includes(key);
102
103
  });
103
104
  await this.dbService.upsertHistory(updateRecords);
@@ -126,12 +127,56 @@ class HistoryService {
126
127
  this.fetchPromise = null;
127
128
  return Promise.resolve();
128
129
  }
130
+ async startRecoverHistories() {
131
+ await this.recoverHistories();
132
+ this.recoverInterval = setInterval(() => {
133
+ this.recoverHistories().catch(console.error);
134
+ }, _constants.CRON_RECOVER_HISTORY_INTERVAL);
135
+ }
136
+ stopRecoverHistories() {
137
+ clearInterval(this.recoverInterval);
138
+ return Promise.resolve();
139
+ }
140
+ async recoverHistories() {
141
+ const list = [];
142
+ for (const processingHistory of Object.values(this.#processingHistories)) {
143
+ const chainState = this.chainService.getChainStateByKey(processingHistory.chain);
144
+ if (chainState.active) {
145
+ list.push(processingHistory);
146
+ }
147
+ if (list.length >= 10) {
148
+ break;
149
+ }
150
+ }
151
+ const promises = list.map(history => (0, _recoverHistoryStatus.historyRecover)(history, this.chainService));
152
+ const result = await Promise.all(promises);
153
+ result.forEach((status, index) => {
154
+ const extrinsicHash = list[index].extrinsicHash;
155
+ switch (status) {
156
+ case _recoverHistoryStatus.HistoryRecoverStatus.API_INACTIVE:
157
+ break;
158
+ case _recoverHistoryStatus.HistoryRecoverStatus.FAILED:
159
+ case _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS:
160
+ this.updateHistoryByExtrinsicHash(extrinsicHash, {
161
+ status: status === _recoverHistoryStatus.HistoryRecoverStatus.SUCCESS ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.FAIL
162
+ }).catch(console.error);
163
+ delete this.#processingHistories[extrinsicHash];
164
+ break;
165
+ default:
166
+ delete this.#processingHistories[extrinsicHash];
167
+ }
168
+ });
169
+ if (!Object.keys(this.#processingHistories).length) {
170
+ await this.stopRecoverHistories();
171
+ }
172
+ }
129
173
  startPromiseHandler = (0, _promise.createPromiseHandler)();
130
174
  async init() {
131
175
  this.status = _types.ServiceStatus.INITIALIZING;
132
176
  await this.loadData();
133
177
  Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
134
178
  this.getHistories().catch(console.log);
179
+ this.getProcessingHistory().catch(console.log);
135
180
  this.eventService.on('account.add', () => {
136
181
  (async () => {
137
182
  await this.stopCron();
@@ -144,12 +189,22 @@ class HistoryService {
144
189
  }).catch(console.error);
145
190
  this.status = _types.ServiceStatus.INITIALIZED;
146
191
  }
192
+ async getProcessingHistory() {
193
+ const histories = await this.dbService.getHistories();
194
+ this.#processingHistories = {};
195
+ histories.filter(history => {
196
+ return history.status === 'processing';
197
+ }).forEach(history => {
198
+ this.#processingHistories[history.extrinsicHash] = history;
199
+ });
200
+ this.startRecoverHistories().catch(console.error);
201
+ }
147
202
  async start() {
148
203
  try {
149
- console.debug('Start history service');
150
204
  this.startPromiseHandler = (0, _promise.createPromiseHandler)();
151
205
  this.status = _types.ServiceStatus.STARTING;
152
206
  await this.startCron();
207
+ await this.startRecoverHistories();
153
208
  this.status = _types.ServiceStatus.STARTED;
154
209
  this.startPromiseHandler.resolve();
155
210
  } catch (e) {
@@ -161,12 +216,12 @@ class HistoryService {
161
216
  }
162
217
  stopPromiseHandler = (0, _promise.createPromiseHandler)();
163
218
  async stop() {
164
- console.debug('Stop history service');
165
219
  try {
166
220
  this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
167
221
  this.status = _types.ServiceStatus.STOPPING;
168
222
  await this.persistData();
169
223
  await this.stopCron();
224
+ await this.stopRecoverHistories();
170
225
  this.stopPromiseHandler.resolve();
171
226
  this.status = _types.ServiceStatus.STOPPED;
172
227
  } catch (e) {
@@ -120,7 +120,7 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
120
120
  const parsedArgs = args;
121
121
  const transaction = data.call.data.args.transaction.value;
122
122
  to = autoFormatAddress(parsedArgs.to);
123
- from = autoFormatAddress(parsedArgs.from);
123
+ from = autoFormatAddress(parsedArgs.from || address);
124
124
  extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
125
125
  amount = transaction.value || '0';
126
126
  fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
@@ -255,7 +255,8 @@ async function fetchMultiChainHistories(addresses, chainMap) {
255
255
  const usedAddresses = relatedAddresses.filter(a => lowerAddresses.includes(a.toLowerCase()));
256
256
  const chainInfo = chainMap[chainId];
257
257
  if (chainInfo === undefined) {
258
- console.warn(`Not found chain info for chain id: ${chainId}`);
258
+ console.warn(`Not found chain info for chain id: ${chainId}`); // TODO: resolve conflicting chainId
259
+
259
260
  return;
260
261
  }
261
262
  usedAddresses.forEach(address => {