@subwallet/extension-base 1.3.7-0 → 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 (90) hide show
  1. package/background/KoniTypes.d.ts +7 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/core/substrate/xcm-parser.js +16 -2
  5. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  6. package/cjs/koni/background/handlers/Extension.js +42 -3
  7. package/cjs/koni/background/handlers/State.js +11 -2
  8. package/cjs/packageInfo.js +1 -1
  9. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  10. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  11. package/cjs/services/chain-online-service/constants.js +32 -0
  12. package/cjs/services/chain-online-service/index.js +190 -0
  13. package/cjs/services/chain-service/index.js +87 -127
  14. package/cjs/services/chain-service/utils/index.js +0 -2
  15. package/cjs/services/chain-service/utils/patch.js +7 -3
  16. package/cjs/services/fee-service/utils/index.js +14 -0
  17. package/cjs/services/inapp-notification-service/consts.js +6 -4
  18. package/cjs/services/inapp-notification-service/index.js +110 -6
  19. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  20. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  21. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  22. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  23. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  24. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  25. package/cjs/services/migration-service/scripts/index.js +3 -1
  26. package/cjs/services/setting-service/SettingService.js +8 -0
  27. package/cjs/services/setting-service/constants.js +2 -1
  28. package/cjs/services/storage-service/DatabaseService.js +3 -0
  29. package/cjs/services/transaction-service/index.js +1 -1
  30. package/cjs/stores/ChainlistStore.js +18 -0
  31. package/cjs/types/index.js +11 -0
  32. package/cjs/utils/account/transform.js +1 -1
  33. package/core/substrate/xcm-parser.d.ts +1 -0
  34. package/core/substrate/xcm-parser.js +15 -2
  35. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  36. package/koni/api/contract-handler/utils/index.js +12 -0
  37. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  38. package/koni/background/handlers/Extension.d.ts +2 -0
  39. package/koni/background/handlers/Extension.js +43 -4
  40. package/koni/background/handlers/State.d.ts +2 -0
  41. package/koni/background/handlers/State.js +11 -2
  42. package/package.json +56 -14
  43. package/packageInfo.js +1 -1
  44. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  45. package/services/balance-service/transfer/xcm/index.js +29 -1
  46. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  47. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  48. package/services/chain-online-service/constants.d.ts +4 -0
  49. package/services/chain-online-service/constants.js +23 -0
  50. package/services/chain-online-service/index.d.ts +22 -0
  51. package/services/chain-online-service/index.js +182 -0
  52. package/services/chain-service/index.d.ts +6 -7
  53. package/services/chain-service/index.js +78 -116
  54. package/services/chain-service/utils/index.js +0 -2
  55. package/services/chain-service/utils/patch.d.ts +16 -1
  56. package/services/chain-service/utils/patch.js +7 -3
  57. package/services/fee-service/utils/index.js +14 -0
  58. package/services/inapp-notification-service/consts.d.ts +3 -1
  59. package/services/inapp-notification-service/consts.js +6 -4
  60. package/services/inapp-notification-service/index.d.ts +10 -2
  61. package/services/inapp-notification-service/index.js +111 -7
  62. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  63. package/services/inapp-notification-service/interfaces.js +7 -0
  64. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  65. package/services/inapp-notification-service/utils/avail.js +73 -0
  66. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  67. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  68. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  69. package/services/inapp-notification-service/utils/index.js +6 -0
  70. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  71. package/services/inapp-notification-service/utils/polygon.js +54 -0
  72. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  73. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  74. package/services/migration-service/scripts/index.js +3 -1
  75. package/services/setting-service/SettingService.d.ts +4 -0
  76. package/services/setting-service/SettingService.js +8 -0
  77. package/services/setting-service/constants.js +2 -1
  78. package/services/storage-service/DatabaseService.d.ts +1 -0
  79. package/services/storage-service/DatabaseService.js +3 -0
  80. package/services/transaction-service/index.js +1 -1
  81. package/stores/ChainlistStore.d.ts +7 -0
  82. package/stores/ChainlistStore.js +10 -0
  83. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  84. package/types/index.d.ts +1 -0
  85. package/types/index.js +1 -0
  86. package/types/notification/index.d.ts +5 -0
  87. package/utils/account/transform.js +1 -1
  88. package/services/inapp-notification-service/utils.d.ts +0 -55
  89. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  90. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ChainOnlineService = void 0;
7
+ var _chainList = require("@subwallet/chain-list");
8
+ var _constants = require("@subwallet/extension-base/services/chain-online-service/constants");
9
+ var _chainService = require("@subwallet/extension-base/services/chain-service");
10
+ var _types = require("@subwallet/extension-base/services/chain-service/types");
11
+ var _utils = require("@subwallet/extension-base/services/chain-service/utils");
12
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
13
+ // SPDX-License-Identifier: Apache-2.0
14
+
15
+ class ChainOnlineService {
16
+ constructor(chainService, settingService, eventService, dbService) {
17
+ this.chainService = chainService;
18
+ this.settingService = settingService;
19
+ this.eventService = eventService;
20
+ this.dbService = dbService;
21
+ this.firstApplied = false;
22
+ }
23
+ validatePatchWithHash(latestPatch) {
24
+ const {
25
+ ChainAsset,
26
+ ChainAssetHashMap,
27
+ ChainInfo,
28
+ ChainInfoHashMap
29
+ } = latestPatch;
30
+ for (const [chainSlug, chain] of Object.entries(ChainInfo)) {
31
+ if ((0, _constants.md5HashChainInfo)(chain) !== ChainInfoHashMap[chainSlug]) {
32
+ return false;
33
+ }
34
+ }
35
+ for (const [assetSlug, asset] of Object.entries(ChainAsset)) {
36
+ if ((0, _constants.md5HashChainAsset)(asset) !== ChainAssetHashMap[assetSlug]) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ }
42
+ validatePatchBeforeStore(candidateChainInfoMap, candidateAssetRegistry, latestPatch) {
43
+ for (const [chainSlug, chainHash] of Object.entries(latestPatch.ChainInfoHashMap)) {
44
+ if ((0, _constants.md5HashChainInfo)(candidateChainInfoMap[chainSlug]) !== chainHash) {
45
+ return false;
46
+ }
47
+ }
48
+ for (const [assetSlug, assetHash] of Object.entries(latestPatch.ChainAssetHashMap)) {
49
+ if (!candidateAssetRegistry[assetSlug]) {
50
+ if (!latestPatch.ChainInfo[assetSlug]) {
51
+ // assets are not existed in case chain is removed
52
+ continue;
53
+ }
54
+ return false;
55
+ }
56
+ if ((0, _constants.md5HashChainAsset)(candidateAssetRegistry[assetSlug]) !== assetHash) {
57
+ return false;
58
+ }
59
+ }
60
+ return true;
61
+ }
62
+ async handleLatestPatch(latestPatch) {
63
+ try {
64
+ var _await$this$settingSe;
65
+ // 1. validate fetch data with its hash
66
+ const isSafePatch = this.validatePatchWithHash(latestPatch);
67
+ const {
68
+ AssetLogoMap: latestAssetLogoMap,
69
+ ChainAsset: latestAssetInfo,
70
+ ChainInfo: latestChainInfo,
71
+ ChainLogoMap: latestChainLogoMap,
72
+ patchVersion: latestPatchVersion
73
+ } = latestPatch;
74
+ const currentPatchVersion = ((_await$this$settingSe = await this.settingService.getChainlistSetting()) === null || _await$this$settingSe === void 0 ? void 0 : _await$this$settingSe.patchVersion) || '';
75
+ const oldChainInfoMap = structuredClone(this.chainService.getChainInfoMap());
76
+ const oldAssetRegistry = structuredClone(this.chainService.getAssetRegistry());
77
+ let chainInfoMap = structuredClone(this.chainService.getChainInfoMap());
78
+ let assetRegistry = structuredClone(this.chainService.getAssetRegistry());
79
+ const currentChainStateMap = structuredClone(this.chainService.getChainStateMap());
80
+ const currentChainStatusMap = structuredClone(this.chainService.getChainStatusMap());
81
+ let addedChain = [];
82
+ if (isSafePatch && (!this.firstApplied || currentPatchVersion !== latestPatchVersion)) {
83
+ this.firstApplied = true;
84
+
85
+ // 2. merge data map
86
+ if (latestChainInfo && Object.keys(latestChainInfo).length > 0) {
87
+ chainInfoMap = Object.assign({}, oldChainInfoMap, latestChainInfo);
88
+ const [currentChainStateKey, newChainKey] = [Object.keys(currentChainStateMap), Object.keys(chainInfoMap)];
89
+ addedChain = newChainKey.filter(chain => !currentChainStateKey.includes(chain));
90
+ addedChain.forEach(key => {
91
+ currentChainStateMap[key] = {
92
+ active: false,
93
+ currentProvider: (0, _utils.randomizeProvider)(chainInfoMap[key].providers).providerKey,
94
+ manualTurnOff: false,
95
+ slug: key
96
+ };
97
+ currentChainStatusMap[key] = {
98
+ slug: key,
99
+ connectionStatus: _types._ChainConnectionStatus.DISCONNECTED,
100
+ lastUpdated: Date.now()
101
+ };
102
+ });
103
+ }
104
+ if (latestAssetInfo && Object.keys(latestAssetInfo).length > 0) {
105
+ assetRegistry = (0, _chainService.filterAssetInfoMap)(oldChainInfoMap, Object.assign({}, oldAssetRegistry, latestAssetInfo), addedChain);
106
+ }
107
+
108
+ // 3. validate data before write
109
+ const isCorrectPatch = this.validatePatchBeforeStore(chainInfoMap, assetRegistry, latestPatch);
110
+
111
+ // 4. write to subject
112
+ if (isCorrectPatch) {
113
+ this.chainService.setChainInfoMap(chainInfoMap);
114
+ this.chainService.subscribeChainInfoMap().next(chainInfoMap);
115
+ this.chainService.setAssetRegistry(assetRegistry);
116
+ this.chainService.subscribeAssetRegistry().next(assetRegistry);
117
+ this.chainService.autoEnableTokens().then(() => {
118
+ this.eventService.emit('asset.updateState', '');
119
+ }).catch(console.error);
120
+ this.chainService.setChainStateMap(currentChainStateMap);
121
+ this.chainService.subscribeChainStateMap().next(currentChainStateMap);
122
+ this.chainService.subscribeChainStatusMap().next(currentChainStatusMap);
123
+ const storedChainInfoList = Object.keys(chainInfoMap).map(chainSlug => {
124
+ return {
125
+ ...chainInfoMap[chainSlug],
126
+ ...currentChainStateMap[chainSlug]
127
+ };
128
+ });
129
+ await this.dbService.bulkUpdateChainStore(storedChainInfoList);
130
+ const addedAssets = [];
131
+
132
+ // todo: the stored asset is lack of adding new assets and edited assets of old chain, update to tracking exactly updated assets from patch online.
133
+ Object.entries(assetRegistry).forEach(_ref => {
134
+ let [slug, asset] = _ref;
135
+ if (addedChain.includes(asset.originChain)) {
136
+ addedAssets.push(asset);
137
+ }
138
+ });
139
+ await this.dbService.bulkUpdateAssetsStore(addedAssets);
140
+ if (latestChainLogoMap) {
141
+ const logoMap = Object.assign({}, _chainList.ChainLogoMap, latestChainLogoMap);
142
+ this.chainService.subscribeChainLogoMap().next(logoMap);
143
+ }
144
+ if (latestAssetLogoMap) {
145
+ const logoMap = Object.assign({}, _chainList.AssetLogoMap, latestAssetLogoMap);
146
+ this.chainService.subscribeAssetLogoMap().next(logoMap);
147
+ }
148
+ this.settingService.setChainlist({
149
+ patchVersion: latestPatchVersion
150
+ });
151
+ }
152
+ }
153
+ } catch (e) {
154
+ console.error('Error fetching latest patch data');
155
+ }
156
+ }
157
+ async fetchLatestPatchData() {
158
+ return await (0, _utils.fetchPatchData)();
159
+ }
160
+ handleLatestPatchData() {
161
+ this.fetchLatestPatchData().then(latestPatch => {
162
+ return new Promise(resolve => {
163
+ if (latestPatch && !this.chainService.getlockChainInfoMap()) {
164
+ this.eventService.waitAssetReady.then(() => {
165
+ this.chainService.setLockChainInfoMap(true);
166
+ this.handleLatestPatch(latestPatch).then(() => this.chainService.setLockChainInfoMap(false)).catch(e => {
167
+ this.chainService.setLockChainInfoMap(false);
168
+ console.error('Error update latest patch', e);
169
+ }).finally(resolve);
170
+ }).catch(e => {
171
+ console.error('Asset fail to ready', e);
172
+ resolve();
173
+ });
174
+ } else {
175
+ resolve();
176
+ }
177
+ });
178
+ }).catch(e => {
179
+ console.error('Error get latest patch or data map is locking', e);
180
+ }).finally(() => {
181
+ this.eventService.emit('asset.online.ready', true);
182
+ });
183
+ }
184
+ checkLatestData() {
185
+ clearInterval(this.refreshLatestChainDataTimeOut);
186
+ this.handleLatestPatchData();
187
+ this.refreshLatestChainDataTimeOut = setInterval(this.handleLatestPatchData.bind(this), _constants.LATEST_CHAIN_PATCH_FETCHING_INTERVAL);
188
+ }
189
+ }
190
+ exports.ChainOnlineService = ChainOnlineService;
@@ -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);
@@ -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;