@subwallet/extension-base 1.0.4-1 → 1.0.5-1

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 (134) hide show
  1. package/background/KoniTypes.d.ts +12 -1
  2. package/background/KoniTypes.js +1 -0
  3. package/background/errors/TransactionError.js +4 -0
  4. package/background/handlers/State.d.ts +1 -1
  5. package/background/handlers/State.js +2 -8
  6. package/background/handlers/subscriptions.js +0 -1
  7. package/background/types.d.ts +2 -2
  8. package/cjs/background/KoniTypes.js +1 -0
  9. package/cjs/background/errors/TransactionError.js +4 -0
  10. package/cjs/background/handlers/State.js +1 -7
  11. package/cjs/background/handlers/subscriptions.js +0 -1
  12. package/cjs/constants/index.js +6 -6
  13. package/cjs/koni/api/coingecko.js +1 -4
  14. package/cjs/koni/api/dotsama/balance.js +7 -5
  15. package/cjs/koni/api/dotsama/crowdloan.js +0 -4
  16. package/cjs/koni/api/dotsama/transfer.js +0 -4
  17. package/cjs/koni/api/nft/acala_nft/index.js +1 -1
  18. package/cjs/koni/api/nft/bit.country/index.js +1 -1
  19. package/cjs/koni/api/nft/evm_nft/index.js +2 -3
  20. package/cjs/koni/api/nft/index.js +1 -2
  21. package/cjs/koni/api/nft/karura_nft/index.js +1 -1
  22. package/cjs/koni/api/nft/quartz_nft/index.js +1 -1
  23. package/cjs/koni/api/nft/rmrk_nft/index.js +2 -3
  24. package/cjs/koni/api/nft/statemine_nft/index.js +1 -1
  25. package/cjs/koni/api/nft/transfer.js +5 -5
  26. package/cjs/koni/api/nft/unique_nft/index.js +1 -1
  27. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  28. package/cjs/koni/api/nft/wasm_nft/index.js +1 -2
  29. package/cjs/koni/api/staking/bonding/astar.js +28 -12
  30. package/cjs/koni/api/staking/bonding/utils.js +4 -0
  31. package/cjs/koni/api/staking/relayChain.js +0 -1
  32. package/cjs/koni/api/staking/subsquidStaking.js +0 -2
  33. package/cjs/koni/api/tokens/wasm/index.js +0 -1
  34. package/cjs/koni/api/tokens/wasm/utils.js +0 -1
  35. package/cjs/koni/api/xcm/index.js +0 -1
  36. package/cjs/koni/background/cron.js +0 -45
  37. package/cjs/koni/background/handlers/Extension.js +163 -133
  38. package/cjs/koni/background/handlers/State.js +18 -3
  39. package/cjs/koni/background/handlers/Tabs.js +34 -2
  40. package/cjs/koni/background/handlers/index.js +3 -2
  41. package/cjs/koni/background/subscription.js +0 -26
  42. package/cjs/packageInfo.js +1 -1
  43. package/cjs/services/chain-service/handler/EvmChainHandler.js +1 -1
  44. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  45. package/cjs/services/chain-service/handler/light-client/index.js +9 -6
  46. package/cjs/services/chain-service/index.js +0 -2
  47. package/cjs/services/chain-service/utils.js +3 -0
  48. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +108 -0
  49. package/cjs/services/history-service/index.js +60 -5
  50. package/cjs/services/history-service/subsquid-multi-chain-history.js +3 -2
  51. package/cjs/services/history-service/testChainMap.js +724 -0
  52. package/cjs/services/keyring-service/index.js +0 -2
  53. package/cjs/services/migration-service/index.js +0 -3
  54. package/cjs/services/migration-service/scripts/MigrateAutoLock.js +30 -0
  55. package/cjs/services/migration-service/scripts/MigrateChainPatrol.js +30 -0
  56. package/cjs/services/migration-service/scripts/index.js +5 -1
  57. package/cjs/services/price-service/coingecko.js +1 -1
  58. package/cjs/services/price-service/index.js +0 -3
  59. package/cjs/services/request-service/handler/AuthRequestHandler.js +1 -1
  60. package/cjs/services/setting-service/constants.js +8 -2
  61. package/cjs/services/storage-service/DatabaseService.js +2 -44
  62. package/cjs/services/transaction-service/constants.js +11 -0
  63. package/cjs/services/transaction-service/index.js +28 -9
  64. package/cjs/services/transaction-service/utils.js +25 -14
  65. package/constants/index.d.ts +1 -1
  66. package/constants/index.js +1 -1
  67. package/koni/api/coingecko.js +1 -4
  68. package/koni/api/dotsama/balance.js +7 -5
  69. package/koni/api/dotsama/crowdloan.js +0 -4
  70. package/koni/api/dotsama/transfer.js +0 -4
  71. package/koni/api/nft/acala_nft/index.js +1 -1
  72. package/koni/api/nft/bit.country/index.js +1 -1
  73. package/koni/api/nft/evm_nft/index.js +2 -3
  74. package/koni/api/nft/index.js +1 -2
  75. package/koni/api/nft/karura_nft/index.js +1 -1
  76. package/koni/api/nft/quartz_nft/index.js +1 -1
  77. package/koni/api/nft/rmrk_nft/index.js +2 -3
  78. package/koni/api/nft/statemine_nft/index.js +1 -1
  79. package/koni/api/nft/transfer.js +5 -5
  80. package/koni/api/nft/unique_nft/index.js +1 -1
  81. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  82. package/koni/api/nft/wasm_nft/index.js +1 -2
  83. package/koni/api/staking/bonding/astar.d.ts +2 -1
  84. package/koni/api/staking/bonding/astar.js +27 -12
  85. package/koni/api/staking/bonding/utils.js +4 -0
  86. package/koni/api/staking/relayChain.js +0 -1
  87. package/koni/api/staking/subsquidStaking.js +0 -2
  88. package/koni/api/tokens/wasm/index.js +0 -1
  89. package/koni/api/tokens/wasm/utils.js +0 -1
  90. package/koni/api/xcm/index.js +0 -1
  91. package/koni/background/cron.js +0 -45
  92. package/koni/background/handlers/Extension.d.ts +2 -0
  93. package/koni/background/handlers/Extension.js +78 -50
  94. package/koni/background/handlers/State.d.ts +3 -1
  95. package/koni/background/handlers/State.js +18 -3
  96. package/koni/background/handlers/Tabs.d.ts +1 -0
  97. package/koni/background/handlers/Tabs.js +32 -1
  98. package/koni/background/handlers/index.js +3 -2
  99. package/koni/background/subscription.d.ts +0 -1
  100. package/koni/background/subscription.js +0 -26
  101. package/package.json +55 -34
  102. package/packageInfo.js +1 -1
  103. package/services/chain-service/handler/EvmChainHandler.js +1 -1
  104. package/services/chain-service/handler/SubstrateChainHandler.js +2 -9
  105. package/services/chain-service/handler/light-client/index.js +8 -6
  106. package/services/chain-service/helper/api-helper/spec/acala.d.ts +3 -3
  107. package/services/chain-service/index.js +0 -2
  108. package/services/chain-service/utils.js +3 -0
  109. package/services/history-service/helpers/recoverHistoryStatus.d.ts +11 -0
  110. package/services/history-service/helpers/recoverHistoryStatus.js +98 -0
  111. package/services/history-service/index.d.ts +6 -0
  112. package/services/history-service/index.js +61 -6
  113. package/services/history-service/subsquid-multi-chain-history.js +3 -2
  114. package/services/history-service/testChainMap.d.ts +3 -0
  115. package/services/history-service/testChainMap.js +716 -0
  116. package/services/keyring-service/index.js +0 -2
  117. package/services/migration-service/index.js +0 -3
  118. package/services/migration-service/scripts/MigrateAutoLock.d.ts +4 -0
  119. package/services/migration-service/scripts/MigrateAutoLock.js +22 -0
  120. package/services/migration-service/scripts/MigrateChainPatrol.d.ts +4 -0
  121. package/services/migration-service/scripts/MigrateChainPatrol.js +22 -0
  122. package/services/migration-service/scripts/index.js +5 -1
  123. package/services/price-service/coingecko.js +1 -1
  124. package/services/price-service/index.js +0 -3
  125. package/services/request-service/handler/AuthRequestHandler.js +1 -1
  126. package/services/setting-service/constants.d.ts +4 -2
  127. package/services/setting-service/constants.js +5 -1
  128. package/services/storage-service/DatabaseService.js +2 -44
  129. package/services/transaction-service/constants.d.ts +1 -0
  130. package/services/transaction-service/constants.js +4 -0
  131. package/services/transaction-service/index.d.ts +1 -0
  132. package/services/transaction-service/index.js +29 -10
  133. package/services/transaction-service/utils.d.ts +1 -1
  134. package/services/transaction-service/utils.js +24 -13
@@ -7,7 +7,7 @@ import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/ext
7
7
  import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
8
8
  import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
9
9
  import { AccountExternalErrorCode, BasicTxErrorType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
10
- import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH, DEFAULT_TIME_AUTO_LOCK } from '@subwallet/extension-base/constants';
10
+ import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
11
11
  import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
12
12
  import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
13
13
  import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic } from '@subwallet/extension-base/koni/api/dotsama/transfer';
@@ -20,6 +20,7 @@ import { getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/to
20
20
  import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
21
21
  import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isLocalToken, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
22
22
  import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
23
+ import { DEFAULT_AUTO_LOCK_TIME } from '@subwallet/extension-base/services/setting-service/constants';
23
24
  import { reformatAddress } from '@subwallet/extension-base/utils';
24
25
  import { convertSubjectInfoToAddresses } from '@subwallet/extension-base/utils/address';
25
26
  import { createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
@@ -55,8 +56,20 @@ const ACCOUNT_ALL_JSON = {
55
56
  export default class KoniExtension {
56
57
  #lockTimeOut = undefined;
57
58
  #koniState;
59
+ #timeAutoLock = DEFAULT_AUTO_LOCK_TIME;
58
60
  constructor(state) {
59
61
  this.#koniState = state;
62
+ const updateTimeAutoLock = rs => {
63
+ this.#timeAutoLock = rs.timeAutoLock;
64
+ clearTimeout(this.#lockTimeOut);
65
+ this.#lockTimeOut = setTimeout(() => {
66
+ this.keyringLock();
67
+ }, this.#timeAutoLock * 60 * 1000);
68
+ };
69
+ this.#koniState.settingService.getSettings(updateTimeAutoLock);
70
+ this.#koniState.settingService.getSubject().subscribe({
71
+ next: updateTimeAutoLock
72
+ });
60
73
  }
61
74
 
62
75
  /// Clone from PolkadotJs
@@ -326,7 +339,6 @@ export default class KoniExtension {
326
339
  windowOpen(path) {
327
340
  const url = `${chrome.extension.getURL('index.html')}#${path}`;
328
341
  if (!ALLOWED_PATH.includes(path)) {
329
- console.error('Not allowed to open the url:', url);
330
342
  return false;
331
343
  }
332
344
  withErrorLog(() => chrome.tabs.create({
@@ -712,7 +724,6 @@ export default class KoniExtension {
712
724
  assert(value, 'The source is not known');
713
725
  if (this.isAddressValidWithAuthType(address, value[url].accountAuthType)) {
714
726
  value[url].isAllowedMap[address] = connectValue;
715
- console.log('Devbu: ', value);
716
727
  this.#koniState.setAuthorize(value, () => {
717
728
  callBack && callBack(value);
718
729
  });
@@ -725,7 +736,6 @@ export default class KoniExtension {
725
736
  this.#koniState.getAuthorize(value => {
726
737
  assert(value, 'The source is not known');
727
738
  value[id].isAllowed = connectValue;
728
- console.log('Devbu: ', value);
729
739
  this.#koniState.setAuthorize(value);
730
740
  });
731
741
  }
@@ -733,7 +743,6 @@ export default class KoniExtension {
733
743
  this.#koniState.getAuthorize(value => {
734
744
  assert(value, 'The source is not known');
735
745
  value[id].isAllowedMap = values;
736
- console.log('Devbu: ', value);
737
746
  this.#koniState.setAuthorize(value);
738
747
  });
739
748
  }
@@ -762,22 +771,18 @@ export default class KoniExtension {
762
771
  });
763
772
  });
764
773
  }
765
- toggleBalancesVisibility(id, port) {
766
- const cb = createSubscription(id, port);
767
- this.#koniState.getSettings(value => {
768
- const updateValue = {
769
- ...value,
770
- isShowBalance: !value.isShowBalance
771
- };
772
- this.#koniState.setSettings(updateValue, () => {
773
- // eslint-disable-next-line node/no-callback-literal
774
- cb(updateValue);
774
+ async toggleBalancesVisibility() {
775
+ return new Promise(resolve => {
776
+ this.#koniState.getSettings(value => {
777
+ const updateValue = {
778
+ ...value,
779
+ isShowBalance: !value.isShowBalance
780
+ };
781
+ this.#koniState.setSettings(updateValue, () => {
782
+ resolve(!value.isShowBalance);
783
+ });
775
784
  });
776
785
  });
777
- port.onDisconnect.addListener(() => {
778
- this.cancelSubscription(id);
779
- });
780
- return true;
781
786
  }
782
787
  saveAccountAllLogo(data, id, port) {
783
788
  const cb = createSubscription(id, port);
@@ -818,6 +823,12 @@ export default class KoniExtension {
818
823
  });
819
824
  return true;
820
825
  }
826
+ setAutoLockTime({
827
+ autoLockTime
828
+ }) {
829
+ this.#koniState.setAutoLockTime(autoLockTime);
830
+ return true;
831
+ }
821
832
  async subscribeSettings(id, port) {
822
833
  const cb = createSubscription(id, port);
823
834
  const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
@@ -831,6 +842,12 @@ export default class KoniExtension {
831
842
  });
832
843
  return await this.getSettings();
833
844
  }
845
+ setEnableChainPatrol({
846
+ enable
847
+ }) {
848
+ this.#koniState.setEnableChainPatrol(enable);
849
+ return true;
850
+ }
834
851
  async subscribeAuthUrls(id, port) {
835
852
  const cb = createSubscription(id, port);
836
853
  const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
@@ -898,7 +915,7 @@ export default class KoniExtension {
898
915
  this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
899
916
  return true;
900
917
  } catch (e) {
901
- console.error('Error updating asset setting', e);
918
+ console.error(e);
902
919
  return false;
903
920
  }
904
921
  }
@@ -1522,7 +1539,7 @@ export default class KoniExtension {
1522
1539
  try {
1523
1540
  return this.#koniState.refreshSubstrateApi(networkKey);
1524
1541
  } catch (e) {
1525
- console.error('error recovering substrate api', e);
1542
+ console.error(e);
1526
1543
  return false;
1527
1544
  }
1528
1545
  }
@@ -1531,7 +1548,7 @@ export default class KoniExtension {
1531
1548
  await this.#koniState.upsertCustomToken(data);
1532
1549
  return true;
1533
1550
  } catch (e) {
1534
- console.error('Error insert/update custom token', e);
1551
+ console.error(e);
1535
1552
  return false;
1536
1553
  }
1537
1554
  }
@@ -1593,26 +1610,39 @@ export default class KoniExtension {
1593
1610
  estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
1594
1611
  } catch (e) {
1595
1612
  estimatedFee = '0';
1596
- console.warn('Error estimating fee', e);
1613
+ console.warn(e);
1597
1614
  }
1598
1615
  }
1599
1616
  } else {
1600
- const [mockTx] = await createTransferExtrinsic({
1601
- from: address,
1602
- networkKey,
1603
- substrateApi,
1604
- to: address,
1605
- tokenInfo,
1606
- transferAll: true,
1607
- value: '0'
1608
- });
1609
- try {
1610
- var _paymentInfo$partialF2;
1611
- const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1612
- estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1613
- } catch (e) {
1614
- estimatedFee = '0';
1615
- console.warn('Error estimating fee', e);
1617
+ const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
1618
+ if (_isChainEvmCompatible(chainInfo)) {
1619
+ const web3 = this.#koniState.chainService.getEvmApi(networkKey);
1620
+ const transaction = {
1621
+ value: 1,
1622
+ to: address,
1623
+ from: address
1624
+ };
1625
+ const gasPrice = await web3.api.eth.getGasPrice();
1626
+ const gasLimit = await web3.api.eth.estimateGas(transaction);
1627
+ estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1628
+ } else {
1629
+ const [mockTx] = await createTransferExtrinsic({
1630
+ from: address,
1631
+ networkKey,
1632
+ substrateApi,
1633
+ to: address,
1634
+ tokenInfo,
1635
+ transferAll: true,
1636
+ value: '0'
1637
+ });
1638
+ try {
1639
+ var _paymentInfo$partialF2;
1640
+ const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1641
+ estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1642
+ } catch (e) {
1643
+ estimatedFee = '0';
1644
+ console.warn('Error estimating fee', e);
1645
+ }
1616
1646
  }
1617
1647
  }
1618
1648
  maxTransferable = maxTransferable.sub(new BN(estimatedFee));
@@ -2147,7 +2177,6 @@ export default class KoniExtension {
2147
2177
  }
2148
2178
  async getNominationPoolOptions(chain) {
2149
2179
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2150
- console.log('chain', chain);
2151
2180
  return await getNominationPoolsInfo(chain, substrateApi);
2152
2181
  }
2153
2182
  async submitBonding(inputData) {
@@ -2169,7 +2198,6 @@ export default class KoniExtension {
2169
2198
  }
2170
2199
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2171
2200
  const extrinsic = await getBondingExtrinsic(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata);
2172
- console.log('Bonding extrinsic: ', chain, extrinsic.toHex());
2173
2201
  return await this.#koniState.transactionService.handleTransaction({
2174
2202
  address,
2175
2203
  chain: chain,
@@ -2198,7 +2226,6 @@ export default class KoniExtension {
2198
2226
  }
2199
2227
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2200
2228
  const extrinsic = await getUnbondingExtrinsic(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
2201
- console.log('Unbonding extrinsic: ', extrinsic.toHex());
2202
2229
  return await this.#koniState.transactionService.handleTransaction({
2203
2230
  address: nominatorMetadata.address,
2204
2231
  chain: chain,
@@ -2219,7 +2246,6 @@ export default class KoniExtension {
2219
2246
  }
2220
2247
  const dotSamaApi = this.#koniState.getSubstrateApi(chain);
2221
2248
  const extrinsic = await getWithdrawalExtrinsic(dotSamaApi, chain, nominatorMetadata, validatorAddress);
2222
- console.log('Stake withdrawal extrinsic: ', extrinsic.toHex());
2223
2249
  return await this.#koniState.transactionService.handleTransaction({
2224
2250
  address: nominatorMetadata.address,
2225
2251
  chain: chain,
@@ -2241,7 +2267,6 @@ export default class KoniExtension {
2241
2267
  }
2242
2268
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2243
2269
  const extrinsic = await getClaimRewardExtrinsic(substrateApi, chain, address, stakingType, bondReward);
2244
- console.log('Staking claim reward extrinsic: ', extrinsic.toHex());
2245
2270
  return await this.#koniState.transactionService.handleTransaction({
2246
2271
  address,
2247
2272
  chain: chain,
@@ -2262,7 +2287,6 @@ export default class KoniExtension {
2262
2287
  }
2263
2288
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2264
2289
  const extrinsic = await getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking);
2265
- console.log('Cancel stake withdrawal extrinsic', extrinsic.toHex());
2266
2290
  return await this.#koniState.transactionService.handleTransaction({
2267
2291
  address,
2268
2292
  chain,
@@ -2291,7 +2315,6 @@ export default class KoniExtension {
2291
2315
  }
2292
2316
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2293
2317
  const extrinsic = await getPoolingBondingExtrinsic(substrateApi, amount, selectedPool.id, nominatorMetadata);
2294
- console.log('Join nomination pool extrinsic', extrinsic.toHex());
2295
2318
  return await this.#koniState.transactionService.handleTransaction({
2296
2319
  address,
2297
2320
  chain,
@@ -2317,7 +2340,6 @@ export default class KoniExtension {
2317
2340
  }
2318
2341
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2319
2342
  const extrinsic = await getPoolingUnbondingExtrinsic(substrateApi, amount, nominatorMetadata);
2320
- console.log('Nomination pool unbond extrinsic', extrinsic.toHex());
2321
2343
  return await this.#koniState.transactionService.handleTransaction({
2322
2344
  address: nominatorMetadata.address,
2323
2345
  chain,
@@ -2623,7 +2645,7 @@ export default class KoniExtension {
2623
2645
  this._addAddressToAuthList(address, isAllowed);
2624
2646
  result.push(childPair);
2625
2647
  } catch (e) {
2626
- console.log(`Fail to derive from ${parentAddress} with path ${item.suri}`, e);
2648
+ console.log(e);
2627
2649
  }
2628
2650
  }
2629
2651
  if (result.length === 1) {
@@ -2867,7 +2889,7 @@ export default class KoniExtension {
2867
2889
  clearTimeout(this.#lockTimeOut);
2868
2890
  this.#lockTimeOut = setTimeout(() => {
2869
2891
  this.keyringLock();
2870
- }, DEFAULT_TIME_AUTO_LOCK);
2892
+ }, this.#timeAutoLock * 60 * 1000);
2871
2893
  switch (type) {
2872
2894
  /// Clone from PolkadotJs
2873
2895
  case 'pri(accounts.create.external)':
@@ -2947,7 +2969,9 @@ export default class KoniExtension {
2947
2969
  case 'pri(authorize.toggle)':
2948
2970
  return this.toggleAuthorization2(request);
2949
2971
  case 'pri(settings.changeBalancesVisibility)':
2950
- return this.toggleBalancesVisibility(id, port);
2972
+ return await this.toggleBalancesVisibility();
2973
+
2974
+ // Settings
2951
2975
  case 'pri(settings.subscribe)':
2952
2976
  return await this.subscribeSettings(id, port);
2953
2977
  case 'pri(settings.saveAccountAllLogo)':
@@ -2958,6 +2982,10 @@ export default class KoniExtension {
2958
2982
  return this.saveTheme(request, id, port);
2959
2983
  case 'pri(settings.saveBrowserConfirmationType)':
2960
2984
  return this.saveBrowserConfirmationType(request, id, port);
2985
+ case 'pri(settings.saveAutoLockTime)':
2986
+ return this.setAutoLockTime(request);
2987
+ case 'pri(settings.saveEnableChainPatrol)':
2988
+ return this.setEnableChainPatrol(request);
2961
2989
  case 'pri(price.getPrice)':
2962
2990
  return await this.getPrice();
2963
2991
  case 'pri(price.getSubscription)':
@@ -65,7 +65,7 @@ export default class KoniState {
65
65
  getMetaRequest(id: string): MetaRequest;
66
66
  getSignRequest(id: string): SignRequest | undefined;
67
67
  rpcListProviders(): Promise<ResponseRpcListProviders>;
68
- rpcSend(request: RequestRpcSend, port: chrome.runtime.Port): Promise<JsonRpcResponse>;
68
+ rpcSend(request: RequestRpcSend, port: chrome.runtime.Port): Promise<JsonRpcResponse<unknown>>;
69
69
  rpcStartProvider(key: string, port: chrome.runtime.Port): Promise<ProviderMeta>;
70
70
  rpcSubscribe({ method, params, type }: RequestRpcSubscribe, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): Promise<number | string>;
71
71
  rpcSubscribeConnected(_request: null, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): void;
@@ -133,6 +133,8 @@ export default class KoniState {
133
133
  setTheme(theme: ThemeNames, callback?: (settingData: UiSettings) => void): void;
134
134
  setBrowserConfirmationType(browserConfirmationType: BrowserConfirmationType, callback?: (settingData: UiSettings) => void): void;
135
135
  setCamera(value: boolean): void;
136
+ setAutoLockTime(value: number): void;
137
+ setEnableChainPatrol(value: boolean): void;
136
138
  subscribeSettingsSubject(): Subject<RequestSettingsType>;
137
139
  getAccountAddress(): string | null;
138
140
  getDecodedAddresses(address?: string): string[];
@@ -198,7 +198,6 @@ export default class KoniState {
198
198
  this.onReady();
199
199
  this.onAccountAdd();
200
200
  this.onAccountRemove();
201
- this.logger.log('Done init state');
202
201
  }
203
202
  startSubscription() {
204
203
  this.dbService.subscribeChainStakingMetadata([], data => {
@@ -214,7 +213,6 @@ export default class KoniState {
214
213
  this.historyService.start().catch(console.error);
215
214
  this.priceService.start().catch(console.error);
216
215
  this.ready = true;
217
- this.logger.log('State is ready');
218
216
  }
219
217
  isReady() {
220
218
  return this.ready;
@@ -607,7 +605,24 @@ export default class KoniState {
607
605
  ...settings,
608
606
  camera: value
609
607
  };
610
- console.log(newSettings, value);
608
+ this.settingService.setSettings(newSettings);
609
+ });
610
+ }
611
+ setAutoLockTime(value) {
612
+ this.settingService.getSettings(settings => {
613
+ const newSettings = {
614
+ ...settings,
615
+ timeAutoLock: value
616
+ };
617
+ this.settingService.setSettings(newSettings);
618
+ });
619
+ }
620
+ setEnableChainPatrol(value) {
621
+ this.settingService.getSettings(settings => {
622
+ const newSettings = {
623
+ ...settings,
624
+ enableChainPatrol: value
625
+ };
611
626
  this.settingService.setSettings(newSettings);
612
627
  });
613
628
  }
@@ -3,6 +3,7 @@ import { AuthUrlInfo } from '@subwallet/extension-base/background/handlers/State
3
3
  import { MessageTypes, RequestTypes, ResponseTypes } from '@subwallet/extension-base/background/types';
4
4
  import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
5
5
  import { RequestArguments } from 'web3-core';
6
+ export declare const chainPatrolCheckUrl: (url: string) => Promise<boolean>;
6
7
  export default class KoniTabs {
7
8
  #private;
8
9
  private evmEventEmitterMap;
@@ -11,6 +11,7 @@ import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestEx
11
11
  import { ALL_ACCOUNT_KEY, CRON_GET_API_MAP_STATUS } from '@subwallet/extension-base/constants';
12
12
  import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
13
13
  import { _generateCustomProviderKey } from '@subwallet/extension-base/services/chain-service/utils';
14
+ import { DEFAULT_CHAIN_PATROL_ENABLE } from '@subwallet/extension-base/services/setting-service/constants';
14
15
  import { canDerive } from '@subwallet/extension-base/utils';
15
16
  import keyring from '@subwallet/ui-keyring';
16
17
  import Web3 from 'web3';
@@ -63,11 +64,35 @@ function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTyp
63
64
  type
64
65
  }));
65
66
  }
67
+ // check if a URL is blocked
68
+ export const chainPatrolCheckUrl = async url => {
69
+ const response = await fetch('https://app.chainpatrol.io/api/v2/asset/check', {
70
+ method: 'POST',
71
+ headers: {
72
+ 'Content-Type': 'application/json',
73
+ 'X-API-KEY': 'e5e88cd0-7994-4667-9071-bab849c2ba71'
74
+ },
75
+ body: JSON.stringify({
76
+ type: 'URL',
77
+ content: url
78
+ })
79
+ });
80
+ const data = await response.json();
81
+ return data.status === 'BLOCKED';
82
+ };
66
83
  export default class KoniTabs {
67
84
  #koniState;
68
85
  evmEventEmitterMap = {};
86
+ #chainPatrolService = DEFAULT_CHAIN_PATROL_ENABLE;
69
87
  constructor(koniState) {
70
88
  this.#koniState = koniState;
89
+ const updateChainPatrolService = rs => {
90
+ this.#chainPatrolService = rs.enableChainPatrol;
91
+ };
92
+ this.#koniState.settingService.getSettings(updateChainPatrolService);
93
+ this.#koniState.settingService.getSubject().subscribe({
94
+ next: updateChainPatrolService
95
+ });
71
96
  }
72
97
 
73
98
  /// Clone from Polkadot.js
@@ -160,6 +185,13 @@ export default class KoniTabs {
160
185
  this.redirectPhishingLanding(url);
161
186
  return true;
162
187
  }
188
+ if (this.#chainPatrolService) {
189
+ const isInChainPatrolDenyList = await chainPatrolCheckUrl(url);
190
+ if (isInChainPatrolDenyList) {
191
+ this.redirectPhishingLanding(url);
192
+ return true;
193
+ }
194
+ }
163
195
  return false;
164
196
  }
165
197
 
@@ -649,7 +681,6 @@ export default class KoniTabs {
649
681
  const {
650
682
  method
651
683
  } = request;
652
- console.log('method: ' + method);
653
684
  try {
654
685
  switch (method) {
655
686
  case 'eth_chainId':
@@ -46,11 +46,12 @@ export default function handlers({
46
46
  const sender = port.sender;
47
47
  const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
48
48
  const source = `${from}: ${id}: ${message}`;
49
- console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
49
+
50
+ // console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
50
51
 
51
52
  const promise = isMobile ? mobile.handle(id, message, request, port) : isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
52
53
  promise.then(response => {
53
- console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
54
+ // console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
54
55
 
55
56
  // between the start and the end of the promise, the user may have closed
56
57
  // the tab, in which case port will be undefined
@@ -17,7 +17,6 @@ export declare class KoniSubscription {
17
17
  stopAllSubscription(): void;
18
18
  start(): void;
19
19
  stop(): void;
20
- init(): void;
21
20
  subscribeBalancesAndCrowdloans(address: string, chainInfoMap: Record<string, _ChainInfo>, chainStateMap: Record<string, _ChainState>, substrateApiMap: Record<string, _SubstrateApi>, web3ApiMap: Record<string, _EvmApi>, onlyRunOnFirstTime?: boolean): void;
22
21
  subscribeStakingOnChain(address: string, substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): void;
23
22
  initStakingOnChainSubscription(addresses: string[], substrateApiMap: Record<string, _SubstrateApi>, onlyRunOnFirstTime?: boolean): (() => void) | undefined;
@@ -25,7 +25,6 @@ export class KoniSubscription {
25
25
  this.dbService = dbService;
26
26
  this.state = state;
27
27
  this.logger = createLogger('Subscription');
28
- this.init();
29
28
  }
30
29
  getSubscriptionMap() {
31
30
  return this.subscriptionMap;
@@ -54,7 +53,6 @@ export class KoniSubscription {
54
53
  }
55
54
  start() {
56
55
  var _this$state$keyringSe;
57
- this.logger.log('Starting subscription');
58
56
  const currentAddress = (_this$state$keyringSe = this.state.keyringService.currentAccount) === null || _this$state$keyringSe === void 0 ? void 0 : _this$state$keyringSe.address;
59
57
  if (currentAddress) {
60
58
  this.subscribeBalancesAndCrowdloans(currentAddress, this.state.getChainInfoMap(), this.state.getChainStateMap(), this.state.getSubstrateApiMap(), this.state.getEvmApiMap());
@@ -67,7 +65,6 @@ export class KoniSubscription {
67
65
  if (!needReload) {
68
66
  return;
69
67
  }
70
- this.logger.log('ServiceInfo updated, restarting...');
71
68
  const address = (_serviceInfo$currentA = serviceInfo.currentAccountInfo) === null || _serviceInfo$currentA === void 0 ? void 0 : _serviceInfo$currentA.address;
72
69
  if (!address) {
73
70
  return;
@@ -78,34 +75,12 @@ export class KoniSubscription {
78
75
  this.state.eventService.onLazy(this.eventHandler);
79
76
  }
80
77
  stop() {
81
- this.logger.log('Stopping subscription');
82
78
  if (this.eventHandler) {
83
79
  this.state.eventService.offLazy(this.eventHandler);
84
80
  this.eventHandler = undefined;
85
81
  }
86
82
  this.stopAllSubscription();
87
83
  }
88
- init() {
89
- this.state.getAuthorize(value => {
90
- const authString = localStorage.getItem('authUrls') || '{}';
91
- const previousAuth = JSON.parse(authString);
92
- if (previousAuth && Object.keys(previousAuth).length) {
93
- Object.keys(previousAuth).forEach(url => {
94
- if (previousAuth[url].isAllowed) {
95
- previousAuth[url].isAllowedMap = this.state.getAddressList(true);
96
- } else {
97
- previousAuth[url].isAllowedMap = this.state.getAddressList();
98
- }
99
- });
100
- }
101
- const migrateValue = {
102
- ...previousAuth,
103
- ...value
104
- };
105
- this.state.setAuthorize(migrateValue);
106
- localStorage.setItem('authUrls', '{}');
107
- });
108
- }
109
84
  subscribeBalancesAndCrowdloans(address, chainInfoMap, chainStateMap, substrateApiMap, web3ApiMap, onlyRunOnFirstTime) {
110
85
  this.state.handleSwitchAccount(address).then(() => {
111
86
  const addresses = this.state.getDecodedAddresses(address);
@@ -254,7 +229,6 @@ export class KoniSubscription {
254
229
  if (dataFromApi[chainInfo.slug]) {
255
230
  this.state.updateChainStakingMetadata(dataFromApi[chainInfo.slug]);
256
231
  } else {
257
- console.warn('Not found staking data from api', chainInfo.slug);
258
232
  const chainStakingMetadata = await getChainStakingMetadata(chainInfo, substrateApiMap[chainInfo.slug]);
259
233
  this.state.updateChainStakingMetadata(chainStakingMetadata);
260
234
  }