@subwallet/extension-base 1.3.46-0 → 1.3.47-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/cjs/koni/api/nft/ordinal_nft/index.js +3 -2
  2. package/cjs/koni/background/handlers/State.js +3 -0
  3. package/cjs/packageInfo.js +1 -1
  4. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +8 -14
  5. package/cjs/services/buy-service/index.js +2 -0
  6. package/cjs/services/chain-service/utils/index.js +3 -0
  7. package/cjs/services/chain-service/utils/patch.js +1 -1
  8. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +32 -0
  9. package/cjs/services/earning-service/handlers/native-staking/astar.js +18 -0
  10. package/cjs/services/earning-service/handlers/native-staking/base.js +37 -29
  11. package/cjs/services/earning-service/handlers/native-staking/dtao.js +5 -0
  12. package/cjs/services/earning-service/handlers/native-staking/mythos.js +28 -0
  13. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +17 -0
  14. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +16 -0
  15. package/cjs/services/earning-service/handlers/native-staking/tao.js +5 -0
  16. package/cjs/services/earning-service/service.js +26 -5
  17. package/cjs/services/history-service/index.js +12 -7
  18. package/cjs/services/subscan-service/index.js +35 -104
  19. package/cjs/services/transaction-service/utils.js +10 -1
  20. package/cjs/strategy/api-request-strategy/index.js +1 -0
  21. package/cjs/strategy/api-request-strategy/utils/index.js +2 -2
  22. package/cjs/strategy/api-request-strategy-v2/index.js +138 -0
  23. package/cjs/strategy/api-request-strategy-v2/types.js +1 -0
  24. package/cjs/utils/gear/combine.js +4 -3
  25. package/cjs/utils/gear/vft.js +104 -135
  26. package/koni/api/nft/ordinal_nft/index.js +3 -2
  27. package/koni/background/handlers/State.js +4 -1
  28. package/package.json +20 -9
  29. package/packageInfo.js +1 -1
  30. package/services/balance-service/helpers/subscribe/substrate/index.js +8 -14
  31. package/services/buy-service/index.js +2 -0
  32. package/services/chain-service/utils/index.js +3 -0
  33. package/services/chain-service/utils/patch.js +1 -1
  34. package/services/earning-service/handlers/native-staking/amplitude.d.ts +1 -0
  35. package/services/earning-service/handlers/native-staking/amplitude.js +32 -0
  36. package/services/earning-service/handlers/native-staking/astar.d.ts +1 -0
  37. package/services/earning-service/handlers/native-staking/astar.js +18 -0
  38. package/services/earning-service/handlers/native-staking/base.d.ts +1 -0
  39. package/services/earning-service/handlers/native-staking/base.js +37 -29
  40. package/services/earning-service/handlers/native-staking/dtao.d.ts +1 -0
  41. package/services/earning-service/handlers/native-staking/dtao.js +5 -0
  42. package/services/earning-service/handlers/native-staking/mythos.d.ts +1 -0
  43. package/services/earning-service/handlers/native-staking/mythos.js +28 -0
  44. package/services/earning-service/handlers/native-staking/para-chain.d.ts +1 -0
  45. package/services/earning-service/handlers/native-staking/para-chain.js +17 -0
  46. package/services/earning-service/handlers/native-staking/relay-chain.d.ts +1 -0
  47. package/services/earning-service/handlers/native-staking/relay-chain.js +16 -0
  48. package/services/earning-service/handlers/native-staking/tao.d.ts +1 -0
  49. package/services/earning-service/handlers/native-staking/tao.js +5 -0
  50. package/services/earning-service/service.d.ts +1 -0
  51. package/services/earning-service/service.js +26 -5
  52. package/services/history-service/index.js +12 -7
  53. package/services/subscan-service/index.d.ts +13 -27
  54. package/services/subscan-service/index.js +26 -95
  55. package/services/transaction-service/utils.js +11 -2
  56. package/strategy/api-request-strategy/context/base.d.ts +2 -6
  57. package/strategy/api-request-strategy/index.js +1 -0
  58. package/strategy/api-request-strategy/types.d.ts +4 -2
  59. package/strategy/api-request-strategy/utils/index.js +2 -2
  60. package/strategy/api-request-strategy-v2/index.d.ts +22 -0
  61. package/strategy/api-request-strategy-v2/index.js +128 -0
  62. package/strategy/api-request-strategy-v2/types.d.ts +11 -0
  63. package/strategy/api-request-strategy-v2/types.js +1 -0
  64. package/types/buy.d.ts +1 -1
  65. package/utils/gear/combine.d.ts +2 -1
  66. package/utils/gear/combine.js +4 -4
  67. package/utils/gear/vft.d.ts +20 -9
  68. package/utils/gear/vft.js +104 -135
@@ -52,10 +52,11 @@ class OrdinalNftApi extends _nft.BaseNftApi {
52
52
  this.subscanService = _subscanService.SubscanService.getInstance();
53
53
  }
54
54
  async handleNft(address, handleNftParams) {
55
- const events = await this.subscanService.getAccountRemarkEvents(this.subscanChain, address);
55
+ const groupId = this.subscanService.getGroupId();
56
+ const events = await this.subscanService.getAccountRemarkEvents(groupId, this.subscanChain, address);
56
57
  if (events && events.length) {
57
58
  const extrinsicIds = events.map(data => data.extrinsic_index);
58
- const extrinsicParams = await this.subscanService.getExtrinsicParams(this.subscanChain, extrinsicIds);
59
+ const extrinsicParams = await this.subscanService.getExtrinsicParams(groupId, this.subscanChain, extrinsicIds);
59
60
  const items = [];
60
61
  for (const data of extrinsicParams) {
61
62
  const {
@@ -248,6 +248,9 @@ class KoniState {
248
248
  this.afterChainServiceInit();
249
249
  });
250
250
 
251
+ // init sails
252
+ await _utils3.sailsCache.init();
253
+
251
254
  // Mark app is ready
252
255
  this.eventService.emit('general.init', true);
253
256
  }
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.3.46-0'
16
+ version: '1.3.47-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -338,17 +338,15 @@ const subscribeTokensAccountsPallet = async _ref6 => {
338
338
  const tokensAccountsKey = 'query_tokens_accounts';
339
339
  const tokenTypes = includeNativeToken ? [_types._AssetType.NATIVE, _types._AssetType.LOCAL] : [_types._AssetType.LOCAL];
340
340
  const tokenMap = (0, _utils3.filterAssetsByChainAndType)(assetMap, chainInfo.slug, tokenTypes);
341
-
342
- // Hotfix balance for gdot
343
- const getGdotBalance = async () => {
344
- const gdotBalances = await queryGdotBalance(substrateApi, addresses, assetMap[gdotSlug], extrinsicType);
345
- callback(gdotBalances);
346
- };
347
341
  const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
348
- // Hotfix balance for gdot
349
- if (tokenInfo.slug === gdotSlug) {
342
+ var _tokenInfo$metadata;
343
+ if ((_tokenInfo$metadata = tokenInfo.metadata) !== null && _tokenInfo$metadata !== void 0 && _tokenInfo$metadata.isGigaToken) {
350
344
  return (0, _rxjs.timer)(0, _constants.CRON_REFRESH_PRICE_INTERVAL).subscribe(() => {
351
- getGdotBalance().catch(console.error);
345
+ const getGigaTokenBalance = async () => {
346
+ const gigaTokenBalances = await queryGigaTokenBalance(substrateApi, addresses, assetMap[tokenInfo.slug], extrinsicType);
347
+ callback(gigaTokenBalances);
348
+ };
349
+ getGigaTokenBalance().catch(console.error);
352
350
  });
353
351
  }
354
352
  try {
@@ -561,11 +559,7 @@ const subscribeSubnetAlphaPallet = async _ref9 => {
561
559
  clearInterval(interval);
562
560
  };
563
561
  };
564
-
565
- // Hot fix for gdot balance
566
-
567
- const gdotSlug = 'hydradx_main-LOCAL-GDOT';
568
- async function queryGdotBalance(substrateApi, addresses, tokenInfo, extrinsicType) {
562
+ async function queryGigaTokenBalance(substrateApi, addresses, tokenInfo, extrinsicType) {
569
563
  return await Promise.all(addresses.map(async address => {
570
564
  const _balanceInfo = await substrateApi.api.call.currenciesApi.account((0, _utils2._getTokenOnChainAssetId)(tokenInfo), address);
571
565
  const balanceInfo = _balanceInfo.toPrimitive();
@@ -21,6 +21,8 @@ const convertSupportType = support => {
21
21
  return _types.AccountChainType.CARDANO;
22
22
  case 'TON':
23
23
  return _types.AccountChainType.TON;
24
+ case 'BITCOIN':
25
+ return _types.AccountChainType.BITCOIN;
24
26
  default:
25
27
  return null;
26
28
  }
@@ -655,6 +655,9 @@ function _getBlockExplorerFromChain(chainInfo) {
655
655
  } else if (_isPureBitcoinChain(chainInfo)) {
656
656
  var _chainInfo$bitcoinInf;
657
657
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.blockExplorer;
658
+ } else if (_isPureTonChain(chainInfo)) {
659
+ var _chainInfo$tonInfo;
660
+ blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$tonInfo = chainInfo.tonInfo) === null || _chainInfo$tonInfo === void 0 ? void 0 : _chainInfo$tonInfo.blockExplorer;
658
661
  } else {
659
662
  var _chainInfo$substrateI18;
660
663
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI18 = chainInfo.substrateInfo) === null || _chainInfo$substrateI18 === void 0 ? void 0 : _chainInfo$substrateI18.blockExplorer;
@@ -11,7 +11,7 @@ const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
11
11
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
12
12
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
13
13
  const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
14
- const ChainListVersion = '0.2.107'; // update this when build chainlist
14
+ const ChainListVersion = '0.2.109'; // update this when build chainlist
15
15
 
16
16
  // todo: move this interface to chainlist
17
17
 
@@ -178,6 +178,38 @@ class AmplitudeNativeStakingPoolHandler extends _basePara.default {
178
178
  unstakings: unstakingList
179
179
  };
180
180
  }
181
+ async checkAccountHaveStake(useAddresses) {
182
+ var _substrateApi$api$que, _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4, _substrateApi$api$que5, _substrateApi$api$que6;
183
+ const result = [];
184
+ const substrateApi = await this.substrateApi.isReady;
185
+ const ledgers = await ((_substrateApi$api$que = substrateApi.api.query.parachainStaking) === null || _substrateApi$api$que === void 0 ? void 0 : (_substrateApi$api$que2 = _substrateApi$api$que.delegatorState) === null || _substrateApi$api$que2 === void 0 ? void 0 : (_substrateApi$api$que3 = _substrateApi$api$que2.multi) === null || _substrateApi$api$que3 === void 0 ? void 0 : _substrateApi$api$que3.call(_substrateApi$api$que2, useAddresses));
186
+ const _unstakingStates = await ((_substrateApi$api$que4 = substrateApi.api.query.parachainStaking) === null || _substrateApi$api$que4 === void 0 ? void 0 : (_substrateApi$api$que5 = _substrateApi$api$que4.unstaking) === null || _substrateApi$api$que5 === void 0 ? void 0 : (_substrateApi$api$que6 = _substrateApi$api$que5.multi) === null || _substrateApi$api$que6 === void 0 ? void 0 : _substrateApi$api$que6.call(_substrateApi$api$que5, useAddresses));
187
+ if (!ledgers || !_unstakingStates) {
188
+ return [];
189
+ }
190
+ for (let i = 0; i < useAddresses.length; i++) {
191
+ const owner = useAddresses[i];
192
+ const _delegatorState = ledgers[i];
193
+ let delegatorState = [];
194
+ const unstakingInfo = _unstakingStates[i].toPrimitive();
195
+ if (_constants2._STAKING_CHAIN_GROUP.krest_network.includes(this.chain)) {
196
+ const krestDelegatorState = _delegatorState.toPrimitive();
197
+ const delegates = krestDelegatorState === null || krestDelegatorState === void 0 ? void 0 : krestDelegatorState.delegations;
198
+ if (delegates) {
199
+ delegatorState = delegatorState.concat(delegates);
200
+ }
201
+ } else {
202
+ const delegate = _delegatorState.toPrimitive();
203
+ if (delegate) {
204
+ delegatorState.push(delegate);
205
+ }
206
+ }
207
+ if (delegatorState.length || unstakingInfo && Object.keys(unstakingInfo).length) {
208
+ result.push(owner);
209
+ }
210
+ }
211
+ return Promise.resolve(result);
212
+ }
181
213
  async subscribePoolPosition(useAddresses, resultCallback) {
182
214
  let cancel = false;
183
215
  const substrateApi = await this.substrateApi.isReady;
@@ -294,6 +294,24 @@ class AstarNativeStakingPoolHandler extends _basePara.default {
294
294
  unsub && unsub();
295
295
  };
296
296
  }
297
+ async checkAccountHaveStake(useAddresses) {
298
+ var _substrateApi$api$que2, _substrateApi$api$que3, _substrateApi$api$que4;
299
+ const result = [];
300
+ const substrateApi = await this.substrateApi.isReady;
301
+ const ledgers = await ((_substrateApi$api$que2 = substrateApi.api.query.dappsStaking) === null || _substrateApi$api$que2 === void 0 ? void 0 : (_substrateApi$api$que3 = _substrateApi$api$que2.ledger) === null || _substrateApi$api$que3 === void 0 ? void 0 : (_substrateApi$api$que4 = _substrateApi$api$que3.multi) === null || _substrateApi$api$que4 === void 0 ? void 0 : _substrateApi$api$que4.call(_substrateApi$api$que3, useAddresses));
302
+ if (!ledgers) {
303
+ return [];
304
+ }
305
+ for (let i = 0; i < useAddresses.length; i++) {
306
+ const owner = useAddresses[i];
307
+ const _ledger = ledgers[i];
308
+ const ledger = _ledger.toPrimitive();
309
+ if (ledger && ledger.locked > 0) {
310
+ result.push(owner);
311
+ }
312
+ }
313
+ return result;
314
+ }
297
315
 
298
316
  /* Subscribe pool position */
299
317
 
@@ -50,40 +50,48 @@ class BaseNativeStakingPoolHandler extends _base.default {
50
50
  async getPoolRewardHistory(useAddresses, callBack) {
51
51
  let cancel = false;
52
52
  const haveSubscanService = this.state.subscanService.checkSupportedSubscanChain(this.chain);
53
+ const requestGroupId = this.state.subscanService.getGroupId();
53
54
  if (haveSubscanService) {
54
- for (const address of useAddresses) {
55
- if (cancel) {
56
- break;
57
- }
58
- try {
59
- const rs = await this.state.subscanService.getRewardHistoryList(this.chain, address);
60
- const items = rs === null || rs === void 0 ? void 0 : rs.list;
61
- if (items) {
62
- for (const item of items) {
63
- const now = new Date();
64
- const isMillisecond = now.getTime().toString().length === item.block_timestamp.toString().length;
65
- const timeStamp = isMillisecond ? item.block_timestamp : item.block_timestamp * 1000;
66
- const data = {
67
- slug: this.slug,
68
- type: this.type,
69
- chain: this.chain,
70
- address: address,
71
- group: this.group,
72
- blockTimestamp: timeStamp,
73
- amount: item.amount,
74
- eventIndex: item.event_index
75
- };
76
- callBack(data);
77
- }
55
+ this.checkAccountHaveStake(useAddresses).then(activeAddresses => {
56
+ for (const address of useAddresses) {
57
+ if (cancel) {
58
+ break;
78
59
  }
79
- } catch (e) {
80
- console.error(e);
60
+ if (!activeAddresses.includes(address)) {
61
+ continue;
62
+ }
63
+ this.state.subscanService.getRewardHistoryList(requestGroupId, this.chain, address).then(rs => {
64
+ const items = rs === null || rs === void 0 ? void 0 : rs.list;
65
+ if (cancel) {
66
+ return;
67
+ }
68
+ if (items) {
69
+ for (const item of items) {
70
+ const now = new Date();
71
+ const isMillisecond = now.getTime().toString().length === item.block_timestamp.toString().length;
72
+ const timeStamp = isMillisecond ? item.block_timestamp : item.block_timestamp * 1000;
73
+ const data = {
74
+ slug: this.slug,
75
+ type: this.type,
76
+ chain: this.chain,
77
+ address: address,
78
+ group: this.group,
79
+ blockTimestamp: timeStamp,
80
+ amount: item.amount,
81
+ eventIndex: item.event_index
82
+ };
83
+ callBack(data);
84
+ }
85
+ }
86
+ }).catch(console.error);
81
87
  }
82
- }
88
+ }).catch(console.error);
83
89
  }
84
- return () => {
90
+ return Promise.resolve(() => {
91
+ console.log('Cancel get pool reward history', requestGroupId);
85
92
  cancel = false;
86
- };
93
+ this.state.subscanService.cancelGroupRequest(requestGroupId);
94
+ });
87
95
  }
88
96
 
89
97
  /* Get pool reward */
@@ -372,6 +372,11 @@ class SubnetTaoStakingPoolHandler extends _basePara.default {
372
372
  };
373
373
  }
374
374
 
375
+ // Because not have subscan api
376
+ async checkAccountHaveStake(useAddresses) {
377
+ return Promise.resolve([]);
378
+ }
379
+
375
380
  /* Subscribe pool position */
376
381
 
377
382
  /* Get pool targets */
@@ -126,6 +126,34 @@ class MythosNativeStakingPoolHandler extends _basePara.default {
126
126
 
127
127
  /* Subscribe pool position */
128
128
 
129
+ async checkAccountHaveStake(useAddresses) {
130
+ var _substrateApi$api$que, _substrateApi$api$que2, _substrateApi$api$que3;
131
+ const result = [];
132
+ const substrateApi = await this.substrateApi.isReady;
133
+ const ledgers = await ((_substrateApi$api$que = substrateApi.api.query.collatorStaking) === null || _substrateApi$api$que === void 0 ? void 0 : (_substrateApi$api$que2 = _substrateApi$api$que.userStake) === null || _substrateApi$api$que2 === void 0 ? void 0 : (_substrateApi$api$que3 = _substrateApi$api$que2.multi) === null || _substrateApi$api$que3 === void 0 ? void 0 : _substrateApi$api$que3.call(_substrateApi$api$que2, useAddresses));
134
+ const _unstakings = await Promise.all(useAddresses.map(stakerAddress => {
135
+ var _substrateApi$api$que4, _substrateApi$api$que5;
136
+ return (_substrateApi$api$que4 = substrateApi.api.query.collatorStaking) === null || _substrateApi$api$que4 === void 0 ? void 0 : (_substrateApi$api$que5 = _substrateApi$api$que4.releaseQueues) === null || _substrateApi$api$que5 === void 0 ? void 0 : _substrateApi$api$que5.call(_substrateApi$api$que4, stakerAddress);
137
+ }));
138
+ if (!ledgers || !_unstakings) {
139
+ return [];
140
+ }
141
+ for (let i = 0; i < useAddresses.length; i++) {
142
+ const owner = useAddresses[i];
143
+ const _userStake = ledgers[i];
144
+ const userStake = _userStake.toPrimitive();
145
+ const _unstaking = _unstakings[i];
146
+ const unstakings = _unstaking.toPrimitive();
147
+
148
+ // TODO: Need to improve, check if can only load stake info
149
+ if (userStake && userStake.stake !== '0') {
150
+ result.push(owner);
151
+ } else if (unstakings && unstakings.some(unstake => unstake.amount !== '0')) {
152
+ result.push(owner);
153
+ }
154
+ }
155
+ return result;
156
+ }
129
157
  async subscribePoolPosition(useAddresses, resultCallback) {
130
158
  let cancel = false;
131
159
  const substrateApi = await this.substrateApi.isReady;
@@ -275,6 +275,23 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
275
275
  unsub();
276
276
  };
277
277
  }
278
+ async checkAccountHaveStake(useAddresses) {
279
+ var _substrateApi$api$que, _substrateApi$api$que2, _substrateApi$api$que3;
280
+ const result = [];
281
+ const substrateApi = await this.substrateApi.isReady;
282
+ const ledgers = await ((_substrateApi$api$que = substrateApi.api.query.parachainStaking) === null || _substrateApi$api$que === void 0 ? void 0 : (_substrateApi$api$que2 = _substrateApi$api$que.delegatorState) === null || _substrateApi$api$que2 === void 0 ? void 0 : (_substrateApi$api$que3 = _substrateApi$api$que2.multi) === null || _substrateApi$api$que3 === void 0 ? void 0 : _substrateApi$api$que3.call(_substrateApi$api$que2, useAddresses));
283
+ if (!ledgers) {
284
+ return [];
285
+ }
286
+ for (let i = 0; i < useAddresses.length; i++) {
287
+ const owner = useAddresses[i];
288
+ const delegatorState = ledgers[i].toPrimitive();
289
+ if (delegatorState && delegatorState.total > 0) {
290
+ result.push(owner);
291
+ }
292
+ }
293
+ return result;
294
+ }
278
295
 
279
296
  /* Subscribe pool position */
280
297
 
@@ -290,6 +290,22 @@ class RelayNativeStakingPoolHandler extends _base.default {
290
290
  unsub === null || unsub === void 0 ? void 0 : unsub();
291
291
  };
292
292
  }
293
+ async checkAccountHaveStake(useAddresses) {
294
+ var _substrateApi$api$que22, _substrateApi$api$que23, _substrateApi$api$que24;
295
+ const result = [];
296
+ const substrateApi = await this.substrateApi.isReady;
297
+ const ledgers = await ((_substrateApi$api$que22 = substrateApi.api.query.staking) === null || _substrateApi$api$que22 === void 0 ? void 0 : (_substrateApi$api$que23 = _substrateApi$api$que22.ledger) === null || _substrateApi$api$que23 === void 0 ? void 0 : (_substrateApi$api$que24 = _substrateApi$api$que23.multi) === null || _substrateApi$api$que24 === void 0 ? void 0 : _substrateApi$api$que24.call(_substrateApi$api$que23, useAddresses));
298
+ if (ledgers) {
299
+ for (let i = 0; i < useAddresses.length; i++) {
300
+ const address = useAddresses[i];
301
+ const _ledger = ledgers[i].toPrimitive();
302
+ if (_ledger.total > 0) {
303
+ result.push(address);
304
+ }
305
+ }
306
+ }
307
+ return result;
308
+ }
293
309
 
294
310
  /* Subscribe pool position */
295
311
 
@@ -387,6 +387,11 @@ class TaoNativeStakingPoolHandler extends _basePara.default {
387
387
  };
388
388
  }
389
389
 
390
+ // Because not have subscan api
391
+ async checkAccountHaveStake(useAddresses) {
392
+ return Promise.resolve([]);
393
+ }
394
+
390
395
  /* Subscribe pool position */
391
396
 
392
397
  /* Get pool targets */
@@ -670,18 +670,39 @@ class EarningService {
670
670
  if (!addresses.length) {
671
671
  return;
672
672
  }
673
- this.fetchPoolRewardHistory(addresses, result => {
674
- this.updateEarningRewardHistory(result);
675
- }).catch(console.error);
676
- this.earningsRewardHistoryInterval = setInterval(() => {
673
+ let cancel = false;
674
+ let unsub;
675
+ this.unSubFetchEarningRewardHistory = () => {
676
+ if (!cancel) {
677
+ var _unsub2;
678
+ (_unsub2 = unsub) === null || _unsub2 === void 0 ? void 0 : _unsub2();
679
+ cancel = true;
680
+ }
681
+ };
682
+ const fetchData = () => {
677
683
  this.fetchPoolRewardHistory(addresses, result => {
684
+ if (cancel) {
685
+ return;
686
+ }
678
687
  this.updateEarningRewardHistory(result);
688
+ }).then(_unsub => {
689
+ if (!cancel) {
690
+ var _unsub3;
691
+ (_unsub3 = unsub) === null || _unsub3 === void 0 ? void 0 : _unsub3();
692
+ unsub = _unsub;
693
+ }
679
694
  }).catch(console.error);
680
- }, _constants.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
695
+ };
696
+ if (!cancel) {
697
+ fetchData();
698
+ }
699
+ this.earningsRewardHistoryInterval = setInterval(fetchData, _constants.CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL);
681
700
  }
682
701
  runUnsubscribeEarningRewardHistoryInterval() {
702
+ var _this$unSubFetchEarni;
683
703
  (0, _utils2.removeLazy)('updateEarningRewardHistory');
684
704
  this.earningRewardHistoryQueue = [];
705
+ (_this$unSubFetchEarni = this.unSubFetchEarningRewardHistory) === null || _this$unSubFetchEarni === void 0 ? void 0 : _this$unSubFetchEarni.call(this);
685
706
  this.earningsRewardHistoryInterval && clearInterval(this.earningsRewardHistoryInterval);
686
707
  }
687
708
 
@@ -81,7 +81,7 @@ class HistoryService {
81
81
  /**
82
82
  * @todo: Must improve performance of this function
83
83
  * */
84
- fetchSubscanTransactionHistory(chain, addresses) {
84
+ fetchSubscanTransactionHistory(chain, addresses, groupId) {
85
85
  if (!this.subscanService.checkSupportedSubscanChain(chain) || !addresses.length) {
86
86
  return;
87
87
  }
@@ -94,7 +94,7 @@ class HistoryService {
94
94
  // However, fetchAllPossibleTransferItems-sent must run after fetchAllPossibleExtrinsicItems,
95
95
  // to avoid "duplicate Extrinsic Hash between items" problem
96
96
 
97
- this.subscanService.fetchAllPossibleExtrinsicItems(chain, address, extrinsicItems => {
97
+ this.subscanService.fetchAllPossibleExtrinsicItems(groupId, chain, address, extrinsicItems => {
98
98
  const result = [];
99
99
  extrinsicItems.forEach(x => {
100
100
  const item = (0, _subscanHistory.parseSubscanExtrinsicData)(address, x, chainInfo);
@@ -112,7 +112,7 @@ class HistoryService {
112
112
  excludeTransferExtrinsicHash.push(x.extrinsic_hash);
113
113
  }
114
114
  });
115
- this.subscanService.fetchAllPossibleTransferItems(chain, address, 'sent').then(rsMap => {
115
+ this.subscanService.fetchAllPossibleTransferItems(groupId, chain, address, 'sent').then(rsMap => {
116
116
  const result = [];
117
117
  Object.keys(rsMap).forEach(hash => {
118
118
  // only push item that does not have same hash with another item
@@ -132,7 +132,7 @@ class HistoryService {
132
132
  }).catch(e => {
133
133
  console.log('fetchAllPossibleExtrinsicItems error', e);
134
134
  });
135
- this.subscanService.fetchAllPossibleTransferItems(chain, address, 'received').then(rsMap => {
135
+ this.subscanService.fetchAllPossibleTransferItems(groupId, chain, address, 'received').then(rsMap => {
136
136
  const result = [];
137
137
  Object.keys(rsMap).forEach(hash => {
138
138
  // only push item that does not have same hash with another item
@@ -179,14 +179,19 @@ class HistoryService {
179
179
  const evmAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.EVM]);
180
180
  const substrateAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.SUBSTRATE]);
181
181
  const bitcoinAddresses = (0, _utils2.getAddressesByChainType)(addresses, [_KoniTypes.ChainType.BITCOIN], chainInfo);
182
+ const groupId = this.subscanService.getGroupId();
182
183
  const subscription = this.historySubject.subscribe(items => {
183
184
  cb(items.filter(filterHistoryItemByAddressAndChain(chain, addresses)));
184
185
  });
186
+ const unsubscribe = () => {
187
+ subscription.unsubscribe();
188
+ this.subscanService.cancelGroupRequest(groupId);
189
+ };
185
190
  if ((0, _utils._isChainSubstrateCompatible)(chainInfo)) {
186
191
  if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
187
- this.fetchSubscanTransactionHistory(chain, evmAddresses);
192
+ this.fetchSubscanTransactionHistory(chain, evmAddresses, groupId);
188
193
  } else {
189
- this.fetchSubscanTransactionHistory(chain, substrateAddresses);
194
+ this.fetchSubscanTransactionHistory(chain, substrateAddresses, groupId);
190
195
  }
191
196
  } else if ((0, _utils._isChainBitcoinCompatible)(chainInfo)) {
192
197
  this.fetchBitcoinTransactionHistory(chain, bitcoinAddresses).catch(e => {
@@ -194,7 +199,7 @@ class HistoryService {
194
199
  });
195
200
  }
196
201
  return {
197
- unsubscribe: subscription.unsubscribe,
202
+ unsubscribe,
198
203
  value: this.historySubject.getValue().filter(filterHistoryItemByAddressAndChain(chain, addresses))
199
204
  };
200
205
  }