@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
@@ -24,6 +24,7 @@ var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
24
24
  var _xcm = require("@subwallet/extension-base/koni/api/xcm");
25
25
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
26
26
  var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
27
+ var _constants3 = require("@subwallet/extension-base/services/setting-service/constants");
27
28
  var _utils2 = require("@subwallet/extension-base/utils");
28
29
  var _address2 = require("@subwallet/extension-base/utils/address");
29
30
  var _eth = require("@subwallet/extension-base/utils/eth");
@@ -65,8 +66,20 @@ const ACCOUNT_ALL_JSON = {
65
66
  class KoniExtension {
66
67
  #lockTimeOut = undefined;
67
68
  #koniState;
69
+ #timeAutoLock = _constants3.DEFAULT_AUTO_LOCK_TIME;
68
70
  constructor(state) {
69
71
  this.#koniState = state;
72
+ const updateTimeAutoLock = rs => {
73
+ this.#timeAutoLock = rs.timeAutoLock;
74
+ clearTimeout(this.#lockTimeOut);
75
+ this.#lockTimeOut = setTimeout(() => {
76
+ this.keyringLock();
77
+ }, this.#timeAutoLock * 60 * 1000);
78
+ };
79
+ this.#koniState.settingService.getSettings(updateTimeAutoLock);
80
+ this.#koniState.settingService.getSubject().subscribe({
81
+ next: updateTimeAutoLock
82
+ });
70
83
  }
71
84
 
72
85
  /// Clone from PolkadotJs
@@ -352,7 +365,6 @@ class KoniExtension {
352
365
  windowOpen(path) {
353
366
  const url = `${chrome.extension.getURL('index.html')}#${path}`;
354
367
  if (!_defaults.ALLOWED_PATH.includes(path)) {
355
- console.error('Not allowed to open the url:', url);
356
368
  return false;
357
369
  }
358
370
  (0, _helpers.withErrorLog)(() => chrome.tabs.create({
@@ -747,7 +759,6 @@ class KoniExtension {
747
759
  (0, _util.assert)(value, 'The source is not known');
748
760
  if (this.isAddressValidWithAuthType(address, value[url].accountAuthType)) {
749
761
  value[url].isAllowedMap[address] = connectValue;
750
- console.log('Devbu: ', value);
751
762
  this.#koniState.setAuthorize(value, () => {
752
763
  callBack && callBack(value);
753
764
  });
@@ -760,7 +771,6 @@ class KoniExtension {
760
771
  this.#koniState.getAuthorize(value => {
761
772
  (0, _util.assert)(value, 'The source is not known');
762
773
  value[id].isAllowed = connectValue;
763
- console.log('Devbu: ', value);
764
774
  this.#koniState.setAuthorize(value);
765
775
  });
766
776
  }
@@ -768,7 +778,6 @@ class KoniExtension {
768
778
  this.#koniState.getAuthorize(value => {
769
779
  (0, _util.assert)(value, 'The source is not known');
770
780
  value[id].isAllowedMap = values;
771
- console.log('Devbu: ', value);
772
781
  this.#koniState.setAuthorize(value);
773
782
  });
774
783
  }
@@ -797,22 +806,18 @@ class KoniExtension {
797
806
  });
798
807
  });
799
808
  }
800
- toggleBalancesVisibility(id, port) {
801
- const cb = (0, _subscriptions.createSubscription)(id, port);
802
- this.#koniState.getSettings(value => {
803
- const updateValue = {
804
- ...value,
805
- isShowBalance: !value.isShowBalance
806
- };
807
- this.#koniState.setSettings(updateValue, () => {
808
- // eslint-disable-next-line node/no-callback-literal
809
- cb(updateValue);
809
+ async toggleBalancesVisibility() {
810
+ return new Promise(resolve => {
811
+ this.#koniState.getSettings(value => {
812
+ const updateValue = {
813
+ ...value,
814
+ isShowBalance: !value.isShowBalance
815
+ };
816
+ this.#koniState.setSettings(updateValue, () => {
817
+ resolve(!value.isShowBalance);
818
+ });
810
819
  });
811
820
  });
812
- port.onDisconnect.addListener(() => {
813
- this.cancelSubscription(id);
814
- });
815
- return true;
816
821
  }
817
822
  saveAccountAllLogo(data, id, port) {
818
823
  const cb = (0, _subscriptions.createSubscription)(id, port);
@@ -854,6 +859,13 @@ class KoniExtension {
854
859
  });
855
860
  return true;
856
861
  }
862
+ setAutoLockTime(_ref28) {
863
+ let {
864
+ autoLockTime
865
+ } = _ref28;
866
+ this.#koniState.setAutoLockTime(autoLockTime);
867
+ return true;
868
+ }
857
869
  async subscribeSettings(id, port) {
858
870
  const cb = (0, _subscriptions.createSubscription)(id, port);
859
871
  const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
@@ -867,6 +879,13 @@ class KoniExtension {
867
879
  });
868
880
  return await this.getSettings();
869
881
  }
882
+ setEnableChainPatrol(_ref29) {
883
+ let {
884
+ enable
885
+ } = _ref29;
886
+ this.#koniState.setEnableChainPatrol(enable);
887
+ return true;
888
+ }
870
889
  async subscribeAuthUrls(id, port) {
871
890
  const cb = (0, _subscriptions.createSubscription)(id, port);
872
891
  const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
@@ -934,7 +953,7 @@ class KoniExtension {
934
953
  this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
935
954
  return true;
936
955
  } catch (e) {
937
- console.error('Error updating asset setting', e);
956
+ console.error(e);
938
957
  return false;
939
958
  }
940
959
  }
@@ -1039,7 +1058,7 @@ class KoniExtension {
1039
1058
  }
1040
1059
  });
1041
1060
  }
1042
- async accountsCreateSuriV2(_ref28) {
1061
+ async accountsCreateSuriV2(_ref30) {
1043
1062
  let {
1044
1063
  genesisHash,
1045
1064
  isAllowed,
@@ -1047,7 +1066,7 @@ class KoniExtension {
1047
1066
  password,
1048
1067
  suri: _suri,
1049
1068
  types
1050
- } = _ref28;
1069
+ } = _ref30;
1051
1070
  const addressDict = {};
1052
1071
  let changedAccount = false;
1053
1072
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
@@ -1095,10 +1114,10 @@ class KoniExtension {
1095
1114
  });
1096
1115
  return addressDict;
1097
1116
  }
1098
- async accountsForgetOverride(_ref29) {
1117
+ async accountsForgetOverride(_ref31) {
1099
1118
  let {
1100
1119
  address
1101
- } = _ref29;
1120
+ } = _ref31;
1102
1121
  _uiKeyring.keyring.forgetAccount(address);
1103
1122
  await new Promise(resolve => {
1104
1123
  this.#koniState.removeAccountRef(address, () => {
@@ -1130,12 +1149,12 @@ class KoniExtension {
1130
1149
  });
1131
1150
  return true;
1132
1151
  }
1133
- seedCreateV2(_ref30) {
1152
+ seedCreateV2(_ref32) {
1134
1153
  let {
1135
1154
  length = _Extension.SEED_DEFAULT_LENGTH,
1136
1155
  seed: _seed,
1137
1156
  types
1138
- } = _ref30;
1157
+ } = _ref32;
1139
1158
  const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
1140
1159
  const rs = {
1141
1160
  seed: seed,
@@ -1146,11 +1165,11 @@ class KoniExtension {
1146
1165
  });
1147
1166
  return rs;
1148
1167
  }
1149
- seedValidateV2(_ref31) {
1168
+ seedValidateV2(_ref33) {
1150
1169
  let {
1151
1170
  suri,
1152
1171
  types
1153
- } = _ref31;
1172
+ } = _ref33;
1154
1173
  const {
1155
1174
  phrase
1156
1175
  } = (0, _utilCrypto.keyExtractSuri)(suri);
@@ -1170,11 +1189,11 @@ class KoniExtension {
1170
1189
  });
1171
1190
  return rs;
1172
1191
  }
1173
- _checkValidatePrivateKey(_ref32) {
1192
+ _checkValidatePrivateKey(_ref34) {
1174
1193
  let {
1175
1194
  suri,
1176
1195
  types
1177
- } = _ref32;
1196
+ } = _ref34;
1178
1197
  let autoAddPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1179
1198
  const {
1180
1199
  phrase
@@ -1197,11 +1216,11 @@ class KoniExtension {
1197
1216
  }
1198
1217
  return rs;
1199
1218
  }
1200
- metamaskPrivateKeyValidateV2(_ref33) {
1219
+ metamaskPrivateKeyValidateV2(_ref35) {
1201
1220
  let {
1202
1221
  suri,
1203
1222
  types
1204
- } = _ref33;
1223
+ } = _ref35;
1205
1224
  const isValidSuri = suri.startsWith('0x');
1206
1225
  if (isValidSuri) {
1207
1226
  return this._checkValidatePrivateKey({
@@ -1226,14 +1245,14 @@ class KoniExtension {
1226
1245
  throw new Error(`"${suri}" is not a valid derivation path`);
1227
1246
  }
1228
1247
  }
1229
- derivationCreateV2(_ref34) {
1248
+ derivationCreateV2(_ref36) {
1230
1249
  let {
1231
1250
  genesisHash,
1232
1251
  isAllowed,
1233
1252
  name,
1234
1253
  parentAddress,
1235
1254
  suri
1236
- } = _ref34;
1255
+ } = _ref36;
1237
1256
  const childPair = this.deriveV2(parentAddress, suri, {
1238
1257
  genesisHash,
1239
1258
  name,
@@ -1247,14 +1266,14 @@ class KoniExtension {
1247
1266
  });
1248
1267
  return true;
1249
1268
  }
1250
- jsonRestoreV2(_ref35) {
1269
+ jsonRestoreV2(_ref37) {
1251
1270
  let {
1252
1271
  address,
1253
1272
  file,
1254
1273
  isAllowed,
1255
1274
  password,
1256
1275
  withMasterPassword
1257
- } = _ref35;
1276
+ } = _ref37;
1258
1277
  const isPasswordValidated = this.validatePassword(file, password);
1259
1278
  if (isPasswordValidated) {
1260
1279
  try {
@@ -1269,13 +1288,13 @@ class KoniExtension {
1269
1288
  throw new Error('Unable to decode using the supplied passphrase');
1270
1289
  }
1271
1290
  }
1272
- batchRestoreV2(_ref36) {
1291
+ batchRestoreV2(_ref38) {
1273
1292
  let {
1274
1293
  accountsInfo,
1275
1294
  file,
1276
1295
  isAllowed,
1277
1296
  password
1278
- } = _ref36;
1297
+ } = _ref38;
1279
1298
  const addressList = accountsInfo.map(acc => acc.address);
1280
1299
  const isPasswordValidated = this.validatedAccountsPassword(file, password);
1281
1300
  if (isPasswordValidated) {
@@ -1555,11 +1574,11 @@ class KoniExtension {
1555
1574
  async enableChain(networkKey) {
1556
1575
  return await this.#koniState.enableChain(networkKey);
1557
1576
  }
1558
- async validateNetwork(_ref37) {
1577
+ async validateNetwork(_ref39) {
1559
1578
  let {
1560
1579
  existedChainSlug,
1561
1580
  provider
1562
- } = _ref37;
1581
+ } = _ref39;
1563
1582
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1564
1583
  }
1565
1584
  resetDefaultNetwork() {
@@ -1569,7 +1588,7 @@ class KoniExtension {
1569
1588
  try {
1570
1589
  return this.#koniState.refreshSubstrateApi(networkKey);
1571
1590
  } catch (e) {
1572
- console.error('error recovering substrate api', e);
1591
+ console.error(e);
1573
1592
  return false;
1574
1593
  }
1575
1594
  }
@@ -1578,7 +1597,7 @@ class KoniExtension {
1578
1597
  await this.#koniState.upsertCustomToken(data);
1579
1598
  return true;
1580
1599
  } catch (e) {
1581
- console.error('Error insert/update custom token', e);
1600
+ console.error(e);
1582
1601
  return false;
1583
1602
  }
1584
1603
  }
@@ -1597,22 +1616,22 @@ class KoniExtension {
1597
1616
  async validateCustomAsset(data) {
1598
1617
  return await this.#koniState.validateCustomAsset(data);
1599
1618
  }
1600
- async getAddressFreeBalance(_ref38) {
1619
+ async getAddressFreeBalance(_ref40) {
1601
1620
  let {
1602
1621
  address,
1603
1622
  networkKey,
1604
1623
  token
1605
- } = _ref38;
1624
+ } = _ref40;
1606
1625
  return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1607
1626
  }
1608
- async transferGetMaxTransferable(_ref39) {
1627
+ async transferGetMaxTransferable(_ref41) {
1609
1628
  let {
1610
1629
  address,
1611
1630
  destChain,
1612
1631
  isXcmTransfer,
1613
1632
  networkKey,
1614
1633
  token
1615
- } = _ref39;
1634
+ } = _ref41;
1616
1635
  const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1617
1636
  const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1618
1637
  if (!(0, _utils._isNativeToken)(tokenInfo)) {
@@ -1642,26 +1661,39 @@ class KoniExtension {
1642
1661
  estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
1643
1662
  } catch (e) {
1644
1663
  estimatedFee = '0';
1645
- console.warn('Error estimating fee', e);
1664
+ console.warn(e);
1646
1665
  }
1647
1666
  }
1648
1667
  } else {
1649
- const [mockTx] = await (0, _transfer.createTransferExtrinsic)({
1650
- from: address,
1651
- networkKey,
1652
- substrateApi,
1653
- to: address,
1654
- tokenInfo,
1655
- transferAll: true,
1656
- value: '0'
1657
- });
1658
- try {
1659
- var _paymentInfo$partialF2;
1660
- const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1661
- estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1662
- } catch (e) {
1663
- estimatedFee = '0';
1664
- console.warn('Error estimating fee', e);
1668
+ const chainInfo = this.#koniState.chainService.getChainInfoByKey(networkKey);
1669
+ if ((0, _utils._isChainEvmCompatible)(chainInfo)) {
1670
+ const web3 = this.#koniState.chainService.getEvmApi(networkKey);
1671
+ const transaction = {
1672
+ value: 1,
1673
+ to: address,
1674
+ from: address
1675
+ };
1676
+ const gasPrice = await web3.api.eth.getGasPrice();
1677
+ const gasLimit = await web3.api.eth.estimateGas(transaction);
1678
+ estimatedFee = (gasLimit * parseInt(gasPrice)).toString();
1679
+ } else {
1680
+ const [mockTx] = await (0, _transfer.createTransferExtrinsic)({
1681
+ from: address,
1682
+ networkKey,
1683
+ substrateApi,
1684
+ to: address,
1685
+ tokenInfo,
1686
+ transferAll: true,
1687
+ value: '0'
1688
+ });
1689
+ try {
1690
+ var _paymentInfo$partialF2;
1691
+ const paymentInfo = await (mockTx === null || mockTx === void 0 ? void 0 : mockTx.paymentInfo(address));
1692
+ estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF2 = paymentInfo.partialFee) === null || _paymentInfo$partialF2 === void 0 ? void 0 : _paymentInfo$partialF2.toString()) || '0';
1693
+ } catch (e) {
1694
+ estimatedFee = '0';
1695
+ console.warn('Error estimating fee', e);
1696
+ }
1665
1697
  }
1666
1698
  }
1667
1699
  maxTransferable = maxTransferable.sub(new _util.BN(estimatedFee));
@@ -1671,12 +1703,12 @@ class KoniExtension {
1671
1703
  };
1672
1704
  }
1673
1705
  }
1674
- async subscribeAddressFreeBalance(_ref40, id, port) {
1706
+ async subscribeAddressFreeBalance(_ref42, id, port) {
1675
1707
  let {
1676
1708
  address,
1677
1709
  networkKey,
1678
1710
  token
1679
- } = _ref40;
1711
+ } = _ref42;
1680
1712
  const cb = (0, _subscriptions.createSubscription)(id, port);
1681
1713
  const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1682
1714
  this.createUnsubscriptionHandle(id, unsub);
@@ -1685,26 +1717,26 @@ class KoniExtension {
1685
1717
  });
1686
1718
  return currentFreeBalance;
1687
1719
  }
1688
- async transferCheckReferenceCount(_ref41) {
1720
+ async transferCheckReferenceCount(_ref43) {
1689
1721
  let {
1690
1722
  address,
1691
1723
  networkKey
1692
- } = _ref41;
1724
+ } = _ref43;
1693
1725
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1694
1726
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1695
1727
  }
1696
- async transferCheckSupporting(_ref42) {
1728
+ async transferCheckSupporting(_ref44) {
1697
1729
  let {
1698
1730
  networkKey,
1699
1731
  tokenSlug
1700
- } = _ref42;
1732
+ } = _ref44;
1701
1733
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1702
1734
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1703
1735
  }
1704
- transferGetExistentialDeposit(_ref43) {
1736
+ transferGetExistentialDeposit(_ref45) {
1705
1737
  let {
1706
1738
  tokenSlug
1707
- } = _ref43;
1739
+ } = _ref45;
1708
1740
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1709
1741
  return (0, _utils._getTokenMinAmount)(tokenInfo);
1710
1742
  }
@@ -1746,24 +1778,24 @@ class KoniExtension {
1746
1778
  }
1747
1779
  return true;
1748
1780
  }
1749
- getAccountMeta(_ref44) {
1781
+ getAccountMeta(_ref46) {
1750
1782
  let {
1751
1783
  address
1752
- } = _ref44;
1784
+ } = _ref46;
1753
1785
  const pair = _uiKeyring.keyring.getPair(address);
1754
1786
  (0, _util.assert)(pair, 'Unable to find pair');
1755
1787
  return {
1756
1788
  meta: pair.meta
1757
1789
  };
1758
1790
  }
1759
- accountsTie2(_ref45) {
1791
+ accountsTie2(_ref47) {
1760
1792
  let {
1761
1793
  address,
1762
1794
  genesisHash
1763
- } = _ref45;
1795
+ } = _ref47;
1764
1796
  return this.#koniState.setAccountTie(address, genesisHash);
1765
1797
  }
1766
- async accountsCreateExternalV2(_ref46) {
1798
+ async accountsCreateExternalV2(_ref48) {
1767
1799
  let {
1768
1800
  address,
1769
1801
  genesisHash,
@@ -1771,7 +1803,7 @@ class KoniExtension {
1771
1803
  isEthereum,
1772
1804
  isReadOnly,
1773
1805
  name
1774
- } = _ref46;
1806
+ } = _ref48;
1775
1807
  try {
1776
1808
  let result;
1777
1809
  try {
@@ -1830,7 +1862,7 @@ class KoniExtension {
1830
1862
  }];
1831
1863
  }
1832
1864
  }
1833
- async accountsCreateHardwareV2(_ref47) {
1865
+ async accountsCreateHardwareV2(_ref49) {
1834
1866
  let {
1835
1867
  accountIndex,
1836
1868
  address,
@@ -1839,7 +1871,7 @@ class KoniExtension {
1839
1871
  hardwareType,
1840
1872
  isAllowed,
1841
1873
  name
1842
- } = _ref47;
1874
+ } = _ref49;
1843
1875
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
1844
1876
  accountIndex,
1845
1877
  addressOffset,
@@ -1862,10 +1894,10 @@ class KoniExtension {
1862
1894
  });
1863
1895
  return true;
1864
1896
  }
1865
- async accountsCreateHardwareMultiple(_ref48) {
1897
+ async accountsCreateHardwareMultiple(_ref50) {
1866
1898
  let {
1867
1899
  accounts
1868
- } = _ref48;
1900
+ } = _ref50;
1869
1901
  const addresses = [];
1870
1902
  if (!accounts.length) {
1871
1903
  throw new Error('No accounts to import');
@@ -1916,14 +1948,14 @@ class KoniExtension {
1916
1948
  });
1917
1949
  return true;
1918
1950
  }
1919
- async accountsCreateWithSecret(_ref49) {
1951
+ async accountsCreateWithSecret(_ref51) {
1920
1952
  let {
1921
1953
  isAllow,
1922
1954
  isEthereum,
1923
1955
  name,
1924
1956
  publicKey,
1925
1957
  secretKey
1926
- } = _ref49;
1958
+ } = _ref51;
1927
1959
  try {
1928
1960
  let keyringPair = null;
1929
1961
  if (isEthereum) {
@@ -2066,30 +2098,30 @@ class KoniExtension {
2066
2098
 
2067
2099
  // Parse transaction
2068
2100
 
2069
- parseSubstrateTransaction(_ref50) {
2101
+ parseSubstrateTransaction(_ref52) {
2070
2102
  let {
2071
2103
  data,
2072
2104
  networkKey
2073
- } = _ref50;
2105
+ } = _ref52;
2074
2106
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2075
2107
  const apiPromise = apiProps.api;
2076
2108
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2077
2109
  }
2078
- async parseEVMRLP(_ref51) {
2110
+ async parseEVMRLP(_ref53) {
2079
2111
  let {
2080
2112
  data
2081
- } = _ref51;
2113
+ } = _ref53;
2082
2114
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2083
2115
  }
2084
2116
 
2085
2117
  // Sign
2086
2118
 
2087
- qrSignSubstrate(_ref52) {
2119
+ qrSignSubstrate(_ref54) {
2088
2120
  let {
2089
2121
  address,
2090
2122
  data,
2091
2123
  networkKey
2092
- } = _ref52;
2124
+ } = _ref54;
2093
2125
  const pair = _uiKeyring.keyring.getPair(address);
2094
2126
  (0, _util.assert)(pair, 'Unable to find pair');
2095
2127
  if (pair.isLocked) {
@@ -2106,13 +2138,13 @@ class KoniExtension {
2106
2138
  signature: signed
2107
2139
  };
2108
2140
  }
2109
- async qrSignEVM(_ref53) {
2141
+ async qrSignEVM(_ref55) {
2110
2142
  let {
2111
2143
  address,
2112
2144
  chainId,
2113
2145
  message,
2114
2146
  type
2115
- } = _ref53;
2147
+ } = _ref55;
2116
2148
  let signed;
2117
2149
  const network = this.getNetworkJsonByChainId(chainId);
2118
2150
  if (!network) {
@@ -2193,11 +2225,11 @@ class KoniExtension {
2193
2225
  });
2194
2226
  return this.#koniState.getNominatorMetadata();
2195
2227
  }
2196
- async getBondingOptions(_ref54) {
2228
+ async getBondingOptions(_ref56) {
2197
2229
  let {
2198
2230
  chain,
2199
2231
  type
2200
- } = _ref54;
2232
+ } = _ref56;
2201
2233
  const apiProps = this.#koniState.getSubstrateApi(chain);
2202
2234
  const chainInfo = this.#koniState.getChainInfo(chain);
2203
2235
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2211,7 +2243,6 @@ class KoniExtension {
2211
2243
  }
2212
2244
  async getNominationPoolOptions(chain) {
2213
2245
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2214
- console.log('chain', chain);
2215
2246
  return await (0, _bonding.getNominationPoolsInfo)(chain, substrateApi);
2216
2247
  }
2217
2248
  async submitBonding(inputData) {
@@ -2233,7 +2264,6 @@ class KoniExtension {
2233
2264
  }
2234
2265
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2235
2266
  const extrinsic = await (0, _bonding.getBondingExtrinsic)(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata);
2236
- console.log('Bonding extrinsic: ', chain, extrinsic.toHex());
2237
2267
  return await this.#koniState.transactionService.handleTransaction({
2238
2268
  address,
2239
2269
  chain: chain,
@@ -2262,7 +2292,6 @@ class KoniExtension {
2262
2292
  }
2263
2293
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2264
2294
  const extrinsic = await (0, _bonding.getUnbondingExtrinsic)(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
2265
- console.log('Unbonding extrinsic: ', extrinsic.toHex());
2266
2295
  return await this.#koniState.transactionService.handleTransaction({
2267
2296
  address: nominatorMetadata.address,
2268
2297
  chain: chain,
@@ -2283,7 +2312,6 @@ class KoniExtension {
2283
2312
  }
2284
2313
  const dotSamaApi = this.#koniState.getSubstrateApi(chain);
2285
2314
  const extrinsic = await (0, _bonding.getWithdrawalExtrinsic)(dotSamaApi, chain, nominatorMetadata, validatorAddress);
2286
- console.log('Stake withdrawal extrinsic: ', extrinsic.toHex());
2287
2315
  return await this.#koniState.transactionService.handleTransaction({
2288
2316
  address: nominatorMetadata.address,
2289
2317
  chain: chain,
@@ -2305,7 +2333,6 @@ class KoniExtension {
2305
2333
  }
2306
2334
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2307
2335
  const extrinsic = await (0, _bonding.getClaimRewardExtrinsic)(substrateApi, chain, address, stakingType, bondReward);
2308
- console.log('Staking claim reward extrinsic: ', extrinsic.toHex());
2309
2336
  return await this.#koniState.transactionService.handleTransaction({
2310
2337
  address,
2311
2338
  chain: chain,
@@ -2326,7 +2353,6 @@ class KoniExtension {
2326
2353
  }
2327
2354
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2328
2355
  const extrinsic = await (0, _bonding.getCancelWithdrawalExtrinsic)(substrateApi, chain, selectedUnstaking);
2329
- console.log('Cancel stake withdrawal extrinsic', extrinsic.toHex());
2330
2356
  return await this.#koniState.transactionService.handleTransaction({
2331
2357
  address,
2332
2358
  chain,
@@ -2355,7 +2381,6 @@ class KoniExtension {
2355
2381
  }
2356
2382
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2357
2383
  const extrinsic = await (0, _relayChain.getPoolingBondingExtrinsic)(substrateApi, amount, selectedPool.id, nominatorMetadata);
2358
- console.log('Join nomination pool extrinsic', extrinsic.toHex());
2359
2384
  return await this.#koniState.transactionService.handleTransaction({
2360
2385
  address,
2361
2386
  chain,
@@ -2381,7 +2406,6 @@ class KoniExtension {
2381
2406
  }
2382
2407
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2383
2408
  const extrinsic = await (0, _relayChain.getPoolingUnbondingExtrinsic)(substrateApi, amount, nominatorMetadata);
2384
- console.log('Nomination pool unbond extrinsic', extrinsic.toHex());
2385
2409
  return await this.#koniState.transactionService.handleTransaction({
2386
2410
  address: nominatorMetadata.address,
2387
2411
  chain,
@@ -2393,12 +2417,12 @@ class KoniExtension {
2393
2417
  }
2394
2418
 
2395
2419
  // EVM Transaction
2396
- async parseContractInput(_ref55) {
2420
+ async parseContractInput(_ref57) {
2397
2421
  let {
2398
2422
  chainId,
2399
2423
  contract,
2400
2424
  data
2401
- } = _ref55;
2425
+ } = _ref57;
2402
2426
  const network = this.getNetworkJsonByChainId(chainId);
2403
2427
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2404
2428
  }
@@ -2469,12 +2493,12 @@ class KoniExtension {
2469
2493
 
2470
2494
  // Change master password
2471
2495
 
2472
- keyringChangeMasterPassword(_ref56) {
2496
+ keyringChangeMasterPassword(_ref58) {
2473
2497
  let {
2474
2498
  createNew,
2475
2499
  newPassword,
2476
2500
  oldPassword
2477
- } = _ref56;
2501
+ } = _ref58;
2478
2502
  try {
2479
2503
  // Remove isMasterPassword meta if createNew
2480
2504
  if (createNew) {
@@ -2508,11 +2532,11 @@ class KoniExtension {
2508
2532
 
2509
2533
  // Migrate password
2510
2534
 
2511
- keyringMigrateMasterPassword(_ref57) {
2535
+ keyringMigrateMasterPassword(_ref59) {
2512
2536
  let {
2513
2537
  address,
2514
2538
  password
2515
- } = _ref57;
2539
+ } = _ref59;
2516
2540
  try {
2517
2541
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2518
2542
  } catch (e) {
@@ -2530,10 +2554,10 @@ class KoniExtension {
2530
2554
 
2531
2555
  // Unlock wallet
2532
2556
 
2533
- keyringUnlock(_ref58) {
2557
+ keyringUnlock(_ref60) {
2534
2558
  let {
2535
2559
  password
2536
- } = _ref58;
2560
+ } = _ref60;
2537
2561
  try {
2538
2562
  _uiKeyring.keyring.unlockKeyring(password);
2539
2563
  } catch (e) {
@@ -2559,11 +2583,11 @@ class KoniExtension {
2559
2583
 
2560
2584
  // Export mnemonic
2561
2585
 
2562
- keyringExportMnemonic(_ref59) {
2586
+ keyringExportMnemonic(_ref61) {
2563
2587
  let {
2564
2588
  address,
2565
2589
  password
2566
- } = _ref59;
2590
+ } = _ref61;
2567
2591
  const pair = _uiKeyring.keyring.getPair(address);
2568
2592
  const result = pair.exportMnemonic(password);
2569
2593
  return {
@@ -2573,10 +2597,10 @@ class KoniExtension {
2573
2597
 
2574
2598
  // Reset wallet
2575
2599
 
2576
- async resetWallet(_ref60) {
2600
+ async resetWallet(_ref62) {
2577
2601
  let {
2578
2602
  resetAll
2579
- } = _ref60;
2603
+ } = _ref62;
2580
2604
  try {
2581
2605
  await this.#koniState.resetWallet(resetAll);
2582
2606
  return {
@@ -2592,10 +2616,10 @@ class KoniExtension {
2592
2616
  }
2593
2617
 
2594
2618
  /// Signing external request
2595
- signingApprovePasswordV2(_ref61) {
2619
+ signingApprovePasswordV2(_ref63) {
2596
2620
  let {
2597
2621
  id
2598
- } = _ref61;
2622
+ } = _ref63;
2599
2623
  const queued = this.#koniState.getSignRequest(id);
2600
2624
  (0, _util.assert)(queued, 'Unable to find request');
2601
2625
  const {
@@ -2648,22 +2672,22 @@ class KoniExtension {
2648
2672
 
2649
2673
  /// Derive account
2650
2674
 
2651
- derivationCreateMultiple(_ref62) {
2675
+ derivationCreateMultiple(_ref64) {
2652
2676
  let {
2653
2677
  isAllowed,
2654
2678
  items,
2655
2679
  parentAddress
2656
- } = _ref62;
2680
+ } = _ref64;
2657
2681
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2658
2682
  const isEvm = parentPair.type === 'ethereum';
2659
2683
  if (parentPair.isLocked) {
2660
2684
  _uiKeyring.keyring.unlockPair(parentPair.address);
2661
2685
  }
2662
- const createChild = _ref63 => {
2686
+ const createChild = _ref65 => {
2663
2687
  let {
2664
2688
  name,
2665
2689
  suri
2666
- } = _ref63;
2690
+ } = _ref65;
2667
2691
  const meta = {
2668
2692
  name: name,
2669
2693
  parentAddress
@@ -2696,7 +2720,7 @@ class KoniExtension {
2696
2720
  this._addAddressToAuthList(address, isAllowed);
2697
2721
  result.push(childPair);
2698
2722
  } catch (e) {
2699
- console.log(`Fail to derive from ${parentAddress} with path ${item.suri}`, e);
2723
+ console.log(e);
2700
2724
  }
2701
2725
  }
2702
2726
  if (result.length === 1) {
@@ -2709,10 +2733,10 @@ class KoniExtension {
2709
2733
  }
2710
2734
  return true;
2711
2735
  }
2712
- derivationCreateV3(_ref64) {
2736
+ derivationCreateV3(_ref66) {
2713
2737
  let {
2714
2738
  address: parentAddress
2715
- } = _ref64;
2739
+ } = _ref66;
2716
2740
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2717
2741
  const isEvm = parentPair.type === 'ethereum';
2718
2742
  if (parentPair.isLocked) {
@@ -2744,11 +2768,11 @@ class KoniExtension {
2744
2768
  });
2745
2769
  return true;
2746
2770
  }
2747
- validateDerivePath(_ref65) {
2771
+ validateDerivePath(_ref67) {
2748
2772
  let {
2749
2773
  parentAddress,
2750
2774
  suri
2751
- } = _ref65;
2775
+ } = _ref67;
2752
2776
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2753
2777
  const isEvm = parentPair.type === 'ethereum';
2754
2778
  if (parentPair.isLocked) {
@@ -2781,12 +2805,12 @@ class KoniExtension {
2781
2805
  suri: meta.suri
2782
2806
  };
2783
2807
  }
2784
- getListDeriveAccounts(_ref66) {
2808
+ getListDeriveAccounts(_ref68) {
2785
2809
  let {
2786
2810
  limit,
2787
2811
  page,
2788
2812
  parentAddress
2789
- } = _ref66;
2813
+ } = _ref68;
2790
2814
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2791
2815
  const isEvm = parentPair.type === 'ethereum';
2792
2816
  if (parentPair.isLocked) {
@@ -2877,10 +2901,10 @@ class KoniExtension {
2877
2901
  getSupportedSmartContractTypes() {
2878
2902
  return this.#koniState.getSupportedSmartContractTypes();
2879
2903
  }
2880
- getTransaction(_ref67) {
2904
+ getTransaction(_ref69) {
2881
2905
  let {
2882
2906
  id
2883
- } = _ref67;
2907
+ } = _ref69;
2884
2908
  const {
2885
2909
  transaction,
2886
2910
  ...transactionResult
@@ -2890,8 +2914,8 @@ class KoniExtension {
2890
2914
  subscribeTransactions(id, port) {
2891
2915
  const cb = (0, _subscriptions.createSubscription)(id, port);
2892
2916
  function convertRs(rs) {
2893
- return Object.fromEntries(Object.entries(rs).map(_ref68 => {
2894
- let [key, value] = _ref68;
2917
+ return Object.fromEntries(Object.entries(rs).map(_ref70 => {
2918
+ let [key, value] = _ref70;
2895
2919
  const {
2896
2920
  transaction,
2897
2921
  ...transactionResult
@@ -2921,10 +2945,10 @@ class KoniExtension {
2921
2945
  });
2922
2946
  return notificationSubject.value;
2923
2947
  }
2924
- async reloadCron(_ref69) {
2948
+ async reloadCron(_ref71) {
2925
2949
  let {
2926
2950
  data
2927
- } = _ref69;
2951
+ } = _ref71;
2928
2952
  if (data === 'nft') {
2929
2953
  return await this.#koniState.reloadNft();
2930
2954
  } else if (data === 'staking') {
@@ -2946,7 +2970,7 @@ class KoniExtension {
2946
2970
  clearTimeout(this.#lockTimeOut);
2947
2971
  this.#lockTimeOut = setTimeout(() => {
2948
2972
  this.keyringLock();
2949
- }, _constants.DEFAULT_TIME_AUTO_LOCK);
2973
+ }, this.#timeAutoLock * 60 * 1000);
2950
2974
  switch (type) {
2951
2975
  /// Clone from PolkadotJs
2952
2976
  case 'pri(accounts.create.external)':
@@ -3026,7 +3050,9 @@ class KoniExtension {
3026
3050
  case 'pri(authorize.toggle)':
3027
3051
  return this.toggleAuthorization2(request);
3028
3052
  case 'pri(settings.changeBalancesVisibility)':
3029
- return this.toggleBalancesVisibility(id, port);
3053
+ return await this.toggleBalancesVisibility();
3054
+
3055
+ // Settings
3030
3056
  case 'pri(settings.subscribe)':
3031
3057
  return await this.subscribeSettings(id, port);
3032
3058
  case 'pri(settings.saveAccountAllLogo)':
@@ -3037,6 +3063,10 @@ class KoniExtension {
3037
3063
  return this.saveTheme(request, id, port);
3038
3064
  case 'pri(settings.saveBrowserConfirmationType)':
3039
3065
  return this.saveBrowserConfirmationType(request, id, port);
3066
+ case 'pri(settings.saveAutoLockTime)':
3067
+ return this.setAutoLockTime(request);
3068
+ case 'pri(settings.saveEnableChainPatrol)':
3069
+ return this.setEnableChainPatrol(request);
3040
3070
  case 'pri(price.getPrice)':
3041
3071
  return await this.getPrice();
3042
3072
  case 'pri(price.getSubscription)':