@subwallet/extension-base 1.0.2-2 → 1.0.2-3

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 +46 -38
  2. package/background/KoniTypes.js +8 -8
  3. package/background/errors/TransactionError.js +25 -1
  4. package/background/types.d.ts +10 -5
  5. package/cjs/background/KoniTypes.js +8 -8
  6. package/cjs/background/errors/TransactionError.js +24 -0
  7. package/cjs/constants/index.js +8 -26
  8. package/cjs/koni/api/dotsama/balance.js +49 -224
  9. package/cjs/koni/api/dotsama/transfer.js +34 -39
  10. package/cjs/koni/api/nft/acala_nft/index.js +7 -7
  11. package/cjs/koni/api/nft/bit.country/index.js +7 -6
  12. package/cjs/koni/api/nft/evm_nft/index.js +8 -3
  13. package/cjs/koni/api/nft/index.js +3 -6
  14. package/cjs/koni/api/nft/karura_nft/index.js +7 -6
  15. package/cjs/koni/api/nft/rmrk_nft/index.js +11 -1
  16. package/cjs/koni/api/nft/statemine_nft/index.js +7 -6
  17. package/cjs/koni/api/nft/unique_nft/index.js +5 -1
  18. package/cjs/koni/api/nft/wasm_nft/index.js +170 -111
  19. package/cjs/koni/api/nft/wasm_nft/utils.js +11 -7
  20. package/cjs/koni/api/staking/bonding/amplitude.js +13 -9
  21. package/cjs/koni/api/staking/bonding/astar.js +15 -13
  22. package/cjs/koni/api/staking/bonding/index.js +22 -10
  23. package/cjs/koni/api/staking/bonding/paraChain.js +85 -2
  24. package/cjs/koni/api/staking/bonding/relayChain.js +122 -16
  25. package/cjs/koni/api/staking/bonding/utils.js +27 -8
  26. package/cjs/koni/api/tokens/wasm/index.js +5 -4
  27. package/cjs/koni/api/tokens/wasm/utils.js +63 -0
  28. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  29. package/cjs/koni/api/xcm/utils.js +18 -13
  30. package/cjs/koni/api/xcm/xTokens.js +1 -1
  31. package/cjs/koni/api/xcm/xcmPallet.js +9 -6
  32. package/cjs/koni/background/cron.js +171 -61
  33. package/cjs/koni/background/handlers/Extension.js +382 -207
  34. package/cjs/koni/background/handlers/State.js +41 -33
  35. package/cjs/koni/background/handlers/Tabs.js +50 -17
  36. package/cjs/koni/background/subscription.js +32 -29
  37. package/cjs/packageInfo.js +1 -1
  38. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +13 -8
  39. package/cjs/services/chain-service/index.js +59 -45
  40. package/cjs/services/event-service/index.js +5 -1
  41. package/cjs/services/event-service/types.js +11 -1
  42. package/cjs/services/history-service/index.js +19 -13
  43. package/cjs/services/history-service/subsquid-multi-chain-history.js +13 -10
  44. package/cjs/services/keyring-service/index.js +11 -13
  45. package/cjs/services/price-service/coingecko.js +0 -1
  46. package/cjs/services/price-service/index.js +2 -3
  47. package/cjs/services/request-service/handler/AuthRequestHandler.js +13 -7
  48. package/cjs/services/request-service/handler/EvmRequestHandler.js +8 -12
  49. package/cjs/services/request-service/index.js +14 -5
  50. package/cjs/services/storage-service/DatabaseService.js +56 -34
  51. package/cjs/services/storage-service/db-stores/Nft.js +7 -15
  52. package/cjs/services/transaction-service/event-parser/index.js +20 -48
  53. package/cjs/services/transaction-service/index.js +26 -15
  54. package/cjs/utils/address.js +10 -1
  55. package/cjs/utils/index.js +9 -15
  56. package/constants/index.d.ts +7 -13
  57. package/constants/index.js +7 -13
  58. package/koni/api/dotsama/balance.d.ts +0 -1
  59. package/koni/api/dotsama/balance.js +22 -197
  60. package/koni/api/dotsama/transfer.js +11 -16
  61. package/koni/api/nft/acala_nft/index.js +7 -7
  62. package/koni/api/nft/bit.country/index.js +7 -6
  63. package/koni/api/nft/evm_nft/index.js +7 -3
  64. package/koni/api/nft/index.d.ts +1 -2
  65. package/koni/api/nft/index.js +3 -6
  66. package/koni/api/nft/karura_nft/index.js +7 -6
  67. package/koni/api/nft/nft.d.ts +1 -0
  68. package/koni/api/nft/rmrk_nft/index.js +11 -1
  69. package/koni/api/nft/statemine_nft/index.js +7 -6
  70. package/koni/api/nft/unique_nft/index.js +5 -1
  71. package/koni/api/nft/wasm_nft/index.d.ts +0 -2
  72. package/koni/api/nft/wasm_nft/index.js +168 -109
  73. package/koni/api/nft/wasm_nft/utils.d.ts +7 -5
  74. package/koni/api/nft/wasm_nft/utils.js +7 -5
  75. package/koni/api/staking/bonding/amplitude.d.ts +0 -1
  76. package/koni/api/staking/bonding/amplitude.js +15 -10
  77. package/koni/api/staking/bonding/astar.js +8 -6
  78. package/koni/api/staking/bonding/index.d.ts +4 -1
  79. package/koni/api/staking/bonding/index.js +23 -13
  80. package/koni/api/staking/bonding/paraChain.d.ts +3 -0
  81. package/koni/api/staking/bonding/paraChain.js +86 -5
  82. package/koni/api/staking/bonding/relayChain.d.ts +5 -1
  83. package/koni/api/staking/bonding/relayChain.js +121 -18
  84. package/koni/api/staking/bonding/utils.d.ts +3 -2
  85. package/koni/api/staking/bonding/utils.js +27 -9
  86. package/koni/api/tokens/wasm/index.js +5 -4
  87. package/koni/api/tokens/wasm/utils.d.ts +6 -0
  88. package/koni/api/tokens/wasm/utils.js +54 -0
  89. package/koni/api/xcm/polkadotXcm.js +2 -2
  90. package/koni/api/xcm/utils.d.ts +5 -6
  91. package/koni/api/xcm/utils.js +15 -10
  92. package/koni/api/xcm/xTokens.js +2 -2
  93. package/koni/api/xcm/xcmPallet.js +10 -9
  94. package/koni/background/cron.d.ts +6 -1
  95. package/koni/background/cron.js +172 -62
  96. package/koni/background/handlers/Extension.d.ts +8 -3
  97. package/koni/background/handlers/Extension.js +297 -126
  98. package/koni/background/handlers/State.d.ts +5 -6
  99. package/koni/background/handlers/State.js +43 -33
  100. package/koni/background/handlers/Tabs.js +50 -17
  101. package/koni/background/subscription.js +31 -30
  102. package/package.json +18 -13
  103. package/packageInfo.js +1 -1
  104. package/services/chain-service/handler/SubstrateChainHandler.js +14 -9
  105. package/services/chain-service/helper/psp22_abi.json +1041 -881
  106. package/services/chain-service/helper/psp34_abi.json +2963 -1807
  107. package/services/chain-service/index.d.ts +3 -2
  108. package/services/chain-service/index.js +53 -40
  109. package/services/chain-service/types.d.ts +1 -0
  110. package/services/event-service/index.js +5 -1
  111. package/services/event-service/types.d.ts +5 -9
  112. package/services/event-service/types.js +4 -1
  113. package/services/history-service/index.d.ts +4 -2
  114. package/services/history-service/index.js +19 -13
  115. package/services/history-service/subsquid-multi-chain-history.js +16 -12
  116. package/services/keyring-service/index.d.ts +4 -2
  117. package/services/keyring-service/index.js +11 -13
  118. package/services/price-service/coingecko.js +0 -1
  119. package/services/price-service/index.js +2 -3
  120. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -1
  121. package/services/request-service/handler/AuthRequestHandler.js +13 -7
  122. package/services/request-service/handler/EvmRequestHandler.js +8 -12
  123. package/services/request-service/index.d.ts +3 -1
  124. package/services/request-service/index.js +14 -5
  125. package/services/storage-service/DatabaseService.d.ts +1 -0
  126. package/services/storage-service/DatabaseService.js +56 -34
  127. package/services/storage-service/db-stores/Nft.d.ts +2 -2
  128. package/services/storage-service/db-stores/Nft.js +7 -14
  129. package/services/transaction-service/event-parser/index.js +21 -49
  130. package/services/transaction-service/index.js +26 -15
  131. package/utils/address.d.ts +3 -0
  132. package/utils/address.js +8 -1
  133. package/utils/index.d.ts +2 -2
  134. package/utils/index.js +7 -13
@@ -24,11 +24,12 @@ 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 _utils2 = require("@subwallet/extension-base/utils");
28
+ var _address2 = require("@subwallet/extension-base/utils/address");
27
29
  var _eth = require("@subwallet/extension-base/utils/eth");
28
30
  var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTransaction");
29
31
  var _keyring = require("@subwallet/keyring");
30
32
  var _uiKeyring = require("@subwallet/ui-keyring");
31
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
32
33
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
33
34
  var _ethereumjsTx = require("ethereumjs-tx");
34
35
  var _types = require("@polkadot/types");
@@ -181,7 +182,8 @@ class KoniExtension {
181
182
  // FIXME This looks very much like what we have in Tabs
182
183
  accountsSubscribe(id, port) {
183
184
  const cb = (0, _subscriptions.createSubscription)(id, port);
184
- const subscription = _accounts.accounts.subject.subscribe(accounts => cb(transformAccounts(accounts)));
185
+ const accountSubject = this.#koniState.keyringService.accountSubject;
186
+ const subscription = accountSubject.subscribe(accounts => cb(transformAccounts(accounts)));
185
187
  port.onDisconnect.addListener(() => {
186
188
  this.cancelSubscription(id);
187
189
  subscription.unsubscribe();
@@ -430,35 +432,37 @@ class KoniExtension {
430
432
  }
431
433
  async accountsGetAllWithCurrentAddress(id, port) {
432
434
  const cb = (0, _subscriptions.createSubscription)(id, port);
433
- return await new Promise(resolve => {
434
- const subscription = _accounts.accounts.subject.subscribe(storedAccounts => {
435
- const transformedAccounts = transformAccounts(storedAccounts);
436
- const accounts = transformedAccounts && transformedAccounts.length ? [{
437
- ...ACCOUNT_ALL_JSON
438
- }, ...transformedAccounts] : [];
439
- const accountsWithCurrentAddress = {
440
- accounts
441
- };
442
- setTimeout(() => {
443
- const accountInfo = this.#koniState.keyringService.currentAccount;
444
- if (accountInfo) {
445
- accountsWithCurrentAddress.currentAddress = accountInfo.address;
446
- if (accountInfo.address === _constants.ALL_ACCOUNT_KEY) {
447
- accountsWithCurrentAddress.currentGenesisHash = accountInfo.currentGenesisHash;
448
- } else {
449
- const acc = accounts.find(a => a.address === accountInfo.address);
450
- accountsWithCurrentAddress.currentGenesisHash = (acc === null || acc === void 0 ? void 0 : acc.genesisHash) || _constants.ALL_GENESIS_HASH;
451
- }
452
- }
453
- resolve(accountsWithCurrentAddress);
454
- cb(accountsWithCurrentAddress);
455
- }, 300);
456
- });
457
- this.createUnsubscriptionHandle(id, subscription.unsubscribe);
458
- port.onDisconnect.addListener(() => {
459
- this.cancelSubscription(id);
460
- });
435
+ const keyringService = this.#koniState.keyringService;
436
+ await this.#koniState.eventService.waitAccountReady;
437
+ const currentAccount = keyringService.currentAccount;
438
+ const transformedAccounts = transformAccounts(keyringService.accounts);
439
+ const responseData = {
440
+ accounts: transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [{
441
+ ...ACCOUNT_ALL_JSON
442
+ }, ...transformedAccounts] : [],
443
+ currentAddress: currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.address,
444
+ currentGenesisHash: currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.currentGenesisHash
445
+ };
446
+ const subscriptionAccounts = keyringService.accountSubject.subscribe(storedAccounts => {
447
+ const transformedAccounts = transformAccounts(storedAccounts);
448
+ responseData.accounts = transformedAccounts !== null && transformedAccounts !== void 0 && transformedAccounts.length ? [{
449
+ ...ACCOUNT_ALL_JSON
450
+ }, ...transformedAccounts] : [];
451
+ cb(responseData);
452
+ });
453
+ const subscriptionCurrentAccount = keyringService.currentAccountSubject.subscribe(currentAccountData => {
454
+ responseData.currentAddress = currentAccountData.address;
455
+ responseData.currentGenesisHash = currentAccountData.currentGenesisHash;
456
+ cb(responseData);
457
+ });
458
+ this.createUnsubscriptionHandle(id, () => {
459
+ subscriptionAccounts.unsubscribe();
460
+ subscriptionCurrentAccount.unsubscribe();
461
461
  });
462
+ port.onDisconnect.addListener(() => {
463
+ this.cancelSubscription(id);
464
+ });
465
+ return responseData;
462
466
  }
463
467
  accountsGetAll(id, port) {
464
468
  const cb = (0, _subscriptions.createSubscription)(id, port);
@@ -474,22 +478,69 @@ class KoniExtension {
474
478
  });
475
479
  return id;
476
480
  }
477
- saveRecentAccountId(_ref21) {
481
+ subscribeAddresses(id, port) {
482
+ const _cb = (0, _subscriptions.createSubscription)(id, port);
483
+ const subscription = this.#koniState.keyringService.addressesSubject.subscribe(subjectInfo => {
484
+ const addresses = (0, _address2.convertSubjectInfoToAddresses)(subjectInfo);
485
+ _cb({
486
+ addresses: addresses
487
+ });
488
+ });
489
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
490
+ port.onDisconnect.addListener(() => {
491
+ this.cancelSubscription(id);
492
+ });
493
+ const subjectInfo = this.#koniState.keyringService.addresses;
494
+ return {
495
+ addresses: (0, _address2.convertSubjectInfoToAddresses)(subjectInfo)
496
+ };
497
+ }
498
+ saveRecentAccount(_ref21) {
478
499
  let {
479
500
  accountId
480
501
  } = _ref21;
481
- return _uiKeyring.keyring.saveRecent(accountId);
502
+ if ((0, _utilCrypto.isAddress)(accountId)) {
503
+ const address = (0, _utils2.reformatAddress)(accountId);
504
+ const account = _uiKeyring.keyring.getAccount(address);
505
+ const contact = _uiKeyring.keyring.getAddress(address);
506
+ return account || contact || {
507
+ ..._uiKeyring.keyring.saveRecent(accountId).json,
508
+ publicKey: (0, _utilCrypto.decodeAddress)(address)
509
+ };
510
+ } else {
511
+ throw Error('Invalid address');
512
+ }
482
513
  }
483
- triggerAccountsSubscription() {
484
- const accountsSubject = _accounts.accounts.subject;
485
- accountsSubject.next(accountsSubject.getValue());
486
- return true;
514
+ editContactAccount(_ref22) {
515
+ let {
516
+ address,
517
+ meta
518
+ } = _ref22;
519
+ if ((0, _utilCrypto.isAddress)(address)) {
520
+ const _address = (0, _utils2.reformatAddress)(address);
521
+ _uiKeyring.keyring.saveAddress(_address, meta);
522
+ return true;
523
+ } else {
524
+ throw Error('Invalid address');
525
+ }
526
+ }
527
+ deleteContactAccount(_ref23) {
528
+ let {
529
+ address
530
+ } = _ref23;
531
+ if ((0, _utilCrypto.isAddress)(address)) {
532
+ const _address = (0, _utils2.reformatAddress)(address);
533
+ _uiKeyring.keyring.forgetAddress(_address);
534
+ return true;
535
+ } else {
536
+ throw Error('Invalid address');
537
+ }
487
538
  }
488
539
  _getAuthListV2() {
540
+ const keyringService = this.#koniState.keyringService;
489
541
  return new Promise((resolve, reject) => {
490
542
  this.#koniState.getAuthorize(rs => {
491
- const accounts = _accounts.accounts.subject.getValue();
492
- const addressList = Object.keys(accounts);
543
+ const addressList = Object.keys(keyringService.accounts);
493
544
  const urlList = Object.keys(rs);
494
545
  if (Object.keys(rs[urlList[0]].isAllowedMap).toString() !== addressList.toString()) {
495
546
  urlList.forEach(url => {
@@ -525,11 +576,11 @@ class KoniExtension {
525
576
  list: authList
526
577
  };
527
578
  }
528
- authorizeApproveV2(_ref22) {
579
+ authorizeApproveV2(_ref24) {
529
580
  let {
530
581
  accounts,
531
582
  id
532
- } = _ref22;
583
+ } = _ref24;
533
584
  const queued = this.#koniState.getAuthRequestV2(id);
534
585
  (0, _util.assert)(queued, 'Unable to find request');
535
586
  const {
@@ -541,10 +592,10 @@ class KoniExtension {
541
592
  });
542
593
  return true;
543
594
  }
544
- authorizeRejectV2(_ref23) {
595
+ authorizeRejectV2(_ref25) {
545
596
  let {
546
597
  id
547
- } = _ref23;
598
+ } = _ref25;
548
599
  const queued = this.#koniState.getAuthRequestV2(id);
549
600
  (0, _util.assert)(queued, 'Unable to find request');
550
601
  const {
@@ -553,10 +604,10 @@ class KoniExtension {
553
604
  reject(new Error('Rejected'));
554
605
  return true;
555
606
  }
556
- authorizeCancelV2(_ref24) {
607
+ authorizeCancelV2(_ref26) {
557
608
  let {
558
609
  id
559
- } = _ref24;
610
+ } = _ref26;
560
611
  const queued = this.#koniState.getAuthRequestV2(id);
561
612
  (0, _util.assert)(queued, 'Unable to find request');
562
613
  const {
@@ -606,7 +657,7 @@ class KoniExtension {
606
657
  return true;
607
658
  }
608
659
  getNonReadonlyAccounts() {
609
- const storedAccounts = _accounts.accounts.subject.getValue();
660
+ const storedAccounts = this.#koniState.keyringService.accounts;
610
661
  const transformedAccounts = transformAccounts(storedAccounts);
611
662
  return transformedAccounts.filter(a => !a.isReadOnly).map(a => a.address);
612
663
  }
@@ -788,10 +839,10 @@ class KoniExtension {
788
839
  });
789
840
  return true;
790
841
  }
791
- setCamera(_ref25) {
842
+ setCamera(_ref27) {
792
843
  let {
793
844
  camera
794
- } = _ref25;
845
+ } = _ref27;
795
846
  this.#koniState.setCamera(camera);
796
847
  return true;
797
848
  }
@@ -840,8 +891,12 @@ class KoniExtension {
840
891
  } else {
841
892
  accountInfo.address = address;
842
893
  if (address !== _constants.ALL_ACCOUNT_KEY) {
843
- const currentKeyPair = _uiKeyring.keyring.getAccount(address);
844
- accountInfo.currentGenesisHash = (currentKeyPair === null || currentKeyPair === void 0 ? void 0 : currentKeyPair.meta.genesisHash) || _constants.ALL_GENESIS_HASH;
894
+ try {
895
+ const currentKeyPair = _uiKeyring.keyring.getPair(address);
896
+ accountInfo.currentGenesisHash = (currentKeyPair === null || currentKeyPair === void 0 ? void 0 : currentKeyPair.meta.genesisHash) || _constants.ALL_GENESIS_HASH;
897
+ } catch {
898
+ accountInfo.currentGenesisHash = _constants.ALL_GENESIS_HASH;
899
+ }
845
900
  } else {
846
901
  accountInfo.currentGenesisHash = accountInfo.allGenesisHash || _constants.ALL_GENESIS_HASH;
847
902
  }
@@ -851,18 +906,15 @@ class KoniExtension {
851
906
  });
852
907
  }
853
908
  updateCurrentAccountAddress(address) {
854
- this._saveCurrentAccountAddress(address, () => {
855
- this.triggerAccountsSubscription();
856
- });
909
+ this._saveCurrentAccountAddress(address);
857
910
  return true;
858
911
  }
859
- saveCurrentAccountAddress(data, id, port) {
860
- const cb = (0, _subscriptions.createSubscription)(id, port);
861
- this._saveCurrentAccountAddress(data.address, cb);
862
- port.onDisconnect.addListener(() => {
863
- this.cancelSubscription(id);
912
+ async saveCurrentAccountAddress(data) {
913
+ return new Promise(resolve => {
914
+ this._saveCurrentAccountAddress(data.address, currentInfo => {
915
+ resolve(currentInfo);
916
+ });
864
917
  });
865
- return true;
866
918
  }
867
919
  async getAssetSetting() {
868
920
  return this.#koniState.chainService.getAssetSettings();
@@ -879,6 +931,7 @@ class KoniExtension {
879
931
  async updateAssetSetting(params) {
880
932
  try {
881
933
  await this.#koniState.chainService.updateAssetSetting(params.tokenSlug, params.assetSetting);
934
+ this.#koniState.eventService.emit('asset.updateState', params.tokenSlug);
882
935
  return true;
883
936
  } catch (e) {
884
937
  console.error('Error updating asset setting', e);
@@ -986,7 +1039,7 @@ class KoniExtension {
986
1039
  }
987
1040
  });
988
1041
  }
989
- async accountsCreateSuriV2(_ref26) {
1042
+ async accountsCreateSuriV2(_ref28) {
990
1043
  let {
991
1044
  genesisHash,
992
1045
  isAllowed,
@@ -994,7 +1047,7 @@ class KoniExtension {
994
1047
  password,
995
1048
  suri: _suri,
996
1049
  types
997
- } = _ref26;
1050
+ } = _ref28;
998
1051
  const addressDict = {};
999
1052
  let changedAccount = false;
1000
1053
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
@@ -1042,10 +1095,10 @@ class KoniExtension {
1042
1095
  });
1043
1096
  return addressDict;
1044
1097
  }
1045
- async accountsForgetOverride(_ref27) {
1098
+ async accountsForgetOverride(_ref29) {
1046
1099
  let {
1047
1100
  address
1048
- } = _ref27;
1101
+ } = _ref29;
1049
1102
  _uiKeyring.keyring.forgetAccount(address);
1050
1103
  await new Promise(resolve => {
1051
1104
  this.#koniState.removeAccountRef(address, () => {
@@ -1077,12 +1130,12 @@ class KoniExtension {
1077
1130
  });
1078
1131
  return true;
1079
1132
  }
1080
- seedCreateV2(_ref28) {
1133
+ seedCreateV2(_ref30) {
1081
1134
  let {
1082
1135
  length = _Extension.SEED_DEFAULT_LENGTH,
1083
1136
  seed: _seed,
1084
1137
  types
1085
- } = _ref28;
1138
+ } = _ref30;
1086
1139
  const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
1087
1140
  const rs = {
1088
1141
  seed: seed,
@@ -1093,11 +1146,11 @@ class KoniExtension {
1093
1146
  });
1094
1147
  return rs;
1095
1148
  }
1096
- seedValidateV2(_ref29) {
1149
+ seedValidateV2(_ref31) {
1097
1150
  let {
1098
1151
  suri,
1099
1152
  types
1100
- } = _ref29;
1153
+ } = _ref31;
1101
1154
  const {
1102
1155
  phrase
1103
1156
  } = (0, _utilCrypto.keyExtractSuri)(suri);
@@ -1117,11 +1170,11 @@ class KoniExtension {
1117
1170
  });
1118
1171
  return rs;
1119
1172
  }
1120
- _checkValidatePrivateKey(_ref30) {
1173
+ _checkValidatePrivateKey(_ref32) {
1121
1174
  let {
1122
1175
  suri,
1123
1176
  types
1124
- } = _ref30;
1177
+ } = _ref32;
1125
1178
  let autoAddPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1126
1179
  const {
1127
1180
  phrase
@@ -1144,11 +1197,11 @@ class KoniExtension {
1144
1197
  }
1145
1198
  return rs;
1146
1199
  }
1147
- metamaskPrivateKeyValidateV2(_ref31) {
1200
+ metamaskPrivateKeyValidateV2(_ref33) {
1148
1201
  let {
1149
1202
  suri,
1150
1203
  types
1151
- } = _ref31;
1204
+ } = _ref33;
1152
1205
  const isValidSuri = suri.startsWith('0x');
1153
1206
  if (isValidSuri) {
1154
1207
  return this._checkValidatePrivateKey({
@@ -1173,14 +1226,14 @@ class KoniExtension {
1173
1226
  throw new Error(`"${suri}" is not a valid derivation path`);
1174
1227
  }
1175
1228
  }
1176
- derivationCreateV2(_ref32) {
1229
+ derivationCreateV2(_ref34) {
1177
1230
  let {
1178
1231
  genesisHash,
1179
1232
  isAllowed,
1180
1233
  name,
1181
1234
  parentAddress,
1182
1235
  suri
1183
- } = _ref32;
1236
+ } = _ref34;
1184
1237
  const childPair = this.deriveV2(parentAddress, suri, {
1185
1238
  genesisHash,
1186
1239
  name,
@@ -1194,14 +1247,14 @@ class KoniExtension {
1194
1247
  });
1195
1248
  return true;
1196
1249
  }
1197
- jsonRestoreV2(_ref33) {
1250
+ jsonRestoreV2(_ref35) {
1198
1251
  let {
1199
1252
  address,
1200
1253
  file,
1201
1254
  isAllowed,
1202
1255
  password,
1203
1256
  withMasterPassword
1204
- } = _ref33;
1257
+ } = _ref35;
1205
1258
  const isPasswordValidated = this.validatePassword(file, password);
1206
1259
  if (isPasswordValidated) {
1207
1260
  try {
@@ -1216,13 +1269,13 @@ class KoniExtension {
1216
1269
  throw new Error('Unable to decode using the supplied passphrase');
1217
1270
  }
1218
1271
  }
1219
- batchRestoreV2(_ref34) {
1272
+ batchRestoreV2(_ref36) {
1220
1273
  let {
1221
1274
  accountsInfo,
1222
1275
  file,
1223
1276
  isAllowed,
1224
1277
  password
1225
- } = _ref34;
1278
+ } = _ref36;
1226
1279
  const addressList = accountsInfo.map(acc => acc.address);
1227
1280
  const isPasswordValidated = this.validatedAccountsPassword(file, password);
1228
1281
  if (isPasswordValidated) {
@@ -1316,6 +1369,14 @@ class KoniExtension {
1316
1369
  });
1317
1370
  return historySubject.getValue();
1318
1371
  }
1372
+ addContact(to) {
1373
+ const toAddress = (0, _utils2.reformatAddress)(to);
1374
+ const account = _uiKeyring.keyring.getAccount(toAddress);
1375
+ const contact = _uiKeyring.keyring.getAddress(toAddress);
1376
+ if (!account && (!contact || contact.meta.isRecent)) {
1377
+ _uiKeyring.keyring.saveAddress(toAddress, {});
1378
+ }
1379
+ }
1319
1380
  validateTransfer(tokenSlug, from, to, value, transferAll) {
1320
1381
  const errors = [];
1321
1382
  const keypair = _uiKeyring.keyring.getPair(from);
@@ -1366,7 +1427,6 @@ class KoniExtension {
1366
1427
 
1367
1428
  // Get native token amount
1368
1429
  const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1369
- let edAsWarning = false;
1370
1430
  if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to)) {
1371
1431
  chainType = _KoniTypes.ChainType.EVM;
1372
1432
  const txVal = transferAll ? freeBalance.value : value || '0';
@@ -1376,7 +1436,6 @@ class KoniExtension {
1376
1436
  [transaction, transferAmount.value] = await (0, _transfer3.getERC20TransactionObject)((0, _utils._getContractAddressOfToken)(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApiMap);
1377
1437
  } else {
1378
1438
  [transaction, transferAmount.value] = await (0, _transfer3.getEVMTransactionObject)(chainInfo, to, txVal, !!transferAll, evmApiMap);
1379
- edAsWarning = true;
1380
1439
  }
1381
1440
  } else {
1382
1441
  const substrateApi = this.#koniState.getSubstrateApi(networkKey);
@@ -1389,9 +1448,9 @@ class KoniExtension {
1389
1448
  to: to,
1390
1449
  substrateApi
1391
1450
  });
1392
- edAsWarning = true;
1393
1451
  }
1394
1452
  const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1453
+ this.addContact(to);
1395
1454
  return this.#koniState.transactionService.handleTransaction({
1396
1455
  errors,
1397
1456
  warnings,
@@ -1404,7 +1463,7 @@ class KoniExtension {
1404
1463
  extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1405
1464
  ignoreWarnings: transferAll,
1406
1465
  isTransferAll: transferAll,
1407
- edAsWarning: edAsWarning
1466
+ edAsWarning: isTransferNativeToken
1408
1467
  });
1409
1468
  }
1410
1469
  validateCrossChainTransfer(destinationNetworkKey, sendingTokenSlug, sender, sendingValue) {
@@ -1444,6 +1503,7 @@ class KoniExtension {
1444
1503
  substrateApi
1445
1504
  });
1446
1505
  }
1506
+ this.addContact(to);
1447
1507
  return await this.#koniState.transactionService.handleTransaction({
1448
1508
  url: _constants2.EXTENSION_REQUEST_URL,
1449
1509
  address: from,
@@ -1453,6 +1513,7 @@ class KoniExtension {
1453
1513
  extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
1454
1514
  chainType: _KoniTypes.ChainType.SUBSTRATE,
1455
1515
  transferNativeAmount: (0, _utils._isNativeToken)(originTokenInfo) ? value : '0',
1516
+ isTransferAll: inputData.transferAll,
1456
1517
  errors
1457
1518
  });
1458
1519
  }
@@ -1466,6 +1527,7 @@ class KoniExtension {
1466
1527
  const contractAddress = params.contractAddress;
1467
1528
  const tokenId = params.tokenId;
1468
1529
  const transaction = await (0, _transfer3.getERC721Transaction)(this.#koniState.getEvmApi(networkKey), contractAddress, senderAddress, recipientAddress, tokenId);
1530
+ this.addContact(recipientAddress);
1469
1531
  return await this.#koniState.transactionService.handleTransaction({
1470
1532
  address: senderAddress,
1471
1533
  chain: networkKey,
@@ -1493,11 +1555,11 @@ class KoniExtension {
1493
1555
  async enableChain(networkKey) {
1494
1556
  return await this.#koniState.enableChain(networkKey);
1495
1557
  }
1496
- async validateNetwork(_ref35) {
1558
+ async validateNetwork(_ref37) {
1497
1559
  let {
1498
1560
  existedChainSlug,
1499
1561
  provider
1500
- } = _ref35;
1562
+ } = _ref37;
1501
1563
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1502
1564
  }
1503
1565
  resetDefaultNetwork() {
@@ -1535,20 +1597,86 @@ class KoniExtension {
1535
1597
  async validateCustomAsset(data) {
1536
1598
  return await this.#koniState.validateCustomAsset(data);
1537
1599
  }
1538
- async getAddressFreeBalance(_ref36) {
1600
+ async getAddressFreeBalance(_ref38) {
1539
1601
  let {
1540
1602
  address,
1541
1603
  networkKey,
1542
1604
  token
1543
- } = _ref36;
1605
+ } = _ref38;
1544
1606
  return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1545
1607
  }
1546
- async subscribeAddressFreeBalance(_ref37, id, port) {
1608
+ async transferGetMaxTransferable(_ref39) {
1547
1609
  let {
1548
1610
  address,
1611
+ destChain,
1612
+ isXcmTransfer,
1549
1613
  networkKey,
1550
1614
  token
1551
- } = _ref37;
1615
+ } = _ref39;
1616
+ const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1617
+ const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
1618
+ if (!(0, _utils._isNativeToken)(tokenInfo)) {
1619
+ return freeBalance;
1620
+ } else {
1621
+ const substrateApi = this.#koniState.chainService.getSubstrateApi(networkKey);
1622
+ let estimatedFee;
1623
+ let maxTransferable = new _util.BN(freeBalance.value);
1624
+ if (isXcmTransfer) {
1625
+ const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
1626
+ const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, tokenInfo.slug);
1627
+ if (!destinationTokenInfo) {
1628
+ estimatedFee = '0';
1629
+ } else {
1630
+ maxTransferable = maxTransferable.sub(new _util.BN(tokenInfo.minAmount || '0'));
1631
+ const mockTx = await (0, _xcm.createXcmExtrinsic)({
1632
+ chainInfoMap,
1633
+ destinationTokenInfo,
1634
+ originTokenInfo: tokenInfo,
1635
+ recipient: address,
1636
+ sendingValue: '0',
1637
+ substrateApi
1638
+ });
1639
+ try {
1640
+ var _paymentInfo$partialF;
1641
+ const paymentInfo = await mockTx.paymentInfo(address);
1642
+ estimatedFee = (paymentInfo === null || paymentInfo === void 0 ? void 0 : (_paymentInfo$partialF = paymentInfo.partialFee) === null || _paymentInfo$partialF === void 0 ? void 0 : _paymentInfo$partialF.toString()) || '0';
1643
+ } catch (e) {
1644
+ estimatedFee = '0';
1645
+ console.warn('Error estimating fee', e);
1646
+ }
1647
+ }
1648
+ } 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);
1665
+ }
1666
+ }
1667
+ maxTransferable = maxTransferable.sub(new _util.BN(estimatedFee));
1668
+ return {
1669
+ ...freeBalance,
1670
+ value: maxTransferable.gt(_util.BN_ZERO) ? maxTransferable.toString() || '0' : '0'
1671
+ };
1672
+ }
1673
+ }
1674
+ async subscribeAddressFreeBalance(_ref40, id, port) {
1675
+ let {
1676
+ address,
1677
+ networkKey,
1678
+ token
1679
+ } = _ref40;
1552
1680
  const cb = (0, _subscriptions.createSubscription)(id, port);
1553
1681
  const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1554
1682
  this.createUnsubscriptionHandle(id, unsub);
@@ -1557,26 +1685,26 @@ class KoniExtension {
1557
1685
  });
1558
1686
  return currentFreeBalance;
1559
1687
  }
1560
- async transferCheckReferenceCount(_ref38) {
1688
+ async transferCheckReferenceCount(_ref41) {
1561
1689
  let {
1562
1690
  address,
1563
1691
  networkKey
1564
- } = _ref38;
1692
+ } = _ref41;
1565
1693
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1566
1694
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1567
1695
  }
1568
- async transferCheckSupporting(_ref39) {
1696
+ async transferCheckSupporting(_ref42) {
1569
1697
  let {
1570
1698
  networkKey,
1571
1699
  tokenSlug
1572
- } = _ref39;
1700
+ } = _ref42;
1573
1701
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1574
1702
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1575
1703
  }
1576
- transferGetExistentialDeposit(_ref40) {
1704
+ transferGetExistentialDeposit(_ref43) {
1577
1705
  let {
1578
1706
  tokenSlug
1579
- } = _ref40;
1707
+ } = _ref43;
1580
1708
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1581
1709
  return (0, _utils._getTokenMinAmount)(tokenInfo);
1582
1710
  }
@@ -1593,6 +1721,7 @@ class KoniExtension {
1593
1721
  const networkKey = params === null || params === void 0 ? void 0 : params.networkKey;
1594
1722
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
1595
1723
  const extrinsic = !isPSP34 ? (0, _transfer2.getNftTransferExtrinsic)(networkKey, apiProps, senderAddress, recipientAddress, params || {}) : await (0, _wasm.getPSP34TransferExtrinsic)(networkKey, apiProps, senderAddress, recipientAddress, params || {});
1724
+ this.addContact(recipientAddress);
1596
1725
  const rs = await this.#koniState.transactionService.handleTransaction({
1597
1726
  address: senderAddress,
1598
1727
  chain: networkKey,
@@ -1617,41 +1746,24 @@ class KoniExtension {
1617
1746
  }
1618
1747
  return true;
1619
1748
  }
1620
- getAccountMeta(_ref41) {
1749
+ getAccountMeta(_ref44) {
1621
1750
  let {
1622
1751
  address
1623
- } = _ref41;
1752
+ } = _ref44;
1624
1753
  const pair = _uiKeyring.keyring.getPair(address);
1625
1754
  (0, _util.assert)(pair, 'Unable to find pair');
1626
1755
  return {
1627
1756
  meta: pair.meta
1628
1757
  };
1629
1758
  }
1630
-
1631
- // private async isInWalletAccount (address?: string) {
1632
- // return new Promise((resolve) => {
1633
- // if (address) {
1634
- // accountsObservable.subject.subscribe((storedAccounts: SubjectInfo): void => {
1635
- // if (storedAccounts[address]) {
1636
- // resolve(true);
1637
- // }
1638
- //
1639
- // resolve(false);
1640
- // });
1641
- // } else {
1642
- // resolve(false);
1643
- // }
1644
- // });
1645
- // }
1646
-
1647
- accountsTie2(_ref42) {
1759
+ accountsTie2(_ref45) {
1648
1760
  let {
1649
1761
  address,
1650
1762
  genesisHash
1651
- } = _ref42;
1763
+ } = _ref45;
1652
1764
  return this.#koniState.setAccountTie(address, genesisHash);
1653
1765
  }
1654
- async accountsCreateExternalV2(_ref43) {
1766
+ async accountsCreateExternalV2(_ref46) {
1655
1767
  let {
1656
1768
  address,
1657
1769
  genesisHash,
@@ -1659,7 +1771,7 @@ class KoniExtension {
1659
1771
  isEthereum,
1660
1772
  isReadOnly,
1661
1773
  name
1662
- } = _ref43;
1774
+ } = _ref46;
1663
1775
  try {
1664
1776
  let result;
1665
1777
  try {
@@ -1718,7 +1830,7 @@ class KoniExtension {
1718
1830
  }];
1719
1831
  }
1720
1832
  }
1721
- async accountsCreateHardwareV2(_ref44) {
1833
+ async accountsCreateHardwareV2(_ref47) {
1722
1834
  let {
1723
1835
  accountIndex,
1724
1836
  address,
@@ -1727,7 +1839,7 @@ class KoniExtension {
1727
1839
  hardwareType,
1728
1840
  isAllowed,
1729
1841
  name
1730
- } = _ref44;
1842
+ } = _ref47;
1731
1843
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
1732
1844
  accountIndex,
1733
1845
  addressOffset,
@@ -1750,10 +1862,10 @@ class KoniExtension {
1750
1862
  });
1751
1863
  return true;
1752
1864
  }
1753
- async accountsCreateHardwareMultiple(_ref45) {
1865
+ async accountsCreateHardwareMultiple(_ref48) {
1754
1866
  let {
1755
1867
  accounts
1756
- } = _ref45;
1868
+ } = _ref48;
1757
1869
  const addresses = [];
1758
1870
  if (!accounts.length) {
1759
1871
  throw new Error('No accounts to import');
@@ -1804,14 +1916,14 @@ class KoniExtension {
1804
1916
  });
1805
1917
  return true;
1806
1918
  }
1807
- async accountsCreateWithSecret(_ref46) {
1919
+ async accountsCreateWithSecret(_ref49) {
1808
1920
  let {
1809
1921
  isAllow,
1810
1922
  isEthereum,
1811
1923
  name,
1812
1924
  publicKey,
1813
1925
  secretKey
1814
- } = _ref46;
1926
+ } = _ref49;
1815
1927
  try {
1816
1928
  let keyringPair = null;
1817
1929
  if (isEthereum) {
@@ -1954,30 +2066,30 @@ class KoniExtension {
1954
2066
 
1955
2067
  // Parse transaction
1956
2068
 
1957
- parseSubstrateTransaction(_ref47) {
2069
+ parseSubstrateTransaction(_ref50) {
1958
2070
  let {
1959
2071
  data,
1960
2072
  networkKey
1961
- } = _ref47;
2073
+ } = _ref50;
1962
2074
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
1963
2075
  const apiPromise = apiProps.api;
1964
2076
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
1965
2077
  }
1966
- async parseEVMRLP(_ref48) {
2078
+ async parseEVMRLP(_ref51) {
1967
2079
  let {
1968
2080
  data
1969
- } = _ref48;
2081
+ } = _ref51;
1970
2082
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
1971
2083
  }
1972
2084
 
1973
2085
  // Sign
1974
2086
 
1975
- qrSignSubstrate(_ref49) {
2087
+ qrSignSubstrate(_ref52) {
1976
2088
  let {
1977
2089
  address,
1978
2090
  data,
1979
2091
  networkKey
1980
- } = _ref49;
2092
+ } = _ref52;
1981
2093
  const pair = _uiKeyring.keyring.getPair(address);
1982
2094
  (0, _util.assert)(pair, 'Unable to find pair');
1983
2095
  if (pair.isLocked) {
@@ -1994,13 +2106,13 @@ class KoniExtension {
1994
2106
  signature: signed
1995
2107
  };
1996
2108
  }
1997
- async qrSignEVM(_ref50) {
2109
+ async qrSignEVM(_ref53) {
1998
2110
  let {
1999
2111
  address,
2000
2112
  chainId,
2001
2113
  message,
2002
2114
  type
2003
- } = _ref50;
2115
+ } = _ref53;
2004
2116
  let signed;
2005
2117
  const network = this.getNetworkJsonByChainId(chainId);
2006
2118
  if (!network) {
@@ -2081,11 +2193,11 @@ class KoniExtension {
2081
2193
  });
2082
2194
  return this.#koniState.getNominatorMetadata();
2083
2195
  }
2084
- async getBondingOptions(_ref51) {
2196
+ async getBondingOptions(_ref54) {
2085
2197
  let {
2086
2198
  chain,
2087
2199
  type
2088
- } = _ref51;
2200
+ } = _ref54;
2089
2201
  const apiProps = this.#koniState.getSubstrateApi(chain);
2090
2202
  const chainInfo = this.#koniState.getChainInfo(chain);
2091
2203
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2099,6 +2211,7 @@ class KoniExtension {
2099
2211
  }
2100
2212
  async getNominationPoolOptions(chain) {
2101
2213
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2214
+ console.log('chain', chain);
2102
2215
  return await (0, _bonding.getNominationPoolsInfo)(chain, substrateApi);
2103
2216
  }
2104
2217
  async submitBonding(inputData) {
@@ -2109,12 +2222,15 @@ class KoniExtension {
2109
2222
  nominatorMetadata,
2110
2223
  selectedValidators
2111
2224
  } = inputData;
2112
- if (!amount || !selectedValidators) {
2113
- // Todo: Check and return error here
2114
-
2115
- return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS)]);
2116
- }
2117
2225
  const chainInfo = this.#koniState.getChainInfo(chain);
2226
+ const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, _KoniTypes.StakingType.NOMINATED);
2227
+ if (!chainStakingMetadata) {
2228
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
2229
+ }
2230
+ const bondingValidation = (0, _bonding.validateBondingCondition)(chainInfo, amount, selectedValidators, address, chainStakingMetadata, nominatorMetadata);
2231
+ if (!amount || !selectedValidators || bondingValidation.length > 0) {
2232
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(bondingValidation);
2233
+ }
2118
2234
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2119
2235
  const extrinsic = await (0, _bonding.getBondingExtrinsic)(chainInfo, amount, selectedValidators, substrateApi, address, nominatorMetadata);
2120
2236
  console.log('Bonding extrinsic: ', chain, extrinsic.toHex());
@@ -2125,7 +2241,8 @@ class KoniExtension {
2125
2241
  data: inputData,
2126
2242
  extrinsicType: _KoniTypes.ExtrinsicType.STAKING_BOND,
2127
2243
  transaction: extrinsic,
2128
- url: _constants2.EXTENSION_REQUEST_URL
2244
+ url: _constants2.EXTENSION_REQUEST_URL,
2245
+ transferNativeAmount: amount
2129
2246
  });
2130
2247
  }
2131
2248
  async submitUnbonding(inputData) {
@@ -2135,12 +2252,17 @@ class KoniExtension {
2135
2252
  nominatorMetadata,
2136
2253
  validatorAddress
2137
2254
  } = inputData;
2138
- if (!amount || !nominatorMetadata) {
2139
- return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INVALID_PARAMS)]);
2255
+ const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, _KoniTypes.StakingType.NOMINATED);
2256
+ if (!chainStakingMetadata || !nominatorMetadata) {
2257
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
2258
+ }
2259
+ const unbondingValidation = (0, _bonding.validateUnbondingCondition)(nominatorMetadata, amount, chain, chainStakingMetadata, validatorAddress);
2260
+ if (!amount || unbondingValidation.length > 0) {
2261
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(unbondingValidation);
2140
2262
  }
2141
2263
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2142
2264
  const extrinsic = await (0, _bonding.getUnbondingExtrinsic)(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
2143
- console.log('unbonding extrinsic: ', extrinsic.toHex());
2265
+ console.log('Unbonding extrinsic: ', extrinsic.toHex());
2144
2266
  return await this.#koniState.transactionService.handleTransaction({
2145
2267
  address: nominatorMetadata.address,
2146
2268
  chain: chain,
@@ -2214,7 +2336,7 @@ class KoniExtension {
2214
2336
  chainType: _KoniTypes.ChainType.SUBSTRATE
2215
2337
  });
2216
2338
  }
2217
- async submitPoolingBonding(inputData) {
2339
+ async submitPoolBonding(inputData) {
2218
2340
  const {
2219
2341
  address,
2220
2342
  amount,
@@ -2222,8 +2344,15 @@ class KoniExtension {
2222
2344
  nominatorMetadata,
2223
2345
  selectedPool
2224
2346
  } = inputData;
2225
-
2226
- // TODO: can't stake when unstake all
2347
+ const chainInfo = this.#koniState.getChainInfo(chain);
2348
+ const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, _KoniTypes.StakingType.NOMINATED);
2349
+ if (!chainStakingMetadata) {
2350
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
2351
+ }
2352
+ const bondingValidation = (0, _relayChain.validatePoolBondingCondition)(chainInfo, amount, selectedPool, address, chainStakingMetadata, nominatorMetadata);
2353
+ if (!amount || bondingValidation.length > 0) {
2354
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(bondingValidation);
2355
+ }
2227
2356
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2228
2357
  const extrinsic = await (0, _relayChain.getPoolingBondingExtrinsic)(substrateApi, amount, selectedPool.id, nominatorMetadata);
2229
2358
  console.log('Join nomination pool extrinsic', extrinsic.toHex());
@@ -2242,6 +2371,14 @@ class KoniExtension {
2242
2371
  chain,
2243
2372
  nominatorMetadata
2244
2373
  } = inputData;
2374
+ const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, _KoniTypes.StakingType.NOMINATED);
2375
+ if (!chainStakingMetadata || !nominatorMetadata) {
2376
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.INTERNAL_ERROR)]);
2377
+ }
2378
+ const unbondingValidation = (0, _relayChain.validateRelayUnbondingCondition)(amount, chainStakingMetadata, nominatorMetadata);
2379
+ if (!amount || unbondingValidation.length > 0) {
2380
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(unbondingValidation);
2381
+ }
2245
2382
  const substrateApi = this.#koniState.getSubstrateApi(chain);
2246
2383
  const extrinsic = await (0, _relayChain.getPoolingUnbondingExtrinsic)(substrateApi, amount, nominatorMetadata);
2247
2384
  console.log('Nomination pool unbond extrinsic', extrinsic.toHex());
@@ -2256,12 +2393,12 @@ class KoniExtension {
2256
2393
  }
2257
2394
 
2258
2395
  // EVM Transaction
2259
- async parseContractInput(_ref52) {
2396
+ async parseContractInput(_ref55) {
2260
2397
  let {
2261
2398
  chainId,
2262
2399
  contract,
2263
2400
  data
2264
- } = _ref52;
2401
+ } = _ref55;
2265
2402
  const network = this.getNetworkJsonByChainId(chainId);
2266
2403
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2267
2404
  }
@@ -2324,12 +2461,12 @@ class KoniExtension {
2324
2461
  });
2325
2462
  return this.#koniState.keyringService.keyringState;
2326
2463
  }
2327
- keyringChangeMasterPassword(_ref53) {
2464
+ keyringChangeMasterPassword(_ref56) {
2328
2465
  let {
2329
2466
  createNew,
2330
2467
  newPassword,
2331
2468
  oldPassword
2332
- } = _ref53;
2469
+ } = _ref56;
2333
2470
  try {
2334
2471
  // Remove isMasterPassword meta if createNew
2335
2472
  if (createNew) {
@@ -2360,11 +2497,11 @@ class KoniExtension {
2360
2497
  errors: []
2361
2498
  };
2362
2499
  }
2363
- keyringMigrateMasterPassword(_ref54) {
2500
+ keyringMigrateMasterPassword(_ref57) {
2364
2501
  let {
2365
2502
  address,
2366
2503
  password
2367
- } = _ref54;
2504
+ } = _ref57;
2368
2505
  try {
2369
2506
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2370
2507
  } catch (e) {
@@ -2379,10 +2516,10 @@ class KoniExtension {
2379
2516
  errors: []
2380
2517
  };
2381
2518
  }
2382
- keyringUnlock(_ref55) {
2519
+ keyringUnlock(_ref58) {
2383
2520
  let {
2384
2521
  password
2385
- } = _ref55;
2522
+ } = _ref58;
2386
2523
  try {
2387
2524
  _uiKeyring.keyring.unlockKeyring(password);
2388
2525
  } catch (e) {
@@ -2402,11 +2539,11 @@ class KoniExtension {
2402
2539
  this.#koniState.updateKeyringState();
2403
2540
  clearTimeout(this.#lockTimeOut);
2404
2541
  }
2405
- keyringExportMnemonic(_ref56) {
2542
+ keyringExportMnemonic(_ref59) {
2406
2543
  let {
2407
2544
  address,
2408
2545
  password
2409
- } = _ref56;
2546
+ } = _ref59;
2410
2547
  const pair = _uiKeyring.keyring.getPair(address);
2411
2548
  const result = pair.exportMnemonic(password);
2412
2549
  return {
@@ -2415,10 +2552,10 @@ class KoniExtension {
2415
2552
  }
2416
2553
 
2417
2554
  /// Signing external request
2418
- signingApprovePasswordV2(_ref57) {
2555
+ signingApprovePasswordV2(_ref60) {
2419
2556
  let {
2420
2557
  id
2421
- } = _ref57;
2558
+ } = _ref60;
2422
2559
  const queued = this.#koniState.getSignRequest(id);
2423
2560
  (0, _util.assert)(queued, 'Unable to find request');
2424
2561
  const {
@@ -2471,22 +2608,22 @@ class KoniExtension {
2471
2608
 
2472
2609
  /// Derive account
2473
2610
 
2474
- derivationCreateMultiple(_ref58) {
2611
+ derivationCreateMultiple(_ref61) {
2475
2612
  let {
2476
2613
  isAllowed,
2477
2614
  items,
2478
2615
  parentAddress
2479
- } = _ref58;
2616
+ } = _ref61;
2480
2617
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2481
2618
  const isEvm = parentPair.type === 'ethereum';
2482
2619
  if (parentPair.isLocked) {
2483
2620
  _uiKeyring.keyring.unlockPair(parentPair.address);
2484
2621
  }
2485
- const createChild = _ref59 => {
2622
+ const createChild = _ref62 => {
2486
2623
  let {
2487
2624
  name,
2488
2625
  suri
2489
- } = _ref59;
2626
+ } = _ref62;
2490
2627
  const meta = {
2491
2628
  name: name,
2492
2629
  parentAddress
@@ -2532,10 +2669,10 @@ class KoniExtension {
2532
2669
  }
2533
2670
  return true;
2534
2671
  }
2535
- derivationCreateV3(_ref60) {
2672
+ derivationCreateV3(_ref63) {
2536
2673
  let {
2537
2674
  address: parentAddress
2538
- } = _ref60;
2675
+ } = _ref63;
2539
2676
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2540
2677
  const isEvm = parentPair.type === 'ethereum';
2541
2678
  if (parentPair.isLocked) {
@@ -2567,11 +2704,11 @@ class KoniExtension {
2567
2704
  });
2568
2705
  return true;
2569
2706
  }
2570
- validateDerivePath(_ref61) {
2707
+ validateDerivePath(_ref64) {
2571
2708
  let {
2572
2709
  parentAddress,
2573
2710
  suri
2574
- } = _ref61;
2711
+ } = _ref64;
2575
2712
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2576
2713
  const isEvm = parentPair.type === 'ethereum';
2577
2714
  if (parentPair.isLocked) {
@@ -2604,12 +2741,12 @@ class KoniExtension {
2604
2741
  suri: meta.suri
2605
2742
  };
2606
2743
  }
2607
- getListDeriveAccounts(_ref62) {
2744
+ getListDeriveAccounts(_ref65) {
2608
2745
  let {
2609
2746
  limit,
2610
2747
  page,
2611
2748
  parentAddress
2612
- } = _ref62;
2749
+ } = _ref65;
2613
2750
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2614
2751
  const isEvm = parentPair.type === 'ethereum';
2615
2752
  if (parentPair.isLocked) {
@@ -2700,10 +2837,10 @@ class KoniExtension {
2700
2837
  getSupportedSmartContractTypes() {
2701
2838
  return this.#koniState.getSupportedSmartContractTypes();
2702
2839
  }
2703
- getTransaction(_ref63) {
2840
+ getTransaction(_ref66) {
2704
2841
  let {
2705
2842
  id
2706
- } = _ref63;
2843
+ } = _ref66;
2707
2844
  const {
2708
2845
  transaction,
2709
2846
  ...transactionResult
@@ -2713,8 +2850,8 @@ class KoniExtension {
2713
2850
  subscribeTransactions(id, port) {
2714
2851
  const cb = (0, _subscriptions.createSubscription)(id, port);
2715
2852
  function convertRs(rs) {
2716
- return Object.fromEntries(Object.entries(rs).map(_ref64 => {
2717
- let [key, value] = _ref64;
2853
+ return Object.fromEntries(Object.entries(rs).map(_ref67 => {
2854
+ let [key, value] = _ref67;
2718
2855
  const {
2719
2856
  transaction,
2720
2857
  ...transactionResult
@@ -2744,6 +2881,17 @@ class KoniExtension {
2744
2881
  });
2745
2882
  return notificationSubject.value;
2746
2883
  }
2884
+ async reloadCron(_ref68) {
2885
+ let {
2886
+ data
2887
+ } = _ref68;
2888
+ if (data === 'nft') {
2889
+ return await this.#koniState.reloadNft();
2890
+ } else if (data === 'staking') {
2891
+ return await this.#koniState.reloadStaking();
2892
+ }
2893
+ return Promise.resolve(false);
2894
+ }
2747
2895
 
2748
2896
  // --------------------------------------------------------------
2749
2897
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -2762,8 +2910,6 @@ class KoniExtension {
2762
2910
  return this.accountsCreateSuri(request);
2763
2911
  case 'pri(accounts.changePassword)':
2764
2912
  return this.accountsChangePassword(request);
2765
- case 'pri(accounts.edit)':
2766
- return this.accountsEdit(request);
2767
2913
  case 'pri(accounts.export)':
2768
2914
  return this.accountsExport(request);
2769
2915
  case 'pri(accounts.show)':
@@ -2832,40 +2978,6 @@ class KoniExtension {
2832
2978
  return this.getAuthListV2();
2833
2979
  case 'pri(authorize.toggle)':
2834
2980
  return this.toggleAuthorization2(request);
2835
- case 'pri(accounts.create.suriV2)':
2836
- return await this.accountsCreateSuriV2(request);
2837
- case 'pri(accounts.forget)':
2838
- return await this.accountsForgetOverride(request);
2839
- case 'pri(accounts.create.externalV2)':
2840
- return await this.accountsCreateExternalV2(request);
2841
- case 'pri(accounts.create.hardwareV2)':
2842
- return await this.accountsCreateHardwareV2(request);
2843
- case 'pri(accounts.create.hardwareMultiple)':
2844
- return await this.accountsCreateHardwareMultiple(request);
2845
- case 'pri(accounts.create.withSecret)':
2846
- return await this.accountsCreateWithSecret(request);
2847
- case 'pri(seed.createV2)':
2848
- return this.seedCreateV2(request);
2849
- case 'pri(seed.validateV2)':
2850
- return this.seedValidateV2(request);
2851
- case 'pri(privateKey.validateV2)':
2852
- return this.metamaskPrivateKeyValidateV2(request);
2853
- case 'pri(accounts.exportPrivateKey)':
2854
- return this.accountExportPrivateKey(request);
2855
- case 'pri(accounts.checkPublicAndSecretKey)':
2856
- return this.checkPublicAndSecretKey(request);
2857
- case 'pri(accounts.subscribeWithCurrentAddress)':
2858
- return await this.accountsGetAllWithCurrentAddress(id, port);
2859
- case 'pri(accounts.subscribeAccountsInputAddress)':
2860
- return this.accountsGetAll(id, port);
2861
- case 'pri(accounts.saveRecent)':
2862
- return this.saveRecentAccountId(request);
2863
- case 'pri(accounts.triggerSubscription)':
2864
- return this.triggerAccountsSubscription();
2865
- case 'pri(currentAccount.saveAddress)':
2866
- return this.saveCurrentAccountAddress(request, id, port);
2867
- case 'pri(accounts.updateCurrentAddress)':
2868
- return this.updateCurrentAccountAddress(request);
2869
2981
  case 'pri(settings.changeBalancesVisibility)':
2870
2982
  return this.toggleBalancesVisibility(id, port);
2871
2983
  case 'pri(settings.subscribe)':
@@ -2915,6 +3027,65 @@ class KoniExtension {
2915
3027
  case 'pri(transaction.history.getSubscription)':
2916
3028
  return await this.subscribeHistory(id, port);
2917
3029
 
3030
+ /// Account management
3031
+ // Add account
3032
+ case 'pri(accounts.create.suriV2)':
3033
+ return await this.accountsCreateSuriV2(request);
3034
+ case 'pri(accounts.create.externalV2)':
3035
+ return await this.accountsCreateExternalV2(request);
3036
+ case 'pri(accounts.create.hardwareV2)':
3037
+ return await this.accountsCreateHardwareV2(request);
3038
+ case 'pri(accounts.create.hardwareMultiple)':
3039
+ return await this.accountsCreateHardwareMultiple(request);
3040
+ case 'pri(accounts.create.withSecret)':
3041
+ return await this.accountsCreateWithSecret(request);
3042
+ case 'pri(seed.createV2)':
3043
+ return this.seedCreateV2(request);
3044
+
3045
+ // Remove account
3046
+ case 'pri(accounts.forget)':
3047
+ return await this.accountsForgetOverride(request);
3048
+
3049
+ // Validate account
3050
+ case 'pri(seed.validateV2)':
3051
+ return this.seedValidateV2(request);
3052
+ case 'pri(privateKey.validateV2)':
3053
+ return this.metamaskPrivateKeyValidateV2(request);
3054
+ case 'pri(accounts.checkPublicAndSecretKey)':
3055
+ return this.checkPublicAndSecretKey(request);
3056
+
3057
+ // Export account
3058
+ case 'pri(accounts.exportPrivateKey)':
3059
+ return this.accountExportPrivateKey(request);
3060
+
3061
+ // Subscribe account
3062
+ case 'pri(accounts.subscribeWithCurrentAddress)':
3063
+ return await this.accountsGetAllWithCurrentAddress(id, port);
3064
+ case 'pri(accounts.subscribeAccountsInputAddress)':
3065
+ return this.accountsGetAll(id, port);
3066
+
3067
+ // Save current account
3068
+ case 'pri(currentAccount.saveAddress)':
3069
+ return await this.saveCurrentAccountAddress(request);
3070
+ case 'pri(accounts.updateCurrentAddress)':
3071
+ return this.updateCurrentAccountAddress(request);
3072
+
3073
+ // Edit account
3074
+ case 'pri(accounts.edit)':
3075
+ return this.accountsEdit(request);
3076
+
3077
+ // Save contact address
3078
+ case 'pri(accounts.saveRecent)':
3079
+ return this.saveRecentAccount(request);
3080
+ case 'pri(accounts.editContact)':
3081
+ return this.editContactAccount(request);
3082
+ case 'pri(accounts.deleteContact)':
3083
+ return this.deleteContactAccount(request);
3084
+
3085
+ // Subscribe address
3086
+ case 'pri(accounts.subscribeAddresses)':
3087
+ return this.subscribeAddresses(id, port);
3088
+
2918
3089
  // ChainService
2919
3090
  case 'pri(chainService.subscribeChainInfoMap)':
2920
3091
  return this.subscribeChainInfoMap(id, port);
@@ -2958,6 +3129,8 @@ class KoniExtension {
2958
3129
  return await this.transferCheckSupporting(request);
2959
3130
  case 'pri(transfer.getExistentialDeposit)':
2960
3131
  return this.transferGetExistentialDeposit(request);
3132
+ case 'pri(transfer.getMaxTransferable)':
3133
+ return this.transferGetMaxTransferable(request);
2961
3134
  case 'pri(freeBalance.get)':
2962
3135
  return this.getAddressFreeBalance(request);
2963
3136
  case 'pri(freeBalance.subscribe)':
@@ -2969,7 +3142,7 @@ class KoniExtension {
2969
3142
  case 'pri(accounts.get.meta)':
2970
3143
  return this.getAccountMeta(request);
2971
3144
 
2972
- // Send NFT
3145
+ /// Send NFT
2973
3146
  case 'pri(evmNft.submitTransaction)':
2974
3147
  return this.evmNftSubmitTransaction(request);
2975
3148
  case 'pri(substrateNft.submitTransaction)':
@@ -3027,7 +3200,7 @@ class KoniExtension {
3027
3200
  case 'pri(staking.submitTuringCancelCompound)':
3028
3201
  return await this.submitTuringCancelStakeCompound(request);
3029
3202
  case 'pri(bonding.nominationPool.submitBonding)':
3030
- return await this.submitPoolingBonding(request);
3203
+ return await this.submitPoolBonding(request);
3031
3204
  case 'pri(bonding.nominationPool.submitUnbonding)':
3032
3205
  return await this.submitPoolingUnbonding(request);
3033
3206
 
@@ -3076,6 +3249,8 @@ class KoniExtension {
3076
3249
  // Notification
3077
3250
  case 'pri(notifications.subscribe)':
3078
3251
  return this.subscribeNotifications(id, port);
3252
+ case 'pri(cron.reload)':
3253
+ return await this.reloadCron(request);
3079
3254
 
3080
3255
  // Default
3081
3256
  default: