@subwallet/extension-base 1.1.65-0 → 1.1.67-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 (65) hide show
  1. package/cjs/koni/api/dotsama/transfer.js +11 -0
  2. package/cjs/koni/api/staking/bonding/relayChain.js +6 -0
  3. package/cjs/koni/api/tokens/wasm/utils.js +5 -3
  4. package/cjs/koni/background/cron.js +13 -0
  5. package/cjs/koni/background/handlers/State.js +2 -0
  6. package/cjs/packageInfo.js +1 -1
  7. package/cjs/services/balance-service/helpers/subscribe/index.js +1 -1
  8. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +67 -0
  9. package/cjs/services/chain-service/constants.js +8 -1
  10. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  11. package/cjs/services/chain-service/handler/SubstrateApi.js +15 -9
  12. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +76 -57
  13. package/cjs/services/chain-service/index.js +45 -30
  14. package/cjs/services/chain-service/types.js +1 -1
  15. package/cjs/services/chain-service/utils/index.js +38 -15
  16. package/cjs/services/chain-service/utils/patch.js +1 -1
  17. package/cjs/services/earning-service/constants/chains.js +2 -2
  18. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
  19. package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -0
  20. package/cjs/services/earning-service/service.js +2 -2
  21. package/cjs/services/price-service/index.js +31 -17
  22. package/cjs/stores/CurrentCurrencyStore.js +18 -0
  23. package/cjs/stores/index.js +8 -1
  24. package/cjs/utils/gear/grc20.js +141 -0
  25. package/cjs/utils/gear/index.js +16 -0
  26. package/cjs/utils/index.js +40 -28
  27. package/koni/api/dotsama/transfer.js +13 -2
  28. package/koni/api/staking/bonding/relayChain.d.ts +1 -2
  29. package/koni/api/staking/bonding/relayChain.js +6 -0
  30. package/koni/api/tokens/wasm/utils.js +5 -3
  31. package/koni/background/cron.d.ts +2 -0
  32. package/koni/background/cron.js +14 -1
  33. package/koni/background/handlers/State.js +2 -0
  34. package/package.json +32 -15
  35. package/packageInfo.js +1 -1
  36. package/services/balance-service/helpers/subscribe/index.js +1 -1
  37. package/services/balance-service/helpers/subscribe/substrate/index.js +67 -2
  38. package/services/chain-service/constants.d.ts +1 -0
  39. package/services/chain-service/constants.js +8 -1
  40. package/services/chain-service/handler/EvmChainHandler.d.ts +1 -1
  41. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  42. package/services/chain-service/handler/SubstrateApi.js +6 -0
  43. package/services/chain-service/handler/SubstrateChainHandler.d.ts +4 -1
  44. package/services/chain-service/handler/SubstrateChainHandler.js +76 -57
  45. package/services/chain-service/index.js +17 -8
  46. package/services/chain-service/types.js +1 -1
  47. package/services/chain-service/utils/index.d.ts +4 -0
  48. package/services/chain-service/utils/index.js +30 -15
  49. package/services/chain-service/utils/patch.js +1 -1
  50. package/services/earning-service/constants/chains.js +2 -2
  51. package/services/earning-service/handlers/native-staking/relay-chain.js +3 -0
  52. package/services/earning-service/handlers/nomination-pool/index.js +1 -0
  53. package/services/earning-service/service.js +2 -2
  54. package/services/price-service/index.d.ts +4 -1
  55. package/services/price-service/index.js +31 -17
  56. package/stores/CurrentCurrencyStore.d.ts +5 -0
  57. package/stores/CurrentCurrencyStore.js +10 -0
  58. package/stores/index.d.ts +1 -0
  59. package/stores/index.js +2 -1
  60. package/utils/gear/grc20.d.ts +29 -0
  61. package/utils/gear/grc20.js +131 -0
  62. package/utils/gear/index.d.ts +1 -0
  63. package/utils/gear/index.js +4 -0
  64. package/utils/index.d.ts +6 -5
  65. package/utils/index.js +7 -6
@@ -22,6 +22,18 @@ var _logger = require("@polkadot/util/logger");
22
22
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
23
23
  // SPDX-License-Identifier: Apache-2.0
24
24
 
25
+ const filterChainInfoMap = data => {
26
+ return Object.fromEntries(Object.entries(data).filter(_ref => {
27
+ let [, info] = _ref;
28
+ return !info.bitcoinInfo;
29
+ }));
30
+ };
31
+ const filterAssetInfoMap = (chainInfo, assets) => {
32
+ return Object.fromEntries(Object.entries(assets).filter(_ref2 => {
33
+ let [, info] = _ref2;
34
+ return chainInfo[info.originChain];
35
+ }));
36
+ };
25
37
  class ChainService {
26
38
  dataMap = {
27
39
  chainInfoMap: {},
@@ -74,8 +86,8 @@ class ChainService {
74
86
  // Getter
75
87
  get xcmRefMap() {
76
88
  const result = {};
77
- Object.entries(this.dataMap.assetRefMap).forEach(_ref => {
78
- let [key, assetRef] = _ref;
89
+ Object.entries(this.dataMap.assetRefMap).forEach(_ref3 => {
90
+ let [key, assetRef] = _ref3;
79
91
  if (assetRef.path === _types._AssetRefPath.XCM) {
80
92
  result[key] = assetRef;
81
93
  }
@@ -84,8 +96,8 @@ class ChainService {
84
96
  }
85
97
  get swapRefMap() {
86
98
  const result = {};
87
- Object.entries(this.dataMap.assetRefMap).forEach(_ref2 => {
88
- let [key, assetRef] = _ref2;
99
+ Object.entries(this.dataMap.assetRefMap).forEach(_ref4 => {
100
+ let [key, assetRef] = _ref4;
89
101
  if (assetRef.path === _types._AssetRefPath.SWAP) {
90
102
  result[key] = assetRef;
91
103
  }
@@ -215,16 +227,16 @@ class ChainService {
215
227
  return this.getChainStatusMap()[key];
216
228
  }
217
229
  getActiveChains() {
218
- return Object.entries(this.dataMap.chainStateMap).filter(_ref3 => {
219
- let [, chainState] = _ref3;
230
+ return Object.entries(this.dataMap.chainStateMap).filter(_ref5 => {
231
+ let [, chainState] = _ref5;
220
232
  return (0, _utils._isChainEnabled)(chainState);
221
- }).map(_ref4 => {
222
- let [key] = _ref4;
233
+ }).map(_ref6 => {
234
+ let [key] = _ref6;
223
235
  return key;
224
236
  });
225
237
  }
226
238
  getSupportedSmartContractTypes() {
227
- return [_types._AssetType.ERC20, _types._AssetType.ERC721, _types._AssetType.PSP22, _types._AssetType.PSP34];
239
+ return [_types._AssetType.ERC20, _types._AssetType.ERC721, _types._AssetType.PSP22, _types._AssetType.PSP34, _types._AssetType.GRC20, _types._AssetType.GRC721];
228
240
  }
229
241
  getActiveChainInfoMap() {
230
242
  const result = {};
@@ -379,8 +391,8 @@ class ChainService {
379
391
  (0, _utils2.addLazy)('updateChainConnectionStatus', () => {
380
392
  const chainStatusMap = this.getChainStatusMap();
381
393
  let update = false;
382
- Object.entries(this.connectionStatusQueueMap).forEach(_ref5 => {
383
- let [slug, status] = _ref5;
394
+ Object.entries(this.connectionStatusQueueMap).forEach(_ref7 => {
395
+ let [slug, status] = _ref7;
384
396
  if (chainStatusMap[slug]) {
385
397
  if (chainStatusMap[slug].connectionStatus !== status) {
386
398
  chainStatusMap[slug].connectionStatus = status;
@@ -517,8 +529,8 @@ class ChainService {
517
529
  }
518
530
  handleLatestPriceId(latestPriceIds) {
519
531
  let isUpdated = false;
520
- Object.entries(latestPriceIds).forEach(_ref6 => {
521
- let [slug, priceId] = _ref6;
532
+ Object.entries(latestPriceIds).forEach(_ref8 => {
533
+ let [slug, priceId] = _ref8;
522
534
  if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
523
535
  isUpdated = true;
524
536
  this.dataMap.assetRegistry[slug].priceId = priceId;
@@ -535,10 +547,10 @@ class ChainService {
535
547
  if (latestAssetInfo) {
536
548
  const latestAssetPatch = JSON.stringify(latestAssetInfo);
537
549
  if (this.assetMapPatch !== latestAssetPatch) {
538
- const assetRegistry = {
550
+ const assetRegistry = filterAssetInfoMap(this.getChainInfoMap(), {
539
551
  ..._chainList.ChainAssetMap,
540
552
  ...latestAssetInfo
541
- };
553
+ });
542
554
  this.assetMapPatch = latestAssetPatch;
543
555
  this.dataMap.assetRegistry = assetRegistry;
544
556
  this.assetRegistrySubject.next(assetRegistry);
@@ -597,8 +609,8 @@ class ChainService {
597
609
  }
598
610
  }
599
611
  handleLatestData() {
600
- this.fetchLatestAssetData().then(_ref7 => {
601
- let [latestAssetInfo, latestAssetLogoMap] = _ref7;
612
+ this.fetchLatestAssetData().then(_ref9 => {
613
+ let [latestAssetInfo, latestAssetLogoMap] = _ref9;
602
614
  this.eventService.waitAssetReady.then(() => {
603
615
  this.handleLatestAssetData(latestAssetInfo, latestAssetLogoMap);
604
616
  }).catch(console.error);
@@ -606,8 +618,8 @@ class ChainService {
606
618
  this.fetchLatestChainData().then(latestChainInfo => {
607
619
  this.handleLatestChainData(latestChainInfo);
608
620
  }).catch(console.error);
609
- this.fetchLatestAssetRef().then(_ref8 => {
610
- let [latestAssetRef, latestAssetRefMap] = _ref8;
621
+ this.fetchLatestAssetRef().then(_ref10 => {
622
+ let [latestAssetRef, latestAssetRefMap] = _ref10;
611
623
  this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
612
624
  }).catch(console.error);
613
625
  this.fetchLatestPriceIdsData().then(latestPriceIds => {
@@ -617,12 +629,12 @@ class ChainService {
617
629
  async initApis() {
618
630
  const chainInfoMap = this.getChainInfoMap();
619
631
  const chainStateMap = this.getChainStateMap();
620
- await Promise.all(Object.entries(chainInfoMap).filter(_ref9 => {
632
+ await Promise.all(Object.entries(chainInfoMap).filter(_ref11 => {
621
633
  var _chainStateMap$slug;
622
- let [slug] = _ref9;
634
+ let [slug] = _ref11;
623
635
  return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
624
- }).map(_ref10 => {
625
- let [, chainInfo] = _ref10;
636
+ }).map(_ref12 => {
637
+ let [, chainInfo] = _ref12;
626
638
  try {
627
639
  return this.initApiForChain(chainInfo);
628
640
  } catch (e) {
@@ -847,7 +859,7 @@ class ChainService {
847
859
  }
848
860
  async initChains() {
849
861
  const storedChainSettings = await this.dbService.getAllChainStore();
850
- const defaultChainInfoMap = _chainList.ChainInfoMap;
862
+ const defaultChainInfoMap = filterChainInfoMap(_chainList.ChainInfoMap);
851
863
  const storedChainSettingMap = {};
852
864
  storedChainSettings.forEach(chainStoredSetting => {
853
865
  storedChainSettingMap[chainStoredSetting.slug] = chainStoredSetting;
@@ -957,6 +969,7 @@ class ChainService {
957
969
  deprecatedChainMap[storedSlug] = duplicatedDefaultSlug;
958
970
  deprecatedChains.push(storedSlug);
959
971
  } else {
972
+ var _storedChainInfo$bitc;
960
973
  mergedChainInfoMap[storedSlug] = {
961
974
  slug: storedSlug,
962
975
  name: storedChainInfo.name,
@@ -964,6 +977,7 @@ class ChainService {
964
977
  // TODO: review
965
978
  evmInfo: storedChainInfo.evmInfo,
966
979
  substrateInfo: storedChainInfo.substrateInfo,
980
+ bitcoinInfo: (_storedChainInfo$bitc = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc !== void 0 ? _storedChainInfo$bitc : null,
967
981
  isTestnet: storedChainInfo.isTestnet,
968
982
  chainStatus: storedChainInfo.chainStatus,
969
983
  icon: storedChainInfo.icon,
@@ -991,8 +1005,8 @@ class ChainService {
991
1005
  }
992
1006
 
993
1007
  // Fill in the missing chainState and storageData (new chains never before seen)
994
- Object.entries(mergedChainInfoMap).forEach(_ref11 => {
995
- let [slug, chainInfo] = _ref11;
1008
+ Object.entries(mergedChainInfoMap).forEach(_ref13 => {
1009
+ let [slug, chainInfo] = _ref13;
996
1010
  if (!(slug in this.dataMap.chainStateMap)) {
997
1011
  this.dataMap.chainStateMap[slug] = {
998
1012
  currentProvider: Object.keys(chainInfo.providers)[0],
@@ -1017,7 +1031,7 @@ class ChainService {
1017
1031
  }
1018
1032
  async initAssetRegistry(deprecatedCustomChainMap) {
1019
1033
  const storedAssetRegistry = await this.dbService.getAllAssetStore();
1020
- const latestAssetRegistry = _chainList.ChainAssetMap;
1034
+ const latestAssetRegistry = filterAssetInfoMap(this.getChainInfoMap(), _chainList.ChainAssetMap);
1021
1035
  const availableChains = Object.values(this.dataMap.chainInfoMap).filter(info => info.chainStatus === _types._ChainStatus.ACTIVE).map(chainInfo => chainInfo.slug);
1022
1036
 
1023
1037
  // Fill out zk assets from latestAssetRegistry if not supported
@@ -1172,6 +1186,7 @@ class ChainService {
1172
1186
  providers: params.chainEditInfo.providers,
1173
1187
  substrateInfo,
1174
1188
  evmInfo,
1189
+ bitcoinInfo: null,
1175
1190
  isTestnet: false,
1176
1191
  chainStatus: _types._ChainStatus.ACTIVE,
1177
1192
  icon: '',
@@ -1416,9 +1431,9 @@ class ChainService {
1416
1431
  }
1417
1432
  async getSmartContractTokenInfo(contractAddress, tokenType, originChain, contractCaller) {
1418
1433
  if ([_types._AssetType.ERC721, _types._AssetType.ERC20].includes(tokenType)) {
1419
- return await this.evmChainHandler.getSmartContractTokenInfo(contractAddress, tokenType, originChain);
1420
- } else if ([_types._AssetType.PSP34, _types._AssetType.PSP22].includes(tokenType)) {
1421
- return await this.substrateChainHandler.getSmartContractTokenInfo(contractAddress, tokenType, originChain, contractCaller);
1434
+ return await this.evmChainHandler.getEvmContractTokenInfo(contractAddress, tokenType, originChain);
1435
+ } else if ([_types._AssetType.PSP34, _types._AssetType.PSP22, _types._AssetType.GRC20].includes(tokenType)) {
1436
+ return await this.substrateChainHandler.getSubstrateContractTokenInfo(contractAddress, tokenType, originChain, contractCaller);
1422
1437
  }
1423
1438
  return {
1424
1439
  decimals: -1,
@@ -18,7 +18,7 @@ exports._ChainConnectionStatus = _ChainConnectionStatus;
18
18
  })(_ChainConnectionStatus || (exports._ChainConnectionStatus = _ChainConnectionStatus = {}));
19
19
  const _CUSTOM_PREFIX = 'custom-';
20
20
  exports._CUSTOM_PREFIX = _CUSTOM_PREFIX;
21
- const _FUNGIBLE_CONTRACT_STANDARDS = [_types._AssetType.ERC20, _types._AssetType.PSP22];
21
+ const _FUNGIBLE_CONTRACT_STANDARDS = [_types._AssetType.ERC20, _types._AssetType.PSP22, _types._AssetType.GRC20];
22
22
  exports._FUNGIBLE_CONTRACT_STANDARDS = _FUNGIBLE_CONTRACT_STANDARDS;
23
23
  const _NFT_CONTRACT_STANDARDS = [_types._AssetType.PSP34, _types._AssetType.ERC721];
24
24
  exports._NFT_CONTRACT_STANDARDS = _NFT_CONTRACT_STANDARDS;
@@ -35,6 +35,9 @@ var _exportNames = {
35
35
  _isChainSupportNativeNft: true,
36
36
  _isChainSupportEvmNft: true,
37
37
  _isChainSupportWasmNft: true,
38
+ _isChainSupportEvmERC20: true,
39
+ _isChainSupportWasmPSP22: true,
40
+ _isChainSupportGRC20: true,
38
41
  _isSupportOrdinal: true,
39
42
  _getNftTypesSupportedByChain: true,
40
43
  _getTokenTypesSupportedByChain: true,
@@ -44,6 +47,7 @@ var _exportNames = {
44
47
  _isTokenEvmSmartContract: true,
45
48
  _isTokenWasmSmartContract: true,
46
49
  _isAssetSmartContractNft: true,
50
+ _isTokenGearSmartContract: true,
47
51
  _parseAssetRefKey: true,
48
52
  _isXcmPathSupported: true,
49
53
  _getXcmAssetType: true,
@@ -119,10 +123,13 @@ exports._isAssetValuable = _isAssetValuable;
119
123
  exports._isBridgedToken = _isBridgedToken;
120
124
  exports._isChainEnabled = _isChainEnabled;
121
125
  exports._isChainEvmCompatible = _isChainEvmCompatible;
126
+ exports._isChainSupportEvmERC20 = _isChainSupportEvmERC20;
122
127
  exports._isChainSupportEvmNft = _isChainSupportEvmNft;
128
+ exports._isChainSupportGRC20 = _isChainSupportGRC20;
123
129
  exports._isChainSupportNativeNft = _isChainSupportNativeNft;
124
130
  exports._isChainSupportSubstrateStaking = _isChainSupportSubstrateStaking;
125
131
  exports._isChainSupportWasmNft = _isChainSupportWasmNft;
132
+ exports._isChainSupportWasmPSP22 = _isChainSupportWasmPSP22;
126
133
  exports._isChainTestNet = _isChainTestNet;
127
134
  exports._isCustomAsset = _isCustomAsset;
128
135
  exports._isCustomChain = _isCustomChain;
@@ -142,6 +149,7 @@ exports._isSubstrateParaChain = _isSubstrateParaChain;
142
149
  exports._isSubstrateRelayChain = _isSubstrateRelayChain;
143
150
  exports._isSupportOrdinal = void 0;
144
151
  exports._isTokenEvmSmartContract = _isTokenEvmSmartContract;
152
+ exports._isTokenGearSmartContract = _isTokenGearSmartContract;
145
153
  exports._isTokenTransferredByEvm = _isTokenTransferredByEvm;
146
154
  exports._isTokenWasmSmartContract = _isTokenWasmSmartContract;
147
155
  exports._isXcmPathSupported = _isXcmPathSupported;
@@ -333,6 +341,18 @@ function _isChainSupportWasmNft(chainInfo) {
333
341
  var _chainInfo$substrateI8, _chainInfo$substrateI9;
334
342
  return ((_chainInfo$substrateI8 = chainInfo.substrateInfo) === null || _chainInfo$substrateI8 === void 0 ? void 0 : (_chainInfo$substrateI9 = _chainInfo$substrateI8.supportSmartContract) === null || _chainInfo$substrateI9 === void 0 ? void 0 : _chainInfo$substrateI9.includes(_types._AssetType.PSP34)) || false;
335
343
  }
344
+ function _isChainSupportEvmERC20(chainInfo) {
345
+ var _chainInfo$evmInfo3, _chainInfo$evmInfo3$s;
346
+ return ((_chainInfo$evmInfo3 = chainInfo.evmInfo) === null || _chainInfo$evmInfo3 === void 0 ? void 0 : (_chainInfo$evmInfo3$s = _chainInfo$evmInfo3.supportSmartContract) === null || _chainInfo$evmInfo3$s === void 0 ? void 0 : _chainInfo$evmInfo3$s.includes(_types._AssetType.ERC20)) || false;
347
+ }
348
+ function _isChainSupportWasmPSP22(chainInfo) {
349
+ var _chainInfo$substrateI10, _chainInfo$substrateI11;
350
+ return ((_chainInfo$substrateI10 = chainInfo.substrateInfo) === null || _chainInfo$substrateI10 === void 0 ? void 0 : (_chainInfo$substrateI11 = _chainInfo$substrateI10.supportSmartContract) === null || _chainInfo$substrateI11 === void 0 ? void 0 : _chainInfo$substrateI11.includes(_types._AssetType.PSP22)) || false;
351
+ }
352
+ function _isChainSupportGRC20(chainInfo) {
353
+ var _chainInfo$substrateI12, _chainInfo$substrateI13;
354
+ return ((_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : (_chainInfo$substrateI13 = _chainInfo$substrateI12.supportSmartContract) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.includes(_types._AssetType.GRC20)) || false;
355
+ }
336
356
  const _isSupportOrdinal = chain => {
337
357
  const chains = ['polkadot', 'astar', 'bifrost_dot', 'moonbeam'];
338
358
  return chains.includes(chain);
@@ -360,7 +380,7 @@ function _getTokenTypesSupportedByChain(chainInfo) {
360
380
  const result = [];
361
381
  if (chainInfo.substrateInfo && chainInfo.substrateInfo.supportSmartContract) {
362
382
  chainInfo.substrateInfo.supportSmartContract.forEach(assetType => {
363
- if ([_types._AssetType.PSP22].includes(assetType)) {
383
+ if ([_types._AssetType.PSP22, _types._AssetType.GRC20].includes(assetType)) {
364
384
  result.push(assetType);
365
385
  }
366
386
  });
@@ -416,6 +436,9 @@ function _isTokenWasmSmartContract(tokenInfo) {
416
436
  function _isAssetSmartContractNft(assetInfo) {
417
437
  return [_types._AssetType.PSP34, _types._AssetType.ERC721].includes(assetInfo.assetType);
418
438
  }
439
+ function _isTokenGearSmartContract(tokenInfo) {
440
+ return [_types._AssetType.GRC20, _types._AssetType.GRC721].includes(tokenInfo.assetType);
441
+ }
419
442
  function _parseAssetRefKey(originTokenSlug, destinationTokenSlug) {
420
443
  return `${originTokenSlug}___${destinationTokenSlug}`;
421
444
  }
@@ -443,16 +466,16 @@ function _getXcmTransferType(originChainInfo, destinationChainInfo) {
443
466
  return `${((_originChainInfo$subs = originChainInfo.substrateInfo) === null || _originChainInfo$subs === void 0 ? void 0 : _originChainInfo$subs.chainType) || ''}-${((_destinationChainInfo = destinationChainInfo.substrateInfo) === null || _destinationChainInfo === void 0 ? void 0 : _destinationChainInfo.chainType) || ''}`;
444
467
  }
445
468
  function _isSubstrateRelayChain(chainInfo) {
446
- var _chainInfo$substrateI10;
447
- return ((_chainInfo$substrateI10 = chainInfo.substrateInfo) === null || _chainInfo$substrateI10 === void 0 ? void 0 : _chainInfo$substrateI10.chainType) === _types._SubstrateChainType.RELAYCHAIN;
469
+ var _chainInfo$substrateI14;
470
+ return ((_chainInfo$substrateI14 = chainInfo.substrateInfo) === null || _chainInfo$substrateI14 === void 0 ? void 0 : _chainInfo$substrateI14.chainType) === _types._SubstrateChainType.RELAYCHAIN;
448
471
  }
449
472
  function _isSubstrateParaChain(chainInfo) {
450
- var _chainInfo$substrateI11;
451
- return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$substrateI11 = chainInfo.substrateInfo) === null || _chainInfo$substrateI11 === void 0 ? void 0 : _chainInfo$substrateI11.chainType) === _types._SubstrateChainType.PARACHAIN;
473
+ var _chainInfo$substrateI15;
474
+ return chainInfo.substrateInfo !== null && chainInfo.substrateInfo.paraId !== null && ((_chainInfo$substrateI15 = chainInfo.substrateInfo) === null || _chainInfo$substrateI15 === void 0 ? void 0 : _chainInfo$substrateI15.chainType) === _types._SubstrateChainType.PARACHAIN;
452
475
  }
453
476
  function _getEvmAbiExplorer(chainInfo) {
454
- var _chainInfo$evmInfo3;
455
- return ((_chainInfo$evmInfo3 = chainInfo.evmInfo) === null || _chainInfo$evmInfo3 === void 0 ? void 0 : _chainInfo$evmInfo3.abiExplorer) || '';
477
+ var _chainInfo$evmInfo4;
478
+ return ((_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.abiExplorer) || '';
456
479
  }
457
480
  function _isAssetValuable(assetInfo) {
458
481
  return assetInfo.hasValue;
@@ -490,11 +513,11 @@ function _getBlockExplorerFromChain(chainInfo) {
490
513
  return;
491
514
  }
492
515
  if (_isPureEvmChain(chainInfo)) {
493
- var _chainInfo$evmInfo4;
494
- blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo4 = chainInfo.evmInfo) === null || _chainInfo$evmInfo4 === void 0 ? void 0 : _chainInfo$evmInfo4.blockExplorer;
516
+ var _chainInfo$evmInfo5;
517
+ blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.blockExplorer;
495
518
  } else {
496
- var _chainInfo$substrateI12;
497
- blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI12 = chainInfo.substrateInfo) === null || _chainInfo$substrateI12 === void 0 ? void 0 : _chainInfo$substrateI12.blockExplorer;
519
+ var _chainInfo$substrateI16;
520
+ blockExplorer = chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI16 = chainInfo.substrateInfo) === null || _chainInfo$substrateI16 === void 0 ? void 0 : _chainInfo$substrateI16.blockExplorer;
498
521
  }
499
522
  if (!blockExplorer) {
500
523
  return undefined;
@@ -521,8 +544,8 @@ const _isAssetAutoEnable = chainAsset => {
521
544
  };
522
545
  exports._isAssetAutoEnable = _isAssetAutoEnable;
523
546
  function _getCrowdloanUrlFromChain(chainInfo) {
524
- var _chainInfo$substrateI13;
525
- return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI13 = chainInfo.substrateInfo) === null || _chainInfo$substrateI13 === void 0 ? void 0 : _chainInfo$substrateI13.crowdloanUrl) || '';
547
+ var _chainInfo$substrateI17;
548
+ return (chainInfo === null || chainInfo === void 0 ? void 0 : (_chainInfo$substrateI17 = chainInfo.substrateInfo) === null || _chainInfo$substrateI17 === void 0 ? void 0 : _chainInfo$substrateI17.crowdloanUrl) || '';
526
549
  }
527
550
  function _isCustomProvider(providerKey) {
528
551
  return providerKey.startsWith(_types2._CUSTOM_PREFIX);
@@ -548,8 +571,8 @@ const findChainInfoByChainId = (chainMap, chainId) => {
548
571
  return null;
549
572
  }
550
573
  for (const chainInfo of Object.values(chainMap)) {
551
- var _chainInfo$evmInfo5;
552
- if (((_chainInfo$evmInfo5 = chainInfo.evmInfo) === null || _chainInfo$evmInfo5 === void 0 ? void 0 : _chainInfo$evmInfo5.evmChainId) === chainId) {
574
+ var _chainInfo$evmInfo6;
575
+ if (((_chainInfo$evmInfo6 = chainInfo.evmInfo) === null || _chainInfo$evmInfo6 === void 0 ? void 0 : _chainInfo$evmInfo6.evmChainId) === chainId) {
553
576
  return chainInfo;
554
577
  }
555
578
  }
@@ -12,7 +12,7 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
12
12
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
13
13
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
14
14
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
15
- const ChainListVersion = '0.2.59';
15
+ const ChainListVersion = '0.2.62';
16
16
  async function fetchPatchData(slug) {
17
17
  try {
18
18
  const fetchPromise = (0, _crossFetch.default)(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
@@ -8,13 +8,13 @@ exports._UPDATED_RUNTIME_STAKING_GROUP = exports._STAKING_CHAIN_GROUP = exports.
8
8
  // SPDX-License-Identifier: Apache-2.0
9
9
 
10
10
  const _STAKING_CHAIN_GROUP = {
11
- relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet'],
11
+ relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet', 'vara_testnet'],
12
12
  para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network', 'polimec'],
13
13
  astar: ['astar', 'shiden', 'shibuya'],
14
14
  amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
15
15
  // amplitude and kilt only share some common logic
16
16
  kilt: ['kilt', 'kilt_peregrine'],
17
- nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet'],
17
+ nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph', 'kate', 'vara_network', 'goldberg_testnet', 'availTuringTest', 'avail_mainnet', 'vara_testnet'],
18
18
  bifrost: ['bifrost', 'bifrost_testnet'],
19
19
  aleph: ['aleph', 'alephTest'],
20
20
  // A0 has distinct tokenomics
@@ -510,6 +510,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
510
510
  if (paramsCount === 2) {
511
511
  bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
512
512
  } else {
513
+ // @ts-ignore
513
514
  bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
514
515
  }
515
516
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
@@ -520,6 +521,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
520
521
  if (paramsCount === 2) {
521
522
  bondTx = chainApi.api.tx.staking.bond(binaryAmount, bondDest);
522
523
  } else {
524
+ // @ts-ignore
523
525
  bondTx = chainApi.api.tx.staking.bond(address, binaryAmount, bondDest);
524
526
  }
525
527
  nominateTx = chainApi.api.tx.staking.nominate(validatorParamList);
@@ -627,6 +629,7 @@ class RelayNativeStakingPoolHandler extends _base.default {
627
629
  const slashingSpanCount = _slashingSpans !== null ? _slashingSpans.spanIndex : '0';
628
630
  return chainApi.api.tx.staking.withdrawUnbonded(slashingSpanCount);
629
631
  } else {
632
+ // @ts-ignore
630
633
  return chainApi.api.tx.staking.withdrawUnbonded();
631
634
  }
632
635
  }
@@ -574,6 +574,7 @@ class NominationPoolHandler extends _base.default {
574
574
  Id: address
575
575
  }, slashingSpanCount);
576
576
  } else {
577
+ // @ts-ignore
577
578
  return chainApi.api.tx.nominationPools.withdrawUnbonded({
578
579
  Id: address
579
580
  });
@@ -197,7 +197,7 @@ class EarningService {
197
197
  this.status = _types.ServiceStatus.STARTING;
198
198
 
199
199
  // Start subscribe pools' info
200
- await this.runSubscribePoolsInfo();
200
+ // await this.runSubscribePoolsInfo();
201
201
 
202
202
  // Start subscribe pools' position
203
203
  await this.runSubscribePoolsPosition();
@@ -224,7 +224,7 @@ class EarningService {
224
224
  await this.persistData();
225
225
 
226
226
  // Stop subscribe pools' info
227
- this.runUnsubscribePoolsInfo();
227
+ // this.runUnsubscribePoolsInfo();
228
228
 
229
229
  // Stop subscribe pools' position
230
230
  this.runUnsubscribePoolsPosition();
@@ -8,6 +8,7 @@ var _constants = require("@subwallet/extension-base/constants");
8
8
  var _types = require("@subwallet/extension-base/services/base/types");
9
9
  var _coingecko = require("@subwallet/extension-base/services/price-service/coingecko");
10
10
  var _storage = require("@subwallet/extension-base/storage");
11
+ var _stores = require("@subwallet/extension-base/stores");
11
12
  var _promise = require("@subwallet/extension-base/utils/promise");
12
13
  var _staticData = require("@subwallet/extension-base/utils/staticData");
13
14
  var _rxjs = require("rxjs");
@@ -29,12 +30,10 @@ const DEFAULT_PRICE_SUBJECT = {
29
30
  };
30
31
  class PriceService {
31
32
  priceIds = new Set();
33
+ currency = new _stores.CurrentCurrencyStore();
32
34
  constructor(dbService, eventService, chainService) {
33
- const currency = _storage.SWStorage.instance.getItem(_constants.CURRENCY);
34
- this.currency = new _rxjs.BehaviorSubject(currency || DEFAULT_CURRENCY);
35
35
  this.priceSubject = new _rxjs.BehaviorSubject({
36
- ...DEFAULT_PRICE_SUBJECT,
37
- currency: this.currency.value
36
+ ...DEFAULT_PRICE_SUBJECT
38
37
  });
39
38
  this.rawPriceSubject = new _rxjs.BehaviorSubject({});
40
39
  this.rawExchangeRateMap = new _rxjs.BehaviorSubject({});
@@ -42,7 +41,11 @@ class PriceService {
42
41
  this.dbService = dbService;
43
42
  this.eventService = eventService;
44
43
  this.chainService = chainService;
45
- this.init().catch(console.error);
44
+ const updateCurrency = currentCurrency => {
45
+ const currency = _storage.SWStorage.instance.getItem(_constants.CURRENCY);
46
+ this.setCurrentCurrency(currency || currentCurrency || DEFAULT_CURRENCY);
47
+ };
48
+ this.init().then(() => this.getCurrentCurrency(updateCurrency)).catch(console.error);
46
49
  }
47
50
  async getTokenPrice(priceIds, currency, resolve, reject) {
48
51
  await Promise.all([(0, _coingecko.getExchangeRateMap)(), (0, _coingecko.getPriceMap)(priceIds, currency)]).then(_ref => {
@@ -51,12 +54,29 @@ class PriceService {
51
54
  this.rawPriceSubject.next(priceMap);
52
55
  });
53
56
  }
57
+ getCurrentCurrencySubject() {
58
+ return this.currency.getSubject();
59
+ }
60
+ setCurrentCurrency(currency) {
61
+ this.currency.set('Currency', currency);
62
+ }
63
+ getCurrentCurrency(update) {
64
+ this.currency.get('Currency', value => {
65
+ update(value || DEFAULT_CURRENCY);
66
+ });
67
+ }
54
68
  refreshPromise = null;
55
69
  refreshPriceMapByAction() {
56
70
  this.refreshPromise = (async () => {
57
71
  try {
58
72
  await this.refreshPromise;
59
- const newPriceMap = await this.calculatePriceMap();
73
+ const {
74
+ promise,
75
+ resolve
76
+ } = (0, _promise.createPromiseHandler)();
77
+ this.getCurrentCurrency(resolve);
78
+ const currencyKey = await promise;
79
+ const newPriceMap = await this.calculatePriceMap(currencyKey || DEFAULT_CURRENCY);
60
80
  if (newPriceMap) {
61
81
  this.priceSubject.next(newPriceMap);
62
82
  }
@@ -67,16 +87,13 @@ class PriceService {
67
87
  }
68
88
  })();
69
89
  }
70
- async calculatePriceMap() {
90
+ async calculatePriceMap(currency) {
71
91
  const {
72
92
  price24hMap,
73
93
  priceMap
74
94
  } = this.rawPriceSubject.value;
75
95
  const exchangeRateData = this.rawExchangeRateMap.value;
76
- const currencyKey = this.currency.value;
77
- if (Object.keys(this.rawPriceSubject.value).length === 0) {
78
- return;
79
- }
96
+ const currencyKey = currency || DEFAULT_CURRENCY;
80
97
  if (Object.keys(exchangeRateData).length === 0) {
81
98
  return;
82
99
  }
@@ -112,10 +129,7 @@ class PriceService {
112
129
  return new Set(priceIdList);
113
130
  }
114
131
  async setPriceCurrency(newCurrencyCode) {
115
- if (newCurrencyCode === this.currency.value) {
116
- return false;
117
- }
118
- this.currency.next(newCurrencyCode);
132
+ this.setCurrentCurrency(newCurrencyCode);
119
133
 
120
134
  // Await 1s to get the latest exchange rate
121
135
  await new Promise(resolve => setTimeout(resolve, 300));
@@ -147,9 +161,9 @@ class PriceService {
147
161
  this.refreshPriceMapByAction();
148
162
  }
149
163
  };
150
- this.currency.subscribe(currency => {
164
+ this.getCurrentCurrencySubject().subscribe(currency => {
151
165
  console.log('Currency changed', currency);
152
- this.calculatePriceMap().then(data => {
166
+ this.calculatePriceMap(currency).then(data => {
153
167
  if (data) {
154
168
  this.priceSubject.next(data);
155
169
  }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defaults = require("@subwallet/extension-base/defaults");
9
+ var _SubscribableStore = _interopRequireDefault(require("@subwallet/extension-base/stores/SubscribableStore"));
10
+ // Copyright 2019-2022 @subwallet/extension-koni-ui authors & contributors
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class CurrentCurrencyStore extends _SubscribableStore.default {
14
+ constructor() {
15
+ super(_defaults.EXTENSION_PREFIX ? `${_defaults.EXTENSION_PREFIX}current_currency` : null);
16
+ }
17
+ }
18
+ exports.default = CurrentCurrencyStore;
@@ -16,6 +16,12 @@ Object.defineProperty(exports, "CurrentAccountStore", {
16
16
  return _CurrentAccountStore.default;
17
17
  }
18
18
  });
19
+ Object.defineProperty(exports, "CurrentCurrencyStore", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _CurrentCurrencyStore.default;
23
+ }
24
+ });
19
25
  Object.defineProperty(exports, "MetadataStore", {
20
26
  enumerable: true,
21
27
  get: function () {
@@ -24,4 +30,5 @@ Object.defineProperty(exports, "MetadataStore", {
24
30
  });
25
31
  var _Accounts = _interopRequireDefault(require("./Accounts"));
26
32
  var _Metadata = _interopRequireDefault(require("./Metadata"));
27
- var _CurrentAccountStore = _interopRequireDefault(require("./CurrentAccountStore"));
33
+ var _CurrentAccountStore = _interopRequireDefault(require("./CurrentAccountStore"));
34
+ var _CurrentCurrencyStore = _interopRequireDefault(require("./CurrentCurrencyStore"));