@subwallet/extension-base 1.1.21-3 → 1.1.23-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 (59) hide show
  1. package/background/KoniTypes.d.ts +10 -1
  2. package/cjs/koni/api/dotsama/balance.js +51 -1
  3. package/cjs/koni/api/dotsama/crowdloan.js +29 -3
  4. package/cjs/koni/api/dotsama/transfer.js +10 -3
  5. package/cjs/koni/api/staking/bonding/astar.js +9 -5
  6. package/cjs/koni/api/staking/bonding/relayChain.js +2 -2
  7. package/cjs/koni/api/xcm/index.js +6 -1
  8. package/cjs/koni/api/xcm/polkadotXcm.js +1 -3
  9. package/cjs/koni/api/xcm/xTokens.js +1 -1
  10. package/cjs/koni/background/handlers/Extension.js +117 -99
  11. package/cjs/koni/background/handlers/State.js +12 -6
  12. package/cjs/koni/background/subscription.js +1 -1
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/chain-service/constants.js +8 -4
  15. package/cjs/services/chain-service/handler/SubstrateApi.js +9 -0
  16. package/cjs/services/chain-service/handler/chain-spec/goldberg.js +123 -0
  17. package/cjs/services/chain-service/index.js +18 -0
  18. package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +53 -0
  19. package/cjs/services/history-service/index.js +78 -21
  20. package/cjs/services/history-service/subscan-history.js +107 -0
  21. package/cjs/services/subscan-service/index.js +109 -4
  22. package/cjs/services/subscan-service/subscan-chain-map.js +82 -8
  23. package/cjs/utils/index.js +10 -1
  24. package/koni/api/dotsama/balance.js +51 -1
  25. package/koni/api/dotsama/crowdloan.d.ts +2 -2
  26. package/koni/api/dotsama/crowdloan.js +29 -2
  27. package/koni/api/dotsama/transfer.js +10 -3
  28. package/koni/api/staking/bonding/astar.js +9 -5
  29. package/koni/api/staking/bonding/relayChain.js +2 -2
  30. package/koni/api/xcm/index.js +6 -1
  31. package/koni/api/xcm/polkadotXcm.js +2 -4
  32. package/koni/api/xcm/xTokens.js +1 -1
  33. package/koni/background/handlers/Extension.d.ts +1 -0
  34. package/koni/background/handlers/Extension.js +20 -3
  35. package/koni/background/handlers/State.d.ts +1 -0
  36. package/koni/background/handlers/State.js +13 -7
  37. package/koni/background/subscription.js +1 -1
  38. package/package.json +21 -6
  39. package/packageInfo.js +1 -1
  40. package/services/chain-service/constants.d.ts +3 -0
  41. package/services/chain-service/constants.js +8 -5
  42. package/services/chain-service/handler/SubstrateApi.js +8 -0
  43. package/services/chain-service/handler/chain-spec/goldberg.d.ts +115 -0
  44. package/services/chain-service/handler/chain-spec/goldberg.js +116 -0
  45. package/services/chain-service/index.d.ts +1 -0
  46. package/services/chain-service/index.js +18 -0
  47. package/services/history-service/helpers/subscan-extrinsic-parser-helper.d.ts +6 -0
  48. package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +44 -0
  49. package/services/history-service/index.d.ts +10 -6
  50. package/services/history-service/index.js +79 -22
  51. package/services/history-service/subscan-history.d.ts +5 -0
  52. package/services/history-service/subscan-history.js +100 -0
  53. package/services/subscan-service/index.d.ts +10 -2
  54. package/services/subscan-service/index.js +105 -4
  55. package/services/subscan-service/subscan-chain-map.d.ts +9 -3
  56. package/services/subscan-service/subscan-chain-map.js +78 -5
  57. package/services/subscan-service/types.d.ts +146 -0
  58. package/utils/index.d.ts +1 -0
  59. package/utils/index.js +7 -0
@@ -91,14 +91,14 @@ class KoniState {
91
91
  this.eventService = new _eventService.EventService();
92
92
  this.dbService = new _DatabaseService.default(this.eventService);
93
93
  this.keyringService = new _keyringService.KeyringService(this.eventService);
94
- this.subscanService = new _subscanService.SubscanService();
95
94
  this.notificationService = new _NotificationService.default();
96
95
  this.chainService = new _chainService.ChainService(this.dbService, this.eventService);
96
+ this.subscanService = new _subscanService.SubscanService(_subscanChainMap.SUBSCAN_API_CHAIN_MAP);
97
97
  this.settingService = new _SettingService.default();
98
98
  this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService);
99
99
  this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
100
100
  this.balanceService = new _balanceService.BalanceService(this.chainService);
101
- this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
101
+ this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService, this.subscanService);
102
102
  this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
103
103
  this.walletConnectService = new _walletConnectService.default(this, this.requestService);
104
104
  this.migrationService = new _migrationService.default(this, this.eventService);
@@ -206,9 +206,13 @@ class KoniState {
206
206
  });
207
207
  return balanceMap;
208
208
  }
209
+ afterChainServiceInit() {
210
+ this.subscanService.setSubscanChainMap(this.chainService.getSubscanChainMap());
211
+ }
209
212
  async init() {
210
213
  await this.eventService.waitCryptoReady;
211
214
  await this.chainService.init();
215
+ this.afterChainServiceInit();
212
216
  await this.migrationService.run();
213
217
  this.eventService.emit('chain.ready', true);
214
218
  this.onReady();
@@ -1494,7 +1498,7 @@ class KoniState {
1494
1498
  network,
1495
1499
  symbol
1496
1500
  } = _ref11;
1497
- const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
1501
+ const chain = _subscanChainMap.SUBSCAN_BALANCE_CHAIN_MAP_REVERSE[network];
1498
1502
  const chainInfo = chain ? chainMap[chain] : null;
1499
1503
  const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
1500
1504
 
@@ -1503,10 +1507,11 @@ class KoniState {
1503
1507
  return;
1504
1508
  }
1505
1509
  const tokenKey = `${chain}-${category === 'native' ? 'NATIVE' : 'LOCAL'}-${symbol.toUpperCase()}`;
1506
- if (assetMap[tokenKey] && !((_currentAssetSettings = currentAssetSettings[tokenKey]) !== null && _currentAssetSettings !== void 0 && _currentAssetSettings.visible)) {
1510
+ const existedKey = Object.keys(assetMap).find(v => v.toLowerCase() === tokenKey.toLowerCase());
1511
+ if (existedKey && !((_currentAssetSettings = currentAssetSettings[existedKey]) !== null && _currentAssetSettings !== void 0 && _currentAssetSettings.visible)) {
1507
1512
  needEnableChains.push(chain);
1508
- needActiveTokens.push(tokenKey);
1509
- currentAssetSettings[tokenKey] = {
1513
+ needActiveTokens.push(existedKey);
1514
+ currentAssetSettings[existedKey] = {
1510
1515
  visible: true
1511
1516
  };
1512
1517
  }
@@ -1578,6 +1583,7 @@ class KoniState {
1578
1583
  this.chainService.resetWallet(resetAll);
1579
1584
  await this.walletConnectService.resetWallet(resetAll);
1580
1585
  await this.chainService.init();
1586
+ this.afterChainServiceInit();
1581
1587
  }
1582
1588
  async enableMantaPay(updateStore, address, password, seedPhrase) {
1583
1589
  var _this$chainService3, _this$chainService3$m, _this$chainService4, _this$chainService4$m, _this$chainService4$m2, _this$chainService11, _this$chainService11$, _this$chainService11$2;
@@ -169,7 +169,7 @@ class KoniSubscription {
169
169
  initCrowdloanSubscription(addresses, substrateApiMap, onlyRunOnFirstTime) {
170
170
  const subscriptionPromise = (0, _crowdloan.subscribeCrowdloan)(addresses, substrateApiMap, (networkKey, rs) => {
171
171
  this.state.setCrowdloanItem(networkKey, rs);
172
- }, this.state.getChainInfoMap());
172
+ });
173
173
  if (onlyRunOnFirstTime) {
174
174
  subscriptionPromise.then(unsub => {
175
175
  unsub && unsub();
@@ -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.1.21-3'
16
+ version: '1.1.23-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -19,7 +19,8 @@ exports.API_MAX_RETRY = API_MAX_RETRY;
19
19
  const _API_OPTIONS_CHAIN_GROUP = {
20
20
  acala: ['acala', 'karura', 'origintrail', 'kintsugi'],
21
21
  turing: ['turingStaging', 'turing'],
22
- avail: ['kate']
22
+ avail: ['kate'],
23
+ goldberg: ['goldberg_testnet']
23
24
  };
24
25
  exports._API_OPTIONS_CHAIN_GROUP = _API_OPTIONS_CHAIN_GROUP;
25
26
  const _PREDEFINED_SINGLE_MODES = {
@@ -40,7 +41,9 @@ const _BALANCE_CHAIN_GROUP = {
40
41
  equilibrium_parachain: ['equilibrium_parachain'],
41
42
  bifrost: ['bifrost', 'acala', 'karura', 'acala_testnet', 'pioneer', 'bitcountry', 'bifrost_dot', 'hydradx_main', 'pendulum', 'amplitude'],
42
43
  statemine: ['statemine', 'astar', 'shiden', 'statemint', 'moonbeam', 'moonbase', 'moonriver', 'crabParachain', 'darwinia2', 'parallel', 'calamari'],
43
- kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'] // perhaps there are some runtime updates
44
+ kusama: ['kusama', 'kintsugi', 'kintsugi_test', 'interlay', 'acala', 'statemint', 'karura', 'bifrost'],
45
+ // perhaps there are some runtime updates
46
+ centrifuge: ['centrifuge']
44
47
  };
45
48
  exports._BALANCE_CHAIN_GROUP = _BALANCE_CHAIN_GROUP;
46
49
  const _BALANCE_TOKEN_GROUP = {
@@ -209,8 +212,9 @@ const _TRANSFER_CHAIN_GROUP = {
209
212
  statemine: ['statemint', 'statemine', 'darwinia2', 'astar', 'shiden', 'shibuya', 'parallel'],
210
213
  riochain: ['riochain'],
211
214
  sora_substrate: ['sora_substrate'],
212
- avail: ['kate'],
213
- pendulum: ['pendulum', 'amplitude', 'amplitude_test']
215
+ avail: ['kate', 'goldberg_testnet'],
216
+ pendulum: ['pendulum', 'amplitude', 'amplitude_test'],
217
+ centrifuge: ['centrifuge']
214
218
  };
215
219
  exports._TRANSFER_CHAIN_GROUP = _TRANSFER_CHAIN_GROUP;
216
220
  const _BALANCE_PARSING_CHAIN_GROUP = {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
@@ -19,6 +20,7 @@ var _api3 = require("@polkadot/apps-config/api");
19
20
  var _create = require("@polkadot/types/create");
20
21
  var _util = require("@polkadot/util");
21
22
  var _defaults = require("@polkadot/util-crypto/address/defaults");
23
+ var _goldberg = _interopRequireDefault(require("./chain-spec/goldberg"));
22
24
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
23
25
  // SPDX-License-Identifier: Apache-2.0
24
26
 
@@ -91,6 +93,13 @@ class SubstrateApi {
91
93
  types: _availJsSdk.spec.types,
92
94
  signedExtensions: _availJsSdk.spec.signedExtensions
93
95
  });
96
+ } else if (_constants._API_OPTIONS_CHAIN_GROUP.goldberg.includes(this.chainSlug)) {
97
+ api = new _api2.ApiPromise({
98
+ provider,
99
+ rpc: _goldberg.default.rpc,
100
+ types: _goldberg.default.types,
101
+ signedExtensions: _goldberg.default.signedExtensions
102
+ });
94
103
  } else {
95
104
  api = new _api2.ApiPromise(apiOption);
96
105
  }
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
8
+ // SPDX-License-Identifier: Apache-2.0
9
+
10
+ const chainSpec = {
11
+ types: {
12
+ AppId: 'Compact<u32>',
13
+ DataLookupIndexItem: {
14
+ appId: 'AppId',
15
+ start: 'Compact<u32>'
16
+ },
17
+ DataLookup: {
18
+ size: 'Compact<u32>',
19
+ index: 'Vec<DataLookupIndexItem>'
20
+ },
21
+ KateCommitment: {
22
+ rows: 'Compact<u16>',
23
+ cols: 'Compact<u16>',
24
+ commitment: 'Vec<u8>',
25
+ dataRoot: 'H256'
26
+ },
27
+ V1HeaderExtension: {
28
+ appLookup: 'DataLookup',
29
+ commitment: 'KateCommitment'
30
+ },
31
+ HeaderExtension: {
32
+ _enum: {
33
+ V1: 'V1HeaderExtension'
34
+ }
35
+ },
36
+ DaHeader: {
37
+ parentHash: 'Hash',
38
+ number: 'Compact<BlockNumber>',
39
+ stateRoot: 'Hash',
40
+ extrinsicsRoot: 'Hash',
41
+ digest: 'Digest',
42
+ extension: 'HeaderExtension'
43
+ },
44
+ Header: 'DaHeader',
45
+ CheckAppIdExtra: {
46
+ appId: 'AppId'
47
+ },
48
+ CheckAppIdTypes: {},
49
+ CheckAppId: {
50
+ extra: 'CheckAppIdExtra',
51
+ types: 'CheckAppIdTypes'
52
+ },
53
+ BlockLength: {
54
+ max: 'PerDispatchClass',
55
+ cols: 'Compact<u32>',
56
+ rows: 'Compact<u32>',
57
+ chunkSize: 'Compact<u32>'
58
+ },
59
+ PerDispatchClass: {
60
+ normal: 'u32',
61
+ operational: 'u32',
62
+ mandatory: 'u32'
63
+ },
64
+ DataProof: {
65
+ root: 'H256',
66
+ proof: 'Vec<H256>',
67
+ numberOfLeaves: 'Compact<u32>',
68
+ leaf_index: 'Compact<u32>',
69
+ leaf: 'H256'
70
+ },
71
+ Cell: {
72
+ row: 'u32',
73
+ col: 'u32'
74
+ }
75
+ },
76
+ rpc: {
77
+ kate: {
78
+ blockLength: {
79
+ description: 'Get Block Length',
80
+ params: [{
81
+ name: 'at',
82
+ type: 'Hash',
83
+ isOptional: true
84
+ }],
85
+ type: 'BlockLength'
86
+ },
87
+ queryProof: {
88
+ description: 'Generate the kate proof for the given `cells`',
89
+ params: [{
90
+ name: 'cells',
91
+ type: 'Vec<Cell>'
92
+ }, {
93
+ name: 'at',
94
+ type: 'Hash',
95
+ isOptional: true
96
+ }],
97
+ type: 'Vec<u8>'
98
+ },
99
+ queryDataProof: {
100
+ description: 'Generate the data proof for the given `index`',
101
+ params: [{
102
+ name: 'data_index',
103
+ type: 'u32'
104
+ }, {
105
+ name: 'at',
106
+ type: 'Hash',
107
+ isOptional: true
108
+ }],
109
+ type: 'DataProof'
110
+ }
111
+ }
112
+ },
113
+ signedExtensions: {
114
+ CheckAppId: {
115
+ extrinsic: {
116
+ appId: 'AppId'
117
+ },
118
+ payload: {}
119
+ }
120
+ }
121
+ };
122
+ var _default = chainSpec;
123
+ exports.default = _default;
@@ -1399,5 +1399,23 @@ class ChainService {
1399
1399
  getMetadataByHash(hash) {
1400
1400
  return this.dbService.stores.metadata.getMetadataByGenesisHash(hash);
1401
1401
  }
1402
+ getSubscanChainMap(reverse) {
1403
+ const result = {};
1404
+ const chainInfoMap = this.getChainInfoMap();
1405
+ Object.values(chainInfoMap).forEach(i => {
1406
+ var _i$extraInfo;
1407
+ if (!((_i$extraInfo = i.extraInfo) !== null && _i$extraInfo !== void 0 && _i$extraInfo.subscanSlug)) {
1408
+ return;
1409
+ }
1410
+ if (!reverse) {
1411
+ var _i$extraInfo2;
1412
+ result[i.slug] = (_i$extraInfo2 = i.extraInfo) === null || _i$extraInfo2 === void 0 ? void 0 : _i$extraInfo2.subscanSlug;
1413
+ } else {
1414
+ var _i$extraInfo3;
1415
+ result[(_i$extraInfo3 = i.extraInfo) === null || _i$extraInfo3 === void 0 ? void 0 : _i$extraInfo3.subscanSlug] = i.slug;
1416
+ }
1417
+ });
1418
+ return result;
1419
+ }
1402
1420
  }
1403
1421
  exports.ChainService = ChainService;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getExtrinsicParserKey = getExtrinsicParserKey;
7
+ exports.supportedExtrinsicParser = exports.subscanExtrinsicParserMap = void 0;
8
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
+ var _utilCrypto = require("@polkadot/util-crypto");
10
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ function getExtrinsicParserKey(extrinsicItem) {
14
+ return `${extrinsicItem.call_module}.${extrinsicItem.call_module_function}`;
15
+ }
16
+ function paramJsonParse(item) {
17
+ try {
18
+ return JSON.parse(item.data || '[]');
19
+ } catch (e) {
20
+ return [];
21
+ }
22
+ }
23
+ function balanceTransferParserFunction(item) {
24
+ const params = paramJsonParse(item);
25
+ params.forEach(p => {
26
+ if (p.name === 'dest') {
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
28
+ const toPublicKey = p.value.id || p.value.Id;
29
+ if (toPublicKey) {
30
+ item.to = (0, _utilCrypto.encodeAddress)(toPublicKey, 42);
31
+ }
32
+ } else if (p.name === 'value') {
33
+ if (item.amount) {
34
+ item.amount.value = p.value;
35
+ }
36
+ }
37
+ });
38
+ item.type = _KoniTypes.ExtrinsicType.TRANSFER_BALANCE;
39
+ if (!item.to) {
40
+ return null;
41
+ }
42
+ return item;
43
+ }
44
+
45
+ // todo: will support other type later
46
+ const subscanExtrinsicParserMap = {
47
+ 'balances.transfer': balanceTransferParserFunction,
48
+ 'balances.transfer_keep_alive': balanceTransferParserFunction,
49
+ 'balances.transfer_allow_death': balanceTransferParserFunction
50
+ };
51
+ exports.subscanExtrinsicParserMap = subscanExtrinsicParserMap;
52
+ const supportedExtrinsicParser = Object.keys(subscanExtrinsicParserMap);
53
+ exports.supportedExtrinsicParser = supportedExtrinsicParser;
@@ -8,24 +8,32 @@ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
8
  var _constants = require("@subwallet/extension-base/constants");
9
9
  var _types = require("@subwallet/extension-base/services/base/types");
10
10
  var _recoverHistoryStatus = require("@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus");
11
+ var _subscanExtrinsicParserHelper = require("@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper");
12
+ var _subscanHistory = require("@subwallet/extension-base/services/history-service/subscan-history");
13
+ var _utils = require("@subwallet/extension-base/utils");
11
14
  var _promise = require("@subwallet/extension-base/utils/promise");
12
15
  var _uiKeyring = require("@subwallet/ui-keyring");
13
16
  var _rxjs = require("rxjs");
14
17
  // Copyright 2019-2022 @subwallet/extension-base
15
18
  // SPDX-License-Identifier: Apache-2.0
16
19
 
20
+ function filterHistoryItemByAddressAndChain(chain, address) {
21
+ return item => {
22
+ return item.chain === chain && item.address === address;
23
+ };
24
+ }
17
25
  class HistoryService {
18
26
  historySubject = new _rxjs.BehaviorSubject([]);
19
27
  #needRecoveryHistories = {};
20
- constructor(dbService, chainService, eventService, keyringService) {
28
+ constructor(dbService, chainService, eventService, keyringService, subscanService) {
21
29
  this.dbService = dbService;
22
30
  this.chainService = chainService;
23
31
  this.eventService = eventService;
24
32
  this.keyringService = keyringService;
33
+ this.subscanService = subscanService;
25
34
  this.init().catch(console.error);
26
35
  }
27
36
  fetchPromise = null;
28
- interval = undefined;
29
37
  recoverInterval = undefined;
30
38
  async fetchAndLoadHistories(addresses) {
31
39
  if (!addresses || addresses.length === 0) {
@@ -67,6 +75,74 @@ class HistoryService {
67
75
  await this.getHistories();
68
76
  return this.historySubject;
69
77
  }
78
+ fetchSubscanTransactionHistory(chain, address) {
79
+ if (!this.subscanService.checkSupportedSubscanChain(chain)) {
80
+ return;
81
+ }
82
+ const chainInfo = this.chainService.getChainInfoByKey(chain);
83
+ const excludeExtrinsicParserKeys = ['balances.transfer_all'];
84
+
85
+ // Note: fetchAllPossibleExtrinsicItems and fetchAllPossibleTransferItems-receive can run parallelly
86
+ // Hover, fetchAllPossibleTransferItems-sent must run after fetchAllPossibleExtrinsicItems,
87
+ // to avoid "duplicate Extrinsic Hash between items" problem
88
+
89
+ this.subscanService.fetchAllPossibleExtrinsicItems(chain, address, extrinsicItems => {
90
+ const result = [];
91
+ extrinsicItems.forEach(x => {
92
+ const item = (0, _subscanHistory.parseSubscanExtrinsicData)(address, x, chainInfo);
93
+ if (item) {
94
+ result.push(item);
95
+ }
96
+ });
97
+ this.addHistoryItems(result).catch(e => {
98
+ console.log('addHistoryItems in fetchAllPossibleExtrinsicItems error', e);
99
+ });
100
+ }).then(extrinsicItems => {
101
+ const excludeTransferExtrinsicHash = [];
102
+ extrinsicItems.forEach(x => {
103
+ if (!excludeExtrinsicParserKeys.includes((0, _subscanExtrinsicParserHelper.getExtrinsicParserKey)(x))) {
104
+ excludeTransferExtrinsicHash.push(x.extrinsic_hash);
105
+ }
106
+ });
107
+ this.subscanService.fetchAllPossibleTransferItems(chain, address, 'sent', transferItems => {
108
+ const result = [];
109
+ transferItems.forEach(t => {
110
+ if (!excludeTransferExtrinsicHash.includes(t.hash)) {
111
+ result.push((0, _subscanHistory.parseSubscanTransferData)(address, t, chainInfo));
112
+ }
113
+ });
114
+ this.addHistoryItems(result).catch(e => {
115
+ console.log('addHistoryItems in fetchAllPossibleTransferItems-sent error', e);
116
+ });
117
+ }).catch(e => {
118
+ console.log('fetchAllPossibleTransferItems-sent error', e);
119
+ });
120
+ }).catch(e => {
121
+ console.log('fetchAllPossibleExtrinsicItems error', e);
122
+ });
123
+ this.subscanService.fetchAllPossibleTransferItems(chain, address, 'received', transferItems => {
124
+ const result = [];
125
+ transferItems.forEach(t => {
126
+ result.push((0, _subscanHistory.parseSubscanTransferData)(address, t, chainInfo));
127
+ });
128
+ this.addHistoryItems(result).catch(e => {
129
+ console.log('addHistoryItems in fetchAllPossibleTransferItems-receive error', e);
130
+ });
131
+ }).catch(e => {
132
+ console.log('fetchAllPossibleTransferItems-receive error', e);
133
+ });
134
+ }
135
+ subscribeHistories(chain, address, cb) {
136
+ const _address = (0, _utils.reformatAddress)(address);
137
+ const subscription = this.historySubject.subscribe(items => {
138
+ cb(items.filter(filterHistoryItemByAddressAndChain(chain, _address)));
139
+ });
140
+ this.fetchSubscanTransactionHistory(chain, _address);
141
+ return {
142
+ unsubscribe: subscription.unsubscribe,
143
+ value: this.historySubject.getValue().filter(filterHistoryItemByAddressAndChain(chain, _address))
144
+ };
145
+ }
70
146
  async updateHistories(chain, extrinsicHash, updateData) {
71
147
  const existedRecords = await this.dbService.getHistories({
72
148
  chain,
@@ -117,17 +193,6 @@ class HistoryService {
117
193
  async persistData() {
118
194
  await this.dbService.upsertHistory(this.historySubject.value);
119
195
  }
120
- async startCron() {
121
- await this.getHistories();
122
- this.interval = setInterval(() => {
123
- this.getHistories().catch(console.error);
124
- }, _constants.CRON_REFRESH_HISTORY_INTERVAL);
125
- }
126
- stopCron() {
127
- clearTimeout(this.interval);
128
- this.fetchPromise = null;
129
- return Promise.resolve();
130
- }
131
196
  async startRecoverHistories() {
132
197
  await this.recoverHistories();
133
198
  this.recoverInterval = setInterval(() => {
@@ -182,12 +247,6 @@ class HistoryService {
182
247
  Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]).then(() => {
183
248
  this.getHistories().catch(console.log);
184
249
  this.recoverProcessingHistory().catch(console.error);
185
- this.eventService.on('account.add', () => {
186
- (async () => {
187
- await this.stopCron();
188
- await this.startCron();
189
- })().catch(console.error);
190
- });
191
250
  this.eventService.on('account.remove', address => {
192
251
  this.removeHistoryByAddress(address).catch(console.error);
193
252
  });
@@ -216,7 +275,6 @@ class HistoryService {
216
275
  await Promise.all([this.eventService.waitKeyringReady, this.eventService.waitChainReady]);
217
276
  this.startPromiseHandler = (0, _promise.createPromiseHandler)();
218
277
  this.status = _types.ServiceStatus.STARTING;
219
- await this.startCron();
220
278
  this.status = _types.ServiceStatus.STARTED;
221
279
  this.startPromiseHandler.resolve();
222
280
  } catch (e) {
@@ -232,7 +290,6 @@ class HistoryService {
232
290
  this.stopPromiseHandler = (0, _promise.createPromiseHandler)();
233
291
  this.status = _types.ServiceStatus.STOPPING;
234
292
  await this.persistData();
235
- await this.stopCron();
236
293
  await this.stopRecoverHistories();
237
294
  this.stopPromiseHandler.resolve();
238
295
  this.status = _types.ServiceStatus.STOPPED;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseSubscanExtrinsicData = parseSubscanExtrinsicData;
7
+ exports.parseSubscanTransferData = parseSubscanTransferData;
8
+ var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
9
+ var _subscanExtrinsicParserHelper = require("@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper");
10
+ var _utilCrypto = require("@polkadot/util-crypto");
11
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
12
+ // SPDX-License-Identifier: Apache-2.0
13
+
14
+ function autoFormatAddress(address) {
15
+ try {
16
+ if ((0, _utilCrypto.isEthereumAddress)(address)) {
17
+ return address;
18
+ } else {
19
+ const decoded = (0, _utilCrypto.decodeAddress)(address);
20
+ return (0, _utilCrypto.encodeAddress)(decoded, 42);
21
+ }
22
+ } catch (e) {
23
+ return '';
24
+ }
25
+ }
26
+ function parseSubscanExtrinsicData(address, extrinsicItem, chainInfo) {
27
+ var _chainInfo$substrateI, _chainInfo$evmInfo, _chainInfo$substrateI2, _chainInfo$evmInfo2;
28
+ const extrinsicParserKey = (0, _subscanExtrinsicParserHelper.getExtrinsicParserKey)(extrinsicItem);
29
+ if (!_subscanExtrinsicParserHelper.supportedExtrinsicParser.includes(extrinsicParserKey)) {
30
+ return null;
31
+ }
32
+ const chainType = chainInfo.substrateInfo ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM;
33
+ const nativeDecimals = ((_chainInfo$substrateI = chainInfo.substrateInfo) === null || _chainInfo$substrateI === void 0 ? void 0 : _chainInfo$substrateI.decimals) || ((_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.decimals) || 18;
34
+ const nativeSymbol = ((_chainInfo$substrateI2 = chainInfo.substrateInfo) === null || _chainInfo$substrateI2 === void 0 ? void 0 : _chainInfo$substrateI2.symbol) || ((_chainInfo$evmInfo2 = chainInfo.evmInfo) === null || _chainInfo$evmInfo2 === void 0 ? void 0 : _chainInfo$evmInfo2.symbol) || '';
35
+ const initData = {
36
+ address,
37
+ origin: 'subscan',
38
+ time: extrinsicItem.block_timestamp * 1000,
39
+ chainType,
40
+ from: address,
41
+ signature: extrinsicItem.signature,
42
+ fromName: undefined,
43
+ direction: _KoniTypes.TransactionDirection.SEND,
44
+ blockNumber: extrinsicItem.block_num,
45
+ blockHash: '',
46
+ chain: chainInfo.slug,
47
+ type: _KoniTypes.ExtrinsicType.UNKNOWN,
48
+ to: '',
49
+ toName: undefined,
50
+ extrinsicHash: extrinsicItem.extrinsic_hash,
51
+ amount: {
52
+ value: '0',
53
+ decimals: nativeDecimals,
54
+ symbol: nativeSymbol
55
+ },
56
+ data: extrinsicItem.params,
57
+ fee: {
58
+ value: extrinsicItem.fee,
59
+ decimals: nativeDecimals,
60
+ symbol: nativeSymbol
61
+ },
62
+ status: extrinsicItem.success ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.FAIL,
63
+ nonce: extrinsicItem.nonce
64
+ };
65
+ try {
66
+ return _subscanExtrinsicParserHelper.subscanExtrinsicParserMap[extrinsicParserKey](initData);
67
+ } catch (e) {
68
+ console.log('parseSubscanExtrinsicData error:', e, initData);
69
+ return null;
70
+ }
71
+ }
72
+ function parseSubscanTransferData(address, transferItem, chainInfo) {
73
+ var _chainInfo$substrateI3, _chainInfo$evmInfo3, _chainInfo$substrateI4, _chainInfo$evmInfo4;
74
+ const chainType = chainInfo.substrateInfo ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM;
75
+ const nativeDecimals = ((_chainInfo$substrateI3 = chainInfo.substrateInfo) === null || _chainInfo$substrateI3 === void 0 ? void 0 : _chainInfo$substrateI3.decimals) || ((_chainInfo$evmInfo3 = chainInfo.evmInfo) === null || _chainInfo$evmInfo3 === void 0 ? void 0 : _chainInfo$evmInfo3.decimals) || 18;
76
+ const nativeSymbol = ((_chainInfo$substrateI4 = chainInfo.substrateInfo) === null || _chainInfo$substrateI4 === void 0 ? void 0 : _chainInfo$substrateI4.symbol) || ((_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.symbol) || '';
77
+ const from = autoFormatAddress(transferItem.from);
78
+ const to = autoFormatAddress(transferItem.to);
79
+ return {
80
+ address,
81
+ origin: 'subscan',
82
+ time: transferItem.block_timestamp * 1000,
83
+ chainType,
84
+ from,
85
+ fromName: transferItem.from_account_display.display,
86
+ direction: address === from ? _KoniTypes.TransactionDirection.SEND : _KoniTypes.TransactionDirection.RECEIVED,
87
+ blockNumber: transferItem.block_num,
88
+ blockHash: '',
89
+ chain: chainInfo.slug,
90
+ type: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE,
91
+ to,
92
+ toName: transferItem.to_account_display.display,
93
+ extrinsicHash: transferItem.hash,
94
+ amount: {
95
+ value: transferItem.amount,
96
+ decimals: 0,
97
+ symbol: transferItem.asset_symbol
98
+ },
99
+ fee: {
100
+ value: transferItem.fee,
101
+ decimals: nativeDecimals,
102
+ symbol: nativeSymbol
103
+ },
104
+ status: transferItem.success ? _KoniTypes.ExtrinsicStatus.SUCCESS : _KoniTypes.ExtrinsicStatus.FAIL,
105
+ nonce: transferItem.nonce
106
+ };
107
+ }