@subwallet/extension-base 1.3.42-0 → 1.3.43-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 (47) hide show
  1. package/background/KoniTypes.d.ts +35 -23
  2. package/background/errors/BitcoinProviderError.d.ts +1 -1
  3. package/background/errors/BitcoinProviderError.js +2 -2
  4. package/background/types.d.ts +1 -1
  5. package/cjs/background/errors/BitcoinProviderError.js +2 -2
  6. package/cjs/core/logic-validation/request.js +316 -3
  7. package/cjs/koni/background/handlers/Extension.js +418 -90
  8. package/cjs/koni/background/handlers/State.js +198 -6
  9. package/cjs/koni/background/handlers/Tabs.js +119 -6
  10. package/cjs/packageInfo.js +1 -1
  11. package/cjs/page/bitcoin/index.js +67 -0
  12. package/cjs/page/index.js +5 -0
  13. package/cjs/services/buy-service/index.js +17 -2
  14. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  15. package/cjs/services/request-service/handler/AuthRequestHandler.js +18 -0
  16. package/cjs/services/request-service/handler/BitcoinRequestHandler.js +48 -61
  17. package/cjs/services/request-service/index.js +2 -2
  18. package/cjs/services/transaction-service/index.js +71 -2
  19. package/cjs/utils/auth.js +2 -1
  20. package/core/logic-validation/request.d.ts +6 -2
  21. package/core/logic-validation/request.js +309 -3
  22. package/koni/background/handlers/Extension.d.ts +3 -0
  23. package/koni/background/handlers/Extension.js +330 -6
  24. package/koni/background/handlers/State.d.ts +4 -1
  25. package/koni/background/handlers/State.js +189 -4
  26. package/koni/background/handlers/Tabs.d.ts +7 -2
  27. package/koni/background/handlers/Tabs.js +119 -9
  28. package/package.json +11 -6
  29. package/packageInfo.js +1 -1
  30. package/page/bitcoin/index.d.ts +17 -0
  31. package/page/bitcoin/index.js +60 -0
  32. package/page/index.d.ts +2 -1
  33. package/page/index.js +4 -0
  34. package/services/balance-service/transfer/cardano-transfer.d.ts +2 -0
  35. package/services/buy-service/index.js +17 -2
  36. package/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  37. package/services/request-service/handler/AuthRequestHandler.js +19 -1
  38. package/services/request-service/handler/BitcoinRequestHandler.d.ts +3 -4
  39. package/services/request-service/handler/BitcoinRequestHandler.js +48 -61
  40. package/services/request-service/index.d.ts +1 -2
  41. package/services/request-service/index.js +2 -2
  42. package/services/transaction-service/index.d.ts +1 -0
  43. package/services/transaction-service/index.js +71 -2
  44. package/services/transaction-service/types.d.ts +1 -0
  45. package/types/balance/transfer.d.ts +4 -2
  46. package/types/buy.d.ts +1 -1
  47. package/utils/auth.js +3 -2
@@ -57,9 +57,10 @@ var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTrans
57
57
  var _getId = require("@subwallet/extension-base/utils/getId");
58
58
  var _keyring = require("@subwallet/keyring");
59
59
  var _types4 = require("@subwallet/keyring/types");
60
+ var _utils9 = require("@subwallet/keyring/utils");
60
61
  var _validate = require("@subwallet/keyring/utils/address/validate");
61
62
  var _uiKeyring = require("@subwallet/ui-keyring");
62
- var _utils9 = require("@walletconnect/utils");
63
+ var _utils10 = require("@walletconnect/utils");
63
64
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
64
65
  var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
65
66
  var _i18next = require("i18next");
@@ -67,7 +68,7 @@ var _rxjs = require("rxjs");
67
68
  var _types5 = require("@polkadot/types");
68
69
  var _util = require("@polkadot/util");
69
70
  var _utilCrypto = require("@polkadot/util-crypto");
70
- var _utils10 = require("../utils");
71
+ var _utils11 = require("../utils");
71
72
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
72
73
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
73
74
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
@@ -590,7 +591,8 @@ class KoniExtension {
590
591
  evm: _types4.EthereumKeypairTypes,
591
592
  substrate: _types4.SubstrateKeypairTypes,
592
593
  ton: _types4.TonKeypairTypes,
593
- cardano: _types4.CardanoKeypairTypes
594
+ cardano: _types4.CardanoKeypairTypes,
595
+ bitcoin: _types4.BitcoinKeypairTypes
594
596
  };
595
597
  return !!accountAuthTypes && accountAuthTypes.some(authType => {
596
598
  var _validTypes$authType;
@@ -705,7 +707,8 @@ class KoniExtension {
705
707
  substrate: 'substrateInfo',
706
708
  evm: 'evmInfo',
707
709
  cardano: 'cardanoInfo',
708
- ton: 'tonInfo'
710
+ ton: 'tonInfo',
711
+ bitcoin: 'bitcoinInfo'
709
712
  };
710
713
  const typeInfoKey = typeInfoMap[authSwitchNetworkType];
711
714
  if (!typeInfoKey || !chainInfo[typeInfoKey]) {
@@ -1401,6 +1404,7 @@ class KoniExtension {
1401
1404
  if (transferAll) {
1402
1405
  inputData.value = transferAmount.value;
1403
1406
  }
1407
+ console.log('PSPT transaction', transaction.toHex());
1404
1408
  } else {
1405
1409
  const substrateApi = this.#koniState.getSubstrateApi(chain);
1406
1410
  [transaction, transferAmount.value] = await (0, _token.createSubstrateExtrinsic)({
@@ -1712,6 +1716,192 @@ class KoniExtension {
1712
1716
  eventsHandler: eventsHandler
1713
1717
  });
1714
1718
  }
1719
+ async makeBitcoinDappTransferConfirmation(inputData) {
1720
+ const {
1721
+ chain,
1722
+ feeCustom,
1723
+ feeOption,
1724
+ from,
1725
+ id,
1726
+ to,
1727
+ tokenSlug,
1728
+ transferAll,
1729
+ value
1730
+ } = inputData;
1731
+ const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(tokenSlug);
1732
+ const errors = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, to, value, transferAll);
1733
+ const warnings = [];
1734
+ const chainInfo = this.#koniState.getChainInfo(chain);
1735
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(chain);
1736
+ const nativeTokenSlug = nativeTokenInfo.slug;
1737
+ const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1738
+ let chainType = _KoniTypes.ChainType.BITCOIN;
1739
+ const tokenBaseAmount = {
1740
+ value: '0',
1741
+ symbol: transferTokenInfo.symbol,
1742
+ decimals: transferTokenInfo.decimals || 0
1743
+ };
1744
+ const transferAmount = {
1745
+ ...tokenBaseAmount
1746
+ };
1747
+ let transaction;
1748
+ let overrideFeeCustom;
1749
+ let calculatedBitcoinFeeRate;
1750
+
1751
+ // Get native token amount
1752
+ const freeBalance = await this.getAddressTransferableBalance({
1753
+ address: from,
1754
+ networkKey: chain,
1755
+ token: tokenSlug
1756
+ });
1757
+ const txVal = transferAll ? freeBalance.value : value || '0';
1758
+ try {
1759
+ if ((0, _utils6._isChainBitcoinCompatible)(chainInfo)) {
1760
+ chainType = _KoniTypes.ChainType.BITCOIN;
1761
+ const bitcoinApi = this.#koniState.getBitcoinApi(chain); // Get Bitcoin API map
1762
+ const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
1763
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'bitcoin');
1764
+ [transaction, transferAmount.value, calculatedBitcoinFeeRate] = await (0, _bitcoinTransfer.createBitcoinTransaction)({
1765
+ bitcoinApi,
1766
+ chain,
1767
+ from,
1768
+ feeInfo,
1769
+ to,
1770
+ transferAll: transferAll,
1771
+ value: txVal,
1772
+ network: network
1773
+ });
1774
+ if (calculatedBitcoinFeeRate) {
1775
+ const feeRate = parseFloat(calculatedBitcoinFeeRate);
1776
+ if (!isNaN(feeRate)) {
1777
+ overrideFeeCustom = {
1778
+ feeRate
1779
+ };
1780
+ }
1781
+ }
1782
+ }
1783
+ } catch (e) {
1784
+ const error = e;
1785
+ if (error.message.includes('transfer amount exceeds balance')) {
1786
+ error.message = (0, _i18next.t)('Insufficient balance');
1787
+ }
1788
+ throw error;
1789
+ }
1790
+ const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1791
+ return this.#koniState.transactionService.handleTransactionAfterConfirmation({
1792
+ id,
1793
+ errors,
1794
+ warnings,
1795
+ address: from,
1796
+ chain: chain,
1797
+ feeCustom: overrideFeeCustom || feeCustom,
1798
+ feeOption: overrideFeeCustom ? 'custom' : feeOption,
1799
+ chainType,
1800
+ transferNativeAmount,
1801
+ transaction,
1802
+ data: inputData,
1803
+ extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1804
+ ignoreWarnings: [],
1805
+ isTransferAll: isTransferNativeToken ? transferAll : false,
1806
+ edAsWarning: isTransferNativeToken
1807
+ });
1808
+ }
1809
+ async makePsbtTransferAfterConfirmation(inputData_) {
1810
+ var _txOutput$;
1811
+ const {
1812
+ chain,
1813
+ from,
1814
+ id,
1815
+ psbt,
1816
+ tokenSlug,
1817
+ txInput,
1818
+ txOutput,
1819
+ value
1820
+ } = inputData_;
1821
+ let inputAmount = new _bignumber.default(0);
1822
+ const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(tokenSlug);
1823
+ const totalUtxoInput = txInput.reduce((total, _ref33) => {
1824
+ let {
1825
+ address,
1826
+ amount
1827
+ } = _ref33;
1828
+ if (!address || !amount) {
1829
+ return total;
1830
+ }
1831
+ if ((0, _utils8.isSameAddress)(address, from)) {
1832
+ inputAmount = new _bignumber.default(amount);
1833
+ }
1834
+ return total.plus(new _bignumber.default(amount || 0));
1835
+ }, new _bignumber.default(0));
1836
+ const totalUtxoOutput = txOutput.reduce((total, _ref34) => {
1837
+ let {
1838
+ address,
1839
+ amount
1840
+ } = _ref34;
1841
+ if (!address || !amount) {
1842
+ return total;
1843
+ }
1844
+ return total.plus(new _bignumber.default(amount));
1845
+ }, new _bignumber.default(0));
1846
+ const estimateFeeValue = totalUtxoInput.minus(totalUtxoOutput).toString();
1847
+ const errors = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, ((_txOutput$ = txOutput[0]) === null || _txOutput$ === void 0 ? void 0 : _txOutput$.address) || '', value, false);
1848
+ const warnings = [];
1849
+ const chainInfo = this.#koniState.getChainInfo(chain);
1850
+ const {
1851
+ decimals,
1852
+ symbol
1853
+ } = (0, _utils6._getChainNativeTokenBasicInfo)(chainInfo);
1854
+ const estimateFee = {
1855
+ symbol,
1856
+ decimals,
1857
+ value: estimateFeeValue,
1858
+ tooHigh: false
1859
+ };
1860
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(chain);
1861
+ const nativeTokenSlug = nativeTokenInfo.slug;
1862
+ const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1863
+ const chainType = _KoniTypes.ChainType.BITCOIN;
1864
+ const bitcoinNetwork = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
1865
+ const psbtGenerate = bitcoin.Psbt.fromHex(psbt, {
1866
+ network: bitcoinNetwork
1867
+ });
1868
+ const tokenBaseAmount = {
1869
+ value: inputData_.value,
1870
+ symbol: transferTokenInfo.symbol,
1871
+ decimals: transferTokenInfo.decimals || 0
1872
+ };
1873
+ const transferAmount = {
1874
+ ...tokenBaseAmount
1875
+ };
1876
+
1877
+ // Get native token amount
1878
+ const freeBalance = await this.getAddressTransferableBalance({
1879
+ address: from,
1880
+ networkKey: chain,
1881
+ token: tokenSlug
1882
+ });
1883
+ if (new _bignumber.default(freeBalance.value).lt(inputAmount)) {
1884
+ throw new Error((0, _i18next.t)('Insufficient balance'));
1885
+ }
1886
+ const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1887
+ return this.#koniState.transactionService.handleTransactionAfterConfirmation({
1888
+ id,
1889
+ errors,
1890
+ warnings,
1891
+ address: from,
1892
+ chain: chain,
1893
+ estimateFee,
1894
+ chainType,
1895
+ transferNativeAmount,
1896
+ transaction: psbtGenerate,
1897
+ data: inputData_,
1898
+ extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1899
+ ignoreWarnings: [],
1900
+ isTransferAll: false,
1901
+ edAsWarning: isTransferNativeToken,
1902
+ skipFeeRecalculation: true
1903
+ });
1904
+ }
1715
1905
  async getTokensCanPayFee(request) {
1716
1906
  var _tokensHasBalanceInfo;
1717
1907
  const {
@@ -1831,28 +2021,28 @@ class KoniExtension {
1831
2021
  disableChain(networkKey) {
1832
2022
  return this.#koniState.disableChain(networkKey);
1833
2023
  }
1834
- async enableChain(_ref33) {
2024
+ async enableChain(_ref35) {
1835
2025
  let {
1836
2026
  chainSlug,
1837
2027
  enableTokens
1838
- } = _ref33;
2028
+ } = _ref35;
1839
2029
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1840
2030
  }
1841
- async enableChainWithPriorityAssets(_ref34) {
2031
+ async enableChainWithPriorityAssets(_ref36) {
1842
2032
  let {
1843
2033
  chainSlug,
1844
2034
  enableTokens
1845
- } = _ref34;
2035
+ } = _ref36;
1846
2036
  return await this.#koniState.enableChainWithPriorityAssets(chainSlug, enableTokens);
1847
2037
  }
1848
2038
  async reconnectChain(chainSlug) {
1849
2039
  return this.#koniState.chainService.reconnectChain(chainSlug);
1850
2040
  }
1851
- async validateNetwork(_ref35) {
2041
+ async validateNetwork(_ref37) {
1852
2042
  let {
1853
2043
  existedChainSlug,
1854
2044
  provider
1855
- } = _ref35;
2045
+ } = _ref37;
1856
2046
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1857
2047
  }
1858
2048
  resetDefaultNetwork() {
@@ -1924,13 +2114,13 @@ class KoniExtension {
1924
2114
  async validateCustomAsset(data) {
1925
2115
  return await this.#koniState.validateCustomAsset(data);
1926
2116
  }
1927
- async getAddressTransferableBalance(_ref36) {
2117
+ async getAddressTransferableBalance(_ref38) {
1928
2118
  let {
1929
2119
  address,
1930
2120
  extrinsicType,
1931
2121
  networkKey,
1932
2122
  token
1933
- } = _ref36;
2123
+ } = _ref38;
1934
2124
  if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1935
2125
  const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1936
2126
  if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
@@ -1939,13 +2129,13 @@ class KoniExtension {
1939
2129
  }
1940
2130
  return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
1941
2131
  }
1942
- async getAddressTotalBalance(_ref37) {
2132
+ async getAddressTotalBalance(_ref39) {
1943
2133
  let {
1944
2134
  address,
1945
2135
  extrinsicType,
1946
2136
  networkKey,
1947
2137
  token
1948
- } = _ref37;
2138
+ } = _ref39;
1949
2139
  return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
1950
2140
  }
1951
2141
  async subscribeMaxTransferable(request, id, port) {
@@ -2000,11 +2190,11 @@ class KoniExtension {
2000
2190
  freeBalance: freeBalanceSubject,
2001
2191
  fee: feeSubject
2002
2192
  }).subscribe({
2003
- next: _ref38 => {
2193
+ next: _ref40 => {
2004
2194
  let {
2005
2195
  fee,
2006
2196
  freeBalance
2007
- } = _ref38;
2197
+ } = _ref40;
2008
2198
  (0, _utils8.calculateMaxTransferable)(id, _request, freeBalance, fee).then(cb).catch(console.error);
2009
2199
  }
2010
2200
  });
@@ -2038,13 +2228,144 @@ class KoniExtension {
2038
2228
  });
2039
2229
  return (0, _utils8.calculateMaxTransferable)(id, _request, freeBalance, fee);
2040
2230
  }
2041
- async subscribeAddressTransferableBalance(_ref39, id, port) {
2231
+ async subscribeTransferableWhenConfirmation(_ref41, id, port) {
2232
+ let {
2233
+ address,
2234
+ chain,
2235
+ feeCustom,
2236
+ feeOption: _feeOptions,
2237
+ to,
2238
+ token,
2239
+ value
2240
+ } = _ref41;
2241
+ const cb = (0, _subscriptions.createSubscription)(id, port);
2242
+ const freeBalanceSubject = new _rxjs.Subject();
2243
+ const feeSubject = new _rxjs.Subject();
2244
+ const feeType = 'bitcoin';
2245
+ let error;
2246
+ const convertData = async (freeBalance, fee, feeOption, feeCustom) => {
2247
+ let estimatedFee = '0';
2248
+ let feeOptions = null;
2249
+ const amount = parseInt(value || '0');
2250
+ const neededUtxos = [];
2251
+ let sum = new _bignumber.default(0);
2252
+ let sizeInfo = null;
2253
+ try {
2254
+ const _fee = fee;
2255
+ const _feeCustom = feeCustom;
2256
+ const combineFee = (0, _utils8.combineBitcoinFee)(_fee, _feeOptions, _feeCustom);
2257
+ const bitcoinApi = this.#koniState.chainService.getBitcoinApi(chain);
2258
+ let utxos = await (0, _utils8.getTransferableBitcoinUtxos)(bitcoinApi, address);
2259
+ const recipients = [address, to || address];
2260
+ utxos = utxos.sort((a, b) => b.value - a.value);
2261
+ const filteredUtxos = (0, _utils8.filterUneconomicalUtxos)({
2262
+ utxos,
2263
+ feeRate: combineFee.feeRate,
2264
+ recipients,
2265
+ sender: address
2266
+ });
2267
+ for (const utxo of filteredUtxos) {
2268
+ sizeInfo = (0, _utils8.getSizeInfo)({
2269
+ inputLength: neededUtxos.length,
2270
+ sender: address,
2271
+ recipients
2272
+ });
2273
+ const currentValue = new _bignumber.default(amount).plus(Math.ceil(sizeInfo.txVBytes * combineFee.feeRate));
2274
+ if (sum.gte(currentValue)) {
2275
+ break;
2276
+ }
2277
+ sum = sum.plus(utxo.value);
2278
+ neededUtxos.push(utxo);
2279
+ }
2280
+
2281
+ // re calculate
2282
+ sizeInfo = (0, _utils8.getSizeInfo)({
2283
+ inputLength: neededUtxos.length,
2284
+ sender: address,
2285
+ recipients
2286
+ });
2287
+ if (!sizeInfo) {
2288
+ sizeInfo = (0, _utils8.getSizeInfo)({
2289
+ inputLength: utxos.length || 1,
2290
+ sender: address,
2291
+ recipients
2292
+ });
2293
+ }
2294
+ estimatedFee = Math.ceil(sizeInfo.txVBytes * combineFee.feeRate).toString();
2295
+ const amountLeft = sum.minus(amount).minus(new _bignumber.default(estimatedFee));
2296
+ if (amountLeft.lte(0)) {
2297
+ error = 'Insufficient balance';
2298
+ } else {
2299
+ const senderAddressInfo = (0, _utils9.getBitcoinAddressInfo)(address);
2300
+ const dustLimit = _constants.BTC_DUST_AMOUNT[senderAddressInfo.type] || 546;
2301
+ if (amountLeft.lte(dustLimit)) {
2302
+ sizeInfo = (0, _utils8.getSizeInfo)({
2303
+ inputLength: neededUtxos.length,
2304
+ sender: address,
2305
+ recipients: [to || address]
2306
+ });
2307
+ estimatedFee = sum.minus(amount).toString();
2308
+ }
2309
+ }
2310
+ feeOptions = {
2311
+ ...fee,
2312
+ vSize: sizeInfo.txVBytes,
2313
+ estimatedFee
2314
+ };
2315
+ } catch (e) {
2316
+ feeOptions = {
2317
+ ...fee,
2318
+ estimatedFee,
2319
+ vSize: 0
2320
+ };
2321
+ error = e.message || e;
2322
+ console.warn('Unable to estimate fee', e);
2323
+ }
2324
+ return {
2325
+ feeOptions: feeOptions,
2326
+ feeType,
2327
+ error,
2328
+ id
2329
+ };
2330
+ };
2331
+ const subscription = (0, _rxjs.combineLatest)({
2332
+ freeBalance: freeBalanceSubject,
2333
+ fee: feeSubject
2334
+ }).subscribe({
2335
+ next: _ref42 => {
2336
+ let {
2337
+ fee,
2338
+ freeBalance
2339
+ } = _ref42;
2340
+ convertData(freeBalance, fee, _feeOptions, feeCustom).then(cb).catch(console.error);
2341
+ }
2342
+ });
2343
+ const [unsubBalance, freeBalance] = await this.#koniState.balanceService.subscribeBalance(address, chain, token, 'transferable', _KoniTypes.ExtrinsicType.TRANSFER_BALANCE, data => {
2344
+ freeBalanceSubject.next(data); // Must be called after subscription
2345
+ });
2346
+
2347
+ const fee = await this.#koniState.feeService.subscribeChainFee(id, chain, feeType, data => {
2348
+ feeSubject.next(data); // Must be called after subscription
2349
+ });
2350
+
2351
+ const unsub = () => {
2352
+ subscription.unsubscribe();
2353
+ unsubBalance();
2354
+ this.#koniState.feeService.unsubscribeChainFee(id, chain, feeType);
2355
+ };
2356
+ this.createUnsubscriptionHandle(id, unsub);
2357
+ port.onDisconnect.addListener(() => {
2358
+ this.cancelSubscription(id);
2359
+ });
2360
+ return convertData(freeBalance, fee, _feeOptions, feeCustom);
2361
+ }
2362
+ async subscribeAddressTransferableBalance(_ref43, id, port) {
2042
2363
  let {
2043
2364
  address,
2044
2365
  extrinsicType,
2045
2366
  networkKey,
2046
2367
  token
2047
- } = _ref39;
2368
+ } = _ref43;
2048
2369
  const cb = (0, _subscriptions.createSubscription)(id, port);
2049
2370
  const convertData = data => {
2050
2371
  return {
@@ -2095,11 +2416,11 @@ class KoniExtension {
2095
2416
  isSendingSelf
2096
2417
  };
2097
2418
  }
2098
- async enableChains(_ref40) {
2419
+ async enableChains(_ref44) {
2099
2420
  let {
2100
2421
  chainSlugs,
2101
2422
  enableTokens
2102
- } = _ref40;
2423
+ } = _ref44;
2103
2424
  try {
2104
2425
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
2105
2426
  chainSlug,
@@ -2243,30 +2564,30 @@ class KoniExtension {
2243
2564
 
2244
2565
  // Parse transaction
2245
2566
 
2246
- parseSubstrateTransaction(_ref41) {
2567
+ parseSubstrateTransaction(_ref45) {
2247
2568
  let {
2248
2569
  data,
2249
2570
  networkKey
2250
- } = _ref41;
2571
+ } = _ref45;
2251
2572
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2252
2573
  const apiPromise = apiProps.api;
2253
2574
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2254
2575
  }
2255
- async parseEVMRLP(_ref42) {
2576
+ async parseEVMRLP(_ref46) {
2256
2577
  let {
2257
2578
  data
2258
- } = _ref42;
2579
+ } = _ref46;
2259
2580
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2260
2581
  }
2261
2582
 
2262
2583
  // Sign
2263
2584
 
2264
- qrSignSubstrate(_ref43) {
2585
+ qrSignSubstrate(_ref47) {
2265
2586
  let {
2266
2587
  address,
2267
2588
  data,
2268
2589
  networkKey
2269
- } = _ref43;
2590
+ } = _ref47;
2270
2591
  const pair = _uiKeyring.keyring.getPair(address);
2271
2592
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
2272
2593
  if (pair.isLocked) {
@@ -2283,13 +2604,13 @@ class KoniExtension {
2283
2604
  signature: signed
2284
2605
  };
2285
2606
  }
2286
- async qrSignEVM(_ref44) {
2607
+ async qrSignEVM(_ref48) {
2287
2608
  let {
2288
2609
  address,
2289
2610
  chainId,
2290
2611
  message,
2291
2612
  type
2292
- } = _ref44;
2613
+ } = _ref48;
2293
2614
  let signed;
2294
2615
  const network = this.getNetworkJsonByChainId(chainId);
2295
2616
  if (!network) {
@@ -2373,11 +2694,11 @@ class KoniExtension {
2373
2694
  });
2374
2695
  return this.#koniState.getNominatorMetadata();
2375
2696
  }
2376
- async getBondingOptions(_ref45) {
2697
+ async getBondingOptions(_ref49) {
2377
2698
  let {
2378
2699
  chain,
2379
2700
  type
2380
- } = _ref45;
2701
+ } = _ref49;
2381
2702
  const apiProps = this.#koniState.getSubstrateApi(chain);
2382
2703
  const chainInfo = this.#koniState.getChainInfo(chain);
2383
2704
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2567,12 +2888,12 @@ class KoniExtension {
2567
2888
  }
2568
2889
 
2569
2890
  // EVM Transaction
2570
- async parseContractInput(_ref46) {
2891
+ async parseContractInput(_ref50) {
2571
2892
  let {
2572
2893
  chainId,
2573
2894
  contract,
2574
2895
  data
2575
- } = _ref46;
2896
+ } = _ref50;
2576
2897
  const network = this.getNetworkJsonByChainId(chainId);
2577
2898
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2578
2899
  }
@@ -2672,10 +2993,10 @@ class KoniExtension {
2672
2993
 
2673
2994
  // Unlock wallet
2674
2995
 
2675
- keyringUnlock(_ref47) {
2996
+ keyringUnlock(_ref51) {
2676
2997
  let {
2677
2998
  password
2678
- } = _ref47;
2999
+ } = _ref51;
2679
3000
  try {
2680
3001
  _uiKeyring.keyring.unlockKeyring(password);
2681
3002
  // this.#koniState.initMantaPay(password)
@@ -2706,11 +3027,11 @@ class KoniExtension {
2706
3027
 
2707
3028
  // Export mnemonic
2708
3029
 
2709
- keyringExportMnemonic(_ref48) {
3030
+ keyringExportMnemonic(_ref52) {
2710
3031
  let {
2711
3032
  address,
2712
3033
  password
2713
- } = _ref48;
3034
+ } = _ref52;
2714
3035
  const pair = _uiKeyring.keyring.getPair(address);
2715
3036
  const result = pair.exportMnemonic(password);
2716
3037
  return {
@@ -2720,10 +3041,10 @@ class KoniExtension {
2720
3041
 
2721
3042
  // Reset wallet
2722
3043
 
2723
- async resetWallet(_ref49) {
3044
+ async resetWallet(_ref53) {
2724
3045
  let {
2725
3046
  resetAll
2726
- } = _ref49;
3047
+ } = _ref53;
2727
3048
  try {
2728
3049
  await this.#koniState.resetWallet(resetAll);
2729
3050
  return {
@@ -2739,10 +3060,10 @@ class KoniExtension {
2739
3060
  }
2740
3061
 
2741
3062
  // Signing substrate request
2742
- async signingApprovePasswordV2(_ref50) {
3063
+ async signingApprovePasswordV2(_ref54) {
2743
3064
  let {
2744
3065
  id
2745
- } = _ref50;
3066
+ } = _ref54;
2746
3067
  const queued = this.#koniState.getSignRequest(id);
2747
3068
  (0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
2748
3069
  const {
@@ -2771,12 +3092,12 @@ class KoniExtension {
2771
3092
  let registry = new _types5.TypeRegistry();
2772
3093
  if (isJsonPayload(payload)) {
2773
3094
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2774
- const registries = await Promise.all([(0, _utils10.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils10.setupDatabaseRegistry)(chainInfo, payload, this.#koniState), (0, _utils10.setupDappRegistry)(payload, this.#koniState)]);
3095
+ const registries = await Promise.all([(0, _utils11.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils11.setupDatabaseRegistry)(chainInfo, payload, this.#koniState), (0, _utils11.setupDappRegistry)(payload, this.#koniState)]);
2775
3096
  const validRegistries = registries.filter(item => !!(item !== null && item !== void 0 && item.registry));
2776
3097
  if (validRegistries.length === 0) {
2777
3098
  registry.setSignedExtensions(payload.signedExtensions);
2778
3099
  } else {
2779
- registry = (0, _utils10.getSuitableRegistry)(validRegistries, payload);
3100
+ registry = (0, _utils11.getSuitableRegistry)(validRegistries, payload);
2780
3101
  }
2781
3102
  }
2782
3103
  const result = request.sign(registry, pair);
@@ -2901,10 +3222,10 @@ class KoniExtension {
2901
3222
  getSupportedSmartContractTypes() {
2902
3223
  return this.#koniState.getSupportedSmartContractTypes();
2903
3224
  }
2904
- getTransaction(_ref51) {
3225
+ getTransaction(_ref55) {
2905
3226
  let {
2906
3227
  id
2907
- } = _ref51;
3228
+ } = _ref55;
2908
3229
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2909
3230
  const {
2910
3231
  transaction,
@@ -2915,11 +3236,12 @@ class KoniExtension {
2915
3236
  async subscribeTransactions(id, port) {
2916
3237
  const cb = (0, _subscriptions.createSubscription)(id, port);
2917
3238
  function convertRs(rs, processMap) {
2918
- return Object.fromEntries(Object.entries(rs).map(_ref52 => {
2919
- let [key, value] = _ref52;
3239
+ return Object.fromEntries(Object.entries(rs).map(_ref56 => {
3240
+ let [key, value] = _ref56;
2920
3241
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2921
3242
  const {
2922
3243
  additionalValidator,
3244
+ emitterTransaction,
2923
3245
  eventsHandler,
2924
3246
  step,
2925
3247
  transaction,
@@ -2941,11 +3263,11 @@ class KoniExtension {
2941
3263
  const subscription = (0, _rxjs.combineLatest)({
2942
3264
  transactions: transactionsObservable,
2943
3265
  processMap: processTransactionObservable
2944
- }).subscribe(_ref53 => {
3266
+ }).subscribe(_ref57 => {
2945
3267
  let {
2946
3268
  processMap,
2947
3269
  transactions
2948
- } = _ref53;
3270
+ } = _ref57;
2949
3271
  cb(convertRs(transactions, processMap));
2950
3272
  });
2951
3273
  port.onDisconnect.addListener(() => {
@@ -2966,10 +3288,10 @@ class KoniExtension {
2966
3288
  });
2967
3289
  return notificationSubject.value;
2968
3290
  }
2969
- async reloadCron(_ref54) {
3291
+ async reloadCron(_ref58) {
2970
3292
  let {
2971
3293
  data
2972
- } = _ref54;
3294
+ } = _ref58;
2973
3295
  if (data === 'nft') {
2974
3296
  return await this.#koniState.reloadNft();
2975
3297
  } else if (data === 'staking') {
@@ -3012,10 +3334,10 @@ class KoniExtension {
3012
3334
  }
3013
3335
 
3014
3336
  // Phishing detect
3015
- async passPhishingPage(_ref55) {
3337
+ async passPhishingPage(_ref59) {
3016
3338
  let {
3017
3339
  url
3018
- } = _ref55;
3340
+ } = _ref59;
3019
3341
  return await this.#koniState.approvePassPhishingPage(url);
3020
3342
  }
3021
3343
 
@@ -3036,10 +3358,10 @@ class KoniExtension {
3036
3358
  /// Wallet connect
3037
3359
 
3038
3360
  // Connect
3039
- async connectWalletConnect(_ref56) {
3361
+ async connectWalletConnect(_ref60) {
3040
3362
  let {
3041
3363
  uri
3042
- } = _ref56;
3364
+ } = _ref60;
3043
3365
  await this.#koniState.walletConnectService.connect(uri);
3044
3366
  return true;
3045
3367
  }
@@ -3052,11 +3374,11 @@ class KoniExtension {
3052
3374
  });
3053
3375
  return this.#koniState.requestService.allConnectWCRequests;
3054
3376
  }
3055
- async approveWalletConnectSession(_ref57) {
3377
+ async approveWalletConnectSession(_ref61) {
3056
3378
  let {
3057
3379
  accounts: selectedAccounts,
3058
3380
  id
3059
- } = _ref57;
3381
+ } = _ref61;
3060
3382
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3061
3383
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3062
3384
  throw new Error('The proposal has been expired');
@@ -3068,22 +3390,22 @@ class KoniExtension {
3068
3390
  const availableNamespaces = {};
3069
3391
  const namespaces = {};
3070
3392
  const chainInfoMap = this.#koniState.getChainInfoMap();
3071
- Object.entries(requiredNamespaces).forEach(_ref58 => {
3072
- let [key, namespace] = _ref58;
3393
+ Object.entries(requiredNamespaces).forEach(_ref62 => {
3394
+ let [key, namespace] = _ref62;
3073
3395
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3074
3396
  if (namespace.chains) {
3075
3397
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
3076
3398
  if (unSupportChains.length) {
3077
- throw new Error((0, _utils9.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
3399
+ throw new Error((0, _utils10.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
3078
3400
  }
3079
3401
  availableNamespaces[key] = namespace;
3080
3402
  }
3081
3403
  } else {
3082
- throw new Error((0, _utils9.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3404
+ throw new Error((0, _utils10.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3083
3405
  }
3084
3406
  });
3085
- Object.entries(optionalNamespaces).forEach(_ref59 => {
3086
- let [key, namespace] = _ref59;
3407
+ Object.entries(optionalNamespaces).forEach(_ref63 => {
3408
+ let [key, namespace] = _ref63;
3087
3409
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3088
3410
  if (namespace.chains) {
3089
3411
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -3107,8 +3429,8 @@ class KoniExtension {
3107
3429
  }
3108
3430
  }
3109
3431
  });
3110
- Object.entries(availableNamespaces).forEach(_ref60 => {
3111
- let [key, namespace] = _ref60;
3432
+ Object.entries(availableNamespaces).forEach(_ref64 => {
3433
+ let [key, namespace] = _ref64;
3112
3434
  if (namespace.chains) {
3113
3435
  const accounts = selectedAccounts.filter(address => {
3114
3436
  const [_namespace] = address.split(':');
@@ -3132,10 +3454,10 @@ class KoniExtension {
3132
3454
  request.resolve();
3133
3455
  return true;
3134
3456
  }
3135
- async rejectWalletConnectSession(_ref61) {
3457
+ async rejectWalletConnectSession(_ref65) {
3136
3458
  let {
3137
3459
  id
3138
- } = _ref61;
3460
+ } = _ref65;
3139
3461
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3140
3462
  const wcId = request.request.id;
3141
3463
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -3157,10 +3479,10 @@ class KoniExtension {
3157
3479
  });
3158
3480
  return this.#koniState.walletConnectService.sessions;
3159
3481
  }
3160
- async disconnectWalletConnectSession(_ref62) {
3482
+ async disconnectWalletConnectSession(_ref66) {
3161
3483
  let {
3162
3484
  topic
3163
- } = _ref62;
3485
+ } = _ref66;
3164
3486
  await this.#koniState.walletConnectService.disconnect(topic);
3165
3487
  return true;
3166
3488
  }
@@ -3173,18 +3495,18 @@ class KoniExtension {
3173
3495
  });
3174
3496
  return this.#koniState.requestService.allNotSupportWCRequests;
3175
3497
  }
3176
- approveWalletConnectNotSupport(_ref63) {
3498
+ approveWalletConnectNotSupport(_ref67) {
3177
3499
  let {
3178
3500
  id
3179
- } = _ref63;
3501
+ } = _ref67;
3180
3502
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3181
3503
  request.resolve();
3182
3504
  return true;
3183
3505
  }
3184
- rejectWalletConnectNotSupport(_ref64) {
3506
+ rejectWalletConnectNotSupport(_ref68) {
3185
3507
  let {
3186
3508
  id
3187
- } = _ref64;
3509
+ } = _ref68;
3188
3510
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3189
3511
  request.reject(new Error('USER_REJECTED'));
3190
3512
  return true;
@@ -3192,11 +3514,11 @@ class KoniExtension {
3192
3514
 
3193
3515
  /// Manta
3194
3516
 
3195
- async enableMantaPay(_ref65) {
3517
+ async enableMantaPay(_ref69) {
3196
3518
  let {
3197
3519
  address,
3198
3520
  password
3199
- } = _ref65;
3521
+ } = _ref69;
3200
3522
  // always takes the current account
3201
3523
  function timeout() {
3202
3524
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -3286,11 +3608,11 @@ class KoniExtension {
3286
3608
  async disableMantaPay(address) {
3287
3609
  return this.#koniState.disableMantaPay(address);
3288
3610
  }
3289
- async isTonBounceableAddress(_ref66) {
3611
+ async isTonBounceableAddress(_ref70) {
3290
3612
  let {
3291
3613
  address,
3292
3614
  chain
3293
- } = _ref66;
3615
+ } = _ref70;
3294
3616
  try {
3295
3617
  const tonApi = this.#koniState.getTonApi(chain);
3296
3618
  const state = await tonApi.getAccountState(address);
@@ -3336,10 +3658,10 @@ class KoniExtension {
3336
3658
 
3337
3659
  /* Metadata */
3338
3660
 
3339
- async findRawMetadata(_ref67) {
3661
+ async findRawMetadata(_ref71) {
3340
3662
  let {
3341
3663
  genesisHash
3342
- } = _ref67;
3664
+ } = _ref71;
3343
3665
  const {
3344
3666
  metadata,
3345
3667
  specVersion,
@@ -3353,20 +3675,20 @@ class KoniExtension {
3353
3675
  userExtensions
3354
3676
  };
3355
3677
  }
3356
- async calculateMetadataHash(_ref68) {
3678
+ async calculateMetadataHash(_ref72) {
3357
3679
  let {
3358
3680
  chain
3359
- } = _ref68;
3681
+ } = _ref72;
3360
3682
  const hash = await this.#koniState.calculateMetadataHash(chain);
3361
3683
  return {
3362
3684
  metadataHash: hash || ''
3363
3685
  };
3364
3686
  }
3365
- async shortenMetadata(_ref69) {
3687
+ async shortenMetadata(_ref73) {
3366
3688
  let {
3367
3689
  chain,
3368
3690
  txBlob
3369
- } = _ref69;
3691
+ } = _ref73;
3370
3692
  const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
3371
3693
  return {
3372
3694
  txMetadata: shorten || ''
@@ -3719,18 +4041,18 @@ class KoniExtension {
3719
4041
 
3720
4042
  /* Campaign */
3721
4043
 
3722
- unlockDotCheckCanMint(_ref70) {
4044
+ unlockDotCheckCanMint(_ref74) {
3723
4045
  let {
3724
4046
  address,
3725
4047
  network,
3726
4048
  slug
3727
- } = _ref70;
4049
+ } = _ref74;
3728
4050
  return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3729
4051
  }
3730
- unlockDotSubscribeMintedData(id, port, _ref71) {
4052
+ unlockDotSubscribeMintedData(id, port, _ref75) {
3731
4053
  let {
3732
4054
  transactionId
3733
- } = _ref71;
4055
+ } = _ref75;
3734
4056
  const cb = (0, _subscriptions.createSubscription)(id, port);
3735
4057
  const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3736
4058
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
@@ -3762,10 +4084,10 @@ class KoniExtension {
3762
4084
  });
3763
4085
  return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3764
4086
  }
3765
- async completeCampaignBanner(_ref72) {
4087
+ async completeCampaignBanner(_ref76) {
3766
4088
  let {
3767
4089
  slug
3768
- } = _ref72;
4090
+ } = _ref76;
3769
4091
  const campaign = await this.#koniState.dbService.getCampaign(slug);
3770
4092
  if (campaign) {
3771
4093
  await this.#koniState.dbService.upsertCampaign({
@@ -4300,8 +4622,8 @@ class KoniExtension {
4300
4622
  resolve();
4301
4623
  }
4302
4624
  };
4303
- this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref73 => {
4304
- let [_unsub, rs] = _ref73;
4625
+ this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref77 => {
4626
+ let [_unsub, rs] = _ref77;
4305
4627
  unsub = _unsub;
4306
4628
  onRs(rs);
4307
4629
  }).catch(console.error);
@@ -4732,6 +5054,8 @@ class KoniExtension {
4732
5054
  return await this.updateAssetSetting(request);
4733
5055
  case 'pri(transfer.subscribe)':
4734
5056
  return this.subscribeMaxTransferable(request, id, port);
5057
+ case 'pri(transfer.confirmation.subscribe)':
5058
+ return this.subscribeTransferableWhenConfirmation(request, id, port);
4735
5059
  case 'pri(freeBalance.get)':
4736
5060
  return this.getAddressTransferableBalance(request);
4737
5061
  case 'pri(freeBalance.subscribe)':
@@ -4750,6 +5074,10 @@ class KoniExtension {
4750
5074
  /// Transfer
4751
5075
  case 'pri(accounts.transfer)':
4752
5076
  return await this.makeTransfer(request);
5077
+ case 'pri(accounts.bitcoin.dapp.transfer.confirmation)':
5078
+ return await this.makeBitcoinDappTransferConfirmation(request);
5079
+ case 'pri(accounts.psbt.transfer.confirmation)':
5080
+ return await this.makePsbtTransferAfterConfirmation(request);
4753
5081
  case 'pri(accounts.crossChainTransfer)':
4754
5082
  return await this.makeCrossChainTransfer(request);
4755
5083
  case 'pri(accounts.getOptimalTransferProcess)':