@subwallet/extension-base 1.3.7-0 → 1.3.9-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 (109) hide show
  1. package/background/KoniTypes.d.ts +11 -5
  2. package/background/KoniTypes.js +1 -1
  3. package/cjs/background/KoniTypes.js +1 -1
  4. package/cjs/core/logic-validation/transfer.js +35 -24
  5. package/cjs/core/substrate/system-pallet.js +1 -1
  6. package/cjs/core/substrate/xcm-parser.js +16 -2
  7. package/cjs/core/utils.js +2 -2
  8. package/cjs/koni/api/contract-handler/utils/index.js +15 -1
  9. package/cjs/koni/background/handlers/Extension.js +158 -86
  10. package/cjs/koni/background/handlers/State.js +11 -2
  11. package/cjs/packageInfo.js +1 -1
  12. package/cjs/services/balance-service/index.js +24 -2
  13. package/cjs/services/balance-service/transfer/smart-contract.js +16 -5
  14. package/cjs/services/balance-service/transfer/xcm/index.js +31 -1
  15. package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +108 -0
  16. package/cjs/services/chain-online-service/constants.js +32 -0
  17. package/cjs/services/chain-online-service/index.js +190 -0
  18. package/cjs/services/chain-service/constants.js +3 -1
  19. package/cjs/services/chain-service/index.js +87 -127
  20. package/cjs/services/chain-service/utils/index.js +0 -2
  21. package/cjs/services/chain-service/utils/patch.js +7 -3
  22. package/cjs/services/fee-service/utils/index.js +14 -0
  23. package/cjs/services/inapp-notification-service/consts.js +6 -4
  24. package/cjs/services/inapp-notification-service/index.js +110 -6
  25. package/cjs/services/inapp-notification-service/interfaces.js +9 -1
  26. package/cjs/services/inapp-notification-service/utils/avail.js +88 -0
  27. package/cjs/services/inapp-notification-service/{utils.js → utils/common.js} +1 -84
  28. package/cjs/services/inapp-notification-service/utils/index.js +38 -0
  29. package/cjs/services/inapp-notification-service/utils/polygon.js +66 -0
  30. package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +37 -0
  31. package/cjs/services/migration-service/scripts/index.js +3 -1
  32. package/cjs/services/setting-service/SettingService.js +8 -0
  33. package/cjs/services/setting-service/constants.js +2 -1
  34. package/cjs/services/storage-service/DatabaseService.js +3 -0
  35. package/cjs/services/transaction-service/index.js +1 -1
  36. package/cjs/stores/ChainlistStore.js +18 -0
  37. package/cjs/types/index.js +11 -0
  38. package/cjs/types/transaction/error.js +1 -0
  39. package/cjs/utils/account/transform.js +1 -1
  40. package/core/logic-validation/transfer.d.ts +2 -1
  41. package/core/logic-validation/transfer.js +36 -25
  42. package/core/substrate/system-pallet.js +1 -1
  43. package/core/substrate/xcm-parser.d.ts +1 -0
  44. package/core/substrate/xcm-parser.js +15 -2
  45. package/core/types.d.ts +1 -0
  46. package/core/utils.js +2 -2
  47. package/koni/api/contract-handler/utils/index.d.ts +2 -0
  48. package/koni/api/contract-handler/utils/index.js +12 -0
  49. package/koni/api/contract-handler/utils/polygon_bridge_abi.json +1004 -0
  50. package/koni/background/handlers/Extension.d.ts +4 -0
  51. package/koni/background/handlers/Extension.js +93 -22
  52. package/koni/background/handlers/State.d.ts +2 -0
  53. package/koni/background/handlers/State.js +11 -2
  54. package/package.json +56 -14
  55. package/packageInfo.js +1 -1
  56. package/services/balance-service/index.d.ts +3 -0
  57. package/services/balance-service/index.js +21 -2
  58. package/services/balance-service/transfer/smart-contract.js +16 -5
  59. package/services/balance-service/transfer/xcm/index.d.ts +1 -0
  60. package/services/balance-service/transfer/xcm/index.js +29 -1
  61. package/services/balance-service/transfer/xcm/polygonBridge.d.ts +22 -0
  62. package/services/balance-service/transfer/xcm/polygonBridge.js +95 -0
  63. package/services/chain-online-service/constants.d.ts +4 -0
  64. package/services/chain-online-service/constants.js +23 -0
  65. package/services/chain-online-service/index.d.ts +22 -0
  66. package/services/chain-online-service/index.js +182 -0
  67. package/services/chain-service/constants.d.ts +1 -0
  68. package/services/chain-service/constants.js +1 -0
  69. package/services/chain-service/index.d.ts +6 -7
  70. package/services/chain-service/index.js +78 -116
  71. package/services/chain-service/utils/index.js +0 -2
  72. package/services/chain-service/utils/patch.d.ts +16 -1
  73. package/services/chain-service/utils/patch.js +7 -3
  74. package/services/fee-service/utils/index.js +14 -0
  75. package/services/inapp-notification-service/consts.d.ts +3 -1
  76. package/services/inapp-notification-service/consts.js +6 -4
  77. package/services/inapp-notification-service/index.d.ts +10 -2
  78. package/services/inapp-notification-service/index.js +111 -7
  79. package/services/inapp-notification-service/interfaces.d.ts +27 -3
  80. package/services/inapp-notification-service/interfaces.js +7 -0
  81. package/services/inapp-notification-service/utils/avail.d.ts +40 -0
  82. package/services/inapp-notification-service/utils/avail.js +73 -0
  83. package/services/inapp-notification-service/utils/common.d.ts +11 -0
  84. package/services/inapp-notification-service/{utils.js → utils/common.js} +1 -72
  85. package/services/inapp-notification-service/utils/index.d.ts +3 -0
  86. package/services/inapp-notification-service/utils/index.js +6 -0
  87. package/services/inapp-notification-service/utils/polygon.d.ts +71 -0
  88. package/services/inapp-notification-service/utils/polygon.js +54 -0
  89. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.d.ts +4 -0
  90. package/services/migration-service/scripts/MigrateTransactionHistoryBridge.js +29 -0
  91. package/services/migration-service/scripts/index.js +3 -1
  92. package/services/setting-service/SettingService.d.ts +4 -0
  93. package/services/setting-service/SettingService.js +8 -0
  94. package/services/setting-service/constants.js +2 -1
  95. package/services/storage-service/DatabaseService.d.ts +1 -0
  96. package/services/storage-service/DatabaseService.js +3 -0
  97. package/services/transaction-service/index.js +1 -1
  98. package/stores/ChainlistStore.d.ts +7 -0
  99. package/stores/ChainlistStore.js +10 -0
  100. package/types/{avail-bridge → bridge}/index.d.ts +1 -1
  101. package/types/index.d.ts +1 -0
  102. package/types/index.js +1 -0
  103. package/types/notification/index.d.ts +5 -0
  104. package/types/transaction/error.d.ts +2 -1
  105. package/types/transaction/error.js +1 -0
  106. package/utils/account/transform.js +1 -1
  107. package/services/inapp-notification-service/utils.d.ts +0 -55
  108. /package/cjs/types/{avail-bridge → bridge}/index.js +0 -0
  109. /package/types/{avail-bridge → bridge}/index.js +0 -0
@@ -10,7 +10,7 @@ import { SubstrateChainHandler } from '@subwallet/extension-base/services/chain-
10
10
  import { TonChainHandler } from '@subwallet/extension-base/services/chain-service/handler/TonChainHandler';
11
11
  import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
12
12
  import { _ChainConnectionStatus, _CUSTOM_PREFIX, _NFT_CONTRACT_STANDARDS, _SMART_CONTRACT_STANDARDS } from '@subwallet/extension-base/services/chain-service/types';
13
- import { _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isLocalToken, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, fetchPatchData, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
13
+ import { _isAssetAutoEnable, _isAssetCanPayTxFee, _isAssetFungibleToken, _isChainEnabled, _isCustomAsset, _isCustomChain, _isCustomProvider, _isEqualContractAddress, _isEqualSmartContractAsset, _isLocalToken, _isMantaZkAsset, _isPureEvmChain, _isPureSubstrateChain, _parseAssetRefKey, randomizeProvider, updateLatestChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
14
14
  import AssetSettingStore from '@subwallet/extension-base/stores/AssetSetting';
15
15
  import { addLazy, calculateMetadataHash, fetchStaticData, filterAssetsByChainAndType, getShortMetadata, MODULE_SUPPORT } from '@subwallet/extension-base/utils';
16
16
  import { BehaviorSubject, Subject } from 'rxjs';
@@ -20,26 +20,9 @@ const filterChainInfoMap = (data, ignoredChains) => {
20
20
  return Object.fromEntries(Object.entries(data).filter(([slug, info]) => !info.bitcoinInfo && !ignoredChains.includes(slug)));
21
21
  };
22
22
  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'];
23
- const filterAssetInfoMap = (chainInfo, assets) => {
24
- return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain]));
23
+ export const filterAssetInfoMap = (chainInfo, assets, addedChains) => {
24
+ return Object.fromEntries(Object.entries(assets).filter(([, info]) => chainInfo[info.originChain] || (addedChains === null || addedChains === void 0 ? void 0 : addedChains.includes(info.originChain))));
25
25
  };
26
-
27
- // const rawAssetRefMap = (assetRefMap: Record<string, _AssetRef>) => {
28
- // const result: Record<string, _AssetRef> = {};
29
- //
30
- // Object.entries(assetRefMap).forEach(([key, assetRef]) => {
31
- // const originChainInfo = ChainInfoMap[assetRef.srcChain];
32
- // const destChainInfo = ChainInfoMap[assetRef.destChain];
33
- // const isSnowBridgeXcm = assetRef.path === _AssetRefPath.XCM && _isSnowBridgeXcm(originChainInfo, destChainInfo);
34
- //
35
- // if (!isSnowBridgeXcm) {
36
- // result[key] = assetRef;
37
- // }
38
- // });
39
- //
40
- // return result;
41
- // };
42
-
43
26
  export class ChainService {
44
27
  dataMap = {
45
28
  chainInfoMap: {},
@@ -64,8 +47,6 @@ export class ChainService {
64
47
  assetLogoMapSubject = new BehaviorSubject(AssetLogoMap);
65
48
  chainLogoMapSubject = new BehaviorSubject(ChainLogoMap);
66
49
  ledgerGenericAllowChainsSubject = new BehaviorSubject([]);
67
- assetMapPatch = JSON.stringify({});
68
- assetLogoPatch = JSON.stringify({});
69
50
 
70
51
  // Todo: Update to new store indexed DB
71
52
  store = new AssetSettingStore();
@@ -126,6 +107,12 @@ export class ChainService {
126
107
  });
127
108
  return result;
128
109
  }
110
+ getlockChainInfoMap() {
111
+ return this.lockChainInfoMap;
112
+ }
113
+ setLockChainInfoMap(isLock) {
114
+ this.lockChainInfoMap = isLock;
115
+ }
129
116
  getEvmApi(slug) {
130
117
  return this.evmChainHandler.getEvmApiByChain(slug);
131
118
  }
@@ -174,6 +161,9 @@ export class ChainService {
174
161
  getAssetRegistry() {
175
162
  return this.dataMap.assetRegistry;
176
163
  }
164
+ setAssetRegistry(assetRegistry) {
165
+ this.dataMap.assetRegistry = assetRegistry;
166
+ }
177
167
  getMultiChainAssetMap() {
178
168
  return MultiChainAssetMap;
179
169
  }
@@ -198,6 +188,9 @@ export class ChainService {
198
188
  getChainInfoMap() {
199
189
  return this.dataMap.chainInfoMap;
200
190
  }
191
+ setChainInfoMap(chainInfoMap) {
192
+ this.dataMap.chainInfoMap = chainInfoMap;
193
+ }
201
194
  getEvmChainInfoMap() {
202
195
  const result = {};
203
196
  Object.values(this.getChainInfoMap()).forEach(chainInfo => {
@@ -254,6 +247,9 @@ export class ChainService {
254
247
  getChainStateMap() {
255
248
  return this.dataMap.chainStateMap;
256
249
  }
250
+ setChainStateMap(chainStateMap) {
251
+ this.dataMap.chainStateMap = chainStateMap;
252
+ }
257
253
  getChainStateByKey(key) {
258
254
  return this.dataMap.chainStateMap[key];
259
255
  }
@@ -498,10 +494,10 @@ export class ChainService {
498
494
  await this.initChains();
499
495
  this.chainInfoMapSubject.next(this.getChainInfoMap());
500
496
  this.assetRegistrySubject.next(this.getAssetRegistry());
497
+ this.initAssetRefMap();
501
498
  this.xcmRefMapSubject.next(this.xcmRefMap);
502
499
  await this.initApis();
503
500
  await this.initAssetSettings();
504
- this.initAssetRefMap();
505
501
  await this.autoEnableTokens();
506
502
  }
507
503
  initAssetRefMap() {
@@ -534,79 +530,25 @@ export class ChainService {
534
530
  console.error('Error fetching latest chain data');
535
531
  }
536
532
  }
537
- handleLatestAssetRef(latestBlockedAssetRefList, latestAssetRefMap) {
538
- const updatedAssetRefMap = {
539
- ...AssetRefMap
540
- };
541
- if (latestAssetRefMap) {
542
- for (const [assetRefKey, assetRef] of Object.entries(latestAssetRefMap)) {
543
- updatedAssetRefMap[assetRefKey] = assetRef;
544
- }
545
- }
546
- latestBlockedAssetRefList.forEach(blockedAssetRef => {
547
- delete updatedAssetRefMap[blockedAssetRef];
548
- });
549
- this.dataMap.assetRefMap = updatedAssetRefMap;
550
- this.xcmRefMapSubject.next(this.xcmRefMap);
551
- this.swapRefMapSubject.next(this.swapRefMap);
552
- this.logger.log('Finished updating latest asset ref');
553
- }
554
- handleLatestPriceId(latestPriceIds) {
555
- let isUpdated = false;
556
- Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
557
- if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
558
- isUpdated = true;
559
- this.dataMap.assetRegistry[slug].priceId = priceId;
560
- }
561
- });
562
- if (isUpdated) {
563
- this.assetRegistrySubject.next(this.dataMap.assetRegistry);
564
- this.eventService.emit('asset.updateState', '');
565
- }
566
- this.logger.log('Finished updating latest price IDs');
567
- }
568
- handleLatestAssetData(latestAssetInfo, latestAssetLogoMap) {
569
- try {
570
- if (latestAssetInfo) {
571
- const latestAssetPatch = JSON.stringify(latestAssetInfo);
572
- if (this.assetMapPatch !== latestAssetPatch) {
573
- const assetRegistry = filterAssetInfoMap(this.getChainInfoMap(), Object.assign({}, this.dataMap.assetRegistry, latestAssetInfo));
574
- this.assetMapPatch = latestAssetPatch;
575
- this.dataMap.assetRegistry = assetRegistry;
576
- this.assetRegistrySubject.next(assetRegistry);
577
- this.autoEnableTokens().then(() => {
578
- this.eventService.emit('asset.updateState', '');
579
- }).catch(console.error);
580
- }
581
- }
582
- if (latestAssetLogoMap) {
583
- const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
584
- if (this.assetLogoPatch !== latestAssetLogoPatch) {
585
- const logoMap = {
586
- ...AssetLogoMap,
587
- ...latestAssetLogoMap
588
- };
589
- this.assetLogoPatch = latestAssetLogoPatch;
590
- this.assetLogoMapSubject.next(logoMap);
591
- }
592
- }
593
- if (latestAssetLogoMap) {
594
- const latestAssetLogoPatch = JSON.stringify(latestAssetLogoMap);
595
- if (this.assetLogoPatch !== latestAssetLogoPatch) {
596
- const logoMap = {
597
- ...AssetLogoMap,
598
- ...latestAssetLogoMap
599
- };
600
- this.assetLogoPatch = latestAssetLogoPatch;
601
- this.assetLogoMapSubject.next(logoMap);
602
- }
603
- }
604
- } catch (e) {
605
- console.error('Error fetching latest asset data');
606
- }
607
- this.eventService.emit('asset.online.ready', true);
608
- this.logger.log('Finished updating latest asset');
609
- }
533
+
534
+ // handleLatestPriceId (latestPriceIds: Record<string, string | null>) {
535
+ // let isUpdated = false;
536
+ //
537
+ // Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
538
+ // if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
539
+ // isUpdated = true;
540
+ // this.dataMap.assetRegistry[slug].priceId = priceId;
541
+ // }
542
+ // });
543
+ //
544
+ // if (isUpdated) {
545
+ // this.assetRegistrySubject.next(this.dataMap.assetRegistry);
546
+ // this.eventService.emit('asset.updateState', '');
547
+ // }
548
+ //
549
+ // this.logger.log('Finished updating latest price IDs');
550
+ // }
551
+
610
552
  async autoEnableTokens() {
611
553
  const autoEnableTokens = Object.values(this.dataMap.assetRegistry).filter(asset => _isAssetAutoEnable(asset));
612
554
  const assetSettings = this.assetSettingSubject.value;
@@ -640,20 +582,19 @@ export class ChainService {
640
582
  this.logger.log('Finished updating latest ledger generic allow chains');
641
583
  }
642
584
  handleLatestData() {
643
- this.fetchLatestAssetData().then(([latestAssetInfo, latestAssetLogoMap]) => {
644
- this.eventService.waitAssetReady.then(() => {
645
- this.handleLatestAssetData(latestAssetInfo, latestAssetLogoMap);
646
- }).catch(console.error);
647
- }).catch(console.error);
648
585
  this.fetchLatestChainData().then(latestChainInfo => {
586
+ this.lockChainInfoMap = true; // do not need to check current lockChainInfoMap because all remains action is fast enough and don't affect this feature.
649
587
  this.handleLatestChainData(latestChainInfo);
650
- }).catch(console.error);
651
- this.fetchLatestAssetRef().then(([latestAssetRef, latestAssetRefMap]) => {
652
- this.handleLatestAssetRef(latestAssetRef, latestAssetRefMap);
653
- }).catch(console.error);
654
- this.fetchLatestPriceIdsData().then(latestPriceIds => {
655
- this.handleLatestPriceId(latestPriceIds);
656
- }).catch(console.error);
588
+ this.lockChainInfoMap = false;
589
+ }).catch(e => {
590
+ this.lockChainInfoMap = false;
591
+ console.error('Error update latest chain data', e);
592
+ });
593
+
594
+ // this.fetchLatestPriceIdsData().then((latestPriceIds) => {
595
+ // this.handleLatestPriceId(latestPriceIds);
596
+ // }).catch(console.error);
597
+
657
598
  this.fetchLatestLedgerGenericAllowChains().then(latestledgerGenericAllowChains => {
658
599
  this.handleLatestLedgerGenericAllowChains(latestledgerGenericAllowChains);
659
600
  }).catch(console.error);
@@ -911,17 +852,10 @@ export class ChainService {
911
852
  // }
912
853
  }
913
854
 
914
- async fetchLatestAssetData() {
915
- return await Promise.all([fetchPatchData('ChainAsset.json'), fetchPatchData('AssetLogoMap.json')]);
916
- }
917
-
918
855
  // @ts-ignore
919
856
  async fetchLatestPriceIdsData() {
920
857
  return await fetchStaticData('chain-assets/price-map');
921
858
  }
922
- async fetchLatestAssetRef() {
923
- return await Promise.all([fetchStaticData('chain-assets/disabled-xcm-channels'), fetchPatchData('AssetRef.json')]);
924
- }
925
859
  async fetchLatestLedgerGenericAllowChains() {
926
860
  return (await fetchStaticData('chains/ledger-generic-allow-chains')) || [];
927
861
  }
@@ -1069,7 +1003,35 @@ export class ChainService {
1069
1003
  });
1070
1004
  }
1071
1005
  } else {
1072
- // Todo: Remove chain from storage
1006
+ var _storedChainInfo$bitc2;
1007
+ // added chain from patch
1008
+ this.dataMap.chainStateMap[storedSlug] = {
1009
+ currentProvider: storedChainInfo.currentProvider,
1010
+ slug: storedSlug,
1011
+ active: storedChainInfo.active,
1012
+ manualTurnOff
1013
+ };
1014
+ this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
1015
+ newStorageData.push({
1016
+ ...storedChainSettingMap[storedSlug],
1017
+ active: storedChainInfo.active,
1018
+ currentProvider: storedChainInfo.currentProvider,
1019
+ manualTurnOff
1020
+ });
1021
+ mergedChainInfoMap[storedSlug] = {
1022
+ slug: storedSlug,
1023
+ name: storedChainInfo.name,
1024
+ providers: storedChainInfo.providers,
1025
+ evmInfo: storedChainInfo.evmInfo,
1026
+ substrateInfo: storedChainInfo.substrateInfo,
1027
+ bitcoinInfo: (_storedChainInfo$bitc2 = storedChainInfo.bitcoinInfo) !== null && _storedChainInfo$bitc2 !== void 0 ? _storedChainInfo$bitc2 : null,
1028
+ tonInfo: storedChainInfo.tonInfo,
1029
+ isTestnet: storedChainInfo.isTestnet,
1030
+ chainStatus: storedChainInfo.chainStatus,
1031
+ icon: storedChainInfo.icon,
1032
+ extraInfo: storedChainInfo.extraInfo
1033
+ };
1034
+ deprecatedChainMap[storedSlug] = storedSlug; // todo: set a better name
1073
1035
  }
1074
1036
  }
1075
1037
 
@@ -525,8 +525,6 @@ export function updateLatestChainInfo(currentDataMap, latestChainInfoList) {
525
525
  }
526
526
  if (currentChainInfo) {
527
527
  needUpdate = true;
528
- currentChainInfo.extraInfo = latestChainInfo.extraInfo;
529
- currentChainInfo.chainStatus = latestChainInfo.chainStatus;
530
528
  if (Object.keys(currentChainInfo.providers).length === 0) {
531
529
  currentChainInfo.chainStatus = _ChainStatus.INACTIVE;
532
530
  }
@@ -1 +1,16 @@
1
- export declare function fetchPatchData<T>(slug: string): Promise<T | null>;
1
+ import { _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
2
+ export interface PatchInfo {
3
+ patchVersion: string;
4
+ appliedVersion: string;
5
+ fetchedDate: string;
6
+ ChainInfo: Record<string, _ChainInfo>;
7
+ ChainInfoHashMap: Record<string, string>;
8
+ ChainAsset: Record<string, _ChainAsset>;
9
+ ChainAssetHashMap: Record<string, string>;
10
+ MultiChainAsset: Record<string, _MultiChainAsset>;
11
+ MultiChainAssetHashMap: Record<string, string>;
12
+ ChainLogoMap: Record<string, string>;
13
+ AssetLogoMap: Record<string, string>;
14
+ mAssetLogoMap: Record<string, string>;
15
+ }
16
+ export declare function fetchPatchData<T>(): Promise<T | null>;
@@ -4,10 +4,14 @@
4
4
  const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
5
5
  const branchName = process.env.BRANCH_NAME || 'subwallet-dev';
6
6
  const fetchDomain = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'https://chain-list-assets.subwallet.app' : 'https://dev.sw-chain-list-assets.pages.dev';
7
- const ChainListVersion = '0.2.62';
8
- export async function fetchPatchData(slug) {
7
+ const fetchFile = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list.json' : 'preview.json';
8
+ const ChainListVersion = '0.2.95'; // update this when build chainlist
9
+
10
+ // todo: move this interface to chainlist
11
+
12
+ export async function fetchPatchData() {
9
13
  try {
10
- const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${slug}`);
14
+ const fetchPromise = fetch(`${fetchDomain}/patch/${ChainListVersion}/${fetchFile}`);
11
15
  const timeout = new Promise(resolve => {
12
16
  const id = setTimeout(() => {
13
17
  clearTimeout(id);
@@ -4,6 +4,7 @@
4
4
  import { GAS_PRICE_RATIO, NETWORK_MULTI_GAS_FEE } from '@subwallet/extension-base/constants';
5
5
  import { BN_WEI, BN_ZERO } from '@subwallet/extension-base/utils';
6
6
  import BigN from 'bignumber.js';
7
+ import { POLYGON_GAS_INDEXER } from "../../balance-service/transfer/xcm/polygonBridge.js";
7
8
  const INFURA_API_KEY = process.env.INFURA_API_KEY || '';
8
9
  const INFURA_API_KEY_SECRET = process.env.INFURA_API_KEY_SECRET || '';
9
10
  const INFURA_AUTH = 'Basic ' + Buffer.from(INFURA_API_KEY + ':' + INFURA_API_KEY_SECRET).toString('base64');
@@ -91,6 +92,19 @@ export const calculateGasFeeParams = async (web3, networkKey, useOnline = true,
91
92
  } catch (e) {}
92
93
  }
93
94
  try {
95
+ if (networkKey === 'polygonzkEvm_cardona' || networkKey === 'polygonZkEvm') {
96
+ const isTestnet = networkKey === 'polygonzkEvm_cardona';
97
+ const gasDomain = isTestnet ? POLYGON_GAS_INDEXER.TESTNET : POLYGON_GAS_INDEXER.MAINNET;
98
+ const gasResponse = await fetch(`${gasDomain}`).then(res => res.json());
99
+ const gasPriceInWei = gasResponse.standard * 1e9 + 200000;
100
+ return {
101
+ gasPrice: gasPriceInWei.toString(),
102
+ maxFeePerGas: undefined,
103
+ maxPriorityFeePerGas: undefined,
104
+ baseGasFee: undefined,
105
+ busyNetwork: false
106
+ };
107
+ }
94
108
  const numBlock = 20;
95
109
  const rewardPercent = [];
96
110
  for (let i = 0; i <= 100; i = i + 5) {
@@ -1,4 +1,4 @@
1
- import { getAvailBridgeClaimDescription, getClaimDescription, getReceiveDescription, getSendDescription, getWithdrawDescription } from '@subwallet/extension-base/services/inapp-notification-service/utils';
1
+ import { getAvailBridgeClaimDescription, getClaimDescription, getPolygonBridgeClaimDescription, getReceiveDescription, getSendDescription, getWithdrawDescription } from './utils';
2
2
  export declare const NotificationTitleMap: {
3
3
  WITHDRAW: string;
4
4
  CLAIM: string;
@@ -6,6 +6,7 @@ export declare const NotificationTitleMap: {
6
6
  RECEIVE: string;
7
7
  CLAIM_AVAIL_BRIDGE_ON_AVAIL: string;
8
8
  CLAIM_AVAIL_BRIDGE_ON_ETHEREUM: string;
9
+ CLAIM_POLYGON_BRIDGE: string;
9
10
  };
10
11
  export declare const NotificationDescriptionMap: {
11
12
  WITHDRAW: typeof getWithdrawDescription;
@@ -14,5 +15,6 @@ export declare const NotificationDescriptionMap: {
14
15
  RECEIVE: typeof getReceiveDescription;
15
16
  CLAIM_AVAIL_BRIDGE_ON_AVAIL: typeof getAvailBridgeClaimDescription;
16
17
  CLAIM_AVAIL_BRIDGE_ON_ETHEREUM: typeof getAvailBridgeClaimDescription;
18
+ CLAIM_POLYGON_BRIDGE: typeof getPolygonBridgeClaimDescription;
17
19
  };
18
20
  export declare const ONE_DAY_MILLISECOND: number;
@@ -1,15 +1,16 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { NotificationActionType } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
5
- import { getAvailBridgeClaimDescription, getClaimDescription, getReceiveDescription, getSendDescription, getWithdrawDescription } from '@subwallet/extension-base/services/inapp-notification-service/utils';
4
+ import { NotificationActionType } from "./interfaces.js";
5
+ import { getAvailBridgeClaimDescription, getClaimDescription, getPolygonBridgeClaimDescription, getReceiveDescription, getSendDescription, getWithdrawDescription } from "./utils/index.js";
6
6
  export const NotificationTitleMap = {
7
7
  [NotificationActionType.WITHDRAW]: '[{{accountName}}] WITHDRAW {{tokenSymbol}}',
8
8
  [NotificationActionType.CLAIM]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
9
9
  [NotificationActionType.SEND]: '[{{accountName}}] SEND {{tokenSymbol}}',
10
10
  [NotificationActionType.RECEIVE]: '[{{accountName}}] RECEIVE {{tokenSymbol}}',
11
11
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
12
- [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: '[{{accountName}}] CLAIM {{tokenSymbol}}'
12
+ [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: '[{{accountName}}] CLAIM {{tokenSymbol}}',
13
+ [NotificationActionType.CLAIM_POLYGON_BRIDGE]: '[{{accountName}}] CLAIM {{tokenSymbol}}'
13
14
  };
14
15
  export const NotificationDescriptionMap = {
15
16
  [NotificationActionType.WITHDRAW]: getWithdrawDescription,
@@ -17,6 +18,7 @@ export const NotificationDescriptionMap = {
17
18
  [NotificationActionType.SEND]: getSendDescription,
18
19
  [NotificationActionType.RECEIVE]: getReceiveDescription,
19
20
  [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_AVAIL]: getAvailBridgeClaimDescription,
20
- [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: getAvailBridgeClaimDescription
21
+ [NotificationActionType.CLAIM_AVAIL_BRIDGE_ON_ETHEREUM]: getAvailBridgeClaimDescription,
22
+ [NotificationActionType.CLAIM_POLYGON_BRIDGE]: getPolygonBridgeClaimDescription
21
23
  };
22
24
  export const ONE_DAY_MILLISECOND = 1000 * 24 * 60 * 60;
@@ -3,7 +3,7 @@ import { CronServiceInterface, ServiceStatus } from '@subwallet/extension-base/s
3
3
  import { ChainService } from '@subwallet/extension-base/services/chain-service';
4
4
  import { EventService } from '@subwallet/extension-base/services/event-service';
5
5
  import { _BaseNotificationInfo, _NotificationInfo, NotificationActionType } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
6
- import { AvailBridgeTransaction } from '@subwallet/extension-base/services/inapp-notification-service/utils';
6
+ import { AvailBridgeTransaction, PolygonTransaction } from '@subwallet/extension-base/services/inapp-notification-service/utils';
7
7
  import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
8
8
  import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
9
9
  import { GetNotificationParams, RequestSwitchStatusParams } from '@subwallet/extension-base/types/notification';
@@ -25,9 +25,17 @@ export declare class InappNotificationService implements CronServiceInterface {
25
25
  cleanUpOldNotifications(overdueTime?: number): Promise<number>;
26
26
  passValidateNotification(candidateNotification: _BaseNotificationInfo, comparedNotifications: _NotificationInfo[], remindTimeConfigInHrs: Record<NotificationActionType, number>): boolean;
27
27
  validateAndWriteNotificationsToDB(notifications: _BaseNotificationInfo[], address: string): Promise<void>;
28
- cronCreateAvailBridgeClaimNotification(): void;
28
+ cronCreateBridgeClaimNotification(): void;
29
+ getCategorizedAddresses(): {
30
+ substrate: string[];
31
+ evm: string[];
32
+ ton: string[];
33
+ bitcoin: string[];
34
+ };
29
35
  createAvailBridgeClaimNotification(): void;
30
36
  processWriteAvailBridgeClaim(address: string, transactions: AvailBridgeTransaction[], token: _ChainAsset): Promise<void>;
37
+ createPolygonClaimableTransactions(): Promise<void>;
38
+ processPolygonClaimNotification(address: string, transactions: PolygonTransaction[], token: _ChainAsset): Promise<void>;
31
39
  start(): Promise<void>;
32
40
  startCron(): Promise<void>;
33
41
  stop(): Promise<void>;
@@ -1,13 +1,14 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
4
5
  import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
6
  import { CRON_LISTEN_AVAIL_BRIDGE_CLAIM } from '@subwallet/extension-base/constants';
6
7
  import { fetchLastestRemindNotificationTime } from '@subwallet/extension-base/constants/remind-notification-time';
7
8
  import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
8
9
  import { NotificationDescriptionMap, NotificationTitleMap, ONE_DAY_MILLISECOND } from '@subwallet/extension-base/services/inapp-notification-service/consts';
9
10
  import { NotificationActionType, NotificationTab } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
10
- import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
11
+ import { AvailBridgeSourceChain, fetchAllAvailBridgeClaimable, fetchPolygonBridgeTransactions, hrsToMillisecond } from '@subwallet/extension-base/services/inapp-notification-service/utils';
11
12
  import { categoryAddresses, formatNumber } from '@subwallet/extension-base/utils';
12
13
  import { isSubstrateAddress } from '@subwallet/keyring';
13
14
  export class InappNotificationService {
@@ -103,6 +104,28 @@ export class InappNotificationService {
103
104
  }
104
105
  }
105
106
  }
107
+ if ([NotificationActionType.CLAIM_POLYGON_BRIDGE].includes(candidateNotification.actionType)) {
108
+ const {
109
+ address,
110
+ metadata,
111
+ time
112
+ } = candidateNotification;
113
+ const candidateMetadata = metadata;
114
+ const remindTime = hrsToMillisecond(remindTimeConfigInHrs[candidateNotification.actionType]);
115
+ for (const notification of comparedNotifications) {
116
+ if (notification.address !== address) {
117
+ continue;
118
+ }
119
+ if (time - notification.time >= remindTime) {
120
+ continue;
121
+ }
122
+ const comparedMetadata = notification.metadata;
123
+ const sameNotification = candidateMetadata._id === comparedMetadata._id && candidateMetadata.transactionHash === comparedMetadata.transactionHash && candidateMetadata.counter === comparedMetadata.counter;
124
+ if (sameNotification) {
125
+ return false;
126
+ }
127
+ }
128
+ }
106
129
  return true;
107
130
  }
108
131
  async validateAndWriteNotificationsToDB(notifications, address) {
@@ -124,17 +147,23 @@ export class InappNotificationService {
124
147
  }
125
148
  await this.dbService.upsertNotifications(passNotifications);
126
149
  }
127
- cronCreateAvailBridgeClaimNotification() {
150
+ cronCreateBridgeClaimNotification() {
128
151
  clearTimeout(this.refeshAvailBridgeClaimTimeOut);
129
152
  this.createAvailBridgeClaimNotification();
130
- this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateAvailBridgeClaimNotification.bind(this), CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
153
+ this.createPolygonClaimableTransactions().catch(err => {
154
+ console.error('Error:', err);
155
+ });
156
+ this.refeshAvailBridgeClaimTimeOut = setTimeout(this.cronCreateBridgeClaimNotification.bind(this), CRON_LISTEN_AVAIL_BRIDGE_CLAIM);
131
157
  }
132
- createAvailBridgeClaimNotification() {
158
+ getCategorizedAddresses() {
133
159
  const addresses = this.keyringService.context.getAllAddresses();
160
+ return categoryAddresses(addresses);
161
+ }
162
+ createAvailBridgeClaimNotification() {
134
163
  const {
135
164
  evm: evmAddresses,
136
165
  substrate: substrateAddresses
137
- } = categoryAddresses(addresses);
166
+ } = this.getCategorizedAddresses();
138
167
  const chainAssets = this.chainService.getAssetRegistry();
139
168
  let ASSET_TYPE;
140
169
  (function (ASSET_TYPE) {
@@ -208,7 +237,7 @@ export class InappNotificationService {
208
237
  title: NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
209
238
  description: NotificationDescriptionMap[actionType](formatNumber(amount, decimals), symbol),
210
239
  time: timestamp,
211
- extrinsicType: ExtrinsicType.CLAIM_AVAIL_BRIDGE,
240
+ extrinsicType: ExtrinsicType.CLAIM_BRIDGE,
212
241
  isRead: false,
213
242
  actionType,
214
243
  metadata
@@ -216,6 +245,81 @@ export class InappNotificationService {
216
245
  });
217
246
  await this.validateAndWriteNotificationsToDB(notifications, address);
218
247
  }
248
+
249
+ // Polygon Claimable Handle
250
+ async createPolygonClaimableTransactions() {
251
+ const {
252
+ evm: evmAddresses
253
+ } = this.getCategorizedAddresses();
254
+ const etherChains = [COMMON_ASSETS.ETH, COMMON_ASSETS.ETH_SEPOLIA];
255
+ const polygonAssets = Object.values(this.chainService.getAssetRegistry()).filter(asset => etherChains.includes(asset.slug));
256
+ for (const polygonAsset of polygonAssets) {
257
+ const isTestnet = (polygonAsset === null || polygonAsset === void 0 ? void 0 : polygonAsset.originChain) === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA;
258
+ if (evmAddresses.length === 0) {
259
+ return;
260
+ }
261
+ for (const address of evmAddresses) {
262
+ const response = await fetchPolygonBridgeTransactions(address, isTestnet);
263
+ if (response && response.success) {
264
+ await this.processPolygonClaimNotification(address, response.result, polygonAsset);
265
+ }
266
+ }
267
+ }
268
+ }
269
+ async processPolygonClaimNotification(address, transactions, token) {
270
+ var _token$decimals2;
271
+ const actionType = NotificationActionType.CLAIM_POLYGON_BRIDGE;
272
+ const timestamp = Date.now();
273
+ const symbol = token.symbol;
274
+ const decimals = (_token$decimals2 = token.decimals) !== null && _token$decimals2 !== void 0 ? _token$decimals2 : 0;
275
+ const notifications = transactions.map(transaction => {
276
+ const {
277
+ _id,
278
+ amounts,
279
+ counter,
280
+ destinationNetwork,
281
+ originTokenAddress,
282
+ originTokenNetwork,
283
+ receiver,
284
+ sourceNetwork,
285
+ status,
286
+ transactionHash,
287
+ transactionInitiator,
288
+ userAddress
289
+ } = transaction;
290
+ const metadata = {
291
+ chainSlug: token.originChain,
292
+ tokenSlug: token.slug,
293
+ _id,
294
+ amounts,
295
+ counter,
296
+ destinationNetwork,
297
+ originTokenAddress,
298
+ originTokenNetwork,
299
+ receiver,
300
+ sourceNetwork,
301
+ status,
302
+ transactionHash,
303
+ transactionInitiator,
304
+ userAddress
305
+ };
306
+ return {
307
+ id: `${actionType}___${_id}___${timestamp}`,
308
+ address: address,
309
+ title: NotificationTitleMap[actionType].replace('{{tokenSymbol}}', symbol),
310
+ description: NotificationDescriptionMap[actionType](formatNumber(amounts[0], decimals), symbol),
311
+ time: timestamp,
312
+ extrinsicType: ExtrinsicType.CLAIM_BRIDGE,
313
+ isRead: false,
314
+ actionType,
315
+ metadata
316
+ };
317
+ });
318
+ await this.validateAndWriteNotificationsToDB(notifications, address);
319
+ }
320
+
321
+ // Polygon Claimable Handle
322
+
219
323
  async start() {
220
324
  if (this.status === ServiceStatus.STARTED) {
221
325
  return;
@@ -228,7 +332,7 @@ export class InappNotificationService {
228
332
  }
229
333
  async startCron() {
230
334
  this.cleanUpOldNotifications().catch(console.error);
231
- this.cronCreateAvailBridgeClaimNotification();
335
+ this.cronCreateBridgeClaimNotification();
232
336
  return Promise.resolve();
233
337
  }
234
338
  async stop() {