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

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 (140) hide show
  1. package/background/KoniTypes.d.ts +14 -1
  2. package/background/KoniTypes.js +1 -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 +1 -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/astar.js +28 -12
  30. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  31. package/cjs/koni/api/staking/relayChain.js +0 -1
  32. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  33. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  34. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  35. package/cjs/koni/api/xcm/index.js +0 -1
  36. package/cjs/koni/background/cron.js +0 -45
  37. package/cjs/koni/background/handlers/Extension.js +164 -134
  38. package/cjs/koni/background/handlers/State.js +18 -3
  39. package/cjs/koni/background/handlers/Tabs.js +34 -2
  40. package/cjs/koni/background/handlers/index.js +3 -2
  41. package/cjs/koni/background/subscription.js +0 -26
  42. package/cjs/packageInfo.js +1 -1
  43. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  44. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  45. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  46. package/cjs/services/chain-service/index.js +0 -2
  47. package/cjs/services/chain-service/utils.js +3 -0
  48. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +227 -0
  49. package/cjs/services/history-service/index.js +68 -6
  50. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  51. package/cjs/services/history-service/testChainMap.js +724 -0
  52. package/cjs/services/keyring-service/index.js +0 -2
  53. package/cjs/services/migration-service/index.js +0 -3
  54. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  55. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  56. package/cjs/services/migration-service/scripts/index.js +5 -1
  57. package/cjs/services/notification-service/NotificationService.js +1 -1
  58. package/cjs/services/price-service/coingecko.js +1 -1
  59. package/cjs/services/price-service/index.js +0 -3
  60. package/cjs/services/request-service/handler/AuthRequestHandler.js +1 -1
  61. package/cjs/services/setting-service/constants.js +8 -2
  62. package/cjs/services/storage-service/DatabaseService.js +3 -45
  63. package/cjs/services/transaction-service/constants.js +11 -0
  64. package/cjs/services/transaction-service/index.js +60 -20
  65. package/cjs/services/transaction-service/utils.js +25 -14
  66. package/cjs/utils/index.js +3 -0
  67. package/constants/index.d.ts +1 -1
  68. package/constants/index.js +1 -1
  69. package/koni/api/coingecko.js +1 -4
  70. package/koni/api/dotsama/balance.js +7 -5
  71. package/koni/api/dotsama/crowdloan.js +0 -4
  72. package/koni/api/dotsama/transfer.js +0 -4
  73. package/koni/api/nft/acala_nft/index.js +1 -1
  74. package/koni/api/nft/bit.country/index.js +1 -1
  75. package/koni/api/nft/evm_nft/index.js +2 -3
  76. package/koni/api/nft/index.js +1 -2
  77. package/koni/api/nft/karura_nft/index.js +1 -1
  78. package/koni/api/nft/quartz_nft/index.js +1 -1
  79. package/koni/api/nft/rmrk_nft/index.js +2 -3
  80. package/koni/api/nft/statemine_nft/index.js +1 -1
  81. package/koni/api/nft/transfer.js +5 -5
  82. package/koni/api/nft/unique_nft/index.js +1 -1
  83. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  84. package/koni/api/nft/wasm_nft/index.js +1 -2
  85. package/koni/api/staking/bonding/astar.d.ts +2 -1
  86. package/koni/api/staking/bonding/astar.js +27 -12
  87. package/koni/api/staking/bonding/utils.js +4 -0
  88. package/koni/api/staking/relayChain.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +0 -2
  90. package/koni/api/tokens/wasm/index.js +0 -1
  91. package/koni/api/tokens/wasm/utils.js +0 -1
  92. package/koni/api/xcm/index.js +0 -1
  93. package/koni/background/cron.js +0 -45
  94. package/koni/background/handlers/Extension.d.ts +2 -0
  95. package/koni/background/handlers/Extension.js +79 -51
  96. package/koni/background/handlers/State.d.ts +3 -1
  97. package/koni/background/handlers/State.js +18 -3
  98. package/koni/background/handlers/Tabs.d.ts +1 -0
  99. package/koni/background/handlers/Tabs.js +32 -1
  100. package/koni/background/handlers/index.js +3 -2
  101. package/koni/background/subscription.d.ts +0 -1
  102. package/koni/background/subscription.js +0 -26
  103. package/package.json +55 -34
  104. package/packageInfo.js +1 -1
  105. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  106. package/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  107. package/services/chain-service/handler/light-client/index.js +8 -6
  108. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  109. package/services/chain-service/index.js +0 -2
  110. package/services/chain-service/utils.js +3 -0
  111. package/services/history-service/helpers/recoverHistoryStatus.d.ts +17 -0
  112. package/services/history-service/helpers/recoverHistoryStatus.js +214 -0
  113. package/services/history-service/index.d.ts +6 -0
  114. package/services/history-service/index.js +69 -7
  115. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  116. package/services/history-service/testChainMap.d.ts +3 -0
  117. package/services/history-service/testChainMap.js +716 -0
  118. package/services/keyring-service/index.js +0 -2
  119. package/services/migration-service/index.js +0 -3
  120. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  121. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  122. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  123. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  124. package/services/migration-service/scripts/index.js +5 -1
  125. package/services/notification-service/NotificationService.js +1 -1
  126. package/services/price-service/coingecko.js +1 -1
  127. package/services/price-service/index.js +0 -3
  128. package/services/request-service/handler/AuthRequestHandler.js +1 -1
  129. package/services/setting-service/constants.d.ts +4 -2
  130. package/services/setting-service/constants.js +5 -1
  131. package/services/storage-service/DatabaseService.d.ts +1 -1
  132. package/services/storage-service/DatabaseService.js +3 -45
  133. package/services/transaction-service/constants.d.ts +1 -0
  134. package/services/transaction-service/constants.js +4 -0
  135. package/services/transaction-service/index.d.ts +1 -0
  136. package/services/transaction-service/index.js +61 -21
  137. package/services/transaction-service/types.d.ts +2 -0
  138. package/services/transaction-service/utils.d.ts +1 -1
  139. package/services/transaction-service/utils.js +24 -13
  140. package/utils/index.js +3 -0
@@ -208,7 +208,6 @@ class KoniState {
208
208
  this.onReady();
209
209
  this.onAccountAdd();
210
210
  this.onAccountRemove();
211
- this.logger.log('Done init state');
212
211
  }
213
212
  startSubscription() {
214
213
  this.dbService.subscribeChainStakingMetadata([], data => {
@@ -224,7 +223,6 @@ class KoniState {
224
223
  this.historyService.start().catch(console.error);
225
224
  this.priceService.start().catch(console.error);
226
225
  this.ready = true;
227
- this.logger.log('State is ready');
228
226
  }
229
227
  isReady() {
230
228
  return this.ready;
@@ -623,7 +621,24 @@ class KoniState {
623
621
  ...settings,
624
622
  camera: value
625
623
  };
626
- console.log(newSettings, value);
624
+ this.settingService.setSettings(newSettings);
625
+ });
626
+ }
627
+ setAutoLockTime(value) {
628
+ this.settingService.getSettings(settings => {
629
+ const newSettings = {
630
+ ...settings,
631
+ timeAutoLock: value
632
+ };
633
+ this.settingService.setSettings(newSettings);
634
+ });
635
+ }
636
+ setEnableChainPatrol(value) {
637
+ this.settingService.getSettings(settings => {
638
+ const newSettings = {
639
+ ...settings,
640
+ enableChainPatrol: value
641
+ };
627
642
  this.settingService.setSettings(newSettings);
628
643
  });
629
644
  }
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = void 0;
7
+ exports.default = exports.chainPatrolCheckUrl = void 0;
8
8
  var _types = require("@subwallet/chain-list/types");
9
9
  var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
10
10
  var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
@@ -15,6 +15,7 @@ var _RequestExtrinsicSign = _interopRequireDefault(require("@subwallet/extension
15
15
  var _constants = require("@subwallet/extension-base/constants");
16
16
  var _defaults = require("@subwallet/extension-base/defaults");
17
17
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
18
+ var _constants2 = require("@subwallet/extension-base/services/setting-service/constants");
18
19
  var _utils2 = require("@subwallet/extension-base/utils");
19
20
  var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
20
21
  var _web = _interopRequireDefault(require("web3"));
@@ -94,11 +95,36 @@ function transformAccountsV2(accounts) {
94
95
  };
95
96
  });
96
97
  }
98
+ // check if a URL is blocked
99
+ const chainPatrolCheckUrl = async url => {
100
+ const response = await fetch('https://app.chainpatrol.io/api/v2/asset/check', {
101
+ method: 'POST',
102
+ headers: {
103
+ 'Content-Type': 'application/json',
104
+ 'X-API-KEY': 'e5e88cd0-7994-4667-9071-bab849c2ba71'
105
+ },
106
+ body: JSON.stringify({
107
+ type: 'URL',
108
+ content: url
109
+ })
110
+ });
111
+ const data = await response.json();
112
+ return data.status === 'BLOCKED';
113
+ };
114
+ exports.chainPatrolCheckUrl = chainPatrolCheckUrl;
97
115
  class KoniTabs {
98
116
  #koniState;
99
117
  evmEventEmitterMap = {};
118
+ #chainPatrolService = _constants2.DEFAULT_CHAIN_PATROL_ENABLE;
100
119
  constructor(koniState) {
101
120
  this.#koniState = koniState;
121
+ const updateChainPatrolService = rs => {
122
+ this.#chainPatrolService = rs.enableChainPatrol;
123
+ };
124
+ this.#koniState.settingService.getSettings(updateChainPatrolService);
125
+ this.#koniState.settingService.getSubject().subscribe({
126
+ next: updateChainPatrolService
127
+ });
102
128
  }
103
129
 
104
130
  /// Clone from Polkadot.js
@@ -197,6 +223,13 @@ class KoniTabs {
197
223
  this.redirectPhishingLanding(url);
198
224
  return true;
199
225
  }
226
+ if (this.#chainPatrolService) {
227
+ const isInChainPatrolDenyList = await chainPatrolCheckUrl(url);
228
+ if (isInChainPatrolDenyList) {
229
+ this.redirectPhishingLanding(url);
230
+ return true;
231
+ }
232
+ }
200
233
  return false;
201
234
  }
202
235
 
@@ -698,7 +731,6 @@ class KoniTabs {
698
731
  const {
699
732
  method
700
733
  } = request;
701
- console.log('method: ' + method);
702
734
  try {
703
735
  switch (method) {
704
736
  case 'eth_chainId':
@@ -60,11 +60,12 @@ function handlers(_ref, port) {
60
60
  const sender = port.sender;
61
61
  const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
62
62
  const source = `${from}: ${id}: ${message}`;
63
- console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
63
+
64
+ // console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
64
65
 
65
66
  const promise = isMobile ? mobile.handle(id, message, request, port) : isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
66
67
  promise.then(response => {
67
- console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
68
+ // console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
68
69
 
69
70
  // between the start and the end of the promise, the user may have closed
70
71
  // the tab, in which case port will be undefined
@@ -32,7 +32,6 @@ class KoniSubscription {
32
32
  this.dbService = dbService;
33
33
  this.state = state;
34
34
  this.logger = (0, _util.logger)('Subscription');
35
- this.init();
36
35
  }
37
36
  getSubscriptionMap() {
38
37
  return this.subscriptionMap;
@@ -61,7 +60,6 @@ class KoniSubscription {
61
60
  }
62
61
  start() {
63
62
  var _this$state$keyringSe;
64
- this.logger.log('Starting subscription');
65
63
  const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
66
64
  if (currentAddress) {
67
65
  this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
@@ -74,7 +72,6 @@ class KoniSubscription {
74
72
  if (!needReload) {
75
73
  return;
76
74
  }
77
- this.logger.log('ServiceInfo updated, restarting...');
78
75
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
79
76
  if (!address) {
80
77
  return;
@@ -85,34 +82,12 @@ class KoniSubscription {
85
82
  this.state.eventService.onLazy(this.eventHandler);
86
83
  }
87
84
  stop() {
88
- this.logger.log('Stopping subscription');
89
85
  if (this.eventHandler) {
90
86
  this.state.eventService.offLazy(this.eventHandler);
91
87
  this.eventHandler = undefined;
92
88
  }
93
89
  this.stopAllSubscription();
94
90
  }
95
- init() {
96
- this.state.getAuthorize(value => {
97
- const authString = localStorage.getItem('authUrls') || '{}';
98
- const previousAuth = JSON.parse(authString);
99
- if (previousAuth && Object.keys(previousAuth).length) {
100
- Object.keys(previousAuth).forEach(url => {
101
- if (previousAuth[url].isAllowed) {
102
- previousAuth[url].isAllowedMap = this.state.getAddressList(true);
103
- } else {
104
- previousAuth[url].isAllowedMap = this.state.getAddressList();
105
- }
106
- });
107
- }
108
- const migrateValue = {
109
- ...previousAuth,
110
- ...value
111
- };
112
- this.state.setAuthorize(migrateValue);
113
- localStorage.setItem('authUrls', '{}');
114
- });
115
- }
116
91
  subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
117
92
  this.state.handleSwitchAccount(address).then(() => {
118
93
  const addresses = this.state.getDecodedAddresses(address);
@@ -270,7 +245,6 @@ class KoniSubscription {
270
245
  if (dataFromApi[chainInfo.slug]) {
271
246
  this.state.updateChainStakingMetadata(dataFromApi[chainInfo.slug]);
272
247
  } else {
273
- console.warn('Not found staking data from api', chainInfo.slug);
274
248
  const chainStakingMetadata = await (0, _bonding.getChainStakingMetadata)(chainInfo, substrateApiMap[chainInfo.slug]);
275
249
  this.state.updateChainStakingMetadata(chainStakingMetadata);
276
250
  }
@@ -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.0.4-1'
16
+ version: '1.0.5-2'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -131,7 +131,7 @@ class EvmChainHandler {
131
131
  contractError
132
132
  };
133
133
  } catch (e) {
134
- this.logger.error('Error response while validating EVM contract', e);
134
+ this.logger.error(e);
135
135
  return {
136
136
  name,
137
137
  decimals,
@@ -37,7 +37,6 @@ class SubstrateChainHandler {
37
37
  resumeAllApis() {
38
38
  return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
39
39
  if (!substrateApi.api.isConnected && substrateApi.api.connect) {
40
- this.logger.log(`[Substrate] Resuming network [${substrateApi.specName}]`);
41
40
  await substrateApi.api.connect();
42
41
  }
43
42
  }));
@@ -46,7 +45,6 @@ class SubstrateChainHandler {
46
45
  return Promise.all(Object.values(this.getSubstrateApiMap()).map(async substrateApi => {
47
46
  if (substrateApi.api.isConnected) {
48
47
  var _substrateApi$api, _substrateApi$api2;
49
- this.logger.log(`[Substrate] Stopping network [${substrateApi.chainSlug}]`);
50
48
  ((_substrateApi$api = substrateApi.api) === null || _substrateApi$api === void 0 ? void 0 : _substrateApi$api.disconnect) && (await ((_substrateApi$api2 = substrateApi.api) === null || _substrateApi$api2 === void 0 ? void 0 : _substrateApi$api2.disconnect()));
51
49
  }
52
50
  }));
@@ -104,7 +102,6 @@ class SubstrateChainHandler {
104
102
  gasLimit: (0, _utils.getDefaultWeightV2)(substrateApi.api)
105
103
  })]);
106
104
  if (!(nameResp.result.isOk && symbolResp.result.isOk && decimalsResp.result.isOk) || !nameResp.output || !decimalsResp.output || !symbolResp.output) {
107
- this.logger.error('Error response while validating WASM contract');
108
105
  return {
109
106
  name: '',
110
107
  decimals: -1,
@@ -131,7 +128,6 @@ class SubstrateChainHandler {
131
128
  }); // read-only operation so no gas limit
132
129
 
133
130
  if (!collectionIdResp.result.isOk || !collectionIdResp.output) {
134
- this.logger.error('Error response while validating WASM contract');
135
131
  return {
136
132
  name: '',
137
133
  decimals: -1,
@@ -156,7 +152,7 @@ class SubstrateChainHandler {
156
152
  contractError
157
153
  };
158
154
  } catch (e) {
159
- this.logger.error('Error validating WASM contract', e);
155
+ this.logger.error(e);
160
156
  return {
161
157
  name: '',
162
158
  decimals: -1,
@@ -222,7 +218,6 @@ class SubstrateChainHandler {
222
218
  defaultFormatBalance: undefined,
223
219
  recoverConnect: () => {
224
220
  substrateApi.apiRetry = 0;
225
- this.logger.log('Recover connect to ', apiUrl);
226
221
  provider.connect().then(this.logger.log).catch(this.logger.error);
227
222
  },
228
223
  get isReady() {
@@ -244,7 +239,6 @@ class SubstrateChainHandler {
244
239
  }
245
240
  };
246
241
  api.on('connected', () => {
247
- this.logger.log('Substrate API connected to ', apiUrl);
248
242
  substrateApi.apiRetry = 0;
249
243
  if (substrateApi.isApiReadyOnce) {
250
244
  substrateApi.isApiReady = true;
@@ -262,7 +256,6 @@ class SubstrateChainHandler {
262
256
  }
263
257
  });
264
258
  api.on('ready', () => {
265
- this.logger.log('Substrate API ready with', apiUrl);
266
259
  this.loadOnReady(registry, api).then(rs => {
267
260
  (0, _util.objectSpread)(substrateApi, rs);
268
261
  }).catch(error => {
@@ -314,7 +307,7 @@ class SubstrateChainHandler {
314
307
  const tokenSymbol = properties.tokenSymbol.unwrapOr([_util.formatBalance.getDefaults().unit, ...DEFAULT_AUX]);
315
308
  const tokenDecimals = properties.tokenDecimals.unwrapOr([DEFAULT_DECIMALS]);
316
309
  const isDevelopment = systemChainType.isDevelopment || systemChainType.isLocal || (0, _util.isTestChain)(systemChain);
317
- this.logger.log(`chain: ${systemChain} (${systemChainType.toString()}), ${(0, _util.stringify)(properties)}`);
310
+ this.logger.log(`Connected to ${systemChain} (${systemChainType.toString()}), ${(0, _util.stringify)(properties)}`);
318
311
 
319
312
  // explicitly override the ss58Format as specified
320
313
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -5,15 +5,18 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getSubstrateConnectProvider = getSubstrateConnectProvider;
7
7
  exports.relayChainSpecs = exports.paraChainSpecs = void 0;
8
+ var Sc = _interopRequireWildcard(require("@substrate/connect"));
8
9
  var _rpcProvider = require("@polkadot/rpc-provider");
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
9
12
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
10
13
  // SPDX-License-Identifier: Apache-2.0
11
14
 
12
15
  const relayChainSpecs = {
13
- kusama: _rpcProvider.ScProvider.WellKnownChain.ksmcc3,
14
- polkadot: _rpcProvider.ScProvider.WellKnownChain.polkadot,
15
- rococo: _rpcProvider.ScProvider.WellKnownChain.rococo_v2_2,
16
- westend: _rpcProvider.ScProvider.WellKnownChain.westend2
16
+ kusama: Sc.WellKnownChain.ksmcc3,
17
+ polkadot: Sc.WellKnownChain.polkadot,
18
+ rococo: Sc.WellKnownChain.rococo_v2_2,
19
+ westend: Sc.WellKnownChain.westend2
17
20
  };
18
21
 
19
22
  // Direct get spec data from @polkadot/react-api repository
@@ -106,14 +109,14 @@ class ProviderPlaceholder {
106
109
  function getSubstrateConnectProvider(specLink) {
107
110
  const [relayName, paraName] = specLink.split('/');
108
111
  const relaySpec = relayChainSpecs[relayName];
109
- const relayProvider = new _rpcProvider.ScProvider(relaySpec);
112
+ const relayProvider = new _rpcProvider.ScProvider(Sc, relaySpec);
110
113
  if (!paraName) {
111
114
  return relayProvider;
112
115
  }
113
116
  const paraChainData = paraChainSpecs[specLink];
114
117
  let scProvider;
115
118
  const scPromise = fetch(paraChainData).then(rs => rs.text()).then(spec => {
116
- scProvider = new _rpcProvider.ScProvider(spec, relayProvider);
119
+ scProvider = new _rpcProvider.ScProvider(Sc, spec);
117
120
  return scProvider;
118
121
  }).catch(console.error);
119
122
  return new ProviderPlaceholder(scPromise);
@@ -367,7 +367,6 @@ class ChainService {
367
367
  this.assetRegistrySubject.next(this.getAssetRegistry());
368
368
  this.initApis();
369
369
  await this.initAssetSettings();
370
- this.logger.log('Initiated chains, assets and APIs');
371
370
  }
372
371
  initApis() {
373
372
  // TODO: this might be async
@@ -1156,7 +1155,6 @@ class ChainService {
1156
1155
  });
1157
1156
  await Promise.all(promiseList);
1158
1157
  if (update) {
1159
- console.log('Update chain connection state');
1160
1158
  this.chainStateMapSubject.next(chainStateMap);
1161
1159
  }
1162
1160
  }
@@ -352,6 +352,9 @@ function _getAssetDecimals(assetInfo) {
352
352
  }
353
353
  function _getBlockExplorerFromChain(chainInfo) {
354
354
  let blockExplorer;
355
+ if (!chainInfo) {
356
+ return;
357
+ }
355
358
  if (_isPureEvmChain(chainInfo)) {
356
359
  var _chainInfo$evmInfo4;
357
360
  blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.blockExplorer;
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.historyRecover = exports.HistoryRecoverStatus = void 0;
7
+ var _utils = require("@subwallet/extension-base/utils");
8
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
9
+ // SPDX-License-Identifier: Apache-2.0
10
+ let HistoryRecoverStatus;
11
+ exports.HistoryRecoverStatus = HistoryRecoverStatus;
12
+ (function (HistoryRecoverStatus) {
13
+ HistoryRecoverStatus["SUCCESS"] = "SUCCESS";
14
+ HistoryRecoverStatus["FAILED"] = "FAILED";
15
+ HistoryRecoverStatus["API_INACTIVE"] = "API_INACTIVE";
16
+ HistoryRecoverStatus["LACK_INFO"] = "LACK_INFO";
17
+ HistoryRecoverStatus["FAIL_DETECT"] = "FAIL_DETECT";
18
+ HistoryRecoverStatus["UNKNOWN"] = "UNKNOWN";
19
+ })(HistoryRecoverStatus || (exports.HistoryRecoverStatus = HistoryRecoverStatus = {}));
20
+ const BLOCK_LIMIT = 6;
21
+ const substrateRecover = async (history, chainService) => {
22
+ const {
23
+ address,
24
+ blockHash,
25
+ chain,
26
+ extrinsicHash,
27
+ from,
28
+ nonce,
29
+ startBlock
30
+ } = history;
31
+ const result = {
32
+ status: HistoryRecoverStatus.UNKNOWN
33
+ };
34
+ try {
35
+ const substrateApi = chainService.getSubstrateApi(chain);
36
+ if (substrateApi) {
37
+ const _api = await substrateApi.isReady;
38
+ const api = _api.api;
39
+ if (!blockHash) {
40
+ if (!nonce || !startBlock) {
41
+ console.log(`Fail to find extrinsic for ${address} on ${chain}: With nonce ${nonce || 'undefined'} from block ${startBlock || 'undefined'}`);
42
+ return {
43
+ status: HistoryRecoverStatus.LACK_INFO
44
+ };
45
+ }
46
+ const currentBlock = (await api.query.system.number()).toPrimitive();
47
+ for (let i = 1, found = false; i < BLOCK_LIMIT && !found && startBlock + i <= currentBlock; i++) {
48
+ const blockHash = (await api.rpc.chain.getBlockHash(startBlock + i)).toHex();
49
+ const block = await api.rpc.chain.getBlock(blockHash);
50
+ const extrinsics = block.block.extrinsics;
51
+ let index;
52
+ for (const [idx, extrinsic] of Object.entries(extrinsics)) {
53
+ if (extrinsic.signer && (0, _utils.isSameAddress)(from, extrinsic.signer.toString()) && nonce === extrinsic.nonce.toNumber()) {
54
+ index = parseInt(idx);
55
+ found = true;
56
+ result.extrinsicHash = extrinsic.hash.toHex();
57
+ result.blockHash = block.block.hash.toHex();
58
+ result.blockNumber = block.block.header.number.toNumber();
59
+ break;
60
+ }
61
+ }
62
+ if (index !== undefined) {
63
+ const allEvents = await api.query.system.events.at(blockHash);
64
+ const events = allEvents.filter(_ref => {
65
+ let {
66
+ phase
67
+ } = _ref;
68
+ return phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index);
69
+ });
70
+ for (const {
71
+ event
72
+ } of events) {
73
+ if (api.events.system.ExtrinsicSuccess.is(event)) {
74
+ return {
75
+ ...result,
76
+ status: HistoryRecoverStatus.SUCCESS
77
+ };
78
+ } else if (api.events.system.ExtrinsicFailed.is(event)) {
79
+ return {
80
+ ...result,
81
+ status: HistoryRecoverStatus.FAILED
82
+ };
83
+ }
84
+ }
85
+ }
86
+ }
87
+ } else {
88
+ const block = await api.rpc.chain.getBlock(blockHash);
89
+ const allEvents = await api.query.system.events.at(blockHash);
90
+ const extrinsics = block.block.extrinsics;
91
+ let index;
92
+ for (const [idx, extrinsic] of Object.entries(extrinsics)) {
93
+ if (extrinsicHash === extrinsic.hash.toHex()) {
94
+ index = parseInt(idx);
95
+ break;
96
+ }
97
+ }
98
+ if (index === undefined) {
99
+ console.log(`Fail to find extrinsic ${extrinsicHash} on ${chain}`);
100
+ return {
101
+ status: HistoryRecoverStatus.FAIL_DETECT
102
+ };
103
+ }
104
+ const events = allEvents.filter(_ref2 => {
105
+ let {
106
+ phase
107
+ } = _ref2;
108
+ return phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index);
109
+ });
110
+ for (const {
111
+ event
112
+ } of events) {
113
+ if (api.events.system.ExtrinsicSuccess.is(event)) {
114
+ return {
115
+ ...result,
116
+ status: HistoryRecoverStatus.SUCCESS
117
+ };
118
+ } else if (api.events.system.ExtrinsicFailed.is(event)) {
119
+ return {
120
+ ...result,
121
+ status: HistoryRecoverStatus.FAILED
122
+ };
123
+ }
124
+ }
125
+ }
126
+ return {
127
+ status: HistoryRecoverStatus.FAIL_DETECT
128
+ };
129
+ } else {
130
+ console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
131
+ return {
132
+ status: HistoryRecoverStatus.API_INACTIVE
133
+ };
134
+ }
135
+ } catch (e) {
136
+ console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
137
+ return {
138
+ status: HistoryRecoverStatus.UNKNOWN
139
+ };
140
+ }
141
+ };
142
+ const evmRecover = async (history, chainService) => {
143
+ const {
144
+ address,
145
+ chain,
146
+ extrinsicHash,
147
+ from,
148
+ nonce,
149
+ startBlock
150
+ } = history;
151
+ const result = {
152
+ status: HistoryRecoverStatus.UNKNOWN
153
+ };
154
+ try {
155
+ const evmApi = chainService.getEvmApi(chain);
156
+ if (evmApi) {
157
+ const _api = await evmApi.isReady;
158
+ const api = _api.api;
159
+ if (extrinsicHash) {
160
+ const transactionReceipt = await api.eth.getTransactionReceipt(extrinsicHash);
161
+ return {
162
+ ...result,
163
+ status: transactionReceipt.status ? HistoryRecoverStatus.SUCCESS : HistoryRecoverStatus.FAILED
164
+ };
165
+ } else {
166
+ if (!nonce || !startBlock) {
167
+ console.log(`Fail to find extrinsic for ${address} on ${chain}: With nonce ${nonce || 'undefined'} from block ${startBlock || 'undefined'}`);
168
+ return {
169
+ ...result,
170
+ status: HistoryRecoverStatus.LACK_INFO
171
+ };
172
+ }
173
+ const currentBlock = await api.eth.getBlockNumber();
174
+ for (let i = 1, found = false; i < BLOCK_LIMIT && !found && startBlock + i <= currentBlock; i++) {
175
+ const block = await api.eth.getBlock(startBlock + i, true);
176
+ for (const transaction of block.transactions) {
177
+ if ((0, _utils.isSameAddress)(transaction.from, from) && nonce === transaction.nonce) {
178
+ result.extrinsicHash = transaction.hash;
179
+ result.blockHash = block.hash;
180
+ result.blockNumber = block.number;
181
+ found = true;
182
+ break;
183
+ }
184
+ }
185
+ if (result.extrinsicHash) {
186
+ const transactionReceipt = await api.eth.getTransactionReceipt(result.extrinsicHash);
187
+ return {
188
+ ...result,
189
+ status: transactionReceipt.status ? HistoryRecoverStatus.SUCCESS : HistoryRecoverStatus.FAILED
190
+ };
191
+ }
192
+ }
193
+ }
194
+ return {
195
+ status: HistoryRecoverStatus.FAIL_DETECT
196
+ };
197
+ } else {
198
+ console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
199
+ return {
200
+ status: HistoryRecoverStatus.API_INACTIVE
201
+ };
202
+ }
203
+ } catch (e) {
204
+ console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
205
+ return {
206
+ status: HistoryRecoverStatus.UNKNOWN
207
+ };
208
+ }
209
+ };
210
+
211
+ // undefined: Cannot check status
212
+ // true: Transaction success
213
+ // false: Transaction failed
214
+ const historyRecover = async (history, chainService) => {
215
+ const {
216
+ chainType
217
+ } = history;
218
+ if (chainType) {
219
+ const checkFunction = chainType === 'substrate' ? substrateRecover : evmRecover;
220
+ return await checkFunction(history, chainService);
221
+ } else {
222
+ return {
223
+ status: HistoryRecoverStatus.LACK_INFO
224
+ };
225
+ }
226
+ };
227
+ exports.historyRecover = historyRecover;