@subwallet/extension-base 1.0.2-1b → 1.0.2-3

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 (78) hide show
  1. package/background/KoniTypes.d.ts +31 -5
  2. package/background/KoniTypes.js +2 -1
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +2 -1
  6. package/cjs/background/errors/TransactionError.js +4 -0
  7. package/cjs/koni/api/dotsama/transfer.js +6 -12
  8. package/cjs/koni/api/nft/acala_nft/index.js +7 -10
  9. package/cjs/koni/api/nft/bit.country/index.js +7 -9
  10. package/cjs/koni/api/nft/evm_nft/index.js +2 -1
  11. package/cjs/koni/api/nft/karura_nft/index.js +7 -9
  12. package/cjs/koni/api/nft/rmrk_nft/index.js +4 -1
  13. package/cjs/koni/api/nft/statemine_nft/index.js +7 -9
  14. package/cjs/koni/api/nft/unique_nft/index.js +5 -6
  15. package/cjs/koni/api/nft/wasm_nft/index.js +2 -1
  16. package/cjs/koni/api/staking/bonding/relayChain.js +3 -0
  17. package/cjs/koni/background/cron.js +53 -46
  18. package/cjs/koni/background/handlers/Extension.js +292 -159
  19. package/cjs/koni/background/handlers/State.js +24 -14
  20. package/cjs/koni/background/handlers/Tabs.js +42 -16
  21. package/cjs/packageInfo.js +1 -1
  22. package/cjs/services/chain-service/handler/light-client/index.js +0 -2
  23. package/cjs/services/chain-service/index.js +53 -38
  24. package/cjs/services/history-service/index.js +3 -3
  25. package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -1
  26. package/cjs/services/keyring-service/index.js +11 -13
  27. package/cjs/services/request-service/handler/AuthRequestHandler.js +7 -5
  28. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  29. package/cjs/services/request-service/index.js +14 -5
  30. package/cjs/services/storage-service/DatabaseService.js +8 -5
  31. package/cjs/services/storage-service/db-stores/Nft.js +9 -4
  32. package/cjs/services/transaction-service/index.js +3 -1
  33. package/cjs/utils/address.js +10 -1
  34. package/cjs/utils/index.js +2 -1
  35. package/koni/api/dotsama/transfer.js +6 -12
  36. package/koni/api/nft/acala_nft/index.js +7 -9
  37. package/koni/api/nft/bit.country/index.js +7 -8
  38. package/koni/api/nft/evm_nft/index.js +2 -1
  39. package/koni/api/nft/index.d.ts +1 -1
  40. package/koni/api/nft/karura_nft/index.js +7 -8
  41. package/koni/api/nft/nft.d.ts +1 -1
  42. package/koni/api/nft/rmrk_nft/index.js +4 -1
  43. package/koni/api/nft/statemine_nft/index.js +7 -8
  44. package/koni/api/nft/unique_nft/index.js +5 -5
  45. package/koni/api/nft/wasm_nft/index.js +2 -1
  46. package/koni/api/staking/bonding/relayChain.js +3 -0
  47. package/koni/background/cron.js +53 -46
  48. package/koni/background/handlers/Extension.d.ts +6 -1
  49. package/koni/background/handlers/Extension.js +203 -73
  50. package/koni/background/handlers/State.d.ts +1 -1
  51. package/koni/background/handlers/State.js +26 -14
  52. package/koni/background/handlers/Tabs.js +42 -16
  53. package/package.json +13 -13
  54. package/packageInfo.js +1 -1
  55. package/services/chain-service/handler/light-client/index.d.ts +1 -17
  56. package/services/chain-service/handler/light-client/index.js +1 -1
  57. package/services/chain-service/index.d.ts +3 -2
  58. package/services/chain-service/index.js +47 -33
  59. package/services/chain-service/types.d.ts +1 -0
  60. package/services/history-service/index.d.ts +3 -1
  61. package/services/history-service/index.js +3 -3
  62. package/services/history-service/subsquid-multi-chain-history.js +1 -1
  63. package/services/keyring-service/index.d.ts +4 -2
  64. package/services/keyring-service/index.js +11 -13
  65. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  66. package/services/request-service/handler/AuthRequestHandler.js +7 -5
  67. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  68. package/services/request-service/index.d.ts +3 -1
  69. package/services/request-service/index.js +14 -5
  70. package/services/storage-service/DatabaseService.d.ts +1 -1
  71. package/services/storage-service/DatabaseService.js +8 -5
  72. package/services/storage-service/db-stores/Nft.d.ts +2 -1
  73. package/services/storage-service/db-stores/Nft.js +9 -4
  74. package/services/transaction-service/index.js +3 -1
  75. package/utils/address.d.ts +3 -0
  76. package/utils/address.js +8 -1
  77. package/utils/index.d.ts +1 -1
  78. package/utils/index.js +1 -1
@@ -31,7 +31,6 @@ var _AccountRef = _interopRequireDefault(require("@subwallet/extension-base/stor
31
31
  var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
32
32
  var _decode = require("@subwallet/keyring/pair/decode");
33
33
  var _uiKeyring = require("@subwallet/ui-keyring");
34
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
35
34
  var _ethSimpleKeyring = _interopRequireDefault(require("eth-simple-keyring"));
36
35
  var _rxjs = require("rxjs");
37
36
  var _util = require("@polkadot/util");
@@ -93,10 +92,10 @@ class KoniState {
93
92
  this.notificationService = new _NotificationService.default();
94
93
  this.chainService = new _chainService.ChainService(this.dbService, this.eventService);
95
94
  this.settingService = new _SettingService.default();
96
- this.requestService = new _requestService.default(this.chainService, this.settingService);
95
+ this.requestService = new _requestService.default(this.chainService, this.settingService, this.keyringService);
97
96
  this.priceService = new _priceService.PriceService(this.dbService, this.eventService, this.chainService);
98
97
  this.balanceService = new _balanceService.BalanceService(this.chainService);
99
- this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService);
98
+ this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
100
99
  this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
101
100
  this.migrationService = new _migrationService.default(this);
102
101
  this.subscription = new _subscription.KoniSubscription(this, this.dbService);
@@ -265,7 +264,7 @@ class KoniState {
265
264
  }
266
265
  getAddressList() {
267
266
  let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
268
- const addressList = Object.keys(_accounts.accounts.subject.value);
267
+ const addressList = Object.keys(this.keyringService.accounts);
269
268
  return addressList.reduce((addressList, v) => ({
270
269
  ...addressList,
271
270
  [v]: value
@@ -369,8 +368,8 @@ class KoniState {
369
368
  deleteNftCollection(chain, collectionId) {
370
369
  return this.dbService.deleteNftCollection(chain, collectionId);
371
370
  }
372
- cleanUpNfts(chain, owner, collectionId, nftIds) {
373
- this.dbService.cleanUpNft(chain, owner, collectionId, nftIds).catch(e => this.logger.warn(e));
371
+ cleanUpNfts(chain, owner, collectionId, nftIds, ownNothing) {
372
+ this.dbService.cleanUpNft(chain, owner, collectionId, nftIds, ownNothing).catch(e => this.logger.warn(e));
374
373
  }
375
374
  async getNft() {
376
375
  const addresses = this.getDecodedAddresses();
@@ -545,7 +544,11 @@ class KoniState {
545
544
  isApproved
546
545
  } = _ref4;
547
546
  if (isApproved) {
548
- await this.upsertChainInfo(networkData);
547
+ if (networkData.mode === 'insert') {
548
+ await this.upsertChainInfo(networkData);
549
+ } else {
550
+ // TODO: update existed network (need more discussion)
551
+ }
549
552
  return null;
550
553
  } else {
551
554
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.USER_REJECTED_REQUEST);
@@ -1009,8 +1012,9 @@ class KoniState {
1009
1012
  return [undefined, undefined];
1010
1013
  }
1011
1014
  const rs = Object.entries(this.chainService.getChainInfoMap()).find(_ref8 => {
1015
+ var _chainInfo$evmInfo;
1012
1016
  let [networkKey, chainInfo] = _ref8;
1013
- return (0, _utils._getEvmChainId)(chainInfo) === chainId;
1017
+ return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo = chainInfo.evmInfo) === null || _chainInfo$evmInfo === void 0 ? void 0 : _chainInfo$evmInfo.evmChainId) === chainId;
1014
1018
  });
1015
1019
  if (rs) {
1016
1020
  return rs;
@@ -1248,17 +1252,23 @@ class KoniState {
1248
1252
  account: account,
1249
1253
  canSign: true
1250
1254
  };
1255
+ const eType = transaction.value ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.EVM_EXECUTE;
1256
+ const transactionData = {
1257
+ ...transaction
1258
+ };
1259
+ if (eType === _KoniTypes.ExtrinsicType.TRANSFER_BALANCE) {
1260
+ // @ts-ignore
1261
+ transactionData.tokenSlug = this.chainService.getNativeTokenInfo(networkKey).slug;
1262
+ }
1251
1263
 
1252
- // Todo: Convert this to handle transaction
1264
+ // Custom handle this instead of general handler transaction
1253
1265
  const transactionEmitter = await this.transactionService.addTransaction({
1254
1266
  transaction: requestPayload,
1255
1267
  address: requestPayload.from,
1256
1268
  chain: networkKey,
1257
1269
  url,
1258
- data: {
1259
- ...transaction
1260
- },
1261
- extrinsicType: transaction.value ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.EVM_EXECUTE,
1270
+ data: transactionData,
1271
+ extrinsicType: eType,
1262
1272
  chainType: _KoniTypes.ChainType.EVM
1263
1273
  });
1264
1274
 
@@ -1386,7 +1396,7 @@ class KoniState {
1386
1396
  } = _ref14;
1387
1397
  const chain = _subscanChainMap.SUBSCAN_CHAIN_MAP_REVERSE[network];
1388
1398
  const chainInfo = chain ? chainMap[chain] : null;
1389
- const balanceIsEmpty = (!balance || balance === '0') && !locked && locked === '0' && (!bonded || bonded === '0');
1399
+ const balanceIsEmpty = (!balance || balance === '0') && (!locked || locked === '0') && (!bonded || bonded === '0');
1390
1400
 
1391
1401
  // Cancel if chain is not supported or is testnet or balance is 0
1392
1402
  if (!chainInfo || chainInfo.isTestnet || balanceIsEmpty) {
@@ -17,7 +17,6 @@ var _defaults = require("@subwallet/extension-base/defaults");
17
17
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
18
18
  var _utils2 = require("@subwallet/extension-base/utils");
19
19
  var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
20
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
21
20
  var _web = _interopRequireDefault(require("web3"));
22
21
  var _phishing = require("@polkadot/phishing");
23
22
  var _util = require("@polkadot/util");
@@ -220,14 +219,14 @@ class KoniTabs {
220
219
  anyType
221
220
  } = _ref10;
222
221
  const authInfo = await this.getAuthInfo(url);
223
- return transformAccountsV2(_accounts.accounts.subject.getValue(), anyType, authInfo, accountAuthType);
222
+ return transformAccountsV2(this.#koniState.keyringService.accounts, anyType, authInfo, accountAuthType);
224
223
  }
225
224
  accountsSubscribeV2(url, _ref11, id, port) {
226
225
  let {
227
226
  accountAuthType
228
227
  } = _ref11;
229
228
  const cb = (0, _subscriptions.createSubscription)(id, port);
230
- const subscription = _accounts.accounts.subject.subscribe(accounts => {
229
+ const subscription = this.#koniState.keyringService.accountSubject.subscribe(accounts => {
231
230
  this.getAuthInfo(url).then(authInfo => {
232
231
  cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
233
232
  }).catch(console.error);
@@ -253,7 +252,7 @@ class KoniTabs {
253
252
  let getAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
254
253
  return await new Promise(resolve => {
255
254
  this.getAuthInfo(url).then(authInfo => {
256
- const allAccounts = _accounts.accounts.subject.getValue();
255
+ const allAccounts = this.#koniState.keyringService.accounts;
257
256
  const accountList = transformAccountsV2(allAccounts, false, authInfo, 'evm').map(a => a.address);
258
257
  let accounts = [];
259
258
  const address = this.#koniState.keyringService.currentAccount.address;
@@ -290,8 +289,8 @@ class KoniTabs {
290
289
  slug
291
290
  } = currentEvmNetwork;
292
291
  const evmApi = this.#koniState.getEvmApi(slug);
293
- const web3 = evmApi.api;
294
- if (web3.currentProvider instanceof _web.default.providers.WebsocketProvider) {
292
+ const web3 = evmApi === null || evmApi === void 0 ? void 0 : evmApi.api;
293
+ if ((web3 === null || web3 === void 0 ? void 0 : web3.currentProvider) instanceof _web.default.providers.WebsocketProvider) {
295
294
  if (!web3.currentProvider.connected) {
296
295
  console.log(`[Web3] ${slug} is disconnected, trying to connect...`);
297
296
  this.#koniState.refreshWeb3Api(slug);
@@ -378,12 +377,16 @@ class KoniTabs {
378
377
  contractAddress: input.options.address,
379
378
  originChain: chain
380
379
  });
381
- if (validate.isExist) {
382
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
383
- } else if (validate.contractError) {
380
+
381
+ // Below code is comment because we will handle exited token in the ui-view
382
+ // if (validate.isExist) {
383
+ // throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, 'Current token is existed');
384
+ // } else
385
+ if (validate.contractError) {
384
386
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Contract address is invalid');
385
387
  }
386
388
  const tokenInfo = {
389
+ slug: validate === null || validate === void 0 ? void 0 : validate.existedSlug,
387
390
  type: tokenType,
388
391
  name: validate.name,
389
392
  contractAddress: input.options.address,
@@ -407,16 +410,38 @@ class KoniTabs {
407
410
  } = input[0];
408
411
  if (chainId) {
409
412
  const chainIdNum = parseInt(chainId, 16);
410
- const [networkKey] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
411
- if (networkKey) {
413
+ const [existedNetworkSlug, existedChainInfo] = this.#koniState.findNetworkKeyByChainId(chainIdNum);
414
+ if (existedNetworkSlug && existedChainInfo && existedChainInfo !== null && existedChainInfo !== void 0 && existedChainInfo.evmInfo) {
415
+ const evmInfo = existedChainInfo.evmInfo;
416
+ const substrateInfo = existedChainInfo.substrateInfo;
417
+ const chainState = this.#koniState.getChainStateByKey(existedNetworkSlug);
418
+ await this.#koniState.addNetworkConfirm(id, url, {
419
+ mode: 'update',
420
+ chainSpec: {
421
+ evmChainId: evmInfo.evmChainId,
422
+ decimals: evmInfo.decimals,
423
+ existentialDeposit: evmInfo.existentialDeposit,
424
+ genesisHash: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.genesisHash) || '',
425
+ paraId: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.paraId) || null,
426
+ addressPrefix: (substrateInfo === null || substrateInfo === void 0 ? void 0 : substrateInfo.addressPrefix) || 0
427
+ },
428
+ chainEditInfo: {
429
+ blockExplorer: blockExplorerUrls === null || blockExplorerUrls === void 0 ? void 0 : blockExplorerUrls[0],
430
+ slug: existedNetworkSlug,
431
+ currentProvider: chainState.currentProvider,
432
+ providers: existedChainInfo.providers,
433
+ symbol: evmInfo.symbol,
434
+ chainType: 'EVM',
435
+ name: existedChainInfo.name
436
+ }
437
+ });
412
438
  return await this.switchEvmChain(id, url, {
413
439
  method: 'wallet_switchEthereumChain',
414
440
  params: [{
415
441
  chainId
416
442
  }]
417
443
  });
418
- }
419
- if (rpcUrls && chainName) {
444
+ } else if (rpcUrls && chainName) {
420
445
  const filteredUrls = rpcUrls.filter(targetString => {
421
446
  let url;
422
447
  try {
@@ -457,6 +482,8 @@ class KoniTabs {
457
482
  name: chainInfo.name
458
483
  }
459
484
  });
485
+ } else {
486
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Invalid provider');
460
487
  }
461
488
  }
462
489
  }
@@ -717,9 +744,8 @@ class KoniTabs {
717
744
  if (e.code) {
718
745
  throw e;
719
746
  } else {
720
- // @ts-ignore
721
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
722
- throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, e.message);
747
+ console.error(e);
748
+ throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INTERNAL_ERROR, e === null || e === void 0 ? void 0 : e.toString());
723
749
  }
724
750
  }
725
751
  }
@@ -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.2-1'
16
+ version: '1.0.2-3'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ProviderPlaceholder = void 0;
7
6
  exports.getSubstrateConnectProvider = getSubstrateConnectProvider;
8
7
  exports.relayChainSpecs = exports.paraChainSpecs = void 0;
9
8
  var _rpcProvider = require("@polkadot/rpc-provider");
@@ -104,7 +103,6 @@ class ProviderPlaceholder {
104
103
  });
105
104
  }
106
105
  }
107
- exports.ProviderPlaceholder = ProviderPlaceholder;
108
106
  function getSubstrateConnectProvider(specLink) {
109
107
  const [relayName, paraName] = specLink.split('/');
110
108
  const relaySpec = relayChainSpecs[relayName];
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.ChainService = void 0;
8
8
  var _chainList = require("@subwallet/chain-list");
9
9
  var _types = require("@subwallet/chain-list/types");
10
- var _constants = require("@subwallet/extension-base/constants");
11
- var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
10
+ var _constants = require("@subwallet/extension-base/services/chain-service/constants");
12
11
  var _EvmChainHandler = require("@subwallet/extension-base/services/chain-service/handler/EvmChainHandler");
13
12
  var _SubstrateChainHandler = require("@subwallet/extension-base/services/chain-service/handler/SubstrateChainHandler");
14
13
  var _types2 = require("@subwallet/extension-base/services/chain-service/handler/types");
@@ -51,7 +50,7 @@ class ChainService {
51
50
  this.multiChainAssetMapSubject.next(_chainList.MultiChainAssetMap);
52
51
  this.xcmRefMapSubject.next(this.getXcmRefMap());
53
52
  this.logger = (0, _logger.logger)('chain-service');
54
- this.refreshChainStateInterval(3000);
53
+ this.refreshChainStateInterval(3000, 6);
55
54
  }
56
55
 
57
56
  // Getter
@@ -296,7 +295,7 @@ class ChainService {
296
295
  this.lockChainInfoMap = true;
297
296
  const chainStateMap = this.getChainStateMap();
298
297
  for (const [slug, chainState] of Object.entries(chainStateMap)) {
299
- if (!_constants2._DEFAULT_ACTIVE_CHAINS.includes(slug) && !(excludedChains !== null && excludedChains !== void 0 && excludedChains.includes(slug))) {
298
+ if (!_constants._DEFAULT_ACTIVE_CHAINS.includes(slug) && !(excludedChains !== null && excludedChains !== void 0 && excludedChains.includes(slug))) {
300
299
  chainState.active = false;
301
300
  }
302
301
  }
@@ -419,7 +418,7 @@ class ChainService {
419
418
  this.lockChainInfoMap = true;
420
419
  chainStateMap[chainSlug].active = true;
421
420
  this.initApiForChain(chainInfo);
422
- this.refreshChainStateInterval(1000);
421
+ this.refreshChainStateInterval(3000, 6);
423
422
  this.dbService.updateChainStore({
424
423
  ...chainInfo,
425
424
  active: true,
@@ -497,13 +496,13 @@ class ChainService {
497
496
  currentProvider: Object.keys(chainInfo.providers)[0],
498
497
  slug: chainInfo.slug,
499
498
  connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
500
- active: _constants2._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
499
+ active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
501
500
  };
502
501
 
503
502
  // create data for storage
504
503
  newStorageData.push({
505
504
  ...chainInfo,
506
- active: _constants2._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
505
+ active: _constants._DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug),
507
506
  currentProvider: Object.keys(chainInfo.providers)[0]
508
507
  });
509
508
  });
@@ -584,11 +583,11 @@ class ChainService {
584
583
  currentProvider: Object.keys(chainInfo.providers)[0],
585
584
  slug,
586
585
  connectionStatus: _types3._ChainConnectionStatus.DISCONNECTED,
587
- active: _constants2._DEFAULT_ACTIVE_CHAINS.includes(slug)
586
+ active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug)
588
587
  };
589
588
  newStorageData.push({
590
589
  ...mergedChainInfoMap[slug],
591
- active: _constants2._DEFAULT_ACTIVE_CHAINS.includes(slug),
590
+ active: _constants._DEFAULT_ACTIVE_CHAINS.includes(slug),
592
591
  currentProvider: Object.keys(chainInfo.providers)[0]
593
592
  });
594
593
  }
@@ -974,21 +973,23 @@ class ChainService {
974
973
  }
975
974
  async validateCustomToken(data) {
976
975
  const assetRegistry = this.getSmartContractTokens();
977
- let isExist = false;
976
+ let existedToken;
978
977
  for (const token of Object.values(assetRegistry)) {
979
978
  var _token$metadata2;
980
979
  const contractAddress = token === null || token === void 0 ? void 0 : (_token$metadata2 = token.metadata) === null || _token$metadata2 === void 0 ? void 0 : _token$metadata2.contractAddress;
981
980
  if ((0, _utils._isEqualContractAddress)(contractAddress, data.contractAddress) && token.assetType === data.type && token.originChain === data.originChain) {
982
- isExist = true;
981
+ existedToken = token;
983
982
  break;
984
983
  }
985
984
  }
986
- if (isExist) {
985
+ if (existedToken) {
986
+ var _existedToken;
987
987
  return {
988
- decimals: -1,
989
- name: '',
990
- symbol: '',
991
- isExist,
988
+ decimals: existedToken.decimals || 0,
989
+ name: existedToken.name,
990
+ symbol: existedToken.symbol,
991
+ isExist: !!existedToken,
992
+ existedSlug: (_existedToken = existedToken) === null || _existedToken === void 0 ? void 0 : _existedToken.slug,
992
993
  contractError: false
993
994
  };
994
995
  }
@@ -1002,7 +1003,7 @@ class ChainService {
1002
1003
  name,
1003
1004
  decimals,
1004
1005
  symbol,
1005
- isExist,
1006
+ isExist: !!existedToken,
1006
1007
  contractError
1007
1008
  };
1008
1009
  }
@@ -1052,20 +1053,28 @@ class ChainService {
1052
1053
 
1053
1054
  return this.substrateChainHandler.resumeAllApis();
1054
1055
  }
1055
-
1056
- // Interval update api status
1056
+ refreshChainStateTimeout = undefined;
1057
+ refreshChainStateTimes = 0;
1057
1058
  refreshChainStateInterval() {
1058
1059
  let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1060
+ let times = arguments.length > 1 ? arguments[1] : undefined;
1059
1061
  clearTimeout(this.refreshChainStateTimeout);
1060
1062
  setTimeout(() => {
1061
- this.updateApiMapStatus();
1063
+ if (times) {
1064
+ this.refreshChainStateTimes = times;
1065
+ }
1066
+ this.refreshChainStateTimes -= 1;
1067
+ if (this.refreshChainStateTimes < 0) {
1068
+ return;
1069
+ }
1070
+ this.updateApiMapStatus().catch(console.error);
1062
1071
  this.refreshChainStateTimeout = setTimeout(() => {
1063
- this.updateApiMapStatus();
1064
- this.refreshChainStateInterval();
1065
- }, _constants.CRON_GET_API_MAP_STATUS);
1072
+ this.updateApiMapStatus().catch(console.error);
1073
+ this.refreshChainStateInterval(0);
1074
+ }, 3000);
1066
1075
  }, delay);
1067
1076
  }
1068
- updateApiMapStatus() {
1077
+ async updateApiMapStatus() {
1069
1078
  const substrateApiMap = this.getSubstrateApiMap();
1070
1079
  const evmApiMap = this.getEvmApiMap();
1071
1080
  const chainStateMap = this.getChainStateMap();
@@ -1076,25 +1085,31 @@ class ChainService {
1076
1085
  update = true;
1077
1086
  }
1078
1087
  }
1079
- Object.entries(chainStateMap).forEach(_ref4 => {
1088
+ const promiseList = Object.entries(chainStateMap).map(async _ref4 => {
1080
1089
  let [chain, chainState] = _ref4;
1081
- if (chainState.active) {
1082
- if (substrateApiMap[chain]) {
1083
- const api = substrateApiMap[chain];
1084
- if (api) {
1085
- updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
1086
- return;
1087
- }
1088
- } else if (evmApiMap[chain]) {
1089
- const api = evmApiMap[chain];
1090
- if (api) {
1091
- updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
1092
- return;
1090
+ try {
1091
+ if (chainState.active) {
1092
+ if (substrateApiMap[chain]) {
1093
+ const api = substrateApiMap[chain];
1094
+ if (api.isApiConnected) {
1095
+ updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
1096
+ return;
1097
+ }
1098
+ } else if (evmApiMap[chain]) {
1099
+ var _api$api;
1100
+ const api = evmApiMap[chain];
1101
+ if (await (api === null || api === void 0 ? void 0 : (_api$api = api.api) === null || _api$api === void 0 ? void 0 : _api$api.eth.net.isListening())) {
1102
+ updateState(chainState, _types3._ChainConnectionStatus.CONNECTED);
1103
+ return;
1104
+ }
1093
1105
  }
1094
1106
  }
1107
+ updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
1108
+ } catch (e) {
1109
+ updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
1095
1110
  }
1096
- updateState(chainState, _types3._ChainConnectionStatus.DISCONNECTED);
1097
1111
  });
1112
+ await Promise.all(promiseList);
1098
1113
  if (update) {
1099
1114
  console.log('Update chain connection state');
1100
1115
  this.chainStateMapSubject.next(chainStateMap);
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.HistoryService = void 0;
7
7
  var _constants = require("@subwallet/extension-base/constants");
8
8
  var _uiKeyring = require("@subwallet/ui-keyring");
9
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
10
9
  var _rxjs = require("rxjs");
11
10
  var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
12
11
  // Copyright 2019-2022 @subwallet/extension-base
@@ -14,10 +13,11 @@ var _subsquidMultiChainHistory = require("./subsquid-multi-chain-history");
14
13
 
15
14
  class HistoryService {
16
15
  historySubject = new _rxjs.BehaviorSubject([]);
17
- constructor(dbService, chainService, eventService) {
16
+ constructor(dbService, chainService, eventService, keyringService) {
18
17
  this.dbService = dbService;
19
18
  this.chainService = chainService;
20
19
  this.eventService = eventService;
20
+ this.keyringService = keyringService;
21
21
  // Load history from database
22
22
  this.dbService.getHistories().then(histories => {
23
23
  this.historySubject.next(histories);
@@ -46,7 +46,7 @@ class HistoryService {
46
46
  const historyRecords = await (0, _subsquidMultiChainHistory.fetchMultiChainHistories)(addresses, chainMap);
47
47
 
48
48
  // Fill additional info
49
- const accountMap = Object.entries(_accounts.accounts.subject.value).reduce((map, _ref) => {
49
+ const accountMap = Object.entries(this.keyringService.accounts).reduce((map, _ref) => {
50
50
  let [address, account] = _ref;
51
51
  map[address.toLowerCase()] = account.json.meta.name || address;
52
52
  return map;
@@ -121,7 +121,7 @@ function parseSubsquidTransactionData(address, type, historyItem, chainInfo, arg
121
121
  const transaction = data.call.data.args.transaction.value;
122
122
  to = autoFormatAddress(parsedArgs.to);
123
123
  from = autoFormatAddress(parsedArgs.from);
124
- extrinsicHash = parsedArgs.transactionHash;
124
+ extrinsicHash = parsedArgs.transactionHash || extrinsic.hash;
125
125
  amount = transaction.value || '0';
126
126
  fee = (parseInt(transaction.gasPrice) * parseInt(transaction.gasLimit)).toString();
127
127
  signature = generateSignature(transaction.signature);
@@ -16,8 +16,9 @@ class KeyringService {
16
16
  address: '',
17
17
  currentGenesisHash: null
18
18
  });
19
- accountsSubject = _uiKeyring.keyring.accounts.subject;
20
- beforeAccount = _uiKeyring.keyring.accounts.subject.value;
19
+ addressesSubject = _uiKeyring.keyring.addresses.subject;
20
+ accountSubject = _uiKeyring.keyring.accounts.subject;
21
+ beforeAccount = this.accountSubject.value;
21
22
  keyringStateSubject = new _rxjs.BehaviorSubject({
22
23
  isReady: false,
23
24
  hasMasterPassword: false,
@@ -26,23 +27,17 @@ class KeyringService {
26
27
  constructor(eventService) {
27
28
  this.eventService = eventService;
28
29
  this.currentAccountStore.get('CurrentAccountInfo', rs => {
29
- this.currentAccountSubject.next(rs);
30
+ rs && this.currentAccountSubject.next(rs);
30
31
  });
31
32
  this.subscribeAccounts().catch(console.error);
32
33
  }
33
34
  async subscribeAccounts() {
34
35
  // Wait until account ready
35
- await new Promise(resolve => {
36
- const onReady = () => {
37
- this.eventService.off('account.ready', onReady);
38
- resolve(true);
39
- };
40
- this.eventService.on('account.ready', onReady);
41
- });
36
+ await this.eventService.waitAccountReady;
42
37
  this.beforeAccount = {
43
- ...this.accountsSubject.value
38
+ ...this.accountSubject.value
44
39
  };
45
- this.accountsSubject.subscribe(subjectInfo => {
40
+ this.accountSubject.subscribe(subjectInfo => {
46
41
  // Check if accounts changed
47
42
  const beforeAddresses = Object.keys(this.beforeAccount);
48
43
  const afterAddresses = Object.keys(subjectInfo);
@@ -87,7 +82,10 @@ class KeyringService {
87
82
  });
88
83
  }
89
84
  get accounts() {
90
- return this.accountsSubject.value;
85
+ return this.accountSubject.value;
86
+ }
87
+ get addresses() {
88
+ return this.addressesSubject.value;
91
89
  }
92
90
  get currentAccount() {
93
91
  return this.currentAccountSubject.value;
@@ -10,7 +10,6 @@ var _constants = require("@subwallet/extension-base/services/request-service/con
10
10
  var _Authorize = _interopRequireDefault(require("@subwallet/extension-base/stores/Authorize"));
11
11
  var _utils2 = require("@subwallet/extension-base/utils");
12
12
  var _getId = require("@subwallet/extension-base/utils/getId");
13
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
14
13
  var _rxjs = require("rxjs");
15
14
  var _util = require("@polkadot/util");
16
15
  var _utilCrypto = require("@polkadot/util-crypto");
@@ -27,7 +26,8 @@ class AuthRequestHandler {
27
26
  authorizeUrlSubject = new _rxjs.Subject();
28
27
  evmChainSubject = new _rxjs.Subject();
29
28
  authSubjectV2 = new _rxjs.BehaviorSubject([]);
30
- constructor(requestService, chainService) {
29
+ constructor(requestService, chainService, keyringService) {
30
+ this.keyringService = keyringService;
31
31
  this.#requestService = requestService;
32
32
  this.#chainService = chainService;
33
33
  }
@@ -38,7 +38,7 @@ class AuthRequestHandler {
38
38
  }
39
39
  getAddressList() {
40
40
  let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
41
- const addressList = Object.keys(_accounts.accounts.subject.value);
41
+ const addressList = Object.keys(this.keyringService.accounts);
42
42
  return addressList.reduce((addressList, v) => ({
43
43
  ...addressList,
44
44
  [v]: value
@@ -112,8 +112,10 @@ class AuthRequestHandler {
112
112
  return (_chainStateMap$chain$ = chainStateMap[chain.slug]) === null || _chainStateMap$chain$ === void 0 ? void 0 : _chainStateMap$chain$.active;
113
113
  })) || evmChains[0];
114
114
  if (options.autoActive) {
115
- if (!needEnableChains.includes(chainInfo.slug)) {
116
- needEnableChains.push(chainInfo.slug);
115
+ var _chainInfo;
116
+ if (!needEnableChains.includes((_chainInfo = chainInfo) === null || _chainInfo === void 0 ? void 0 : _chainInfo.slug)) {
117
+ var _chainInfo2;
118
+ needEnableChains.push((_chainInfo2 = chainInfo) === null || _chainInfo2 === void 0 ? void 0 : _chainInfo2.slug);
117
119
  }
118
120
  }
119
121
  }
@@ -76,16 +76,7 @@ class EvmRequestHandler {
76
76
  });
77
77
  this.confirmationsQueueSubject.next(confirmations);
78
78
  if (!isInternal) {
79
- // Not open new popup and use existed
80
- const popupList = this.#requestService.popup;
81
- if (this.#requestService.popup.length > 0) {
82
- // eslint-disable-next-line no-void
83
- void chrome.windows.update(popupList[0], {
84
- focused: true
85
- });
86
- } else {
87
- this.#requestService.popupOpen();
88
- }
79
+ this.#requestService.popupOpen();
89
80
  }
90
81
  this.#requestService.updateIconV2();
91
82
  return promise;
@@ -136,7 +127,8 @@ class EvmRequestHandler {
136
127
  data: (0, _ethereumjsUtil.toBuffer)(config.data)
137
128
  };
138
129
  const common = _common.default.custom({
139
- chainId: config.chainId
130
+ chainId: config.chainId,
131
+ defaultHardfork: 'petersburg'
140
132
  });
141
133
 
142
134
  // @ts-ignore
@@ -149,11 +141,15 @@ class EvmRequestHandler {
149
141
  const {
150
142
  estimateGas,
151
143
  from,
152
- gasPrice
144
+ gas,
145
+ gasPrice,
146
+ value
153
147
  } = transaction;
154
148
  const pair = _uiKeyring.default.getPair(from);
155
149
  const params = {
156
150
  ...transaction,
151
+ gas: (0, _eth.anyNumberToBN)(gas).toNumber(),
152
+ value: (0, _eth.anyNumberToBN)(value).toNumber(),
157
153
  gasPrice: (0, _eth.anyNumberToBN)(gasPrice).toNumber(),
158
154
  gasLimit: (0, _eth.anyNumberToBN)(estimateGas).toNumber()
159
155
  // nonce: await web3.eth.getTransactionCount(from) // Todo: fill this value from transaction service