@subwallet/extension-base 0.8.1-wr2x → 0.8.1-wr3

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 (47) hide show
  1. package/background/KoniTypes.d.ts +31 -1
  2. package/background/KoniTypes.js +15 -1
  3. package/background/errors/BalanceError.d.ts +6 -0
  4. package/background/errors/BalanceError.js +33 -0
  5. package/background/handlers/State.js +2 -1
  6. package/cjs/background/KoniTypes.js +18 -2
  7. package/cjs/background/errors/BalanceError.js +39 -0
  8. package/cjs/background/handlers/State.js +2 -1
  9. package/cjs/koni/api/dotsama/balance.js +1 -0
  10. package/cjs/koni/background/handlers/Extension.js +140 -94
  11. package/cjs/koni/background/handlers/State.js +15 -11
  12. package/cjs/services/balance-service/index.js +95 -2
  13. package/cjs/services/chain-service/utils.js +13 -3
  14. package/cjs/services/notification-service/NotificationService.js +23 -1
  15. package/cjs/services/request-service/handler/PopupHandler.js +10 -16
  16. package/cjs/services/request-service/index.js +2 -6
  17. package/cjs/services/setting-service/SettingService.js +2 -1
  18. package/cjs/services/storage-service/DatabaseService.js +3 -2
  19. package/cjs/services/storage-service/db-stores/Balance.js +0 -25
  20. package/cjs/services/transaction-service/index.js +22 -6
  21. package/koni/api/dotsama/balance.d.ts +1 -0
  22. package/koni/api/dotsama/balance.js +1 -1
  23. package/koni/background/handlers/Extension.d.ts +4 -0
  24. package/koni/background/handlers/Extension.js +58 -14
  25. package/koni/background/handlers/State.d.ts +3 -1
  26. package/koni/background/handlers/State.js +15 -11
  27. package/package.json +8 -3
  28. package/services/balance-service/index.d.ts +7 -5
  29. package/services/balance-service/index.js +95 -2
  30. package/services/chain-service/utils.d.ts +1 -1
  31. package/services/chain-service/utils.js +13 -3
  32. package/services/notification-service/NotificationService.d.ts +6 -1
  33. package/services/notification-service/NotificationService.js +23 -1
  34. package/services/request-service/handler/PopupHandler.d.ts +0 -1
  35. package/services/request-service/handler/PopupHandler.js +10 -15
  36. package/services/request-service/index.d.ts +3 -2
  37. package/services/request-service/index.js +2 -6
  38. package/services/setting-service/SettingService.js +2 -1
  39. package/services/storage-service/DatabaseService.d.ts +2 -1
  40. package/services/storage-service/DatabaseService.js +3 -2
  41. package/services/storage-service/db-stores/Balance.js +0 -25
  42. package/services/transaction-service/index.d.ts +3 -1
  43. package/services/transaction-service/index.js +23 -7
  44. package/cjs/background/errors/EvmRpcError.js +0 -21
  45. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  46. package/cjs/constants/ethereum.js +0 -19
  47. package/cjs/utils/eth/parseTransactionData.js +0 -284
@@ -13,7 +13,6 @@ var _subscriptions = require("@subwallet/extension-base/background/handlers/subs
13
13
  var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
14
14
  var _constants = require("@subwallet/extension-base/constants");
15
15
  var _defaults = require("@subwallet/extension-base/defaults");
16
- var _balance = require("@subwallet/extension-base/koni/api/dotsama/balance");
17
16
  var _parseTransaction = require("@subwallet/extension-base/koni/api/dotsama/parseTransaction");
18
17
  var _transfer = require("@subwallet/extension-base/koni/api/dotsama/transfer");
19
18
  var _transfer2 = require("@subwallet/extension-base/koni/api/nft/transfer");
@@ -607,6 +606,14 @@ class KoniExtension {
607
606
  const transformedAccounts = transformAccounts(storedAccounts);
608
607
  return transformedAccounts.filter(a => !a.isReadOnly).map(a => a.address);
609
608
  }
609
+ isAddressValidWithAuthType(address, accountAuthType) {
610
+ if (accountAuthType === 'substrate') {
611
+ return !(0, _utilCrypto.isEthereumAddress)(address);
612
+ } else if (accountAuthType === 'evm') {
613
+ return (0, _utilCrypto.isEthereumAddress)(address);
614
+ }
615
+ return true;
616
+ }
610
617
  filterAccountsByAccountAuthType(accounts, accountAuthType) {
611
618
  if (accountAuthType === 'substrate') {
612
619
  return accounts.filter(address => !(0, _utilCrypto.isEthereumAddress)(address));
@@ -680,11 +687,15 @@ class KoniExtension {
680
687
  _changeAuthorizationPerAcc(address, connectValue, url, callBack) {
681
688
  this.#koniState.getAuthorize(value => {
682
689
  (0, _util.assert)(value, 'The source is not known');
683
- value[url].isAllowedMap[address] = connectValue;
684
- console.log('Devbu: ', value);
685
- this.#koniState.setAuthorize(value, () => {
690
+ if (this.isAddressValidWithAuthType(address, value[url].accountAuthType)) {
691
+ value[url].isAllowedMap[address] = connectValue;
692
+ console.log('Devbu: ', value);
693
+ this.#koniState.setAuthorize(value, () => {
694
+ callBack && callBack(value);
695
+ });
696
+ } else {
686
697
  callBack && callBack(value);
687
- });
698
+ }
688
699
  });
689
700
  }
690
701
  _changeAuthorizationBlock(connectValue, id) {
@@ -770,6 +781,13 @@ class KoniExtension {
770
781
  });
771
782
  return true;
772
783
  }
784
+ setCamera(_ref25) {
785
+ let {
786
+ camera
787
+ } = _ref25;
788
+ this.#koniState.setCamera(camera);
789
+ return true;
790
+ }
773
791
  saveBrowserConfirmationType(data, id, port) {
774
792
  const cb = (0, _subscriptions.createSubscription)(id, port);
775
793
  this.#koniState.setBrowserConfirmationType(data, cb);
@@ -947,7 +965,9 @@ class KoniExtension {
947
965
  this.#koniState.getAuthorize(value => {
948
966
  if (value && Object.keys(value).length) {
949
967
  Object.keys(value).forEach(url => {
950
- value[url].isAllowedMap[address] = isAllowed;
968
+ if (this.isAddressValidWithAuthType(address, value[url].accountAuthType)) {
969
+ value[url].isAllowedMap[address] = isAllowed;
970
+ }
951
971
  });
952
972
  this.#koniState.setAuthorize(value);
953
973
  }
@@ -966,7 +986,7 @@ class KoniExtension {
966
986
  }
967
987
  });
968
988
  }
969
- async accountsCreateSuriV2(_ref25) {
989
+ async accountsCreateSuriV2(_ref26) {
970
990
  let {
971
991
  genesisHash,
972
992
  isAllowed,
@@ -974,7 +994,7 @@ class KoniExtension {
974
994
  password,
975
995
  suri: _suri,
976
996
  types
977
- } = _ref25;
997
+ } = _ref26;
978
998
  const addressDict = {};
979
999
  let changedAccount = false;
980
1000
  const hasMasterPassword = _uiKeyring.keyring.keyring.hasMasterPassword;
@@ -1028,10 +1048,10 @@ class KoniExtension {
1028
1048
  });
1029
1049
  return addressDict;
1030
1050
  }
1031
- async accountsForgetOverride(_ref26) {
1051
+ async accountsForgetOverride(_ref27) {
1032
1052
  let {
1033
1053
  address
1034
- } = _ref26;
1054
+ } = _ref27;
1035
1055
  _uiKeyring.keyring.forgetAccount(address);
1036
1056
  await new Promise(resolve => {
1037
1057
  this.#koniState.removeAccountRef(address, () => {
@@ -1053,10 +1073,10 @@ class KoniExtension {
1053
1073
 
1054
1074
  // Set current account to all account
1055
1075
  await new Promise(resolve => {
1056
- this.#koniState.getCurrentAccount(_ref27 => {
1076
+ this.#koniState.getCurrentAccount(_ref28 => {
1057
1077
  let {
1058
1078
  allGenesisHash
1059
- } = _ref27;
1079
+ } = _ref28;
1060
1080
  this.#koniState.setCurrentAccount({
1061
1081
  currentGenesisHash: allGenesisHash || null,
1062
1082
  address: _constants.ALL_ACCOUNT_KEY
@@ -1065,12 +1085,12 @@ class KoniExtension {
1065
1085
  });
1066
1086
  return true;
1067
1087
  }
1068
- seedCreateV2(_ref28) {
1088
+ seedCreateV2(_ref29) {
1069
1089
  let {
1070
1090
  length = _Extension.SEED_DEFAULT_LENGTH,
1071
1091
  seed: _seed,
1072
1092
  types
1073
- } = _ref28;
1093
+ } = _ref29;
1074
1094
  const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
1075
1095
  const rs = {
1076
1096
  seed: seed,
@@ -1081,11 +1101,11 @@ class KoniExtension {
1081
1101
  });
1082
1102
  return rs;
1083
1103
  }
1084
- seedValidateV2(_ref29) {
1104
+ seedValidateV2(_ref30) {
1085
1105
  let {
1086
1106
  suri,
1087
1107
  types
1088
- } = _ref29;
1108
+ } = _ref30;
1089
1109
  const {
1090
1110
  phrase
1091
1111
  } = (0, _utilCrypto.keyExtractSuri)(suri);
@@ -1105,11 +1125,11 @@ class KoniExtension {
1105
1125
  });
1106
1126
  return rs;
1107
1127
  }
1108
- _checkValidatePrivateKey(_ref30) {
1128
+ _checkValidatePrivateKey(_ref31) {
1109
1129
  let {
1110
1130
  suri,
1111
1131
  types
1112
- } = _ref30;
1132
+ } = _ref31;
1113
1133
  let autoAddPrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1114
1134
  const {
1115
1135
  phrase
@@ -1132,11 +1152,11 @@ class KoniExtension {
1132
1152
  }
1133
1153
  return rs;
1134
1154
  }
1135
- metamaskPrivateKeyValidateV2(_ref31) {
1155
+ metamaskPrivateKeyValidateV2(_ref32) {
1136
1156
  let {
1137
1157
  suri,
1138
1158
  types
1139
- } = _ref31;
1159
+ } = _ref32;
1140
1160
  const isValidSuri = suri.startsWith('0x');
1141
1161
  if (isValidSuri) {
1142
1162
  return this._checkValidatePrivateKey({
@@ -1161,14 +1181,14 @@ class KoniExtension {
1161
1181
  throw new Error(`"${suri}" is not a valid derivation path`);
1162
1182
  }
1163
1183
  }
1164
- derivationCreateV2(_ref32) {
1184
+ derivationCreateV2(_ref33) {
1165
1185
  let {
1166
1186
  genesisHash,
1167
1187
  isAllowed,
1168
1188
  name,
1169
1189
  parentAddress,
1170
1190
  suri
1171
- } = _ref32;
1191
+ } = _ref33;
1172
1192
  const childPair = this.deriveV2(parentAddress, suri, {
1173
1193
  genesisHash,
1174
1194
  name,
@@ -1182,14 +1202,14 @@ class KoniExtension {
1182
1202
  });
1183
1203
  return true;
1184
1204
  }
1185
- jsonRestoreV2(_ref33) {
1205
+ jsonRestoreV2(_ref34) {
1186
1206
  let {
1187
1207
  address,
1188
1208
  file,
1189
1209
  isAllowed,
1190
1210
  password,
1191
1211
  withMasterPassword
1192
- } = _ref33;
1212
+ } = _ref34;
1193
1213
  const isPasswordValidated = this.validatePassword(file, password);
1194
1214
  if (isPasswordValidated) {
1195
1215
  try {
@@ -1204,13 +1224,13 @@ class KoniExtension {
1204
1224
  throw new Error('Unable to decode using the supplied passphrase');
1205
1225
  }
1206
1226
  }
1207
- batchRestoreV2(_ref34) {
1227
+ batchRestoreV2(_ref35) {
1208
1228
  let {
1209
1229
  accountsInfo,
1210
1230
  file,
1211
1231
  isAllowed,
1212
1232
  password
1213
- } = _ref34;
1233
+ } = _ref35;
1214
1234
  const addressList = accountsInfo.map(acc => acc.address);
1215
1235
  const isPasswordValidated = this.validatedAccountsPassword(file, password);
1216
1236
  if (isPasswordValidated) {
@@ -1371,7 +1391,6 @@ class KoniExtension {
1371
1391
  } = inputData;
1372
1392
  const [errors,,, tokenInfo] = this.validateTransfer(tokenSlug, from, to, value, transferAll);
1373
1393
  const warnings = [];
1374
- const substrateApiMap = this.#koniState.getSubstrateApiMap();
1375
1394
  const evmApiMap = this.#koniState.getEvmApiMap();
1376
1395
  const chainInfo = this.#koniState.getChainInfo(networkKey);
1377
1396
  const nativeTokenInfo = this.#koniState.getNativeTokenInfo(networkKey);
@@ -1389,10 +1408,10 @@ class KoniExtension {
1389
1408
  let transaction;
1390
1409
 
1391
1410
  // Get native token amount
1392
- const freeBalance = await (0, _balance.getFreeBalance)(networkKey, from, substrateApiMap, evmApiMap, tokenSlug);
1411
+ const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
1393
1412
  if ((0, _utilCrypto.isEthereumAddress)(from) && (0, _utilCrypto.isEthereumAddress)(to)) {
1394
1413
  chainType = _KoniTypes.ChainType.EVM;
1395
- const txVal = transferAll ? freeBalance : value || '0';
1414
+ const txVal = transferAll ? freeBalance.value : value || '0';
1396
1415
 
1397
1416
  // Estimate with EVM API
1398
1417
  if ((0, _utils._isTokenEvmSmartContract)(tokenInfo)) {
@@ -1415,7 +1434,7 @@ class KoniExtension {
1415
1434
 
1416
1435
  // Additional validator
1417
1436
  const additionalValidator = swTran => {
1418
- if (new _util.BN(freeBalance).lt(new _util.BN(transferAmount.value))) {
1437
+ if (new _util.BN(freeBalance.value).lt(new _util.BN(transferAmount.value))) {
1419
1438
  var _swTran$errors;
1420
1439
  (_swTran$errors = swTran.errors) === null || _swTran$errors === void 0 ? void 0 : _swTran$errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE));
1421
1440
  }
@@ -1521,11 +1540,11 @@ class KoniExtension {
1521
1540
  enableChain(networkKey) {
1522
1541
  return this.#koniState.enableChain(networkKey);
1523
1542
  }
1524
- async validateNetwork(_ref35) {
1543
+ async validateNetwork(_ref36) {
1525
1544
  let {
1526
1545
  existedChainSlug,
1527
1546
  provider
1528
- } = _ref35;
1547
+ } = _ref36;
1529
1548
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1530
1549
  }
1531
1550
  resetDefaultNetwork() {
@@ -1563,39 +1582,48 @@ class KoniExtension {
1563
1582
  async validateCustomAsset(data) {
1564
1583
  return await this.#koniState.validateCustomAsset(data);
1565
1584
  }
1566
- async subscribeAddressFreeBalance(_ref36, id, port) {
1585
+ async getAddressFreeBalance(_ref37) {
1567
1586
  let {
1568
1587
  address,
1569
1588
  networkKey,
1570
1589
  token
1571
- } = _ref36;
1590
+ } = _ref37;
1591
+ return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
1592
+ }
1593
+ async subscribeAddressFreeBalance(_ref38, id, port) {
1594
+ let {
1595
+ address,
1596
+ networkKey,
1597
+ token
1598
+ } = _ref38;
1572
1599
  const cb = (0, _subscriptions.createSubscription)(id, port);
1573
- this.createUnsubscriptionHandle(id, await (0, _balance.subscribeFreeBalance)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getEvmApiMap(), token, cb));
1600
+ const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
1601
+ this.createUnsubscriptionHandle(id, unsub);
1574
1602
  port.onDisconnect.addListener(() => {
1575
1603
  this.cancelSubscription(id);
1576
1604
  });
1577
- return id;
1605
+ return currentFreeBalance;
1578
1606
  }
1579
- async transferCheckReferenceCount(_ref37) {
1607
+ async transferCheckReferenceCount(_ref39) {
1580
1608
  let {
1581
1609
  address,
1582
1610
  networkKey
1583
- } = _ref37;
1611
+ } = _ref39;
1584
1612
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1585
1613
  return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1586
1614
  }
1587
- async transferCheckSupporting(_ref38) {
1615
+ async transferCheckSupporting(_ref40) {
1588
1616
  let {
1589
1617
  networkKey,
1590
1618
  tokenSlug
1591
- } = _ref38;
1619
+ } = _ref40;
1592
1620
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1593
1621
  return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1594
1622
  }
1595
- transferGetExistentialDeposit(_ref39) {
1623
+ transferGetExistentialDeposit(_ref41) {
1596
1624
  let {
1597
1625
  tokenSlug
1598
- } = _ref39;
1626
+ } = _ref41;
1599
1627
  const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1600
1628
  return (0, _utils._getTokenMinAmount)(tokenInfo);
1601
1629
  }
@@ -1638,10 +1666,10 @@ class KoniExtension {
1638
1666
  }
1639
1667
  return true;
1640
1668
  }
1641
- getAccountMeta(_ref40) {
1669
+ getAccountMeta(_ref42) {
1642
1670
  let {
1643
1671
  address
1644
- } = _ref40;
1672
+ } = _ref42;
1645
1673
  const pair = _uiKeyring.keyring.getPair(address);
1646
1674
  (0, _util.assert)(pair, 'Unable to find pair');
1647
1675
  return {
@@ -1662,14 +1690,14 @@ class KoniExtension {
1662
1690
  }
1663
1691
  });
1664
1692
  }
1665
- accountsTie2(_ref41) {
1693
+ accountsTie2(_ref43) {
1666
1694
  let {
1667
1695
  address,
1668
1696
  genesisHash
1669
- } = _ref41;
1697
+ } = _ref43;
1670
1698
  return this.#koniState.setAccountTie(address, genesisHash);
1671
1699
  }
1672
- async accountsCreateExternalV2(_ref42) {
1700
+ async accountsCreateExternalV2(_ref44) {
1673
1701
  let {
1674
1702
  address,
1675
1703
  genesisHash,
@@ -1677,7 +1705,7 @@ class KoniExtension {
1677
1705
  isEthereum,
1678
1706
  isReadOnly,
1679
1707
  name
1680
- } = _ref42;
1708
+ } = _ref44;
1681
1709
  try {
1682
1710
  let result;
1683
1711
  try {
@@ -1736,7 +1764,7 @@ class KoniExtension {
1736
1764
  }];
1737
1765
  }
1738
1766
  }
1739
- async accountsCreateHardwareV2(_ref43) {
1767
+ async accountsCreateHardwareV2(_ref45) {
1740
1768
  let {
1741
1769
  accountIndex,
1742
1770
  address,
@@ -1745,7 +1773,7 @@ class KoniExtension {
1745
1773
  hardwareType,
1746
1774
  isAllowed,
1747
1775
  name
1748
- } = _ref43;
1776
+ } = _ref45;
1749
1777
  const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
1750
1778
  accountIndex,
1751
1779
  addressOffset,
@@ -1768,10 +1796,10 @@ class KoniExtension {
1768
1796
  });
1769
1797
  return true;
1770
1798
  }
1771
- async accountsCreateHardwareMultiple(_ref44) {
1799
+ async accountsCreateHardwareMultiple(_ref46) {
1772
1800
  let {
1773
1801
  accounts
1774
- } = _ref44;
1802
+ } = _ref46;
1775
1803
  const addresses = [];
1776
1804
  if (!accounts.length) {
1777
1805
  throw new Error('No accounts to import');
@@ -1824,14 +1852,14 @@ class KoniExtension {
1824
1852
  });
1825
1853
  return true;
1826
1854
  }
1827
- async accountsCreateWithSecret(_ref45) {
1855
+ async accountsCreateWithSecret(_ref47) {
1828
1856
  let {
1829
1857
  isAllow,
1830
1858
  isEthereum,
1831
1859
  name,
1832
1860
  publicKey,
1833
1861
  secretKey
1834
- } = _ref45;
1862
+ } = _ref47;
1835
1863
  try {
1836
1864
  let keyringPair = null;
1837
1865
  if (isEthereum) {
@@ -1974,30 +2002,30 @@ class KoniExtension {
1974
2002
 
1975
2003
  // Parse transaction
1976
2004
 
1977
- parseSubstrateTransaction(_ref46) {
2005
+ parseSubstrateTransaction(_ref48) {
1978
2006
  let {
1979
2007
  data,
1980
2008
  networkKey
1981
- } = _ref46;
2009
+ } = _ref48;
1982
2010
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
1983
2011
  const apiPromise = apiProps.api;
1984
2012
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
1985
2013
  }
1986
- async parseEVMRLP(_ref47) {
2014
+ async parseEVMRLP(_ref49) {
1987
2015
  let {
1988
2016
  data
1989
- } = _ref47;
2017
+ } = _ref49;
1990
2018
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
1991
2019
  }
1992
2020
 
1993
2021
  // Sign
1994
2022
 
1995
- qrSignSubstrate(_ref48) {
2023
+ qrSignSubstrate(_ref50) {
1996
2024
  let {
1997
2025
  address,
1998
2026
  data,
1999
2027
  networkKey
2000
- } = _ref48;
2028
+ } = _ref50;
2001
2029
  const pair = _uiKeyring.keyring.getPair(address);
2002
2030
  (0, _util.assert)(pair, 'Unable to find pair');
2003
2031
  if (pair.isLocked) {
@@ -2014,13 +2042,13 @@ class KoniExtension {
2014
2042
  signature: signed
2015
2043
  };
2016
2044
  }
2017
- async qrSignEVM(_ref49) {
2045
+ async qrSignEVM(_ref51) {
2018
2046
  let {
2019
2047
  address,
2020
2048
  chainId,
2021
2049
  message,
2022
2050
  type
2023
- } = _ref49;
2051
+ } = _ref51;
2024
2052
  let signed;
2025
2053
  const network = this.getNetworkJsonByChainId(chainId);
2026
2054
  if (!network) {
@@ -2101,11 +2129,11 @@ class KoniExtension {
2101
2129
  });
2102
2130
  return this.#koniState.getNominatorMetadata();
2103
2131
  }
2104
- async getBondingOptions(_ref50) {
2132
+ async getBondingOptions(_ref52) {
2105
2133
  let {
2106
2134
  chain,
2107
2135
  type
2108
- } = _ref50;
2136
+ } = _ref52;
2109
2137
  const apiProps = this.#koniState.getSubstrateApi(chain);
2110
2138
  const chainInfo = this.#koniState.getChainInfo(chain);
2111
2139
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2283,12 +2311,12 @@ class KoniExtension {
2283
2311
  }
2284
2312
 
2285
2313
  // EVM Transaction
2286
- async parseContractInput(_ref51) {
2314
+ async parseContractInput(_ref53) {
2287
2315
  let {
2288
2316
  chainId,
2289
2317
  contract,
2290
2318
  data
2291
- } = _ref51;
2319
+ } = _ref53;
2292
2320
  const network = this.getNetworkJsonByChainId(chainId);
2293
2321
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2294
2322
  }
@@ -2341,13 +2369,13 @@ class KoniExtension {
2341
2369
  chainType: _KoniTypes.ChainType.SUBSTRATE
2342
2370
  });
2343
2371
  }
2344
- async wasmNftGetTransaction(_ref52) {
2372
+ async wasmNftGetTransaction(_ref54) {
2345
2373
  let {
2346
2374
  networkKey,
2347
2375
  params,
2348
2376
  recipientAddress,
2349
2377
  senderAddress
2350
- } = _ref52;
2378
+ } = _ref54;
2351
2379
  const contractAddress = params.contractAddress;
2352
2380
  const onChainOption = params.onChainOption;
2353
2381
  try {
@@ -2369,12 +2397,12 @@ class KoniExtension {
2369
2397
  });
2370
2398
  return this.#koniState.getKeyringState();
2371
2399
  }
2372
- keyringChangeMasterPassword(_ref53) {
2400
+ keyringChangeMasterPassword(_ref55) {
2373
2401
  let {
2374
2402
  createNew,
2375
2403
  newPassword,
2376
2404
  oldPassword
2377
- } = _ref53;
2405
+ } = _ref55;
2378
2406
  try {
2379
2407
  // Remove isMasterPassword meta if createNew
2380
2408
  if (createNew) {
@@ -2409,11 +2437,11 @@ class KoniExtension {
2409
2437
  errors: []
2410
2438
  };
2411
2439
  }
2412
- keyringMigrateMasterPassword(_ref54) {
2440
+ keyringMigrateMasterPassword(_ref56) {
2413
2441
  let {
2414
2442
  address,
2415
2443
  password
2416
- } = _ref54;
2444
+ } = _ref56;
2417
2445
  try {
2418
2446
  _uiKeyring.keyring.migrateWithMasterPassword(address, password);
2419
2447
  } catch (e) {
@@ -2428,10 +2456,10 @@ class KoniExtension {
2428
2456
  errors: []
2429
2457
  };
2430
2458
  }
2431
- keyringUnlock(_ref55) {
2459
+ keyringUnlock(_ref57) {
2432
2460
  let {
2433
2461
  password
2434
- } = _ref55;
2462
+ } = _ref57;
2435
2463
  try {
2436
2464
  _uiKeyring.keyring.unlockKeyring(password);
2437
2465
  } catch (e) {
@@ -2458,11 +2486,11 @@ class KoniExtension {
2458
2486
  isLocked: true
2459
2487
  });
2460
2488
  }
2461
- keyringExportMnemonic(_ref56) {
2489
+ keyringExportMnemonic(_ref58) {
2462
2490
  let {
2463
2491
  address,
2464
2492
  password
2465
- } = _ref56;
2493
+ } = _ref58;
2466
2494
  const pair = _uiKeyring.keyring.getPair(address);
2467
2495
  const result = pair.exportMnemonic(password);
2468
2496
  return {
@@ -2471,10 +2499,10 @@ class KoniExtension {
2471
2499
  }
2472
2500
 
2473
2501
  /// Signing external request
2474
- signingApprovePasswordV2(_ref57) {
2502
+ signingApprovePasswordV2(_ref59) {
2475
2503
  let {
2476
2504
  id
2477
- } = _ref57;
2505
+ } = _ref59;
2478
2506
  const queued = this.#koniState.getSignRequest(id);
2479
2507
  (0, _util.assert)(queued, 'Unable to find request');
2480
2508
  const {
@@ -2521,22 +2549,22 @@ class KoniExtension {
2521
2549
 
2522
2550
  /// Derive account
2523
2551
 
2524
- derivationCreateMultiple(_ref58) {
2552
+ derivationCreateMultiple(_ref60) {
2525
2553
  let {
2526
2554
  isAllowed,
2527
2555
  items,
2528
2556
  parentAddress
2529
- } = _ref58;
2557
+ } = _ref60;
2530
2558
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2531
2559
  const isEvm = parentPair.type === 'ethereum';
2532
2560
  if (parentPair.isLocked) {
2533
2561
  _uiKeyring.keyring.unlockPair(parentPair.address);
2534
2562
  }
2535
- const createChild = _ref59 => {
2563
+ const createChild = _ref61 => {
2536
2564
  let {
2537
2565
  name,
2538
2566
  suri
2539
- } = _ref59;
2567
+ } = _ref61;
2540
2568
  const meta = {
2541
2569
  name: name,
2542
2570
  parentAddress
@@ -2582,10 +2610,10 @@ class KoniExtension {
2582
2610
  }
2583
2611
  return true;
2584
2612
  }
2585
- derivationCreateV3(_ref60) {
2613
+ derivationCreateV3(_ref62) {
2586
2614
  let {
2587
2615
  address: parentAddress
2588
- } = _ref60;
2616
+ } = _ref62;
2589
2617
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2590
2618
  const isEvm = parentPair.type === 'ethereum';
2591
2619
  if (parentPair.isLocked) {
@@ -2617,11 +2645,11 @@ class KoniExtension {
2617
2645
  });
2618
2646
  return true;
2619
2647
  }
2620
- validateDerivePath(_ref61) {
2648
+ validateDerivePath(_ref63) {
2621
2649
  let {
2622
2650
  parentAddress,
2623
2651
  suri
2624
- } = _ref61;
2652
+ } = _ref63;
2625
2653
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2626
2654
  const isEvm = parentPair.type === 'ethereum';
2627
2655
  if (parentPair.isLocked) {
@@ -2654,12 +2682,12 @@ class KoniExtension {
2654
2682
  suri: meta.suri
2655
2683
  };
2656
2684
  }
2657
- getListDeriveAccounts(_ref62) {
2685
+ getListDeriveAccounts(_ref64) {
2658
2686
  let {
2659
2687
  limit,
2660
2688
  page,
2661
2689
  parentAddress
2662
- } = _ref62;
2690
+ } = _ref64;
2663
2691
  const parentPair = _uiKeyring.keyring.getPair(parentAddress);
2664
2692
  const isEvm = parentPair.type === 'ethereum';
2665
2693
  if (parentPair.isLocked) {
@@ -2737,10 +2765,10 @@ class KoniExtension {
2737
2765
  getSupportedSmartContractTypes() {
2738
2766
  return this.#koniState.getSupportedSmartContractTypes();
2739
2767
  }
2740
- getTransaction(_ref63) {
2768
+ getTransaction(_ref65) {
2741
2769
  let {
2742
2770
  id
2743
- } = _ref63;
2771
+ } = _ref65;
2744
2772
  const {
2745
2773
  transaction,
2746
2774
  ...transactionResult
@@ -2750,8 +2778,8 @@ class KoniExtension {
2750
2778
  subscribeTransactions(id, port) {
2751
2779
  const cb = (0, _subscriptions.createSubscription)(id, port);
2752
2780
  function convertRs(rs) {
2753
- return Object.fromEntries(Object.entries(rs).map(_ref64 => {
2754
- let [key, value] = _ref64;
2781
+ return Object.fromEntries(Object.entries(rs).map(_ref66 => {
2782
+ let [key, value] = _ref66;
2755
2783
  const {
2756
2784
  transaction,
2757
2785
  ...transactionResult
@@ -2769,6 +2797,18 @@ class KoniExtension {
2769
2797
  });
2770
2798
  return convertRs(transactionsSubject.getValue());
2771
2799
  }
2800
+ subscribeNotifications(id, port) {
2801
+ const cb = (0, _subscriptions.createSubscription)(id, port);
2802
+ const notificationSubject = this.#koniState.notificationService.getNotificationSubject();
2803
+ const notificationSubscription = notificationSubject.subscribe(rs => {
2804
+ cb(rs);
2805
+ });
2806
+ port.onDisconnect.addListener(() => {
2807
+ notificationSubscription.unsubscribe();
2808
+ this.cancelSubscription(id);
2809
+ });
2810
+ return notificationSubject.value;
2811
+ }
2772
2812
 
2773
2813
  // --------------------------------------------------------------
2774
2814
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -2817,8 +2857,6 @@ class KoniExtension {
2817
2857
  return this.seedCreate(request);
2818
2858
  case 'pri(seed.validate)':
2819
2859
  return this.seedValidate(request);
2820
- case 'pri(settings.notification)':
2821
- return this.#koniState.setNotification(request);
2822
2860
  case 'pri(signing.approve.signature)':
2823
2861
  return this.signingApproveSignature(request);
2824
2862
  case 'pri(signing.cancel)':
@@ -2895,6 +2933,8 @@ class KoniExtension {
2895
2933
  return await this.subscribeSettings(id, port);
2896
2934
  case 'pri(settings.saveAccountAllLogo)':
2897
2935
  return this.saveAccountAllLogo(request, id, port);
2936
+ case 'pri(settings.saveCamera)':
2937
+ return this.setCamera(request);
2898
2938
  case 'pri(settings.saveTheme)':
2899
2939
  return this.saveTheme(request, id, port);
2900
2940
  case 'pri(settings.saveBrowserConfirmationType)':
@@ -2977,6 +3017,8 @@ class KoniExtension {
2977
3017
  return await this.transferCheckSupporting(request);
2978
3018
  case 'pri(transfer.getExistentialDeposit)':
2979
3019
  return this.transferGetExistentialDeposit(request);
3020
+ case 'pri(freeBalance.get)':
3021
+ return this.getAddressFreeBalance(request);
2980
3022
  case 'pri(freeBalance.subscribe)':
2981
3023
  return this.subscribeAddressFreeBalance(request, id, port);
2982
3024
  case 'pri(subscription.cancel)':
@@ -3104,6 +3146,10 @@ class KoniExtension {
3104
3146
  case 'pri(transactions.subscribe)':
3105
3147
  return this.subscribeTransactions(id, port);
3106
3148
 
3149
+ // Notification
3150
+ case 'pri(notifications.subscribe)':
3151
+ return this.subscribeNotifications(id, port);
3152
+
3107
3153
  // Default
3108
3154
  default:
3109
3155
  throw new Error(`Unable to handle message of type ${type}`);