@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
@@ -33,12 +33,12 @@ var _token = require("@subwallet/extension-base/services/balance-service/transfe
33
33
  var _tonTransfer = require("@subwallet/extension-base/services/balance-service/transfer/ton-transfer");
34
34
  var _xcm = require("@subwallet/extension-base/services/balance-service/transfer/xcm");
35
35
  var _availBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge");
36
+ var _polygonBridge = require("@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge");
36
37
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
37
38
  var _types2 = require("@subwallet/extension-base/services/chain-service/types");
38
39
  var _utils4 = require("@subwallet/extension-base/services/chain-service/utils");
39
40
  var _constants3 = require("@subwallet/extension-base/services/request-service/constants");
40
41
  var _constants4 = require("@subwallet/extension-base/services/setting-service/constants");
41
- var _constants5 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
42
42
  var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
43
43
  var _storage = require("@subwallet/extension-base/storage");
44
44
  var _stores = require("@subwallet/extension-base/stores");
@@ -1218,35 +1218,41 @@ class KoniExtension {
1218
1218
  }
1219
1219
  const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1220
1220
  const additionalValidator = async inputTransaction => {
1221
- let senderTransferTokenTransferable;
1222
- let receiverNativeTransferable;
1221
+ let senderSendingTokenTransferable;
1222
+ let receiverSystemAccountInfo;
1223
+ if (!(0, _utils4._isChainSubstrateCompatible)(chainInfo)) {
1224
+ return undefined;
1225
+ }
1223
1226
 
1224
1227
  // Check ed for sender
1225
1228
  if (!isTransferNativeToken) {
1226
- const [_senderTransferTokenTransferable, _receiverNativeTransferable] = await Promise.all([this.getAddressTransferableBalance({
1229
+ const [_senderSendingTokenTransferable, _receiverNativeTotal] = await Promise.all([this.getAddressTransferableBalance({
1227
1230
  address: from,
1228
1231
  networkKey,
1229
1232
  token: tokenSlug,
1230
1233
  extrinsicType
1231
- }), this.getAddressTransferableBalance({
1234
+ }), this.getAddressTotalBalance({
1232
1235
  address: to,
1233
1236
  networkKey,
1234
1237
  token: nativeTokenSlug,
1235
1238
  extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_BALANCE
1236
1239
  })]);
1237
- senderTransferTokenTransferable = _senderTransferTokenTransferable.value;
1238
- receiverNativeTransferable = _receiverNativeTransferable.value;
1240
+ senderSendingTokenTransferable = BigInt(_senderSendingTokenTransferable.value);
1241
+ receiverSystemAccountInfo = _receiverNativeTotal.metadata;
1239
1242
  }
1240
1243
  const {
1241
- value: receiverTransferTokenTransferable
1242
- } = await this.getAddressTransferableBalance({
1244
+ value: _receiverSendingTokenKeepAliveBalance
1245
+ } = await this.getAddressTotalBalance({
1243
1246
  address: to,
1244
1247
  networkKey,
1245
1248
  token: tokenSlug,
1246
1249
  extrinsicType
1247
1250
  }); // todo: shouldn't be just transferable, locked also counts
1248
-
1249
- const [warnings, errors] = (0, _transfer.additionalValidateTransfer)(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverTransferTokenTransferable, transferAmount.value, senderTransferTokenTransferable, receiverNativeTransferable);
1251
+ const receiverSendingTokenKeepAliveBalance = BigInt(_receiverSendingTokenKeepAliveBalance);
1252
+ const amount = BigInt(transferAmount.value);
1253
+ const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1254
+ const isSendingTokenSufficient = await this.isSufficientToken(transferTokenInfo, substrateApi);
1255
+ const [warnings, errors] = (0, _transfer.additionalValidateTransferForRecipient)(transferTokenInfo, nativeTokenInfo, extrinsicType, receiverSendingTokenKeepAliveBalance, amount, senderSendingTokenTransferable, receiverSystemAccountInfo, isSendingTokenSufficient);
1250
1256
  warnings.length && inputTransaction.warnings.push(...warnings);
1251
1257
  errors.length && inputTransaction.errors.push(...errors);
1252
1258
  };
@@ -1295,6 +1301,7 @@ class KoniExtension {
1295
1301
  const isAvailBridgeFromEvm = (0, _utils4._isPureEvmChain)(chainInfoMap[originNetworkKey]) && (0, _availBridge.isAvailChainBridge)(destinationNetworkKey);
1296
1302
  const isAvailBridgeFromAvail = (0, _availBridge.isAvailChainBridge)(originNetworkKey) && (0, _utils4._isPureEvmChain)(chainInfoMap[destinationNetworkKey]);
1297
1303
  const isSnowBridgeEvmTransfer = (0, _utils4._isPureEvmChain)(chainInfoMap[originNetworkKey]) && (0, _xcmParser._isSnowBridgeXcm)(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]) && !isAvailBridgeFromEvm;
1304
+ const isPolygonBridgeTransfer = (0, _polygonBridge._isPolygonChainBridge)(originNetworkKey, destinationNetworkKey);
1298
1305
  let additionalValidator;
1299
1306
  let eventsHandler;
1300
1307
  if (fromKeyPair && destinationTokenInfo) {
@@ -1311,7 +1318,9 @@ class KoniExtension {
1311
1318
  evmApi
1312
1319
  };
1313
1320
  let funcCreateExtrinsic;
1314
- if (isSnowBridgeEvmTransfer) {
1321
+ if (isPolygonBridgeTransfer) {
1322
+ funcCreateExtrinsic = _xcm.createPolygonBridgeExtrinsic;
1323
+ } else if (isSnowBridgeEvmTransfer) {
1315
1324
  funcCreateExtrinsic = _xcm.createSnowBridgeExtrinsic;
1316
1325
  } else if (isAvailBridgeFromEvm) {
1317
1326
  funcCreateExtrinsic = _xcm.createAvailBridgeTxFromEth;
@@ -1376,7 +1385,7 @@ class KoniExtension {
1376
1385
  transaction: extrinsic,
1377
1386
  data: inputData,
1378
1387
  extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
1379
- chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM,
1388
+ chainType: !isSnowBridgeEvmTransfer && !isAvailBridgeFromEvm && !isPolygonBridgeTransfer ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM,
1380
1389
  transferNativeAmount: (0, _utils4._isNativeToken)(originTokenInfo) ? value : '0',
1381
1390
  ignoreWarnings,
1382
1391
  isTransferAll: transferAll,
@@ -1504,6 +1513,25 @@ class KoniExtension {
1504
1513
  };
1505
1514
  }
1506
1515
  }
1516
+ async isSufficientToken(tokenInfo, substrateApi) {
1517
+ let metadata;
1518
+ if (_constants2.SUFFICIENT_CHAIN.includes(tokenInfo.originChain) && tokenInfo.assetType !== _types._AssetType.NATIVE) {
1519
+ const assetId = (0, _utils4._isBridgedToken)(tokenInfo) ? (0, _utils4._getXcmAssetMultilocation)(tokenInfo) : (0, _utils4._getTokenOnChainAssetId)(tokenInfo);
1520
+ const queryParams = {
1521
+ section: 'query',
1522
+ module: 'foreignAssets',
1523
+ method: 'asset',
1524
+ args: [assetId]
1525
+ };
1526
+ if (!(0, _utils4._isBridgedToken)(tokenInfo)) {
1527
+ queryParams.module = 'assets';
1528
+ }
1529
+ metadata = await substrateApi.makeRpcQuery(queryParams);
1530
+ } else {
1531
+ return false;
1532
+ }
1533
+ return metadata.isSufficient;
1534
+ }
1507
1535
  async deleteCustomAsset(assetSlug) {
1508
1536
  const assetInfo = this.#koniState.getAssetBySlug(assetSlug);
1509
1537
  if (assetInfo && (0, _utils4._isCustomAsset)(assetSlug)) {
@@ -1534,14 +1562,23 @@ class KoniExtension {
1534
1562
  }
1535
1563
  return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
1536
1564
  }
1537
- async getMaxTransferable(_ref30) {
1565
+ async getAddressTotalBalance(_ref30) {
1566
+ let {
1567
+ address,
1568
+ extrinsicType,
1569
+ networkKey,
1570
+ token
1571
+ } = _ref30;
1572
+ return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
1573
+ }
1574
+ async getMaxTransferable(_ref31) {
1538
1575
  let {
1539
1576
  address,
1540
1577
  destChain,
1541
1578
  isXcmTransfer,
1542
1579
  networkKey,
1543
1580
  token
1544
- } = _ref30;
1581
+ } = _ref31;
1545
1582
  const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1546
1583
  if (!(0, _utils4._isNativeToken)(tokenInfo)) {
1547
1584
  return await this.getAddressTransferableBalance({
@@ -1599,13 +1636,13 @@ class KoniExtension {
1599
1636
  const bnMaxTransferable = new _bignumber.default(value);
1600
1637
  return bnMaxTransferable.minus(mockTxFee);
1601
1638
  }
1602
- async subscribeAddressTransferableBalance(_ref31, id, port) {
1639
+ async subscribeAddressTransferableBalance(_ref32, id, port) {
1603
1640
  let {
1604
1641
  address,
1605
1642
  extrinsicType,
1606
1643
  networkKey,
1607
1644
  token
1608
- } = _ref31;
1645
+ } = _ref32;
1609
1646
  const cb = (0, _subscriptions.createSubscription)(id, port);
1610
1647
  const convertData = data => {
1611
1648
  return {
@@ -1656,11 +1693,11 @@ class KoniExtension {
1656
1693
  isSendingSelf
1657
1694
  };
1658
1695
  }
1659
- async enableChains(_ref32) {
1696
+ async enableChains(_ref33) {
1660
1697
  let {
1661
1698
  chainSlugs,
1662
1699
  enableTokens
1663
- } = _ref32;
1700
+ } = _ref33;
1664
1701
  try {
1665
1702
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
1666
1703
  chainSlug,
@@ -1781,30 +1818,30 @@ class KoniExtension {
1781
1818
 
1782
1819
  // Parse transaction
1783
1820
 
1784
- parseSubstrateTransaction(_ref33) {
1821
+ parseSubstrateTransaction(_ref34) {
1785
1822
  let {
1786
1823
  data,
1787
1824
  networkKey
1788
- } = _ref33;
1825
+ } = _ref34;
1789
1826
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
1790
1827
  const apiPromise = apiProps.api;
1791
1828
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
1792
1829
  }
1793
- async parseEVMRLP(_ref34) {
1830
+ async parseEVMRLP(_ref35) {
1794
1831
  let {
1795
1832
  data
1796
- } = _ref34;
1833
+ } = _ref35;
1797
1834
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
1798
1835
  }
1799
1836
 
1800
1837
  // Sign
1801
1838
 
1802
- qrSignSubstrate(_ref35) {
1839
+ qrSignSubstrate(_ref36) {
1803
1840
  let {
1804
1841
  address,
1805
1842
  data,
1806
1843
  networkKey
1807
- } = _ref35;
1844
+ } = _ref36;
1808
1845
  const pair = _uiKeyring.keyring.getPair(address);
1809
1846
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
1810
1847
  if (pair.isLocked) {
@@ -1821,13 +1858,13 @@ class KoniExtension {
1821
1858
  signature: signed
1822
1859
  };
1823
1860
  }
1824
- async qrSignEVM(_ref36) {
1861
+ async qrSignEVM(_ref37) {
1825
1862
  let {
1826
1863
  address,
1827
1864
  chainId,
1828
1865
  message,
1829
1866
  type
1830
- } = _ref36;
1867
+ } = _ref37;
1831
1868
  let signed;
1832
1869
  const network = this.getNetworkJsonByChainId(chainId);
1833
1870
  if (!network) {
@@ -1911,11 +1948,11 @@ class KoniExtension {
1911
1948
  });
1912
1949
  return this.#koniState.getNominatorMetadata();
1913
1950
  }
1914
- async getBondingOptions(_ref37) {
1951
+ async getBondingOptions(_ref38) {
1915
1952
  let {
1916
1953
  chain,
1917
1954
  type
1918
- } = _ref37;
1955
+ } = _ref38;
1919
1956
  const apiProps = this.#koniState.getSubstrateApi(chain);
1920
1957
  const chainInfo = this.#koniState.getChainInfo(chain);
1921
1958
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2105,12 +2142,12 @@ class KoniExtension {
2105
2142
  }
2106
2143
 
2107
2144
  // EVM Transaction
2108
- async parseContractInput(_ref38) {
2145
+ async parseContractInput(_ref39) {
2109
2146
  let {
2110
2147
  chainId,
2111
2148
  contract,
2112
2149
  data
2113
- } = _ref38;
2150
+ } = _ref39;
2114
2151
  const network = this.getNetworkJsonByChainId(chainId);
2115
2152
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2116
2153
  }
@@ -2210,10 +2247,10 @@ class KoniExtension {
2210
2247
 
2211
2248
  // Unlock wallet
2212
2249
 
2213
- keyringUnlock(_ref39) {
2250
+ keyringUnlock(_ref40) {
2214
2251
  let {
2215
2252
  password
2216
- } = _ref39;
2253
+ } = _ref40;
2217
2254
  try {
2218
2255
  _uiKeyring.keyring.unlockKeyring(password);
2219
2256
  // this.#koniState.initMantaPay(password)
@@ -2244,11 +2281,11 @@ class KoniExtension {
2244
2281
 
2245
2282
  // Export mnemonic
2246
2283
 
2247
- keyringExportMnemonic(_ref40) {
2284
+ keyringExportMnemonic(_ref41) {
2248
2285
  let {
2249
2286
  address,
2250
2287
  password
2251
- } = _ref40;
2288
+ } = _ref41;
2252
2289
  const pair = _uiKeyring.keyring.getPair(address);
2253
2290
  const result = pair.exportMnemonic(password);
2254
2291
  return {
@@ -2258,10 +2295,10 @@ class KoniExtension {
2258
2295
 
2259
2296
  // Reset wallet
2260
2297
 
2261
- async resetWallet(_ref41) {
2298
+ async resetWallet(_ref42) {
2262
2299
  let {
2263
2300
  resetAll
2264
- } = _ref41;
2301
+ } = _ref42;
2265
2302
  try {
2266
2303
  await this.#koniState.resetWallet(resetAll);
2267
2304
  return {
@@ -2277,10 +2314,10 @@ class KoniExtension {
2277
2314
  }
2278
2315
 
2279
2316
  /// Signing substrate request
2280
- async signingApprovePasswordV2(_ref42) {
2317
+ async signingApprovePasswordV2(_ref43) {
2281
2318
  let {
2282
2319
  id
2283
- } = _ref42;
2320
+ } = _ref43;
2284
2321
  const queued = this.#koniState.getSignRequest(id);
2285
2322
  (0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
2286
2323
  const {
@@ -2486,10 +2523,10 @@ class KoniExtension {
2486
2523
  getSupportedSmartContractTypes() {
2487
2524
  return this.#koniState.getSupportedSmartContractTypes();
2488
2525
  }
2489
- getTransaction(_ref43) {
2526
+ getTransaction(_ref44) {
2490
2527
  let {
2491
2528
  id
2492
- } = _ref43;
2529
+ } = _ref44;
2493
2530
  const {
2494
2531
  transaction,
2495
2532
  ...transactionResult
@@ -2499,8 +2536,8 @@ class KoniExtension {
2499
2536
  subscribeTransactions(id, port) {
2500
2537
  const cb = (0, _subscriptions.createSubscription)(id, port);
2501
2538
  function convertRs(rs) {
2502
- return Object.fromEntries(Object.entries(rs).map(_ref44 => {
2503
- let [key, value] = _ref44;
2539
+ return Object.fromEntries(Object.entries(rs).map(_ref45 => {
2540
+ let [key, value] = _ref45;
2504
2541
  const {
2505
2542
  additionalValidator,
2506
2543
  eventsHandler,
@@ -2532,10 +2569,10 @@ class KoniExtension {
2532
2569
  });
2533
2570
  return notificationSubject.value;
2534
2571
  }
2535
- async reloadCron(_ref45) {
2572
+ async reloadCron(_ref46) {
2536
2573
  let {
2537
2574
  data
2538
- } = _ref45;
2575
+ } = _ref46;
2539
2576
  if (data === 'nft') {
2540
2577
  return await this.#koniState.reloadNft();
2541
2578
  } else if (data === 'staking') {
@@ -2578,10 +2615,10 @@ class KoniExtension {
2578
2615
  }
2579
2616
 
2580
2617
  // Phishing detect
2581
- async passPhishingPage(_ref46) {
2618
+ async passPhishingPage(_ref47) {
2582
2619
  let {
2583
2620
  url
2584
- } = _ref46;
2621
+ } = _ref47;
2585
2622
  return await this.#koniState.approvePassPhishingPage(url);
2586
2623
  }
2587
2624
 
@@ -2602,10 +2639,10 @@ class KoniExtension {
2602
2639
  /// Wallet connect
2603
2640
 
2604
2641
  // Connect
2605
- async connectWalletConnect(_ref47) {
2642
+ async connectWalletConnect(_ref48) {
2606
2643
  let {
2607
2644
  uri
2608
- } = _ref47;
2645
+ } = _ref48;
2609
2646
  await this.#koniState.walletConnectService.connect(uri);
2610
2647
  return true;
2611
2648
  }
@@ -2618,11 +2655,11 @@ class KoniExtension {
2618
2655
  });
2619
2656
  return this.#koniState.requestService.allConnectWCRequests;
2620
2657
  }
2621
- async approveWalletConnectSession(_ref48) {
2658
+ async approveWalletConnectSession(_ref49) {
2622
2659
  let {
2623
2660
  accounts: selectedAccounts,
2624
2661
  id
2625
- } = _ref48;
2662
+ } = _ref49;
2626
2663
  const request = this.#koniState.requestService.getConnectWCRequest(id);
2627
2664
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
2628
2665
  throw new Error('The proposal has been expired');
@@ -2634,8 +2671,8 @@ class KoniExtension {
2634
2671
  const availableNamespaces = {};
2635
2672
  const namespaces = {};
2636
2673
  const chainInfoMap = this.#koniState.getChainInfoMap();
2637
- Object.entries(requiredNamespaces).forEach(_ref49 => {
2638
- let [key, namespace] = _ref49;
2674
+ Object.entries(requiredNamespaces).forEach(_ref50 => {
2675
+ let [key, namespace] = _ref50;
2639
2676
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
2640
2677
  if (namespace.chains) {
2641
2678
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
@@ -2648,8 +2685,8 @@ class KoniExtension {
2648
2685
  throw new Error((0, _utils6.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
2649
2686
  }
2650
2687
  });
2651
- Object.entries(optionalNamespaces).forEach(_ref50 => {
2652
- let [key, namespace] = _ref50;
2688
+ Object.entries(optionalNamespaces).forEach(_ref51 => {
2689
+ let [key, namespace] = _ref51;
2653
2690
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
2654
2691
  if (namespace.chains) {
2655
2692
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -2673,14 +2710,14 @@ class KoniExtension {
2673
2710
  }
2674
2711
  }
2675
2712
  });
2676
- Object.entries(availableNamespaces).forEach(_ref51 => {
2677
- let [key, namespace] = _ref51;
2713
+ Object.entries(availableNamespaces).forEach(_ref52 => {
2714
+ let [key, namespace] = _ref52;
2678
2715
  if (namespace.chains) {
2679
- const accounts = [];
2680
- const chains = (0, _utils5.uniqueStringArray)(namespace.chains);
2681
- chains.forEach(chain => {
2682
- accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants5.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
2716
+ const accounts = selectedAccounts.filter(address => {
2717
+ const [_namespace] = address.split(':');
2718
+ return _namespace === key;
2683
2719
  });
2720
+ const chains = (0, _utils5.uniqueStringArray)(namespace.chains);
2684
2721
  namespaces[key] = {
2685
2722
  accounts,
2686
2723
  methods: namespace.methods,
@@ -2698,10 +2735,10 @@ class KoniExtension {
2698
2735
  request.resolve();
2699
2736
  return true;
2700
2737
  }
2701
- async rejectWalletConnectSession(_ref52) {
2738
+ async rejectWalletConnectSession(_ref53) {
2702
2739
  let {
2703
2740
  id
2704
- } = _ref52;
2741
+ } = _ref53;
2705
2742
  const request = this.#koniState.requestService.getConnectWCRequest(id);
2706
2743
  const wcId = request.request.id;
2707
2744
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -2723,10 +2760,10 @@ class KoniExtension {
2723
2760
  });
2724
2761
  return this.#koniState.walletConnectService.sessions;
2725
2762
  }
2726
- async disconnectWalletConnectSession(_ref53) {
2763
+ async disconnectWalletConnectSession(_ref54) {
2727
2764
  let {
2728
2765
  topic
2729
- } = _ref53;
2766
+ } = _ref54;
2730
2767
  await this.#koniState.walletConnectService.disconnect(topic);
2731
2768
  return true;
2732
2769
  }
@@ -2739,18 +2776,18 @@ class KoniExtension {
2739
2776
  });
2740
2777
  return this.#koniState.requestService.allNotSupportWCRequests;
2741
2778
  }
2742
- approveWalletConnectNotSupport(_ref54) {
2779
+ approveWalletConnectNotSupport(_ref55) {
2743
2780
  let {
2744
2781
  id
2745
- } = _ref54;
2782
+ } = _ref55;
2746
2783
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
2747
2784
  request.resolve();
2748
2785
  return true;
2749
2786
  }
2750
- rejectWalletConnectNotSupport(_ref55) {
2787
+ rejectWalletConnectNotSupport(_ref56) {
2751
2788
  let {
2752
2789
  id
2753
- } = _ref55;
2790
+ } = _ref56;
2754
2791
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
2755
2792
  request.reject(new Error('USER_REJECTED'));
2756
2793
  return true;
@@ -2758,11 +2795,11 @@ class KoniExtension {
2758
2795
 
2759
2796
  /// Manta
2760
2797
 
2761
- async enableMantaPay(_ref56) {
2798
+ async enableMantaPay(_ref57) {
2762
2799
  let {
2763
2800
  address,
2764
2801
  password
2765
- } = _ref56;
2802
+ } = _ref57;
2766
2803
  // always takes the current account
2767
2804
  function timeout() {
2768
2805
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -2852,11 +2889,11 @@ class KoniExtension {
2852
2889
  async disableMantaPay(address) {
2853
2890
  return this.#koniState.disableMantaPay(address);
2854
2891
  }
2855
- async isTonBounceableAddress(_ref57) {
2892
+ async isTonBounceableAddress(_ref58) {
2856
2893
  let {
2857
2894
  address,
2858
2895
  chain
2859
- } = _ref57;
2896
+ } = _ref58;
2860
2897
  try {
2861
2898
  const tonApi = this.#koniState.getTonApi(chain);
2862
2899
  const state = await tonApi.getAccountState(address);
@@ -2902,10 +2939,10 @@ class KoniExtension {
2902
2939
 
2903
2940
  /* Metadata */
2904
2941
 
2905
- async findRawMetadata(_ref58) {
2942
+ async findRawMetadata(_ref59) {
2906
2943
  let {
2907
2944
  genesisHash
2908
- } = _ref58;
2945
+ } = _ref59;
2909
2946
  const {
2910
2947
  metadata,
2911
2948
  specVersion,
@@ -2919,20 +2956,20 @@ class KoniExtension {
2919
2956
  userExtensions
2920
2957
  };
2921
2958
  }
2922
- async calculateMetadataHash(_ref59) {
2959
+ async calculateMetadataHash(_ref60) {
2923
2960
  let {
2924
2961
  chain
2925
- } = _ref59;
2962
+ } = _ref60;
2926
2963
  const hash = await this.#koniState.calculateMetadataHash(chain);
2927
2964
  return {
2928
2965
  metadataHash: hash || ''
2929
2966
  };
2930
2967
  }
2931
- async shortenMetadata(_ref60) {
2968
+ async shortenMetadata(_ref61) {
2932
2969
  let {
2933
2970
  chain,
2934
2971
  txBlob
2935
- } = _ref60;
2972
+ } = _ref61;
2936
2973
  const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
2937
2974
  return {
2938
2975
  txMetadata: shorten || ''
@@ -3178,18 +3215,18 @@ class KoniExtension {
3178
3215
 
3179
3216
  /* Campaign */
3180
3217
 
3181
- unlockDotCheckCanMint(_ref61) {
3218
+ unlockDotCheckCanMint(_ref62) {
3182
3219
  let {
3183
3220
  address,
3184
3221
  network,
3185
3222
  slug
3186
- } = _ref61;
3223
+ } = _ref62;
3187
3224
  return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3188
3225
  }
3189
- unlockDotSubscribeMintedData(id, port, _ref62) {
3226
+ unlockDotSubscribeMintedData(id, port, _ref63) {
3190
3227
  let {
3191
3228
  transactionId
3192
- } = _ref62;
3229
+ } = _ref63;
3193
3230
  const cb = (0, _subscriptions.createSubscription)(id, port);
3194
3231
  const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3195
3232
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
@@ -3221,10 +3258,10 @@ class KoniExtension {
3221
3258
  });
3222
3259
  return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3223
3260
  }
3224
- async completeCampaignBanner(_ref63) {
3261
+ async completeCampaignBanner(_ref64) {
3225
3262
  let {
3226
3263
  slug
3227
- } = _ref63;
3264
+ } = _ref64;
3228
3265
  const campaign = await this.#koniState.dbService.getCampaign(slug);
3229
3266
  if (campaign) {
3230
3267
  await this.#koniState.dbService.upsertCampaign({
@@ -3452,7 +3489,7 @@ class KoniExtension {
3452
3489
  chain,
3453
3490
  notification
3454
3491
  } = data;
3455
- const extrinsicType = _KoniTypes.ExtrinsicType.CLAIM_AVAIL_BRIDGE;
3492
+ const extrinsicType = _KoniTypes.ExtrinsicType.CLAIM_BRIDGE;
3456
3493
  let transaction = null;
3457
3494
  let chainType;
3458
3495
  if ((0, _keyring.isSubstrateAddress)(address)) {
@@ -3473,6 +3510,32 @@ class KoniExtension {
3473
3510
  chainType
3474
3511
  });
3475
3512
  }
3513
+ async getIsClaimedPolygonBridge(data) {
3514
+ const evmApi = this.#koniState.getEvmApi(data.chainslug);
3515
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3516
+ const isClaimed = await (0, _polygonBridge.isClaimedPolygonBridge)(data.chainslug, data.counter, data.sourceNetwork, evmApi);
3517
+ return isClaimed;
3518
+ }
3519
+ async submitClaimPolygonBridge(data) {
3520
+ const {
3521
+ address,
3522
+ chain,
3523
+ notification
3524
+ } = data;
3525
+ const extrinsicType = _KoniTypes.ExtrinsicType.CLAIM_BRIDGE;
3526
+ let transaction = null;
3527
+ const evmApi = this.#koniState.getEvmApi(chain);
3528
+ transaction = await (0, _polygonBridge.getClaimPolygonBridge)(chain, notification, evmApi);
3529
+ const chainType = _KoniTypes.ChainType.EVM;
3530
+ return await this.#koniState.transactionService.handleTransaction({
3531
+ address,
3532
+ chain,
3533
+ transaction,
3534
+ data,
3535
+ extrinsicType,
3536
+ chainType
3537
+ });
3538
+ }
3476
3539
 
3477
3540
  /* Ledger */
3478
3541
 
@@ -4060,6 +4123,8 @@ class KoniExtension {
4060
4123
  return this.fetchInappNotifications(request);
4061
4124
  case 'pri(inappNotification.get)':
4062
4125
  return this.getInappNotification(request);
4126
+ case 'pri(inappNotification.isClaimedPolygonBridge)':
4127
+ return this.getIsClaimedPolygonBridge(request);
4063
4128
  /* Notification service */
4064
4129
 
4065
4130
  /* Avail Bridge */
@@ -4067,6 +4132,13 @@ class KoniExtension {
4067
4132
  return this.submitClaimAvailBridge(request);
4068
4133
  /* Avail Bridge */
4069
4134
 
4135
+ /* Polygon Bridge */
4136
+
4137
+ case 'pri(polygonBridge.submitClaimPolygonBridge)':
4138
+ return this.submitClaimPolygonBridge(request);
4139
+
4140
+ /* Polygon Bridge */
4141
+
4070
4142
  /* Ledger */
4071
4143
  case 'pri(ledger.generic.allow)':
4072
4144
  return this.subscribeLedgerGenericAllowChains(id, port);
@@ -15,6 +15,7 @@ var _balanceService = require("@subwallet/extension-base/services/balance-servic
15
15
  var _types = require("@subwallet/extension-base/services/base/types");
16
16
  var _buyService = _interopRequireDefault(require("@subwallet/extension-base/services/buy-service"));
17
17
  var _campaignService = _interopRequireDefault(require("@subwallet/extension-base/services/campaign-service"));
18
+ var _chainOnlineService = require("@subwallet/extension-base/services/chain-online-service");
18
19
  var _chainService = require("@subwallet/extension-base/services/chain-service");
19
20
  var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
20
21
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
@@ -112,6 +113,7 @@ class KoniState {
112
113
  this.feeService = new _service2.default(this);
113
114
  this.swapService = new _swapService.SwapService(this);
114
115
  this.inappNotificationService = new _inappNotificationService.InappNotificationService(this.dbService, this.keyringService, this.eventService, this.chainService);
116
+ this.chainOnlineService = new _chainOnlineService.ChainOnlineService(this.chainService, this.settingService, this.eventService, this.dbService);
115
117
  this.subscription = new _subscription.KoniSubscription(this, this.dbService);
116
118
  this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
117
119
  this.logger = (0, _util.logger)('State');
@@ -206,7 +208,6 @@ class KoniState {
206
208
  async init() {
207
209
  await this.eventService.waitCryptoReady;
208
210
  await this.chainService.init();
209
- this.afterChainServiceInit();
210
211
  await this.migrationService.run();
211
212
  this.campaignService.init();
212
213
  this.mktCampaignService.init();
@@ -222,7 +223,11 @@ class KoniState {
222
223
  // TODO: consider moving this to a separate service
223
224
  await this.dbService.stores.crowdloan.removeEndedCrowdloans();
224
225
  await this.startSubscription();
226
+ this.chainOnlineService.checkLatestData();
225
227
  this.chainService.checkLatestData();
228
+ this.chainService.subscribeChainInfoMap().subscribe(() => {
229
+ this.afterChainServiceInit();
230
+ });
226
231
  }
227
232
  async initMantaPay(password) {
228
233
  var _this$chainService, _this$chainService$ma;
@@ -792,6 +797,7 @@ class KoniState {
792
797
  return this.chainService.stopAllChainApis();
793
798
  }
794
799
  async resumeAllNetworks() {
800
+ this.chainOnlineService.checkLatestData();
795
801
  return this.chainService.resumeAllChainApis();
796
802
  }
797
803
  publishCrowdloan(reset) {
@@ -1351,8 +1357,11 @@ class KoniState {
1351
1357
  this.chainService.resetWallet(resetAll);
1352
1358
  await this.walletConnectService.resetWallet(resetAll);
1353
1359
  await this.chainService.init();
1354
- this.afterChainServiceInit();
1360
+ this.chainOnlineService.checkLatestData();
1355
1361
  this.chainService.checkLatestData();
1362
+ this.chainService.subscribeChainInfoMap().subscribe(() => {
1363
+ this.afterChainServiceInit();
1364
+ });
1356
1365
  }
1357
1366
  async enableMantaPay(updateStore, address, password, seedPhrase) {
1358
1367
  var _this$chainService3, _this$chainService3$m, _this$chainService4, _this$chainService4$m, _this$chainService4$m2, _this$chainService11, _this$chainService11$, _this$chainService11$2;