@subwallet/extension-base 1.0.13-0 → 1.1.1-dev.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 (81) hide show
  1. package/background/KoniTypes.d.ts +37 -0
  2. package/background/KoniTypes.js +8 -1
  3. package/background/handlers/Extension.js +17 -2
  4. package/background/types.d.ts +6 -1
  5. package/bundle-polkadot-extension-base.js +20 -0
  6. package/cjs/background/KoniTypes.js +10 -2
  7. package/cjs/background/handlers/Extension.js +22 -6
  8. package/cjs/constants/index.js +7 -1
  9. package/cjs/defaults.js +1 -1
  10. package/cjs/koni/api/dotsama/balance.js +5 -0
  11. package/cjs/koni/api/dotsama/transfer.js +6 -0
  12. package/cjs/koni/api/staking/bonding/astar.js +2 -2
  13. package/cjs/koni/api/staking/bonding/relayChain.js +12 -2
  14. package/cjs/koni/api/staking/bonding/utils.js +2 -2
  15. package/cjs/koni/background/cron.js +13 -37
  16. package/cjs/koni/background/handlers/Extension.js +324 -147
  17. package/cjs/koni/background/handlers/State.js +224 -51
  18. package/cjs/koni/background/subscription.js +9 -86
  19. package/cjs/packageInfo.js +1 -1
  20. package/cjs/services/chain-service/constants.js +10 -4
  21. package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
  22. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  23. package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
  24. package/cjs/services/chain-service/helper/erc20_abi.json +224 -0
  25. package/cjs/services/chain-service/helper/erc721_abi.json +384 -0
  26. package/cjs/services/chain-service/helper/psp22_abi.json +1127 -0
  27. package/cjs/services/chain-service/helper/psp34_abi.json +3144 -0
  28. package/cjs/services/chain-service/helper/test_erc721_abi.json +393 -0
  29. package/cjs/services/chain-service/index.js +54 -5
  30. package/cjs/services/chain-service/utils.js +6 -1
  31. package/cjs/services/event-service/types.js +3 -1
  32. package/cjs/services/storage-service/DatabaseService.js +31 -1
  33. package/cjs/services/storage-service/databases/index.js +3 -0
  34. package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
  35. package/cjs/utils/index.js +12 -0
  36. package/cjs/utils/lazy.js +52 -0
  37. package/constants/index.d.ts +2 -0
  38. package/constants/index.js +2 -0
  39. package/defaults.d.ts +1 -1
  40. package/defaults.js +1 -1
  41. package/koni/api/dotsama/balance.js +6 -1
  42. package/koni/api/dotsama/transfer.js +7 -1
  43. package/koni/api/staking/bonding/astar.d.ts +1 -1
  44. package/koni/api/staking/bonding/astar.js +1 -1
  45. package/koni/api/staking/bonding/relayChain.js +12 -2
  46. package/koni/api/staking/bonding/utils.js +3 -3
  47. package/koni/background/cron.d.ts +1 -5
  48. package/koni/background/cron.js +15 -39
  49. package/koni/background/handlers/Extension.d.ts +5 -0
  50. package/koni/background/handlers/Extension.js +186 -11
  51. package/koni/background/handlers/State.d.ts +15 -3
  52. package/koni/background/handlers/State.js +226 -50
  53. package/koni/background/subscription.d.ts +1 -4
  54. package/koni/background/subscription.js +11 -87
  55. package/package.json +23 -6
  56. package/packageInfo.js +1 -1
  57. package/services/chain-service/constants.d.ts +3 -0
  58. package/services/chain-service/constants.js +5 -2
  59. package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
  60. package/services/chain-service/handler/SubstrateApi.js +2 -1
  61. package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
  62. package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
  63. package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
  64. package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
  65. package/services/chain-service/handler/types.d.ts +2 -0
  66. package/services/chain-service/index.d.ts +7 -3
  67. package/services/chain-service/index.js +56 -7
  68. package/services/chain-service/utils.d.ts +1 -0
  69. package/services/chain-service/utils.js +5 -1
  70. package/services/event-service/types.d.ts +3 -0
  71. package/services/event-service/types.js +3 -1
  72. package/services/storage-service/DatabaseService.d.ts +10 -1
  73. package/services/storage-service/DatabaseService.js +31 -1
  74. package/services/storage-service/databases/index.d.ts +2 -0
  75. package/services/storage-service/databases/index.js +3 -0
  76. package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
  77. package/services/storage-service/db-stores/MantaPay.js +32 -0
  78. package/utils/index.d.ts +1 -0
  79. package/utils/index.js +2 -1
  80. package/utils/lazy.d.ts +2 -0
  81. package/utils/lazy.js +43 -0
@@ -24,10 +24,12 @@ var _relayChain = require("@subwallet/extension-base/koni/api/staking/bonding/re
24
24
  var _transfer3 = require("@subwallet/extension-base/koni/api/tokens/evm/transfer");
25
25
  var _wasm = require("@subwallet/extension-base/koni/api/tokens/wasm");
26
26
  var _xcm = require("@subwallet/extension-base/koni/api/xcm");
27
+ var _constants2 = require("@subwallet/extension-base/services/chain-service/constants");
28
+ var _types2 = require("@subwallet/extension-base/services/chain-service/types");
27
29
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
28
- var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
29
- var _constants3 = require("@subwallet/extension-base/services/setting-service/constants");
30
- var _constants4 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
30
+ var _constants3 = require("@subwallet/extension-base/services/request-service/constants");
31
+ var _constants4 = require("@subwallet/extension-base/services/setting-service/constants");
32
+ var _constants5 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
31
33
  var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
32
34
  var _utils2 = require("@subwallet/extension-base/utils");
33
35
  var _address2 = require("@subwallet/extension-base/utils/address");
@@ -39,7 +41,7 @@ var _uiKeyring = require("@subwallet/ui-keyring");
39
41
  var _utils3 = require("@walletconnect/utils");
40
42
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
41
43
  var _ethereumjsTx = require("ethereumjs-tx");
42
- var _types2 = require("@polkadot/types");
44
+ var _types3 = require("@polkadot/types");
43
45
  var _util = require("@polkadot/util");
44
46
  var _utilCrypto = require("@polkadot/util-crypto");
45
47
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
@@ -72,14 +74,17 @@ const ACCOUNT_ALL_JSON = {
72
74
  class KoniExtension {
73
75
  #lockTimeOut = undefined;
74
76
  #koniState;
75
- #timeAutoLock = _constants3.DEFAULT_AUTO_LOCK_TIME;
77
+ #timeAutoLock = _constants4.DEFAULT_AUTO_LOCK_TIME;
78
+ #skipAutoLock = false;
76
79
  constructor(state) {
77
80
  this.#koniState = state;
78
81
  const updateTimeAutoLock = rs => {
79
82
  this.#timeAutoLock = rs.timeAutoLock;
80
83
  clearTimeout(this.#lockTimeOut);
81
84
  this.#lockTimeOut = setTimeout(() => {
82
- this.keyringLock();
85
+ if (!this.#skipAutoLock) {
86
+ this.keyringLock();
87
+ }
83
88
  }, this.#timeAutoLock * 60 * 1000);
84
89
  };
85
90
  this.#koniState.settingService.getSettings(updateTimeAutoLock);
@@ -368,9 +373,26 @@ class KoniExtension {
368
373
  });
369
374
  return true;
370
375
  }
371
- windowOpen(path) {
372
- const url = `${chrome.extension.getURL('index.html')}#${path}`;
376
+ windowOpen(_ref18) {
377
+ let {
378
+ allowedPath: path,
379
+ params,
380
+ subPath
381
+ } = _ref18;
382
+ let paramString = '';
383
+ if (params) {
384
+ paramString += '?';
385
+ for (let i = 0; i < Object.keys(params).length; i++) {
386
+ const [key, value] = Object.entries(params)[i];
387
+ paramString += `${key}=${value}`;
388
+ if (i !== Object.keys(params).length - 1) {
389
+ paramString += '&';
390
+ }
391
+ }
392
+ }
393
+ const url = `${chrome.extension.getURL('index.html')}#${path}${subPath || ''}${paramString}`;
373
394
  if (!_defaults.ALLOWED_PATH.includes(path)) {
395
+ console.error('Not allowed to open the url:', url);
374
396
  return false;
375
397
  }
376
398
  (0, _helpers.withErrorLog)(() => chrome.tabs.create({
@@ -391,26 +413,26 @@ class KoniExtension {
391
413
  throw new Error(`"${suri}" is not a valid derivation path`);
392
414
  }
393
415
  }
394
- derivationValidate(_ref18) {
416
+ derivationValidate(_ref19) {
395
417
  let {
396
418
  parentAddress,
397
419
  parentPassword,
398
420
  suri
399
- } = _ref18;
421
+ } = _ref19;
400
422
  const childPair = this.derive(parentAddress, suri, parentPassword, {});
401
423
  return {
402
424
  address: childPair.address,
403
425
  suri
404
426
  };
405
427
  }
406
- derivationCreate(_ref19) {
428
+ derivationCreate(_ref20) {
407
429
  let {
408
430
  genesisHash,
409
431
  name,
410
432
  parentAddress,
411
433
  parentPassword,
412
434
  suri
413
- } = _ref19;
435
+ } = _ref20;
414
436
  const childPair = this.derive(parentAddress, suri, parentPassword, {
415
437
  genesisHash,
416
438
  name,
@@ -435,11 +457,11 @@ class KoniExtension {
435
457
  encodeAddress = (key, ss58Format) => {
436
458
  return _uiKeyring.keyring.encodeAddress(key, ss58Format);
437
459
  };
438
- accountExportPrivateKey(_ref20) {
460
+ accountExportPrivateKey(_ref21) {
439
461
  let {
440
462
  address,
441
463
  password
442
- } = _ref20;
464
+ } = _ref21;
443
465
  return this.#koniState.accountExportPrivateKey({
444
466
  address,
445
467
  password
@@ -513,10 +535,10 @@ class KoniExtension {
513
535
  addresses: (0, _address2.convertSubjectInfoToAddresses)(subjectInfo)
514
536
  };
515
537
  }
516
- saveRecentAccount(_ref21) {
538
+ saveRecentAccount(_ref22) {
517
539
  let {
518
540
  accountId
519
- } = _ref21;
541
+ } = _ref22;
520
542
  if ((0, _utilCrypto.isAddress)(accountId)) {
521
543
  const address = (0, _utils2.reformatAddress)(accountId);
522
544
  const account = _uiKeyring.keyring.getAccount(address);
@@ -529,11 +551,11 @@ class KoniExtension {
529
551
  throw Error('Invalid address');
530
552
  }
531
553
  }
532
- editContactAccount(_ref22) {
554
+ editContactAccount(_ref23) {
533
555
  let {
534
556
  address,
535
557
  meta
536
- } = _ref22;
558
+ } = _ref23;
537
559
  if ((0, _utilCrypto.isAddress)(address)) {
538
560
  const _address = (0, _utils2.reformatAddress)(address);
539
561
  _uiKeyring.keyring.saveAddress(_address, meta);
@@ -542,10 +564,10 @@ class KoniExtension {
542
564
  throw Error('Invalid address');
543
565
  }
544
566
  }
545
- deleteContactAccount(_ref23) {
567
+ deleteContactAccount(_ref24) {
546
568
  let {
547
569
  address
548
- } = _ref23;
570
+ } = _ref24;
549
571
  if ((0, _utilCrypto.isAddress)(address)) {
550
572
  const _address = (0, _utils2.reformatAddress)(address);
551
573
  _uiKeyring.keyring.forgetAddress(_address);
@@ -594,11 +616,11 @@ class KoniExtension {
594
616
  list: authList
595
617
  };
596
618
  }
597
- authorizeApproveV2(_ref24) {
619
+ authorizeApproveV2(_ref25) {
598
620
  let {
599
621
  accounts,
600
622
  id
601
- } = _ref24;
623
+ } = _ref25;
602
624
  const queued = this.#koniState.getAuthRequestV2(id);
603
625
  (0, _util.assert)(queued, 'Unable to find request');
604
626
  const {
@@ -610,10 +632,10 @@ class KoniExtension {
610
632
  });
611
633
  return true;
612
634
  }
613
- authorizeRejectV2(_ref25) {
635
+ authorizeRejectV2(_ref26) {
614
636
  let {
615
637
  id
616
- } = _ref25;
638
+ } = _ref26;
617
639
  const queued = this.#koniState.getAuthRequestV2(id);
618
640
  (0, _util.assert)(queued, 'Unable to find request');
619
641
  const {
@@ -622,10 +644,10 @@ class KoniExtension {
622
644
  reject(new Error('Rejected'));
623
645
  return true;
624
646
  }
625
- authorizeCancelV2(_ref26) {
647
+ authorizeCancelV2(_ref27) {
626
648
  let {
627
649
  id
628
- } = _ref26;
650
+ } = _ref27;
629
651
  const queued = this.#koniState.getAuthRequestV2(id);
630
652
  (0, _util.assert)(queued, 'Unable to find request');
631
653
  const {
@@ -850,10 +872,10 @@ class KoniExtension {
850
872
  });
851
873
  return true;
852
874
  }
853
- setCamera(_ref27) {
875
+ setCamera(_ref28) {
854
876
  let {
855
877
  camera
856
- } = _ref27;
878
+ } = _ref28;
857
879
  this.#koniState.setCamera(camera);
858
880
  return true;
859
881
  }
@@ -865,10 +887,10 @@ class KoniExtension {
865
887
  });
866
888
  return true;
867
889
  }
868
- setAutoLockTime(_ref28) {
890
+ setAutoLockTime(_ref29) {
869
891
  let {
870
892
  autoLockTime
871
- } = _ref28;
893
+ } = _ref29;
872
894
  this.#koniState.setAutoLockTime(autoLockTime);
873
895
  return true;
874
896
  }
@@ -885,10 +907,10 @@ class KoniExtension {
885
907
  });
886
908
  return await this.getSettings();
887
909
  }
888
- setEnableChainPatrol(_ref29) {
910
+ setEnableChainPatrol(_ref30) {
889
911
  let {
890
912
  enable
891
- } = _ref29;
913
+ } = _ref30;
892
914
  this.#koniState.setEnableChainPatrol(enable);
893
915
  return true;
894
916
  }
@@ -1064,7 +1086,7 @@ class KoniExtension {
1064
1086
  }
1065
1087
  });
1066
1088
  }
1067
- async accountsCreateSuriV2(_ref30) {
1089
+ async accountsCreateSuriV2(_ref31) {
1068
1090
  let {
1069
1091
  genesisHash,
1070
1092
  isAllowed,
@@ -1072,7 +1094,7 @@ class KoniExtension {
1072
1094
  password,
1073
1095
  suri: _suri,
1074
1096
  types
1075
- } = _ref30;
1097
+ } = _ref31;
1076
1098
  const addressDict = {};
1077
1099
  let changedAccount = false;
1078
1100
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
@@ -1120,10 +1142,10 @@ class KoniExtension {
1120
1142
  });
1121
1143
  return addressDict;
1122
1144
  }
1123
- async accountsForgetOverride(_ref31) {
1145
+ async accountsForgetOverride(_ref32) {
1124
1146
  let {
1125
1147
  address
1126
- } = _ref31;
1148
+ } = _ref32;
1127
1149
  _uiKeyring.keyring.forgetAccount(address);
1128
1150
  await new Promise(resolve => {
1129
1151
  this.#koniState.removeAccountRef(address, () => {
@@ -1153,14 +1175,15 @@ class KoniExtension {
1153
1175
  address: _constants.ALL_ACCOUNT_KEY
1154
1176
  }, resolve);
1155
1177
  });
1178
+ await this.#koniState.disableMantaPay(address);
1156
1179
  return true;
1157
1180
  }
1158
- seedCreateV2(_ref32) {
1181
+ seedCreateV2(_ref33) {
1159
1182
  let {
1160
1183
  length = _Extension.SEED_DEFAULT_LENGTH,
1161
1184
  seed: _seed,
1162
1185
  types
1163
- } = _ref32;
1186
+ } = _ref33;
1164
1187
  const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
1165
1188
  const rs = {
1166
1189
  seed: seed,
@@ -1171,11 +1194,11 @@ class KoniExtension {
1171
1194
  });
1172
1195
  return rs;
1173
1196
  }
1174
- seedValidateV2(_ref33) {
1197
+ seedValidateV2(_ref34) {
1175
1198
  let {
1176
1199
  suri,
1177
1200
  types
1178
- } = _ref33;
1201
+ } = _ref34;
1179
1202
  const {
1180
1203
  phrase
1181
1204
  } = (0, _utilCrypto.keyExtractSuri)(suri);
@@ -1195,11 +1218,11 @@ class KoniExtension {
1195
1218
  });
1196
1219
  return rs;
1197
1220
  }
1198
- _checkValidatePrivateKey(_ref34) {
1221
+ _checkValidatePrivateKey(_ref35) {
1199
1222
  let {
1200
1223
  suri,
1201
1224
  types
1202
- } = _ref34;
1225
+ } = _ref35;
1203
1226
  let autoAddPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1204
1227
  const {
1205
1228
  phrase
@@ -1222,11 +1245,11 @@ class KoniExtension {
1222
1245
  }
1223
1246
  return rs;
1224
1247
  }
1225
- metamaskPrivateKeyValidateV2(_ref35) {
1248
+ metamaskPrivateKeyValidateV2(_ref36) {
1226
1249
  let {
1227
1250
  suri,
1228
1251
  types
1229
- } = _ref35;
1252
+ } = _ref36;
1230
1253
  const isValidSuri = suri.startsWith('0x');
1231
1254
  if (isValidSuri) {
1232
1255
  return this._checkValidatePrivateKey({
@@ -1251,14 +1274,14 @@ class KoniExtension {
1251
1274
  throw new Error(`"${suri}" is not a valid derivation path`);
1252
1275
  }
1253
1276
  }
1254
- derivationCreateV2(_ref36) {
1277
+ derivationCreateV2(_ref37) {
1255
1278
  let {
1256
1279
  genesisHash,
1257
1280
  isAllowed,
1258
1281
  name,
1259
1282
  parentAddress,
1260
1283
  suri
1261
- } = _ref36;
1284
+ } = _ref37;
1262
1285
  const childPair = this.deriveV2(parentAddress, suri, {
1263
1286
  genesisHash,
1264
1287
  name,
@@ -1272,14 +1295,14 @@ class KoniExtension {
1272
1295
  });
1273
1296
  return true;
1274
1297
  }
1275
- jsonRestoreV2(_ref37) {
1298
+ jsonRestoreV2(_ref38) {
1276
1299
  let {
1277
1300
  address,
1278
1301
  file,
1279
1302
  isAllowed,
1280
1303
  password,
1281
1304
  withMasterPassword
1282
- } = _ref37;
1305
+ } = _ref38;
1283
1306
  const isPasswordValidated = this.validatePassword(file, password);
1284
1307
  if (isPasswordValidated) {
1285
1308
  try {
@@ -1294,13 +1317,13 @@ class KoniExtension {
1294
1317
  throw new Error('Unable to decode using the supplied passphrase');
1295
1318
  }
1296
1319
  }
1297
- batchRestoreV2(_ref38) {
1320
+ batchRestoreV2(_ref39) {
1298
1321
  let {
1299
1322
  accountsInfo,
1300
1323
  file,
1301
1324
  isAllowed,
1302
1325
  password
1303
- } = _ref38;
1326
+ } = _ref39;
1304
1327
  const addressList = accountsInfo.map(acc => acc.address);
1305
1328
  const isPasswordValidated = this.validatedAccountsPassword(file, password);
1306
1329
  if (isPasswordValidated) {
@@ -1455,7 +1478,11 @@ class KoniExtension {
1455
1478
  let transaction;
1456
1479
 
1457
1480
  // Get native token amount
1458
- const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1481
+ const freeBalance = await this.getAddressFreeBalance({
1482
+ address: from,
1483
+ networkKey,
1484
+ token: tokenSlug
1485
+ });
1459
1486
  try {
1460
1487
  if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to) && (0, _utils._isTokenTransferredByEvm)(tokenInfo)) {
1461
1488
  // TODO: review this
@@ -1468,6 +1495,10 @@ class KoniExtension {
1468
1495
  } else {
1469
1496
  [transaction, transferAmount.value] = await (0, _transfer3.getEVMTransactionObject)(chainInfo, to, txVal, !!transferAll, evmApiMap);
1470
1497
  }
1498
+ } else if ((0, _utils._isMantaZkAsset)(tokenInfo)) {
1499
+ // TODO
1500
+ transaction = undefined;
1501
+ transferAmount.value = '0';
1471
1502
  } else {
1472
1503
  const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1473
1504
  [transaction, transferAmount.value] = await (0, _transfer.createTransferExtrinsic)({
@@ -1496,14 +1527,22 @@ class KoniExtension {
1496
1527
  if (!isTransferNativeToken) {
1497
1528
  const {
1498
1529
  value: balance
1499
- } = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1530
+ } = await this.getAddressFreeBalance({
1531
+ address: from,
1532
+ networkKey,
1533
+ token: tokenSlug
1534
+ });
1500
1535
  if (new _bignumber.default(balance).minus(transferAmount.value).lt(minAmount)) {
1501
1536
  inputTransaction.warnings.push(new _TransactionWarning.TransactionWarning(_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
1502
1537
  }
1503
1538
  }
1504
1539
  const {
1505
1540
  value: receiverBalance
1506
- } = await this.#koniState.balanceService.getTokenFreeBalance(to, networkKey, tokenSlug);
1541
+ } = await this.getAddressFreeBalance({
1542
+ address: from,
1543
+ networkKey,
1544
+ token: tokenSlug
1545
+ });
1507
1546
  if (new _bignumber.default(receiverBalance).plus(transferAmount.value).lt(minAmount)) {
1508
1547
  const atLeast = new _bignumber.default(minAmount).minus(receiverBalance).plus((tokenInfo.decimals || 0) === 0 ? 0 : 1);
1509
1548
  const atLeastStr = (0, _number.formatNumber)(atLeast, tokenInfo.decimals || 0, _number.balanceFormatter);
@@ -1603,7 +1642,7 @@ class KoniExtension {
1603
1642
  // this.addContact(to);
1604
1643
 
1605
1644
  return await this.#koniState.transactionService.handleTransaction({
1606
- url: _constants2.EXTENSION_REQUEST_URL,
1645
+ url: _constants3.EXTENSION_REQUEST_URL,
1607
1646
  address: from,
1608
1647
  chain: originNetworkKey,
1609
1648
  transaction: extrinsic,
@@ -1638,7 +1677,7 @@ class KoniExtension {
1638
1677
  data: inputData,
1639
1678
  extrinsicType: _KoniTypes.ExtrinsicType.SEND_NFT,
1640
1679
  transaction,
1641
- url: _constants2.EXTENSION_REQUEST_URL
1680
+ url: _constants3.EXTENSION_REQUEST_URL
1642
1681
  });
1643
1682
  }
1644
1683
  async upsertChain(data) {
@@ -1655,18 +1694,18 @@ class KoniExtension {
1655
1694
  disableChain(networkKey) {
1656
1695
  return this.#koniState.disableChain(networkKey);
1657
1696
  }
1658
- async enableChain(_ref39) {
1697
+ async enableChain(_ref40) {
1659
1698
  let {
1660
1699
  chainSlug,
1661
1700
  enableTokens
1662
- } = _ref39;
1701
+ } = _ref40;
1663
1702
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1664
1703
  }
1665
- async validateNetwork(_ref40) {
1704
+ async validateNetwork(_ref41) {
1666
1705
  let {
1667
1706
  existedChainSlug,
1668
1707
  provider
1669
- } = _ref40;
1708
+ } = _ref41;
1670
1709
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1671
1710
  }
1672
1711
  resetDefaultNetwork() {
@@ -1704,23 +1743,33 @@ class KoniExtension {
1704
1743
  async validateCustomAsset(data) {
1705
1744
  return await this.#koniState.validateCustomAsset(data);
1706
1745
  }
1707
- async getAddressFreeBalance(_ref41) {
1746
+ async getAddressFreeBalance(_ref42) {
1708
1747
  let {
1709
1748
  address,
1710
1749
  networkKey,
1711
1750
  token
1712
- } = _ref41;
1751
+ } = _ref42;
1752
+ if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1753
+ const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1754
+ if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
1755
+ return await this.#koniState.getMantaPayZkBalance(address, tokenInfo);
1756
+ }
1757
+ }
1713
1758
  return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1714
1759
  }
1715
- async transferGetMaxTransferable(_ref42) {
1760
+ async transferGetMaxTransferable(_ref43) {
1716
1761
  let {
1717
1762
  address,
1718
1763
  destChain,
1719
1764
  isXcmTransfer,
1720
1765
  networkKey,
1721
1766
  token
1722
- } = _ref42;
1723
- const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1767
+ } = _ref43;
1768
+ const freeBalance = await this.getAddressFreeBalance({
1769
+ address,
1770
+ networkKey,
1771
+ token
1772
+ });
1724
1773
  const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1725
1774
  if (!(0, _utils._isNativeToken)(tokenInfo)) {
1726
1775
  return freeBalance;
@@ -1790,12 +1839,12 @@ class KoniExtension {
1790
1839
  };
1791
1840
  }
1792
1841
  }
1793
- async subscribeAddressFreeBalance(_ref43, id, port) {
1842
+ async subscribeAddressFreeBalance(_ref44, id, port) {
1794
1843
  let {
1795
1844
  address,
1796
1845
  networkKey,
1797
1846
  token
1798
- } = _ref43;
1847
+ } = _ref44;
1799
1848
  const cb = (0, _subscriptions.createSubscription)(id, port);
1800
1849
  const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1801
1850
  this.createUnsubscriptionHandle(id, unsub);
@@ -1804,26 +1853,26 @@ class KoniExtension {
1804
1853
  });
1805
1854
  return currentFreeBalance;
1806
1855
  }
1807
- async transferCheckReferenceCount(_ref44) {
1856
+ async transferCheckReferenceCount(_ref45) {
1808
1857
  let {
1809
1858
  address,
1810
1859
  networkKey
1811
- } = _ref44;
1860
+ } = _ref45;
1812
1861
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1813
1862
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1814
1863
  }
1815
- async transferCheckSupporting(_ref45) {
1864
+ async transferCheckSupporting(_ref46) {
1816
1865
  let {
1817
1866
  networkKey,
1818
1867
  tokenSlug
1819
- } = _ref45;
1868
+ } = _ref46;
1820
1869
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1821
1870
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1822
1871
  }
1823
- transferGetExistentialDeposit(_ref46) {
1872
+ transferGetExistentialDeposit(_ref47) {
1824
1873
  let {
1825
1874
  tokenSlug
1826
- } = _ref46;
1875
+ } = _ref47;
1827
1876
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1828
1877
  return (0, _utils._getTokenMinAmount)(tokenInfo);
1829
1878
  }
@@ -1859,11 +1908,11 @@ class KoniExtension {
1859
1908
  isSendingSelf
1860
1909
  };
1861
1910
  }
1862
- async enableChains(_ref47) {
1911
+ async enableChains(_ref48) {
1863
1912
  let {
1864
1913
  chainSlugs,
1865
1914
  enableTokens
1866
- } = _ref47;
1915
+ } = _ref48;
1867
1916
  try {
1868
1917
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
1869
1918
  chainSlug,
@@ -1874,24 +1923,24 @@ class KoniExtension {
1874
1923
  }
1875
1924
  return true;
1876
1925
  }
1877
- getAccountMeta(_ref48) {
1926
+ getAccountMeta(_ref49) {
1878
1927
  let {
1879
1928
  address
1880
- } = _ref48;
1929
+ } = _ref49;
1881
1930
  const pair = _uiKeyring.keyring.getPair(address);
1882
1931
  (0, _util.assert)(pair, 'Unable to find pair');
1883
1932
  return {
1884
1933
  meta: pair.meta
1885
1934
  };
1886
1935
  }
1887
- accountsTie2(_ref49) {
1936
+ accountsTie2(_ref50) {
1888
1937
  let {
1889
1938
  address,
1890
1939
  genesisHash
1891
- } = _ref49;
1940
+ } = _ref50;
1892
1941
  return this.#koniState.setAccountTie(address, genesisHash);
1893
1942
  }
1894
- async accountsCreateExternalV2(_ref50) {
1943
+ async accountsCreateExternalV2(_ref51) {
1895
1944
  let {
1896
1945
  address,
1897
1946
  genesisHash,
@@ -1899,7 +1948,7 @@ class KoniExtension {
1899
1948
  isEthereum,
1900
1949
  isReadOnly,
1901
1950
  name
1902
- } = _ref50;
1951
+ } = _ref51;
1903
1952
  try {
1904
1953
  let result;
1905
1954
  try {
@@ -1958,7 +2007,7 @@ class KoniExtension {
1958
2007
  }];
1959
2008
  }
1960
2009
  }
1961
- async accountsCreateHardwareV2(_ref51) {
2010
+ async accountsCreateHardwareV2(_ref52) {
1962
2011
  let {
1963
2012
  accountIndex,
1964
2013
  address,
@@ -1967,7 +2016,7 @@ class KoniExtension {
1967
2016
  hardwareType,
1968
2017
  isAllowed,
1969
2018
  name
1970
- } = _ref51;
2019
+ } = _ref52;
1971
2020
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
1972
2021
  accountIndex,
1973
2022
  addressOffset,
@@ -1990,10 +2039,10 @@ class KoniExtension {
1990
2039
  });
1991
2040
  return true;
1992
2041
  }
1993
- async accountsCreateHardwareMultiple(_ref52) {
2042
+ async accountsCreateHardwareMultiple(_ref53) {
1994
2043
  let {
1995
2044
  accounts
1996
- } = _ref52;
2045
+ } = _ref53;
1997
2046
  const addresses = [];
1998
2047
  if (!accounts.length) {
1999
2048
  throw new Error('No accounts to import');
@@ -2071,14 +2120,14 @@ class KoniExtension {
2071
2120
  }
2072
2121
  return true;
2073
2122
  }
2074
- async accountsCreateWithSecret(_ref53) {
2123
+ async accountsCreateWithSecret(_ref54) {
2075
2124
  let {
2076
2125
  isAllow,
2077
2126
  isEthereum,
2078
2127
  name,
2079
2128
  publicKey,
2080
2129
  secretKey
2081
- } = _ref53;
2130
+ } = _ref54;
2082
2131
  try {
2083
2132
  let keyringPair = null;
2084
2133
  if (isEthereum) {
@@ -2221,30 +2270,30 @@ class KoniExtension {
2221
2270
 
2222
2271
  // Parse transaction
2223
2272
 
2224
- parseSubstrateTransaction(_ref54) {
2273
+ parseSubstrateTransaction(_ref55) {
2225
2274
  let {
2226
2275
  data,
2227
2276
  networkKey
2228
- } = _ref54;
2277
+ } = _ref55;
2229
2278
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2230
2279
  const apiPromise = apiProps.api;
2231
2280
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2232
2281
  }
2233
- async parseEVMRLP(_ref55) {
2282
+ async parseEVMRLP(_ref56) {
2234
2283
  let {
2235
2284
  data
2236
- } = _ref55;
2285
+ } = _ref56;
2237
2286
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2238
2287
  }
2239
2288
 
2240
2289
  // Sign
2241
2290
 
2242
- qrSignSubstrate(_ref56) {
2291
+ qrSignSubstrate(_ref57) {
2243
2292
  let {
2244
2293
  address,
2245
2294
  data,
2246
2295
  networkKey
2247
- } = _ref56;
2296
+ } = _ref57;
2248
2297
  const pair = _uiKeyring.keyring.getPair(address);
2249
2298
  (0, _util.assert)(pair, 'Unable to find pair');
2250
2299
  if (pair.isLocked) {
@@ -2261,13 +2310,13 @@ class KoniExtension {
2261
2310
  signature: signed
2262
2311
  };
2263
2312
  }
2264
- async qrSignEVM(_ref57) {
2313
+ async qrSignEVM(_ref58) {
2265
2314
  let {
2266
2315
  address,
2267
2316
  chainId,
2268
2317
  message,
2269
2318
  type
2270
- } = _ref57;
2319
+ } = _ref58;
2271
2320
  let signed;
2272
2321
  const network = this.getNetworkJsonByChainId(chainId);
2273
2322
  if (!network) {
@@ -2348,11 +2397,11 @@ class KoniExtension {
2348
2397
  });
2349
2398
  return this.#koniState.getNominatorMetadata();
2350
2399
  }
2351
- async getBondingOptions(_ref58) {
2400
+ async getBondingOptions(_ref59) {
2352
2401
  let {
2353
2402
  chain,
2354
2403
  type
2355
- } = _ref58;
2404
+ } = _ref59;
2356
2405
  const apiProps = this.#koniState.getSubstrateApi(chain);
2357
2406
  const chainInfo = this.#koniState.getChainInfo(chain);
2358
2407
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2394,7 +2443,7 @@ class KoniExtension {
2394
2443
  data: inputData,
2395
2444
  extrinsicType: _KoniTypes.ExtrinsicType.STAKING_BOND,
2396
2445
  transaction: extrinsic,
2397
- url: _constants2.EXTENSION_REQUEST_URL,
2446
+ url: _constants3.EXTENSION_REQUEST_URL,
2398
2447
  transferNativeAmount: amount
2399
2448
  });
2400
2449
  }
@@ -2541,12 +2590,12 @@ class KoniExtension {
2541
2590
  }
2542
2591
 
2543
2592
  // EVM Transaction
2544
- async parseContractInput(_ref59) {
2593
+ async parseContractInput(_ref60) {
2545
2594
  let {
2546
2595
  chainId,
2547
2596
  contract,
2548
2597
  data
2549
- } = _ref59;
2598
+ } = _ref60;
2550
2599
  const network = this.getNetworkJsonByChainId(chainId);
2551
2600
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2552
2601
  }
@@ -2617,12 +2666,12 @@ class KoniExtension {
2617
2666
 
2618
2667
  // Change master password
2619
2668
 
2620
- keyringChangeMasterPassword(_ref60) {
2669
+ keyringChangeMasterPassword(_ref61) {
2621
2670
  let {
2622
2671
  createNew,
2623
2672
  newPassword,
2624
2673
  oldPassword
2625
- } = _ref60;
2674
+ } = _ref61;
2626
2675
  try {
2627
2676
  // Remove isMasterPassword meta if createNew
2628
2677
  if (createNew) {
@@ -2656,11 +2705,11 @@ class KoniExtension {
2656
2705
 
2657
2706
  // Migrate password
2658
2707
 
2659
- keyringMigrateMasterPassword(_ref61) {
2708
+ keyringMigrateMasterPassword(_ref62) {
2660
2709
  let {
2661
2710
  address,
2662
2711
  password
2663
- } = _ref61;
2712
+ } = _ref62;
2664
2713
  try {
2665
2714
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2666
2715
  } catch (e) {
@@ -2678,12 +2727,13 @@ class KoniExtension {
2678
2727
 
2679
2728
  // Unlock wallet
2680
2729
 
2681
- keyringUnlock(_ref62) {
2730
+ keyringUnlock(_ref63) {
2682
2731
  let {
2683
2732
  password
2684
- } = _ref62;
2733
+ } = _ref63;
2685
2734
  try {
2686
2735
  _uiKeyring.keyring.unlockKeyring(password);
2736
+ this.#koniState.initMantaPay(password).catch(console.error);
2687
2737
  } catch (e) {
2688
2738
  return {
2689
2739
  errors: [e.message],
@@ -2707,11 +2757,11 @@ class KoniExtension {
2707
2757
 
2708
2758
  // Export mnemonic
2709
2759
 
2710
- keyringExportMnemonic(_ref63) {
2760
+ keyringExportMnemonic(_ref64) {
2711
2761
  let {
2712
2762
  address,
2713
2763
  password
2714
- } = _ref63;
2764
+ } = _ref64;
2715
2765
  const pair = _uiKeyring.keyring.getPair(address);
2716
2766
  const result = pair.exportMnemonic(password);
2717
2767
  return {
@@ -2721,10 +2771,10 @@ class KoniExtension {
2721
2771
 
2722
2772
  // Reset wallet
2723
2773
 
2724
- async resetWallet(_ref64) {
2774
+ async resetWallet(_ref65) {
2725
2775
  let {
2726
2776
  resetAll
2727
- } = _ref64;
2777
+ } = _ref65;
2728
2778
  try {
2729
2779
  await this.#koniState.resetWallet(resetAll);
2730
2780
  return {
@@ -2740,10 +2790,10 @@ class KoniExtension {
2740
2790
  }
2741
2791
 
2742
2792
  /// Signing external request
2743
- signingApprovePasswordV2(_ref65) {
2793
+ signingApprovePasswordV2(_ref66) {
2744
2794
  let {
2745
2795
  id
2746
- } = _ref65;
2796
+ } = _ref66;
2747
2797
  const queued = this.#koniState.getSignRequest(id);
2748
2798
  (0, _util.assert)(queued, 'Unable to find request');
2749
2799
  const {
@@ -2769,7 +2819,7 @@ class KoniExtension {
2769
2819
  const {
2770
2820
  payload
2771
2821
  } = request;
2772
- const registry = new _types2.TypeRegistry();
2822
+ const registry = new _types3.TypeRegistry();
2773
2823
  let isEvm = false;
2774
2824
  if ((0, _Extension.isJsonPayload)(payload)) {
2775
2825
  // Get the metadata for the genesisHash
@@ -2796,22 +2846,22 @@ class KoniExtension {
2796
2846
 
2797
2847
  /// Derive account
2798
2848
 
2799
- derivationCreateMultiple(_ref66) {
2849
+ derivationCreateMultiple(_ref67) {
2800
2850
  let {
2801
2851
  isAllowed,
2802
2852
  items,
2803
2853
  parentAddress
2804
- } = _ref66;
2854
+ } = _ref67;
2805
2855
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2806
2856
  const isEvm = parentPair.type === 'ethereum';
2807
2857
  if (parentPair.isLocked) {
2808
2858
  _uiKeyring.keyring.unlockPair(parentPair.address);
2809
2859
  }
2810
- const createChild = _ref67 => {
2860
+ const createChild = _ref68 => {
2811
2861
  let {
2812
2862
  name,
2813
2863
  suri
2814
- } = _ref67;
2864
+ } = _ref68;
2815
2865
  const meta = {
2816
2866
  name: name,
2817
2867
  parentAddress
@@ -2857,10 +2907,10 @@ class KoniExtension {
2857
2907
  }
2858
2908
  return true;
2859
2909
  }
2860
- derivationCreateV3(_ref68) {
2910
+ derivationCreateV3(_ref69) {
2861
2911
  let {
2862
2912
  address: parentAddress
2863
- } = _ref68;
2913
+ } = _ref69;
2864
2914
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2865
2915
  const isEvm = parentPair.type === 'ethereum';
2866
2916
  if (parentPair.isLocked) {
@@ -2892,11 +2942,11 @@ class KoniExtension {
2892
2942
  });
2893
2943
  return true;
2894
2944
  }
2895
- validateDerivePath(_ref69) {
2945
+ validateDerivePath(_ref70) {
2896
2946
  let {
2897
2947
  parentAddress,
2898
2948
  suri
2899
- } = _ref69;
2949
+ } = _ref70;
2900
2950
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2901
2951
  const isEvm = parentPair.type === 'ethereum';
2902
2952
  if (parentPair.isLocked) {
@@ -2929,12 +2979,12 @@ class KoniExtension {
2929
2979
  suri: meta.suri
2930
2980
  };
2931
2981
  }
2932
- getListDeriveAccounts(_ref70) {
2982
+ getListDeriveAccounts(_ref71) {
2933
2983
  let {
2934
2984
  limit,
2935
2985
  page,
2936
2986
  parentAddress
2937
- } = _ref70;
2987
+ } = _ref71;
2938
2988
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2939
2989
  const isEvm = parentPair.type === 'ethereum';
2940
2990
  if (parentPair.isLocked) {
@@ -3025,10 +3075,10 @@ class KoniExtension {
3025
3075
  getSupportedSmartContractTypes() {
3026
3076
  return this.#koniState.getSupportedSmartContractTypes();
3027
3077
  }
3028
- getTransaction(_ref71) {
3078
+ getTransaction(_ref72) {
3029
3079
  let {
3030
3080
  id
3031
- } = _ref71;
3081
+ } = _ref72;
3032
3082
  const {
3033
3083
  transaction,
3034
3084
  ...transactionResult
@@ -3038,8 +3088,8 @@ class KoniExtension {
3038
3088
  subscribeTransactions(id, port) {
3039
3089
  const cb = (0, _subscriptions.createSubscription)(id, port);
3040
3090
  function convertRs(rs) {
3041
- return Object.fromEntries(Object.entries(rs).map(_ref72 => {
3042
- let [key, value] = _ref72;
3091
+ return Object.fromEntries(Object.entries(rs).map(_ref73 => {
3092
+ let [key, value] = _ref73;
3043
3093
  const {
3044
3094
  additionalValidator,
3045
3095
  eventsHandler,
@@ -3071,10 +3121,10 @@ class KoniExtension {
3071
3121
  });
3072
3122
  return notificationSubject.value;
3073
3123
  }
3074
- async reloadCron(_ref73) {
3124
+ async reloadCron(_ref74) {
3075
3125
  let {
3076
3126
  data
3077
- } = _ref73;
3127
+ } = _ref74;
3078
3128
  if (data === 'nft') {
3079
3129
  return await this.#koniState.reloadNft();
3080
3130
  } else if (data === 'staking') {
@@ -3092,20 +3142,20 @@ class KoniExtension {
3092
3142
 
3093
3143
  // Phishing detect
3094
3144
 
3095
- async passPhishingPage(_ref74) {
3145
+ async passPhishingPage(_ref75) {
3096
3146
  let {
3097
3147
  url
3098
- } = _ref74;
3148
+ } = _ref75;
3099
3149
  return await this.#koniState.approvePassPhishingPage(url);
3100
3150
  }
3101
3151
 
3102
3152
  /// Wallet connect
3103
3153
 
3104
3154
  // Connect
3105
- async connectWalletConnect(_ref75) {
3155
+ async connectWalletConnect(_ref76) {
3106
3156
  let {
3107
3157
  uri
3108
- } = _ref75;
3158
+ } = _ref76;
3109
3159
  await this.#koniState.walletConnectService.connect(uri);
3110
3160
  return true;
3111
3161
  }
@@ -3118,11 +3168,11 @@ class KoniExtension {
3118
3168
  });
3119
3169
  return this.#koniState.requestService.allConnectWCRequests;
3120
3170
  }
3121
- async approveWalletConnectSession(_ref76) {
3171
+ async approveWalletConnectSession(_ref77) {
3122
3172
  let {
3123
3173
  accounts: selectedAccounts,
3124
3174
  id
3125
- } = _ref76;
3175
+ } = _ref77;
3126
3176
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3127
3177
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3128
3178
  throw new Error('The proposal has been expired');
@@ -3134,8 +3184,8 @@ class KoniExtension {
3134
3184
  const availableNamespaces = {};
3135
3185
  const namespaces = {};
3136
3186
  const chainInfoMap = this.#koniState.getChainInfoMap();
3137
- Object.entries(requiredNamespaces).forEach(_ref77 => {
3138
- let [key, namespace] = _ref77;
3187
+ Object.entries(requiredNamespaces).forEach(_ref78 => {
3188
+ let [key, namespace] = _ref78;
3139
3189
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3140
3190
  if (namespace.chains) {
3141
3191
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
@@ -3148,8 +3198,8 @@ class KoniExtension {
3148
3198
  throw new Error((0, _utils3.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3149
3199
  }
3150
3200
  });
3151
- Object.entries(optionalNamespaces).forEach(_ref78 => {
3152
- let [key, namespace] = _ref78;
3201
+ Object.entries(optionalNamespaces).forEach(_ref79 => {
3202
+ let [key, namespace] = _ref79;
3153
3203
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3154
3204
  if (namespace.chains) {
3155
3205
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -3173,13 +3223,13 @@ class KoniExtension {
3173
3223
  }
3174
3224
  }
3175
3225
  });
3176
- Object.entries(availableNamespaces).forEach(_ref79 => {
3177
- let [key, namespace] = _ref79;
3226
+ Object.entries(availableNamespaces).forEach(_ref80 => {
3227
+ let [key, namespace] = _ref80;
3178
3228
  if (namespace.chains) {
3179
3229
  const accounts = [];
3180
3230
  const chains = (0, _utils2.uniqueStringArray)(namespace.chains);
3181
3231
  chains.forEach(chain => {
3182
- accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants4.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
3232
+ accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants5.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
3183
3233
  });
3184
3234
  namespaces[key] = {
3185
3235
  accounts,
@@ -3198,10 +3248,10 @@ class KoniExtension {
3198
3248
  request.resolve();
3199
3249
  return true;
3200
3250
  }
3201
- async rejectWalletConnectSession(_ref80) {
3251
+ async rejectWalletConnectSession(_ref81) {
3202
3252
  let {
3203
3253
  id
3204
- } = _ref80;
3254
+ } = _ref81;
3205
3255
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3206
3256
  const wcId = request.request.id;
3207
3257
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -3223,20 +3273,138 @@ class KoniExtension {
3223
3273
  });
3224
3274
  return this.#koniState.walletConnectService.sessions;
3225
3275
  }
3226
- async disconnectWalletConnectSession(_ref81) {
3276
+ async disconnectWalletConnectSession(_ref82) {
3227
3277
  let {
3228
3278
  topic
3229
- } = _ref81;
3279
+ } = _ref82;
3230
3280
  await this.#koniState.walletConnectService.disconnect(topic);
3231
3281
  return true;
3232
3282
  }
3283
+ async enableMantaPay(_ref83) {
3284
+ let {
3285
+ address,
3286
+ password
3287
+ } = _ref83;
3288
+ // always takes the current account
3289
+ function timeout() {
3290
+ return new Promise(resolve => setTimeout(resolve, 1500));
3291
+ }
3292
+ try {
3293
+ await this.#koniState.chainService.enableChain(_constants2._DEFAULT_MANTA_ZK_CHAIN);
3294
+ this.#koniState.chainService.setMantaZkAssetSettings(true);
3295
+ const mnemonic = this.keyringExportMnemonic({
3296
+ address,
3297
+ password
3298
+ });
3299
+ const {
3300
+ connectionStatus
3301
+ } = this.#koniState.chainService.getChainStateByKey(_constants2._DEFAULT_MANTA_ZK_CHAIN);
3302
+ if (connectionStatus !== _types2._ChainConnectionStatus.CONNECTED) {
3303
+ // TODO: do better
3304
+ await timeout();
3305
+ }
3306
+ const result = await this.#koniState.enableMantaPay(true, address, password, mnemonic.result);
3307
+ this.#skipAutoLock = true;
3308
+ await this.saveCurrentAccountAddress({
3309
+ address
3310
+ });
3311
+ const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3312
+ console.debug('Start initial sync for MantaPay');
3313
+ this.#koniState.initialSyncMantaPay(address).then(() => {
3314
+ console.debug('Finished initial sync for MantaPay');
3315
+ this.#skipAutoLock = false;
3316
+ unsubSyncProgress();
3317
+ }).catch(e => {
3318
+ console.error('Error syncing MantaPay', e);
3319
+ this.#skipAutoLock = false;
3320
+ unsubSyncProgress();
3321
+ });
3322
+ return {
3323
+ success: !!result,
3324
+ message: result ? _KoniTypes.MantaPayEnableMessage.SUCCESS : _KoniTypes.MantaPayEnableMessage.UNKNOWN_ERROR
3325
+ };
3326
+ } catch (e) {
3327
+ // @ts-ignore
3328
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
3329
+ if (e.toString() === 'Error: Unable to decode using the supplied passphrase') {
3330
+ return {
3331
+ success: false,
3332
+ message: _KoniTypes.MantaPayEnableMessage.WRONG_PASSWORD
3333
+ };
3334
+ }
3335
+ return {
3336
+ success: false,
3337
+ message: _KoniTypes.MantaPayEnableMessage.UNKNOWN_ERROR
3338
+ };
3339
+ }
3340
+ }
3341
+ async initSyncMantaPay(address) {
3342
+ if (this.#koniState.chainService.mantaPay.getSyncState().isSyncing) {
3343
+ return;
3344
+ }
3345
+ this.#skipAutoLock = true;
3346
+ await this.saveCurrentAccountAddress({
3347
+ address
3348
+ });
3349
+ const unsubSyncProgress = await this.#koniState.chainService.mantaPay.subscribeSyncProgress();
3350
+ console.debug('Start initial sync for MantaPay');
3351
+ this.#koniState.initialSyncMantaPay(address).then(() => {
3352
+ console.debug('Finished initial sync for MantaPay');
3353
+ this.#skipAutoLock = false;
3354
+ unsubSyncProgress();
3355
+ // make sure the sync state is set, just in case it gets unsubscribed
3356
+ this.#koniState.chainService.mantaPay.setSyncState({
3357
+ progress: 100,
3358
+ isSyncing: false
3359
+ });
3360
+ }).catch(e => {
3361
+ console.error('Error syncing MantaPay', e);
3362
+ this.#skipAutoLock = false;
3363
+ unsubSyncProgress();
3364
+ this.#koniState.chainService.mantaPay.setSyncState({
3365
+ progress: 0,
3366
+ isSyncing: false
3367
+ });
3368
+ });
3369
+ }
3370
+ async disableMantaPay(address) {
3371
+ return this.#koniState.disableMantaPay(address);
3372
+ }
3373
+ subscribeMantaPayConfig(id, port) {
3374
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3375
+ const mantaPayConfigSubscription = this.#koniState.subscribeMantaPayConfig().subscribe({
3376
+ next: rs => {
3377
+ cb(rs);
3378
+ }
3379
+ });
3380
+ this.createUnsubscriptionHandle(id, mantaPayConfigSubscription.unsubscribe);
3381
+ port.onDisconnect.addListener(() => {
3382
+ this.cancelSubscription(id);
3383
+ });
3384
+ return this.#koniState.getMantaPayConfig('calamari');
3385
+ }
3386
+ subscribeMantaPaySyncState(id, port) {
3387
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3388
+ const syncingStateSubscription = this.#koniState.subscribeMantaPaySyncState().subscribe({
3389
+ next: rs => {
3390
+ cb(rs);
3391
+ }
3392
+ });
3393
+ this.createUnsubscriptionHandle(id, syncingStateSubscription.unsubscribe);
3394
+ port.onDisconnect.addListener(() => {
3395
+ this.cancelSubscription(id);
3396
+ });
3397
+ return this.#koniState.chainService.mantaPay.getSyncState();
3398
+ }
3233
3399
 
3234
3400
  // --------------------------------------------------------------
3235
3401
  // eslint-disable-next-line @typescript-eslint/require-await
3236
3402
  async handle(id, type, request, port) {
3237
3403
  clearTimeout(this.#lockTimeOut);
3238
3404
  this.#lockTimeOut = setTimeout(() => {
3239
- this.keyringLock();
3405
+ if (!this.#skipAutoLock) {
3406
+ this.keyringLock();
3407
+ }
3240
3408
  }, this.#timeAutoLock * 60 * 1000);
3241
3409
  switch (type) {
3242
3410
  /// Clone from PolkadotJs
@@ -3617,7 +3785,16 @@ class KoniExtension {
3617
3785
  return this.subscribeWalletConnectSessions(id, port);
3618
3786
  case 'pri(walletConnect.session.disconnect)':
3619
3787
  return this.disconnectWalletConnectSession(request);
3620
-
3788
+ case 'pri(mantaPay.enable)':
3789
+ return await this.enableMantaPay(request);
3790
+ case 'pri(mantaPay.initSyncMantaPay)':
3791
+ return await this.initSyncMantaPay(request);
3792
+ case 'pri(mantaPay.subscribeConfig)':
3793
+ return await this.subscribeMantaPayConfig(id, port);
3794
+ case 'pri(mantaPay.disable)':
3795
+ return await this.disableMantaPay(request);
3796
+ case 'pri(mantaPay.subscribeSyncingState)':
3797
+ return this.subscribeMantaPaySyncState(id, port);
3621
3798
  // Default
3622
3799
  default:
3623
3800
  throw new Error(`Unable to handle message of type ${type}`);