@subwallet/extension-base 1.3.6-1 → 1.3.8-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 (132) hide show
  1. package/background/KoniTypes.d.ts +20 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/constants/blocked-actions.js +108 -0
  5. package/cjs/constants/index.js +4 -4
  6. package/cjs/core/substrate/xcm-parser.js +20 -5
  7. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  8. package/cjs/koni/api/nft/config.js +6 -4
  9. package/cjs/koni/api/nft/index.js +9 -0
  10. package/cjs/koni/api/nft/story_odyssey_nft/index.js +126 -0
  11. package/cjs/koni/background/handlers/Extension.js +64 -4
  12. package/cjs/koni/background/handlers/State.js +23 -2
  13. package/cjs/packageInfo.js +1 -1
  14. package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  15. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  16. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  17. package/cjs/services/chain-online-service/constants.js +32 -0
  18. package/cjs/services/chain-online-service/index.js +190 -0
  19. package/cjs/services/chain-service/constants.js +2 -1
  20. package/cjs/services/chain-service/index.js +87 -127
  21. package/cjs/services/chain-service/utils/index.js +0 -2
  22. package/cjs/services/chain-service/utils/patch.js +7 -3
  23. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  24. package/cjs/services/environment-service/stores/Environment.js +19 -0
  25. package/cjs/services/fee-service/utils/index.js +14 -0
  26. package/cjs/services/inapp-notification-service/consts.js +6 -4
  27. package/cjs/services/inapp-notification-service/index.js +110 -6
  28. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  29. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  30. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  31. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  32. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  33. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  34. package/cjs/services/migration-service/scripts/index.js +3 -1
  35. package/cjs/services/setting-service/SettingService.js +21 -0
  36. package/cjs/services/setting-service/constants.js +2 -1
  37. package/cjs/services/storage-service/DatabaseService.js +3 -0
  38. package/cjs/services/transaction-service/index.js +13 -7
  39. package/cjs/services/transaction-service/utils.js +3 -0
  40. package/cjs/stores/ChainlistStore.js +18 -0
  41. package/cjs/stores/EnvironmentStore.js +18 -0
  42. package/cjs/stores/index.js +8 -1
  43. package/cjs/types/index.js +11 -0
  44. package/cjs/utils/account/transform.js +1 -1
  45. package/cjs/utils/environment.js +15 -1
  46. package/cjs/utils/staticData/index.js +7 -2
  47. package/constants/blocked-actions.d.ts +29 -0
  48. package/constants/blocked-actions.js +96 -0
  49. package/constants/index.d.ts +1 -1
  50. package/constants/index.js +1 -1
  51. package/core/substrate/xcm-parser.d.ts +2 -1
  52. package/core/substrate/xcm-parser.js +19 -5
  53. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  54. package/koni/api/contract-handler/utils/index.js +12 -0
  55. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  56. package/koni/api/nft/config.d.ts +1 -1
  57. package/koni/api/nft/config.js +5 -2
  58. package/koni/api/nft/index.js +9 -0
  59. package/koni/api/nft/story_odyssey_nft/index.d.ts +40 -0
  60. package/koni/api/nft/story_odyssey_nft/index.js +119 -0
  61. package/koni/background/handlers/Extension.d.ts +5 -0
  62. package/koni/background/handlers/Extension.js +65 -5
  63. package/koni/background/handlers/State.d.ts +5 -0
  64. package/koni/background/handlers/State.js +23 -2
  65. package/package.json +76 -18
  66. package/packageInfo.js +1 -1
  67. package/services/balance-service/helpers/subscribe/substrate/index.js +2 -1
  68. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  69. package/services/balance-service/transfer/xcm/index.js +29 -1
  70. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  71. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  72. package/services/chain-online-service/constants.d.ts +4 -0
  73. package/services/chain-online-service/constants.js +23 -0
  74. package/services/chain-online-service/index.d.ts +22 -0
  75. package/services/chain-online-service/index.js +182 -0
  76. package/services/chain-service/constants.d.ts +1 -0
  77. package/services/chain-service/constants.js +2 -1
  78. package/services/chain-service/index.d.ts +6 -7
  79. package/services/chain-service/index.js +78 -116
  80. package/services/chain-service/utils/index.js +0 -2
  81. package/services/chain-service/utils/patch.d.ts +16 -1
  82. package/services/chain-service/utils/patch.js +7 -3
  83. package/services/earning-service/handlers/native-staking/para-chain.js +20 -17
  84. package/services/environment-service/stores/Environment.d.ts +10 -0
  85. package/services/environment-service/stores/Environment.js +12 -0
  86. package/services/fee-service/utils/index.js +14 -0
  87. package/services/inapp-notification-service/consts.d.ts +3 -1
  88. package/services/inapp-notification-service/consts.js +6 -4
  89. package/services/inapp-notification-service/index.d.ts +10 -2
  90. package/services/inapp-notification-service/index.js +111 -7
  91. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  92. package/services/inapp-notification-service/interfaces.js +7 -0
  93. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  94. package/services/inapp-notification-service/utils/avail.js +73 -0
  95. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  96. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  97. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  98. package/services/inapp-notification-service/utils/index.js +6 -0
  99. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  100. package/services/inapp-notification-service/utils/polygon.js +54 -0
  101. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  103. package/services/migration-service/scripts/index.js +3 -1
  104. package/services/setting-service/SettingService.d.ts +9 -0
  105. package/services/setting-service/SettingService.js +21 -0
  106. package/services/setting-service/constants.js +2 -1
  107. package/services/storage-service/DatabaseService.d.ts +1 -0
  108. package/services/storage-service/DatabaseService.js +3 -0
  109. package/services/transaction-service/index.js +14 -8
  110. package/services/transaction-service/utils.js +3 -0
  111. package/stores/ChainlistStore.d.ts +7 -0
  112. package/stores/ChainlistStore.js +10 -0
  113. package/stores/EnvironmentStore.d.ts +5 -0
  114. package/stores/EnvironmentStore.js +10 -0
  115. package/stores/index.d.ts +1 -0
  116. package/stores/index.js +2 -1
  117. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  118. package/types/index.d.ts +1 -0
  119. package/types/index.js +1 -0
  120. package/types/notification/index.d.ts +5 -0
  121. package/utils/account/transform.js +1 -1
  122. package/utils/environment.d.ts +6 -0
  123. package/utils/environment.js +8 -0
  124. package/utils/staticData/blockedActions.json +1 -0
  125. package/utils/staticData/index.d.ts +7 -3
  126. package/utils/staticData/index.js +5 -1
  127. package/cjs/constants/blocked-actions-list.js +0 -14
  128. package/constants/blocked-actions-list.d.ts +0 -7
  129. package/constants/blocked-actions-list.js +0 -7
  130. package/services/inapp-notification-service/utils.d.ts +0 -55
  131. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  132. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -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.ChainService = void 0;
7
+ exports.filterAssetInfoMap = exports.ChainService = void 0;
8
8
  var _chainList = require("@subwallet/chain-list");
9
9
  var _types = require("@subwallet/chain-list/types");
10
10
  var _constants = require("@subwallet/extension-base/services/chain-service/constants");
@@ -30,29 +30,13 @@ const filterChainInfoMap = (data, ignoredChains) => {
30
30
  }));
31
31
  };
32
32
  const ignoredList = ['bevm', 'bevmTest', 'bevm_testnet', 'layerEdge_testnet', 'merlinEvm', 'botanixEvmTest', 'syscoin_evm', 'syscoin_evm_testnet', 'rollux_evm', 'rollux_testnet', 'boolAlpha', 'boolBeta_testnet', 'core', 'satoshivm', 'satoshivm_testnet', 'storyPartner_testnet'];
33
- const filterAssetInfoMap = (chainInfo, assets) => {
33
+ const filterAssetInfoMap = (chainInfo, assets, addedChains) => {
34
34
  return Object.fromEntries(Object.entries(assets).filter(_ref2 => {
35
35
  let [, info] = _ref2;
36
- return chainInfo[info.originChain];
36
+ return chainInfo[info.originChain] || (addedChains === null || addedChains === void 0 ? void 0 : addedChains.includes(info.originChain));
37
37
  }));
38
38
  };
39
-
40
- // const rawAssetRefMap = (assetRefMap: Record<string, _AssetRef>) => {
41
- // const result: Record<string, _AssetRef> = {};
42
- //
43
- // Object.entries(assetRefMap).forEach(([key, assetRef]) => {
44
- // const originChainInfo = ChainInfoMap[assetRef.srcChain];
45
- // const destChainInfo = ChainInfoMap[assetRef.destChain];
46
- // const isSnowBridgeXcm = assetRef.path === _AssetRefPath.XCM && _isSnowBridgeXcm(originChainInfo, destChainInfo);
47
- //
48
- // if (!isSnowBridgeXcm) {
49
- // result[key] = assetRef;
50
- // }
51
- // });
52
- //
53
- // return result;
54
- // };
55
-
39
+ exports.filterAssetInfoMap = filterAssetInfoMap;
56
40
  class ChainService {
57
41
  dataMap = {
58
42
  chainInfoMap: {},
@@ -77,8 +61,6 @@ class ChainService {
77
61
  assetLogoMapSubject = new _rxjs.BehaviorSubject(_chainList.AssetLogoMap);
78
62
  chainLogoMapSubject = new _rxjs.BehaviorSubject(_chainList.ChainLogoMap);
79
63
  ledgerGenericAllowChainsSubject = new _rxjs.BehaviorSubject([]);
80
- assetMapPatch = JSON.stringify({});
81
- assetLogoPatch = JSON.stringify({});
82
64
 
83
65
  // Todo: Update to new store indexed DB
84
66
  store = new _AssetSetting.default();
@@ -141,6 +123,12 @@ class ChainService {
141
123
  });
142
124
  return result;
143
125
  }
126
+ getlockChainInfoMap() {
127
+ return this.lockChainInfoMap;
128
+ }
129
+ setLockChainInfoMap(isLock) {
130
+ this.lockChainInfoMap = isLock;
131
+ }
144
132
  getEvmApi(slug) {
145
133
  return this.evmChainHandler.getEvmApiByChain(slug);
146
134
  }
@@ -189,6 +177,9 @@ class ChainService {
189
177
  getAssetRegistry() {
190
178
  return this.dataMap.assetRegistry;
191
179
  }
180
+ setAssetRegistry(assetRegistry) {
181
+ this.dataMap.assetRegistry = assetRegistry;
182
+ }
192
183
  getMultiChainAssetMap() {
193
184
  return _chainList.MultiChainAssetMap;
194
185
  }
@@ -213,6 +204,9 @@ class ChainService {
213
204
  getChainInfoMap() {
214
205
  return this.dataMap.chainInfoMap;
215
206
  }
207
+ setChainInfoMap(chainInfoMap) {
208
+ this.dataMap.chainInfoMap = chainInfoMap;
209
+ }
216
210
  getEvmChainInfoMap() {
217
211
  const result = {};
218
212
  Object.values(this.getChainInfoMap()).forEach(chainInfo => {
@@ -269,6 +263,9 @@ class ChainService {
269
263
  getChainStateMap() {
270
264
  return this.dataMap.chainStateMap;
271
265
  }
266
+ setChainStateMap(chainStateMap) {
267
+ this.dataMap.chainStateMap = chainStateMap;
268
+ }
272
269
  getChainStateByKey(key) {
273
270
  return this.dataMap.chainStateMap[key];
274
271
  }
@@ -521,10 +518,10 @@ class ChainService {
521
518
  await this.initChains();
522
519
  this.chainInfoMapSubject.next(this.getChainInfoMap());
523
520
  this.assetRegistrySubject.next(this.getAssetRegistry());
521
+ this.initAssetRefMap();
524
522
  this.xcmRefMapSubject.next(this.xcmRefMap);
525
523
  await this.initApis();
526
524
  await this.initAssetSettings();
527
- this.initAssetRefMap();
528
525
  await this.autoEnableTokens();
529
526
  }
530
527
  initAssetRefMap() {
@@ -557,80 +554,25 @@ class ChainService {
557
554
  console.error('Error fetching latest chain data');
558
555
  }
559
556
  }
560
- handleLatestAssetRef(latestBlockedAssetRefList, latestAssetRefMap) {
561
- const updatedAssetRefMap = {
562
- ..._chainList.AssetRefMap
563
- };
564
- if (latestAssetRefMap) {
565
- for (const [assetRefKey, assetRef] of Object.entries(latestAssetRefMap)) {
566
- updatedAssetRefMap[assetRefKey] = assetRef;
567
- }
568
- }
569
- latestBlockedAssetRefList.forEach(blockedAssetRef => {
570
- delete updatedAssetRefMap[blockedAssetRef];
571
- });
572
- this.dataMap.assetRefMap = updatedAssetRefMap;
573
- this.xcmRefMapSubject.next(this.xcmRefMap);
574
- this.swapRefMapSubject.next(this.swapRefMap);
575
- this.logger.log('Finished updating latest asset ref');
576
- }
577
- handleLatestPriceId(latestPriceIds) {
578
- let isUpdated = false;
579
- Object.entries(latestPriceIds).forEach(_ref8 => {
580
- let [slug, priceId] = _ref8;
581
- if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
582
- isUpdated = true;
583
- this.dataMap.assetRegistry[slug].priceId = priceId;
584
- }
585
- });
586
- if (isUpdated) {
587
- this.assetRegistrySubject.next(this.dataMap.assetRegistry);
588
- this.eventService.emit('asset.updateState', '');
589
- }
590
- this.logger.log('Finished updating latest price IDs');
591
- }
592
- handleLatestAssetData(latestAssetInfo, latestAssetLogoMap) {
593
- try {
594
- if (latestAssetInfo) {
595
- const latestAssetPatch = JSON.stringify(latestAssetInfo);
596
- if (this.assetMapPatch !== latestAssetPatch) {
597
- const assetRegistry = filterAssetInfoMap(this.getChainInfoMap(), Object.assign({}, this.dataMap.assetRegistry, latestAssetInfo));
598
- this.assetMapPatch = latestAssetPatch;
599
- this.dataMap.assetRegistry = assetRegistry;
600
- this.assetRegistrySubject.next(assetRegistry);
601
- this.autoEnableTokens().then(() => {
602
- this.eventService.emit('asset.updateState', '');
603
- }).catch(console.error);
604
- }
605
- }
606
- if (latestAssetLogoMap) {
607
- const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
608
- if (this.assetLogoPatch !== latestAssetLogoPatch) {
609
- const logoMap = {
610
- ..._chainList.AssetLogoMap,
611
- ...latestAssetLogoMap
612
- };
613
- this.assetLogoPatch = latestAssetLogoPatch;
614
- this.assetLogoMapSubject.next(logoMap);
615
- }
616
- }
617
- if (latestAssetLogoMap) {
618
- const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
619
- if (this.assetLogoPatch !== latestAssetLogoPatch) {
620
- const logoMap = {
621
- ..._chainList.AssetLogoMap,
622
- ...latestAssetLogoMap
623
- };
624
- this.assetLogoPatch = latestAssetLogoPatch;
625
- this.assetLogoMapSubject.next(logoMap);
626
- }
627
- }
628
- } catch (e) {
629
- console.error('Error fetching latest asset data');
630
- }
631
- this.eventService.emit('asset.online.ready', true);
632
- this.logger.log('Finished updating latest asset');
633
- }
557
+
558
+ // handleLatestPriceId (latestPriceIds: Record<string, string | null>) {
559
+ // let isUpdated = false;
560
+ //
561
+ // Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
562
+ // if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
563
+ // isUpdated = true;
564
+ // this.dataMap.assetRegistry[slug].priceId = priceId;
565
+ // }
566
+ // });
567
+ //
568
+ // if (isUpdated) {
569
+ // this.assetRegistrySubject.next(this.dataMap.assetRegistry);
570
+ // this.eventService.emit('asset.updateState', '');
571
+ // }
572
+ //
573
+ // this.logger.log('Finished updating latest price IDs');
574
+ // }
575
+
634
576
  async autoEnableTokens() {
635
577
  const autoEnableTokens = Object.values(this.dataMap.assetRegistry).filter(asset => (0, _utils._isAssetAutoEnable)(asset));
636
578
  const assetSettings = this.assetSettingSubject.value;
@@ -664,22 +606,19 @@ class ChainService {
664
606
  this.logger.log('Finished updating latest ledger generic allow chains');
665
607
  }
666
608
  handleLatestData() {
667
- this.fetchLatestAssetData().then(_ref9 => {
668
- let [latestAssetInfo, latestAssetLogoMap] = _ref9;
669
- this.eventService.waitAssetReady.then(() => {
670
- this.handleLatestAssetData(latestAssetInfo, latestAssetLogoMap);
671
- }).catch(console.error);
672
- }).catch(console.error);
673
609
  this.fetchLatestChainData().then(latestChainInfo => {
610
+ this.lockChainInfoMap = true; // do not need to check current lockChainInfoMap because all remains action is fast enough and don't affect this feature.
674
611
  this.handleLatestChainData(latestChainInfo);
675
- }).catch(console.error);
676
- this.fetchLatestAssetRef().then(_ref10 => {
677
- let [latestAssetRef, latestAssetRefMap] = _ref10;
678
- this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
679
- }).catch(console.error);
680
- this.fetchLatestPriceIdsData().then(latestPriceIds => {
681
- this.handleLatestPriceId(latestPriceIds);
682
- }).catch(console.error);
612
+ this.lockChainInfoMap = false;
613
+ }).catch(e => {
614
+ this.lockChainInfoMap = false;
615
+ console.error('Error update latest chain data', e);
616
+ });
617
+
618
+ // this.fetchLatestPriceIdsData().then((latestPriceIds) => {
619
+ // this.handleLatestPriceId(latestPriceIds);
620
+ // }).catch(console.error);
621
+
683
622
  this.fetchLatestLedgerGenericAllowChains().then(latestledgerGenericAllowChains => {
684
623
  this.handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains);
685
624
  }).catch(console.error);
@@ -687,12 +626,12 @@ class ChainService {
687
626
  async initApis() {
688
627
  const chainInfoMap = this.getChainInfoMap();
689
628
  const chainStateMap = this.getChainStateMap();
690
- await Promise.all(Object.entries(chainInfoMap).filter(_ref11 => {
629
+ await Promise.all(Object.entries(chainInfoMap).filter(_ref8 => {
691
630
  var _chainStateMap$slug;
692
- let [slug] = _ref11;
631
+ let [slug] = _ref8;
693
632
  return (_chainStateMap$slug = chainStateMap[slug]) === null || _chainStateMap$slug === void 0 ? void 0 : _chainStateMap$slug.active;
694
- }).map(_ref12 => {
695
- let [, chainInfo] = _ref12;
633
+ }).map(_ref9 => {
634
+ let [, chainInfo] = _ref9;
696
635
  try {
697
636
  return this.initApiForChain(chainInfo);
698
637
  } catch (e) {
@@ -939,17 +878,10 @@ class ChainService {
939
878
  // }
940
879
  }
941
880
 
942
- async fetchLatestAssetData() {
943
- return await Promise.all([(0, _utils.fetchPatchData)('ChainAsset.json'), (0, _utils.fetchPatchData)('AssetLogoMap.json')]);
944
- }
945
-
946
881
  // @ts-ignore
947
882
  async fetchLatestPriceIdsData() {
948
883
  return await (0, _utils2.fetchStaticData)('chain-assets/price-map');
949
884
  }
950
- async fetchLatestAssetRef() {
951
- return await Promise.all([(0, _utils2.fetchStaticData)('chain-assets/disabled-xcm-channels'), (0, _utils.fetchPatchData)('AssetRef.json')]);
952
- }
953
885
  async fetchLatestLedgerGenericAllowChains() {
954
886
  return (await (0, _utils2.fetchStaticData)('chains/ledger-generic-allow-chains')) || [];
955
887
  }
@@ -1097,13 +1029,41 @@ class ChainService {
1097
1029
  });
1098
1030
  }
1099
1031
  } else {
1100
- // Todo: Remove chain from storage
1032
+ var _storedChainInfo$bitc2;
1033
+ // added chain from patch
1034
+ this.dataMap.chainStateMap[storedSlug] = {
1035
+ currentProvider: storedChainInfo.currentProvider,
1036
+ slug: storedSlug,
1037
+ active: storedChainInfo.active,
1038
+ manualTurnOff
1039
+ };
1040
+ this.updateChainConnectionStatus(storedSlug, _types3._ChainConnectionStatus.DISCONNECTED);
1041
+ newStorageData.push({
1042
+ ...storedChainSettingMap[storedSlug],
1043
+ active: storedChainInfo.active,
1044
+ currentProvider: storedChainInfo.currentProvider,
1045
+ manualTurnOff
1046
+ });
1047
+ mergedChainInfoMap[storedSlug] = {
1048
+ slug: storedSlug,
1049
+ name: storedChainInfo.name,
1050
+ providers: storedChainInfo.providers,
1051
+ evmInfo: storedChainInfo.evmInfo,
1052
+ substrateInfo: storedChainInfo.substrateInfo,
1053
+ bitcoinInfo: (_storedChainInfo$bitc2 = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc2 !== void 0 ? _storedChainInfo$bitc2 : null,
1054
+ tonInfo: storedChainInfo.tonInfo,
1055
+ isTestnet: storedChainInfo.isTestnet,
1056
+ chainStatus: storedChainInfo.chainStatus,
1057
+ icon: storedChainInfo.icon,
1058
+ extraInfo: storedChainInfo.extraInfo
1059
+ };
1060
+ deprecatedChainMap[storedSlug] = storedSlug; // todo: set a better name
1101
1061
  }
1102
1062
  }
1103
1063
 
1104
1064
  // Fill in the missing chainState and storageData (new chains never before seen)
1105
- Object.entries(mergedChainInfoMap).forEach(_ref13 => {
1106
- let [slug, chainInfo] = _ref13;
1065
+ Object.entries(mergedChainInfoMap).forEach(_ref10 => {
1066
+ let [slug, chainInfo] = _ref10;
1107
1067
  if (!(slug in this.dataMap.chainStateMap)) {
1108
1068
  this.dataMap.chainStateMap[slug] = {
1109
1069
  currentProvider: Object.keys(chainInfo.providers)[0],
@@ -1181,8 +1141,8 @@ class ChainService {
1181
1141
  // Fill out zk assets from finalAssetRegistry if not supported
1182
1142
  if (!_utils2.MODULE_SUPPORT.MANTA_ZK) {
1183
1143
  const zkAssets = [];
1184
- Object.entries(finalAssetRegistry).forEach(_ref14 => {
1185
- let [slug, assets] = _ref14;
1144
+ Object.entries(finalAssetRegistry).forEach(_ref11 => {
1145
+ let [slug, assets] = _ref11;
1186
1146
  if ((0, _utils._isMantaZkAsset)(assets)) {
1187
1147
  zkAssets.push(slug);
1188
1148
  delete finalAssetRegistry[slug];
@@ -730,8 +730,6 @@ function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
730
730
  }
731
731
  if (currentChainInfo) {
732
732
  needUpdate = true;
733
- currentChainInfo.extraInfo = latestChainInfo.extraInfo;
734
- currentChainInfo.chainStatus = latestChainInfo.chainStatus;
735
733
  if (Object.keys(currentChainInfo.providers).length === 0) {
736
734
  currentChainInfo.chainStatus = _types._ChainStatus.INACTIVE;
737
735
  }
@@ -10,10 +10,14 @@ exports.fetchPatchData = fetchPatchData;
10
10
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
11
11
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
12
12
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
13
- const ChainListVersion = '0.2.62';
14
- async function fetchPatchData(slug) {
13
+ const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
14
+ const ChainListVersion = '0.2.95'; // update this when build chainlist
15
+
16
+ // todo: move this interface to chainlist
17
+
18
+ async function fetchPatchData() {
15
19
  try {
16
- const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
20
+ const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${fetchFile}`);
17
21
  const timeout = new Promise(resolve => {
18
22
  const id = setTimeout(() => {
19
23
  clearTimeout(id);
@@ -308,7 +308,7 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
308
308
  for (const collator of _allCollators) {
309
309
  const _collatorAddress = collator[0].toHuman();
310
310
  const collatorAddress = _collatorAddress[0];
311
- if (allCollatorsPool.includes(collatorAddress)) {
311
+ if (selectedCollators.includes(collatorAddress)) {
312
312
  const collatorInfo = collator[1].toPrimitive();
313
313
  const bnTotalStake = new _util.BN(collatorInfo.totalCounted);
314
314
  const bnOwnStake = new _util.BN(collatorInfo.bond);
@@ -331,7 +331,7 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
331
331
  }
332
332
  }
333
333
  await Promise.all(allCollators.map(async collator => {
334
- if (allCollatorsPool.includes(collator.address)) {
334
+ if (selectedCollators.includes(collator.address)) {
335
335
  // noted: number of blocks = total points / points per block
336
336
  const _collatorPoints = await apiProps.api.query.parachainStaking.awardedPts(parseInt(round.current) - 1, collator.address);
337
337
  const collatorPoints = _collatorPoints.toPrimitive();
@@ -362,10 +362,11 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
362
362
  async getParachainPoolTargets() {
363
363
  const apiProps = await this.substrateApi.isReady;
364
364
  const allCollators = [];
365
- const [_allCollators, _collatorCommission] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission()]);
365
+ const [_allCollators, _collatorCommission, _selectedCandidates] = await Promise.all([apiProps.api.query.parachainStaking.candidateInfo.entries(), apiProps.api.query.parachainStaking.collatorCommission(), apiProps.api.query.parachainStaking.selectedCandidates()]);
366
366
  const maxDelegationPerCollator = apiProps.api.consts.parachainStaking.maxTopDelegationsPerCandidate.toString();
367
367
  const rawCollatorCommission = _collatorCommission.toHuman();
368
368
  const collatorCommission = parseFloat(rawCollatorCommission.split('%')[0]);
369
+ const selectedCollators = _selectedCandidates.toPrimitive();
369
370
  for (const collator of _allCollators) {
370
371
  const _collatorAddress = collator[0].toHuman();
371
372
  const collatorAddress = _collatorAddress[0];
@@ -375,20 +376,22 @@ class ParaNativeStakingPoolHandler extends _basePara.default {
375
376
  const bnOtherStake = bnTotalStake.sub(bnOwnStake);
376
377
  const bnMinBond = new _util.BN(collatorInfo.lowestTopDelegationAmount);
377
378
  const maxNominatorRewarded = parseInt(maxDelegationPerCollator);
378
- allCollators.push({
379
- commission: 0,
380
- expectedReturn: 0,
381
- address: collatorAddress,
382
- totalStake: bnTotalStake.toString(),
383
- ownStake: bnOwnStake.toString(),
384
- otherStake: bnOtherStake.toString(),
385
- nominatorCount: collatorInfo.delegationCount,
386
- blocked: false,
387
- isVerified: false,
388
- minBond: bnMinBond.toString(),
389
- chain: this.chain,
390
- isCrowded: collatorInfo.delegationCount ? collatorInfo.delegationCount >= maxNominatorRewarded : false
391
- });
379
+ if (selectedCollators.includes(collatorAddress)) {
380
+ allCollators.push({
381
+ commission: 0,
382
+ expectedReturn: 0,
383
+ address: collatorAddress,
384
+ totalStake: bnTotalStake.toString(),
385
+ ownStake: bnOwnStake.toString(),
386
+ otherStake: bnOtherStake.toString(),
387
+ nominatorCount: collatorInfo.delegationCount,
388
+ blocked: false,
389
+ isVerified: false,
390
+ minBond: bnMinBond.toString(),
391
+ chain: this.chain,
392
+ isCrowded: collatorInfo.delegationCount ? collatorInfo.delegationCount >= maxNominatorRewarded : false
393
+ });
394
+ }
392
395
  }
393
396
  const extraInfoMap = {};
394
397
  await Promise.all(allCollators.map(async collator => {
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EnvironmentStoreSubject = void 0;
7
+ var _Base = require("@subwallet/extension-base/services/keyring-service/context/stores/Base");
8
+ var _stores = require("@subwallet/extension-base/stores");
9
+ var _rxjs = require("rxjs");
10
+ // Copyright 2019-2022 @subwallet/extension-base
11
+ // SPDX-License-Identifier: Apache-2.0
12
+
13
+ class EnvironmentStoreSubject extends _Base.StoreSubject {
14
+ store = new _stores.EnvironmentStore();
15
+ subject = new _rxjs.BehaviorSubject({});
16
+ key = 'Environment';
17
+ defaultValue = {};
18
+ }
19
+ exports.EnvironmentStoreSubject = EnvironmentStoreSubject;
@@ -8,6 +8,7 @@ exports.recalculateGasPrice = exports.parseInfuraFee = exports.fetchSubWalletFee
8
8
  var _constants = require("@subwallet/extension-base/constants");
9
9
  var _utils = require("@subwallet/extension-base/utils");
10
10
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
11
+ var _polygonBridge = require("../../balance-service/transfer/xcm/polygonBridge");
11
12
  // Copyright 2019-2022 @subwallet/extension-base
12
13
  // SPDX-License-Identifier: Apache-2.0
13
14
 
@@ -106,6 +107,19 @@ const calculateGasFeeParams = async function (web3, networkKey) {
106
107
  } catch (e) {}
107
108
  }
108
109
  try {
110
+ if (networkKey === 'polygonzkEvm_cardona' || networkKey === 'polygonZkEvm') {
111
+ const isTestnet = networkKey === 'polygonzkEvm_cardona';
112
+ const gasDomain = isTestnet ? _polygonBridge.POLYGON_GAS_INDEXER.TESTNET : _polygonBridge.POLYGON_GAS_INDEXER.MAINNET;
113
+ const gasResponse = await fetch(`${gasDomain}`).then(res => res.json());
114
+ const gasPriceInWei = gasResponse.standard * 1e9 + 200000;
115
+ return {
116
+ gasPrice: gasPriceInWei.toString(),
117
+ maxFeePerGas: undefined,
118
+ maxPriorityFeePerGas: undefined,
119
+ baseGasFee: undefined,
120
+ busyNetwork: false
121
+ };
122
+ }
109
123
  const numBlock = 20;
110
124
  const rewardPercent = [];
111
125
  for (let i = 0; i <= 100; i = i + 5) {
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ONE_DAY_MILLISECOND = exports.NotificationTitleMap = exports.NotificationDescriptionMap = void 0;
7
- var _interfaces = require("@subwallet/extension-base/services/inapp-notification-service/interfaces");
8
- var _utils = require("@subwallet/extension-base/services/inapp-notification-service/utils");
7
+ var _interfaces = require("./interfaces");
8
+ var _utils = require("./utils");
9
9
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
@@ -15,7 +15,8 @@ const NotificationTitleMap = {
15
15
  [_interfaces.NotificationActionType.SEND]: '[{{accountName}}] SEND {{tokenSymbol}}',
16
16
  [_interfaces.NotificationActionType.RECEIVE]: '[{{accountName}}] RECEIVE {{tokenSymbol}}',
17
17
  [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
18
- [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: '[{{accountName}}] CLAIM {{tokenSymbol}}'
18
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
19
+ [_interfaces.NotificationActionType.CLAIM_POLYGON_BRIDGE]: '[{{accountName}}] CLAIM {{tokenSymbol}}'
19
20
  };
20
21
  exports.NotificationTitleMap = NotificationTitleMap;
21
22
  const NotificationDescriptionMap = {
@@ -24,7 +25,8 @@ const NotificationDescriptionMap = {
24
25
  [_interfaces.NotificationActionType.SEND]: _utils.getSendDescription,
25
26
  [_interfaces.NotificationActionType.RECEIVE]: _utils.getReceiveDescription,
26
27
  [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: _utils.getAvailBridgeClaimDescription,
27
- [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: _utils.getAvailBridgeClaimDescription
28
+ [_interfaces.NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: _utils.getAvailBridgeClaimDescription,
29
+ [_interfaces.NotificationActionType.CLAIM_POLYGON_BRIDGE]: _utils.getPolygonBridgeClaimDescription
28
30
  };
29
31
  exports.NotificationDescriptionMap = NotificationDescriptionMap;
30
32
  const ONE_DAY_MILLISECOND = 1000 * 24 * 60 * 60;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.InappNotificationService = void 0;
7
+ var _chainList = require("@subwallet/chain-list");
7
8
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
8
9
  var _constants = require("@subwallet/extension-base/constants");
9
10
  var _remindNotificationTime = require("@subwallet/extension-base/constants/remind-notification-time");
@@ -110,6 +111,28 @@ class InappNotificationService {
110
111
  }
111
112
  }
112
113
  }
114
+ if ([_interfaces.NotificationActionType.CLAIM_POLYGON_BRIDGE].includes(candidateNotification.actionType)) {
115
+ const {
116
+ address,
117
+ metadata,
118
+ time
119
+ } = candidateNotification;
120
+ const candidateMetadata = metadata;
121
+ const remindTime = (0, _utils.hrsToMillisecond)(remindTimeConfigInHrs[candidateNotification.actionType]);
122
+ for (const notification of comparedNotifications) {
123
+ if (notification.address !== address) {
124
+ continue;
125
+ }
126
+ if (time - notification.time >= remindTime) {
127
+ continue;
128
+ }
129
+ const comparedMetadata = notification.metadata;
130
+ const sameNotification = candidateMetadata._id === comparedMetadata._id && candidateMetadata.transactionHash === comparedMetadata.transactionHash && candidateMetadata.counter === comparedMetadata.counter;
131
+ if (sameNotification) {
132
+ return false;
133
+ }
134
+ }
135
+ }
113
136
  return true;
114
137
  }
115
138
  async validateAndWriteNotificationsToDB(notifications, address) {
@@ -131,17 +154,23 @@ class InappNotificationService {
131
154
  }
132
155
  await this.dbService.upsertNotifications(passNotifications);
133
156
  }
134
- cronCreateAvailBridgeClaimNotification() {
157
+ cronCreateBridgeClaimNotification() {
135
158
  clearTimeout(this.refeshAvailBridgeClaimTimeOut);
136
159
  this.createAvailBridgeClaimNotification();
137
- this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateAvailBridgeClaimNotification.bind(this), _constants.CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
160
+ this.createPolygonClaimableTransactions().catch(err => {
161
+ console.error('Error:', err);
162
+ });
163
+ this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateBridgeClaimNotification.bind(this), _constants.CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
138
164
  }
139
- createAvailBridgeClaimNotification() {
165
+ getCategorizedAddresses() {
140
166
  const addresses = this.keyringService.context.getAllAddresses();
167
+ return (0, _utils2.categoryAddresses)(addresses);
168
+ }
169
+ createAvailBridgeClaimNotification() {
141
170
  const {
142
171
  evm: evmAddresses,
143
172
  substrate: substrateAddresses
144
- } = (0, _utils2.categoryAddresses)(addresses);
173
+ } = this.getCategorizedAddresses();
145
174
  const chainAssets = this.chainService.getAssetRegistry();
146
175
  let ASSET_TYPE;
147
176
  (function (ASSET_TYPE) {
@@ -215,7 +244,7 @@ class InappNotificationService {
215
244
  title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
216
245
  description: _consts.NotificationDescriptionMap[actionType]((0, _utils2.formatNumber)(amount, decimals), symbol),
217
246
  time: timestamp,
218
- extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_AVAIL_BRIDGE,
247
+ extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_BRIDGE,
219
248
  isRead: false,
220
249
  actionType,
221
250
  metadata
@@ -223,6 +252,81 @@ class InappNotificationService {
223
252
  });
224
253
  await this.validateAndWriteNotificationsToDB(notifications, address);
225
254
  }
255
+
256
+ // Polygon Claimable Handle
257
+ async createPolygonClaimableTransactions() {
258
+ const {
259
+ evm: evmAddresses
260
+ } = this.getCategorizedAddresses();
261
+ const etherChains = [_chainList.COMMON_ASSETS.ETH, _chainList.COMMON_ASSETS.ETH_SEPOLIA];
262
+ const polygonAssets = Object.values(this.chainService.getAssetRegistry()).filter(asset => etherChains.includes(asset.slug));
263
+ for (const polygonAsset of polygonAssets) {
264
+ const isTestnet = (polygonAsset === null || polygonAsset === void 0 ? void 0 : polygonAsset.originChain) === _chainList.COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
265
+ if (evmAddresses.length === 0) {
266
+ return;
267
+ }
268
+ for (const address of evmAddresses) {
269
+ const response = await (0, _utils.fetchPolygonBridgeTransactions)(address, isTestnet);
270
+ if (response && response.success) {
271
+ await this.processPolygonClaimNotification(address, response.result, polygonAsset);
272
+ }
273
+ }
274
+ }
275
+ }
276
+ async processPolygonClaimNotification(address, transactions, token) {
277
+ var _token$decimals2;
278
+ const actionType = _interfaces.NotificationActionType.CLAIM_POLYGON_BRIDGE;
279
+ const timestamp = Date.now();
280
+ const symbol = token.symbol;
281
+ const decimals = (_token$decimals2 = token.decimals) !== null && _token$decimals2 !== void 0 ? _token$decimals2 : 0;
282
+ const notifications = transactions.map(transaction => {
283
+ const {
284
+ _id,
285
+ amounts,
286
+ counter,
287
+ destinationNetwork,
288
+ originTokenAddress,
289
+ originTokenNetwork,
290
+ receiver,
291
+ sourceNetwork,
292
+ status,
293
+ transactionHash,
294
+ transactionInitiator,
295
+ userAddress
296
+ } = transaction;
297
+ const metadata = {
298
+ chainSlug: token.originChain,
299
+ tokenSlug: token.slug,
300
+ _id,
301
+ amounts,
302
+ counter,
303
+ destinationNetwork,
304
+ originTokenAddress,
305
+ originTokenNetwork,
306
+ receiver,
307
+ sourceNetwork,
308
+ status,
309
+ transactionHash,
310
+ transactionInitiator,
311
+ userAddress
312
+ };
313
+ return {
314
+ id: `${actionType}___${_id}___${timestamp}`,
315
+ address: address,
316
+ title: _consts.NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
317
+ description: _consts.NotificationDescriptionMap[actionType]((0, _utils2.formatNumber)(amounts[0], decimals), symbol),
318
+ time: timestamp,
319
+ extrinsicType: _KoniTypes.ExtrinsicType.CLAIM_BRIDGE,
320
+ isRead: false,
321
+ actionType,
322
+ metadata
323
+ };
324
+ });
325
+ await this.validateAndWriteNotificationsToDB(notifications, address);
326
+ }
327
+
328
+ // Polygon Claimable Handle
329
+
226
330
  async start() {
227
331
  if (this.status === _types.ServiceStatus.STARTED) {
228
332
  return;
@@ -235,7 +339,7 @@ class InappNotificationService {
235
339
  }
236
340
  async startCron() {
237
341
  this.cleanUpOldNotifications().catch(console.error);
238
- this.cronCreateAvailBridgeClaimNotification();
342
+ this.cronCreateBridgeClaimNotification();
239
343
  return Promise.resolve();
240
344
  }
241
345
  async stop() {