@multiversx/sdk-dapp-liquidity 1.0.12 → 1.0.14

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 (302) hide show
  1. package/ConstantsUtil-BinYIDR2.mjs +8 -0
  2. package/ConstantsUtil-CbnVdQ5P.js +8 -0
  3. package/add-D-ECcdUh.mjs +19 -0
  4. package/add-Diz8heiY.js +20 -0
  5. package/all-wallets-_iOQf3bl.js +11 -0
  6. package/all-wallets-puIIQy3Y.mjs +10 -0
  7. package/app-store-BGTKFL27.js +22 -0
  8. package/app-store-Bsf7w3pv.mjs +21 -0
  9. package/apple-Cw8e8IGH.mjs +22 -0
  10. package/apple-DF7n_Yzl.js +23 -0
  11. package/arrow-bottom-Cp2C4fQv.mjs +12 -0
  12. package/arrow-bottom-DTvIR3s3.js +13 -0
  13. package/arrow-bottom-circle-CN6i5mHz.mjs +15 -0
  14. package/arrow-bottom-circle-CzPwiwWH.js +16 -0
  15. package/arrow-left-9VFYHQSW.js +13 -0
  16. package/arrow-left-BDQHoEvX.mjs +12 -0
  17. package/arrow-right-BxkuSpWU.mjs +12 -0
  18. package/arrow-right-DBLQ6w92.js +13 -0
  19. package/arrow-top-BiQd5Aey.js +13 -0
  20. package/arrow-top-BrLVX4Rj.mjs +12 -0
  21. package/bank-B7EC6Kdz.mjs +18 -0
  22. package/bank-CvPn9sfV.js +19 -0
  23. package/{bignumber-CKZkoo0g.mjs → bignumber-2Z7uapuD.mjs} +6 -6
  24. package/{bignumber-B8vjg9qn.js → bignumber-D1Wl54dL.js} +6 -6
  25. package/bin-BXO1kNZh.js +9 -0
  26. package/bin-CwiYVJ1L.mjs +8 -0
  27. package/bitcoin-C3kBVar_.mjs +17 -0
  28. package/bitcoin-DAvQGpeP.js +3251 -0
  29. package/bitcoin-dNBGbS2B.mjs +3251 -0
  30. package/bitcoin-k6bvmzMA.js +18 -0
  31. package/browser-ShRLuKKz.mjs +18 -0
  32. package/browser-t7nfT7HL.js +19 -0
  33. package/card-BJg5bdoM.mjs +18 -0
  34. package/card-hxUDXttT.js +19 -0
  35. package/checkmark-BpR0Yy93.mjs +15 -0
  36. package/checkmark-D9AVWgl5.js +16 -0
  37. package/checkmark-bold-D3Xcby1U.mjs +12 -0
  38. package/checkmark-bold-De02hde8.js +13 -0
  39. package/chevron-bottom-DcBf7T5F.js +13 -0
  40. package/chevron-bottom-DfGpWIz7.mjs +12 -0
  41. package/chevron-left-BKvYVnUo.js +13 -0
  42. package/chevron-left-DGSG9WJQ.mjs +12 -0
  43. package/chevron-right-BLgYIEeO.js +13 -0
  44. package/chevron-right-C2nsTx_Y.mjs +12 -0
  45. package/chevron-top-CwFOEFy8.js +13 -0
  46. package/chevron-top-vk-9DvUU.mjs +12 -0
  47. package/chrome-store-4H_ie3vA.mjs +65 -0
  48. package/chrome-store-BWarxVMl.js +66 -0
  49. package/circle-BtqWJU0_.mjs +8 -0
  50. package/circle-DYjG6o7-.js +9 -0
  51. package/clock-Ba5SM-pl.mjs +12 -0
  52. package/clock-DPzNREdU.js +13 -0
  53. package/close-CJHKFOyp.mjs +12 -0
  54. package/close-DDWnJdJe.js +13 -0
  55. package/coinPlaceholder-Cbba3D1H.mjs +12 -0
  56. package/coinPlaceholder-DdxQIc2D.js +13 -0
  57. package/compass-CugCxeSC.js +13 -0
  58. package/compass-DbN5DkTl.mjs +12 -0
  59. package/copy-CHSZprYJ.mjs +19 -0
  60. package/copy-En5h5Uhu.js +20 -0
  61. package/cursor-DCRkvEhr.mjs +7 -0
  62. package/cursor-DnEQtrUK.js +8 -0
  63. package/cursor-transparent-CU8lk-xg.js +17 -0
  64. package/cursor-transparent-CliETg4d.mjs +16 -0
  65. package/desktop-BgD7aypB.js +14 -0
  66. package/desktop-Cg5I32-p.mjs +13 -0
  67. package/disconnect-CCyMbAdw.js +13 -0
  68. package/disconnect-Cp2vRWB2.mjs +12 -0
  69. package/discord-B1d-qeSk.mjs +21 -0
  70. package/discord-BEB5klec.js +22 -0
  71. package/email-CorlePKz.js +873 -0
  72. package/email-Znno7H8_.mjs +878 -0
  73. package/embedded-wallet-B9ro9Tel.js +549 -0
  74. package/embedded-wallet-CnTWeseG.mjs +552 -0
  75. package/ethereum-BRcsRjUU.mjs +14 -0
  76. package/ethereum-CZ_xe09e.js +15 -0
  77. package/etherscan-BZKGpKp8.mjs +10 -0
  78. package/etherscan-DtLi-C3z.js +11 -0
  79. package/exclamation-triangle-BLNnBLEc.js +9 -0
  80. package/exclamation-triangle-CFThXxRT.mjs +8 -0
  81. package/extension-CwUepr-W.mjs +12 -0
  82. package/extension-DOD67G1k.js +13 -0
  83. package/external-link-CZkQS5XK.js +13 -0
  84. package/external-link-ClYNKSPt.mjs +12 -0
  85. package/facebook-CFjrd4my.mjs +30 -0
  86. package/facebook-CbE6K6AK.js +31 -0
  87. package/farcaster-Ba7_C-Vm.js +17 -0
  88. package/farcaster-DyVJtVS9.mjs +16 -0
  89. package/filters-CpHaFNjT.mjs +12 -0
  90. package/filters-w5LC-r6e.js +13 -0
  91. package/github-CeO70C3E.mjs +22 -0
  92. package/github-uLFBWAa5.js +23 -0
  93. package/google-CyOdUlbw.mjs +22 -0
  94. package/google-ILGK-opP.js +23 -0
  95. package/help-circle-Dh3dRNoB.mjs +16 -0
  96. package/help-circle-HUMbz_KN.js +17 -0
  97. package/id-Cy3Qkrvb.js +17 -0
  98. package/id-D-Q0uPFM.mjs +16 -0
  99. package/if-defined-CJ5EZLw2.js +815 -0
  100. package/if-defined-DjC5UMfF.mjs +815 -0
  101. package/image-BTGOf8bb.mjs +8 -0
  102. package/image-WFQO5bWa.js +9 -0
  103. package/index--O5ypTeK.mjs +70 -0
  104. package/index--Vg7VI9t.js +173 -0
  105. package/index-2iRSO1sa.mjs +9964 -0
  106. package/index-42Rpweo5.mjs +95 -0
  107. package/index-70kjE43k.mjs +90 -0
  108. package/index-8VyNYS01.js +273 -0
  109. package/index-B-dx8l0g.mjs +82 -0
  110. package/index-BB0nW9RB.mjs +198 -0
  111. package/index-BBwuv2SS.js +97 -0
  112. package/index-BIe-kofv.mjs +273 -0
  113. package/index-BQf6VHil.js +278 -0
  114. package/index-BWIZXhFv.mjs +630 -0
  115. package/index-BXkamf-I.js +337 -0
  116. package/index-BYTxCmKH.js +64 -0
  117. package/index-BYoOxo0S.js +218 -0
  118. package/index-Ba0tVdql.js +200 -0
  119. package/index-BdOAPWyt.mjs +210 -0
  120. package/index-BirWzf8c.mjs +71 -0
  121. package/index-BnCJUHtW.mjs +346 -0
  122. package/index-BuL2FC61.mjs +216 -0
  123. package/index-BxSUTfaY.js +88 -0
  124. package/index-C49C5Rxf.js +743 -0
  125. package/index-CNMDBpW7.js +346 -0
  126. package/index-CP0CGjqQ.mjs +263 -0
  127. package/index-CQaHcTZM.mjs +86 -0
  128. package/index-CRGXQei1.js +178 -0
  129. package/index-CSykUIfV.mjs +176 -0
  130. package/index-CWIHaLkQ.mjs +101 -0
  131. package/index-CZSDJd0P.mjs +1070 -0
  132. package/index-CZaV8JgR.mjs +49 -0
  133. package/index-CZjdy6QP.js +101 -0
  134. package/index-C_lIGGlC.js +632 -0
  135. package/index-CcgeRPs2.mjs +57 -0
  136. package/index-CeY_DRuc.js +566 -0
  137. package/index-ChFNkSxT.js +92 -0
  138. package/index-CkjZc20w.js +677 -0
  139. package/index-CtFcWwAd.js +72 -0
  140. package/index-D0mOfznC.mjs +362 -0
  141. package/index-DAtWLY21.js +84 -0
  142. package/index-DEs8H3w2.js +262 -0
  143. package/index-DLnxotbC.mjs +566 -0
  144. package/index-DN4fGDgg.mjs +743 -0
  145. package/index-DT_mc1hV.mjs +335 -0
  146. package/index-DZEwxUMS.js +59 -0
  147. package/index-DaRH_4bD.js +9939 -0
  148. package/index-Daok2ZKn.js +73 -0
  149. package/index-DomzHmwk.js +210 -0
  150. package/index-Dx7NyDyv.mjs +101 -0
  151. package/index-DyGir6_2.mjs +675 -0
  152. package/index-GglJmM2C.js +2237 -0
  153. package/index-H5b7UTeJ.mjs +173 -0
  154. package/index-NNZ1lNuc.mjs +168 -0
  155. package/index-RJd-gQcv.mjs +2235 -0
  156. package/index-dnFzVpGy.js +103 -0
  157. package/index-kwVLu8EV.js +168 -0
  158. package/index-miQwZPmn.js +51 -0
  159. package/index-oCj_SpOa.mjs +62 -0
  160. package/index-pNK-h_x9.js +1069 -0
  161. package/index-r6Kre1rx.js +362 -0
  162. package/index-xBD0nXoB.mjs +276 -0
  163. package/index.js +3 -3
  164. package/index.mjs +3 -3
  165. package/info-BKNAiN0k.js +8 -0
  166. package/info-DQE0s-A4.mjs +7 -0
  167. package/info-circle-C3uTocjH.js +17 -0
  168. package/info-circle-CIn6yeQo.mjs +16 -0
  169. package/lightbulb-CB-BmIop.js +8 -0
  170. package/lightbulb-Gv7IbnzO.mjs +7 -0
  171. package/mail-CFYm95wn.mjs +12 -0
  172. package/mail-GEwk-Fzr.js +13 -0
  173. package/mobile-CZ7ZBfa5.js +14 -0
  174. package/mobile-OIbnpFsU.mjs +13 -0
  175. package/more-C8N_RV55.mjs +15 -0
  176. package/more-CiQpPZwq.js +16 -0
  177. package/network-placeholder-CxEcczEx.mjs +18 -0
  178. package/network-placeholder-DwR8E8hP.js +19 -0
  179. package/nftPlaceholder-BFexVcGX.js +13 -0
  180. package/nftPlaceholder-MiYL110I.mjs +12 -0
  181. package/off-BNiMlpUU.mjs +8 -0
  182. package/off-iJHSK3Z7.js +9 -0
  183. package/onramp-Bs8HHFFY.js +1474 -0
  184. package/onramp-C6fuQfX7.mjs +1480 -0
  185. package/package.json +11 -11
  186. package/play-store-B4ssIYUA.js +37 -0
  187. package/play-store-D6nmQXhX.mjs +36 -0
  188. package/plus-Bh7z7Oc0.js +18 -0
  189. package/plus-C8ioZuCD.mjs +17 -0
  190. package/qr-code-CSVwaBLf.mjs +10 -0
  191. package/qr-code-YgtXPokK.js +11 -0
  192. package/react-BWxe90Ar.mjs +6342 -0
  193. package/react-BzZcQig5.js +6342 -0
  194. package/react-C_wTMVq_.js +23003 -0
  195. package/react-M-DnxvZl.mjs +23003 -0
  196. package/reactjs/components/BridgeForm/BridgeForm.js +2 -1
  197. package/reactjs/components/BridgeForm/BridgeForm.mjs +2 -1
  198. package/reactjs/components/Connect/BridgeAccountDisplay.js +3 -2
  199. package/reactjs/components/Connect/BridgeAccountDisplay.mjs +3 -2
  200. package/reactjs/components/Connect/CustomConnectButton.js +3 -2
  201. package/reactjs/components/Connect/CustomConnectButton.mjs +3 -2
  202. package/reactjs/components/Connect/SwitchChainButton.js +4 -3
  203. package/reactjs/components/Connect/SwitchChainButton.mjs +4 -3
  204. package/reactjs/components/DisplayAmount/DisplayAmount.js +1 -1
  205. package/reactjs/components/DisplayAmount/DisplayAmount.mjs +1 -1
  206. package/reactjs/components/TokenSelector/components/TokenItem.js +1 -1
  207. package/reactjs/components/TokenSelector/components/TokenItem.mjs +1 -1
  208. package/reactjs/hooks/useAccount.d.ts +4 -4
  209. package/reactjs/hooks/useAccount.js +3 -2
  210. package/reactjs/hooks/useAccount.mjs +3 -2
  211. package/reactjs/hooks/useGetChainId.js +1 -1
  212. package/reactjs/hooks/useGetChainId.mjs +1 -1
  213. package/reactjs/index.js +3 -3
  214. package/reactjs/index.mjs +3 -3
  215. package/reactjs/init/init.js +4 -3
  216. package/reactjs/init/init.mjs +4 -3
  217. package/reactjs/init/tests/init.spec.js +2 -2
  218. package/reactjs/init/tests/init.spec.mjs +2 -2
  219. package/reactjs/queries/useGetEvmTokensBalances.query.js +3 -2
  220. package/reactjs/queries/useGetEvmTokensBalances.query.mjs +3 -2
  221. package/reactjs/reexports.js +3 -3
  222. package/reactjs/reexports.mjs +3 -3
  223. package/reactjs/utils/getCleanStringAmount.js +1 -1
  224. package/reactjs/utils/getCleanStringAmount.mjs +1 -1
  225. package/reactjs/utils/hasEnoughFunds.js +1 -1
  226. package/reactjs/utils/hasEnoughFunds.mjs +1 -1
  227. package/reactjs/utils/isStringFloat.js +1 -1
  228. package/reactjs/utils/isStringFloat.mjs +1 -1
  229. package/reactjs/utils/roundAmount.js +1 -1
  230. package/reactjs/utils/roundAmount.mjs +1 -1
  231. package/receive-CK0hRQPr.js +212 -0
  232. package/receive-CQcD6bZf.mjs +212 -0
  233. package/recycle-horizontal--x5cMoTE.js +14 -0
  234. package/recycle-horizontal-QI0xtDHK.mjs +13 -0
  235. package/ref-CqxfRkBm.mjs +41 -0
  236. package/ref-FGI2cUQB.js +41 -0
  237. package/refresh-CFNHjhDi.js +13 -0
  238. package/refresh-CSOC1NUY.mjs +12 -0
  239. package/reown-logo-BfU5xFX5.js +17 -0
  240. package/reown-logo-CZAEp1jU.mjs +16 -0
  241. package/search-Do_rb-9-.mjs +12 -0
  242. package/search-V9CGMHkm.js +13 -0
  243. package/send-D-5G7tDL.mjs +1204 -0
  244. package/send-D4yYsIHV.mjs +19 -0
  245. package/send-DoiSHLsX.js +1202 -0
  246. package/send-_jfNFrys.js +20 -0
  247. package/socials-BL7-97fT.mjs +758 -0
  248. package/socials-DF0CK9cN.js +756 -0
  249. package/solana-BQ0Jh8lh.js +18 -0
  250. package/solana-YAkDp6j_.mjs +17 -0
  251. package/swapHorizontal-DOIo-Ccx.mjs +12 -0
  252. package/swapHorizontal-OHKtz4Gu.js +13 -0
  253. package/swapHorizontalBold-D7QmFj-c.js +13 -0
  254. package/swapHorizontalBold-DDroA0Af.mjs +12 -0
  255. package/swapHorizontalMedium-CU_v0kFz.mjs +20 -0
  256. package/swapHorizontalMedium-D-yMmtml.js +21 -0
  257. package/swapHorizontalRoundedBold-CHvbmnjw.js +13 -0
  258. package/swapHorizontalRoundedBold-DXMH0sgK.mjs +12 -0
  259. package/swapVertical-CH7fTK6w.js +13 -0
  260. package/swapVertical-HJZ6rFcr.mjs +12 -0
  261. package/swaps-CETflhdU.js +1952 -0
  262. package/swaps-DRUV6d3p.mjs +1954 -0
  263. package/telegram-CsCauOwj.mjs +20 -0
  264. package/telegram-DKEcF_Tq.js +21 -0
  265. package/three-dots-B-7hr8Nl.js +10 -0
  266. package/three-dots-LNZ_fjP7.mjs +9 -0
  267. package/transactions-BTTsGV2W.mjs +37 -0
  268. package/transactions-mpNNlClw.js +37 -0
  269. package/twitch-CCWVT2ij.js +23 -0
  270. package/twitch-Dg1CCQvd.mjs +22 -0
  271. package/twitterIcon-BjR09Cj9.mjs +10 -0
  272. package/twitterIcon-CeEs0iDJ.js +11 -0
  273. package/verify-B8WZq7kt.mjs +12 -0
  274. package/verify-filled-BeqC1imk.mjs +12 -0
  275. package/verify-filled-C-mv3ApD.js +13 -0
  276. package/verify-yATdPqt-.js +13 -0
  277. package/w3m-modal-3GziKj7h.js +1254 -0
  278. package/w3m-modal-81Z5PngE.mjs +1255 -0
  279. package/wallet-BMXEH23x.js +13 -0
  280. package/wallet-CNAVQCfm.mjs +12 -0
  281. package/wallet-placeholder-CQ-7CmVN.mjs +18 -0
  282. package/wallet-placeholder-CdoQy2e6.js +19 -0
  283. package/walletconnect-ACr-R1QZ.mjs +38 -0
  284. package/walletconnect-BWSkiS2F.js +39 -0
  285. package/warning-circle-CYnuYwpt.js +17 -0
  286. package/warning-circle-HV2lOiCj.mjs +16 -0
  287. package/x-CW5dozRj.js +17 -0
  288. package/x-Cgm2OFpL.mjs +16 -0
  289. package/x-mark-CR8SpZvu.js +8 -0
  290. package/x-mark-u0KJjUJ1.mjs +7 -0
  291. package/index-B4Eq5P3w.mjs +0 -91
  292. package/index-C4WV9nam.js +0 -329
  293. package/index-CWMcKi_X.js +0 -107
  294. package/index-D8E0O3qL.mjs +0 -68744
  295. package/index-DJ8CdHSw.mjs +0 -107
  296. package/index-nigVQYBu.js +0 -68665
  297. package/react-C43nEIqn.js +0 -3133
  298. package/react-DKUsVej7.js +0 -50
  299. package/react-Dp0H8q2z.mjs +0 -50
  300. package/react-wMhOUFOm.mjs +0 -3133
  301. package/w3m-modal-DLyg7Voy.js +0 -356
  302. package/w3m-modal-hC-B8qZP.mjs +0 -356
@@ -0,0 +1,743 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const bitcoin = require("./bitcoin-DAvQGpeP.js");
4
+ const react = require("./react-BzZcQig5.js");
5
+ const ifDefined = require("./if-defined-CJ5EZLw2.js");
6
+ require("./index-CtFcWwAd.js");
7
+ require("./index-BBwuv2SS.js");
8
+ const SwapCalculationUtil = {
9
+ getGasPriceInEther(gas, gasPrice) {
10
+ const totalGasCostInWei = gasPrice * gas;
11
+ const totalGasCostInEther = Number(totalGasCostInWei) / 1e18;
12
+ return totalGasCostInEther;
13
+ },
14
+ getGasPriceInUSD(networkPrice, gas, gasPrice) {
15
+ const totalGasCostInEther = SwapCalculationUtil.getGasPriceInEther(gas, gasPrice);
16
+ const networkPriceInUSD = react.NumberUtil.bigNumber(networkPrice);
17
+ const gasCostInUSD = networkPriceInUSD.times(totalGasCostInEther);
18
+ return gasCostInUSD.toNumber();
19
+ },
20
+ getPriceImpact({ sourceTokenAmount, sourceTokenPriceInUSD, toTokenPriceInUSD, toTokenAmount }) {
21
+ const inputValue = react.NumberUtil.bigNumber(sourceTokenAmount).times(sourceTokenPriceInUSD);
22
+ const outputValue = react.NumberUtil.bigNumber(toTokenAmount).times(toTokenPriceInUSD);
23
+ const priceImpact = inputValue.minus(outputValue).div(inputValue).times(100);
24
+ return priceImpact.toNumber();
25
+ },
26
+ getMaxSlippage(slippage, toTokenAmount) {
27
+ const slippageToleranceDecimal = react.NumberUtil.bigNumber(slippage).div(100);
28
+ const maxSlippageAmount = react.NumberUtil.multiply(toTokenAmount, slippageToleranceDecimal);
29
+ return maxSlippageAmount.toNumber();
30
+ },
31
+ getProviderFee(sourceTokenAmount, feePercentage = 85e-4) {
32
+ const providerFee = react.NumberUtil.bigNumber(sourceTokenAmount).times(feePercentage);
33
+ return providerFee.toString();
34
+ },
35
+ isInsufficientNetworkTokenForGas(networkBalanceInUSD, gasPriceInUSD) {
36
+ const gasPrice = gasPriceInUSD || "0";
37
+ if (react.NumberUtil.bigNumber(networkBalanceInUSD).eq(0)) {
38
+ return true;
39
+ }
40
+ return react.NumberUtil.bigNumber(react.NumberUtil.bigNumber(gasPrice)).gt(networkBalanceInUSD);
41
+ },
42
+ isInsufficientSourceTokenForSwap(sourceTokenAmount, sourceTokenAddress, balance) {
43
+ var _a, _b;
44
+ const sourceTokenBalance = (_b = (_a = balance == null ? void 0 : balance.find((token) => token.address === sourceTokenAddress)) == null ? void 0 : _a.quantity) == null ? void 0 : _b.numeric;
45
+ const isInSufficientBalance = react.NumberUtil.bigNumber(sourceTokenBalance || "0").lt(sourceTokenAmount);
46
+ return isInSufficientBalance;
47
+ },
48
+ getToTokenAmount({ sourceToken, toToken, sourceTokenPrice, toTokenPrice, sourceTokenAmount }) {
49
+ if (sourceTokenAmount === "0") {
50
+ return "0";
51
+ }
52
+ if (!sourceToken || !toToken) {
53
+ return "0";
54
+ }
55
+ const sourceTokenDecimals = sourceToken.decimals;
56
+ const sourceTokenPriceInUSD = sourceTokenPrice;
57
+ const toTokenDecimals = toToken.decimals;
58
+ const toTokenPriceInUSD = toTokenPrice;
59
+ if (toTokenPriceInUSD <= 0) {
60
+ return "0";
61
+ }
62
+ const providerFee = react.NumberUtil.bigNumber(sourceTokenAmount).times(85e-4);
63
+ const adjustedSourceTokenAmount = react.NumberUtil.bigNumber(sourceTokenAmount).minus(providerFee);
64
+ const sourceAmountInSmallestUnit = adjustedSourceTokenAmount.times(react.NumberUtil.bigNumber(10).pow(sourceTokenDecimals));
65
+ const priceRatio = react.NumberUtil.bigNumber(sourceTokenPriceInUSD).div(toTokenPriceInUSD);
66
+ const decimalDifference = sourceTokenDecimals - toTokenDecimals;
67
+ const toTokenAmountInSmallestUnit = sourceAmountInSmallestUnit.times(priceRatio).div(react.NumberUtil.bigNumber(10).pow(decimalDifference));
68
+ const toTokenAmount = toTokenAmountInSmallestUnit.div(react.NumberUtil.bigNumber(10).pow(toTokenDecimals));
69
+ const amount = toTokenAmount.toFixed(toTokenDecimals).toString();
70
+ return amount;
71
+ }
72
+ };
73
+ const INITIAL_GAS_LIMIT = 15e4;
74
+ const TO_AMOUNT_DECIMALS = 6;
75
+ const initialState = {
76
+ // Loading states
77
+ initializing: false,
78
+ initialized: false,
79
+ loadingPrices: false,
80
+ loadingQuote: false,
81
+ loadingApprovalTransaction: false,
82
+ loadingBuildTransaction: false,
83
+ loadingTransaction: false,
84
+ // Error states
85
+ fetchError: false,
86
+ // Approval & Swap transaction states
87
+ approvalTransaction: void 0,
88
+ swapTransaction: void 0,
89
+ transactionError: void 0,
90
+ // Input values
91
+ sourceToken: void 0,
92
+ sourceTokenAmount: "",
93
+ sourceTokenPriceInUSD: 0,
94
+ toToken: void 0,
95
+ toTokenAmount: "",
96
+ toTokenPriceInUSD: 0,
97
+ networkPrice: "0",
98
+ networkBalanceInUSD: "0",
99
+ networkTokenSymbol: "",
100
+ inputError: void 0,
101
+ // Request values
102
+ slippage: react.ConstantsUtil.CONVERT_SLIPPAGE_TOLERANCE,
103
+ // Tokens
104
+ tokens: void 0,
105
+ popularTokens: void 0,
106
+ suggestedTokens: void 0,
107
+ foundTokens: void 0,
108
+ myTokensWithBalance: void 0,
109
+ tokensPriceMap: {},
110
+ // Calculations
111
+ gasFee: "0",
112
+ gasPriceInUSD: 0,
113
+ priceImpact: void 0,
114
+ maxSlippage: void 0,
115
+ providerFee: void 0
116
+ };
117
+ const state = bitcoin.proxy(initialState);
118
+ const controller = {
119
+ state,
120
+ subscribe(callback) {
121
+ return bitcoin.subscribe(state, () => callback(state));
122
+ },
123
+ subscribeKey(key, callback) {
124
+ return bitcoin.subscribeKey(state, key, callback);
125
+ },
126
+ getParams() {
127
+ var _a, _b, _c, _d, _e, _f, _g, _h;
128
+ const caipAddress = react.ChainController.state.activeCaipAddress;
129
+ const namespace = react.ChainController.state.activeChain;
130
+ const address = react.CoreHelperUtil.getPlainAddress(caipAddress);
131
+ const networkAddress = react.getActiveNetworkTokenAddress();
132
+ const connectorId = react.ConnectorController.getConnectorId(namespace);
133
+ if (!address) {
134
+ throw new Error("No address found to swap the tokens from.");
135
+ }
136
+ const invalidToToken = !((_a = state.toToken) == null ? void 0 : _a.address) || !((_b = state.toToken) == null ? void 0 : _b.decimals);
137
+ const invalidSourceToken = !((_c = state.sourceToken) == null ? void 0 : _c.address) || !((_d = state.sourceToken) == null ? void 0 : _d.decimals) || !react.NumberUtil.bigNumber(state.sourceTokenAmount).gt(0);
138
+ const invalidSourceTokenAmount = !state.sourceTokenAmount;
139
+ return {
140
+ networkAddress,
141
+ fromAddress: address,
142
+ fromCaipAddress: caipAddress,
143
+ sourceTokenAddress: (_e = state.sourceToken) == null ? void 0 : _e.address,
144
+ toTokenAddress: (_f = state.toToken) == null ? void 0 : _f.address,
145
+ toTokenAmount: state.toTokenAmount,
146
+ toTokenDecimals: (_g = state.toToken) == null ? void 0 : _g.decimals,
147
+ sourceTokenAmount: state.sourceTokenAmount,
148
+ sourceTokenDecimals: (_h = state.sourceToken) == null ? void 0 : _h.decimals,
149
+ invalidToToken,
150
+ invalidSourceToken,
151
+ invalidSourceTokenAmount,
152
+ availableToSwap: caipAddress && !invalidToToken && !invalidSourceToken && !invalidSourceTokenAmount,
153
+ isAuthConnector: connectorId === react.ConstantsUtil$1.CONNECTOR_ID.AUTH
154
+ };
155
+ },
156
+ setSourceToken(sourceToken) {
157
+ if (!sourceToken) {
158
+ state.sourceToken = sourceToken;
159
+ state.sourceTokenAmount = "";
160
+ state.sourceTokenPriceInUSD = 0;
161
+ return;
162
+ }
163
+ state.sourceToken = sourceToken;
164
+ SwapController.setTokenPrice(sourceToken.address, "sourceToken");
165
+ },
166
+ setSourceTokenAmount(amount) {
167
+ state.sourceTokenAmount = amount;
168
+ },
169
+ setToToken(toToken) {
170
+ if (!toToken) {
171
+ state.toToken = toToken;
172
+ state.toTokenAmount = "";
173
+ state.toTokenPriceInUSD = 0;
174
+ return;
175
+ }
176
+ state.toToken = toToken;
177
+ SwapController.setTokenPrice(toToken.address, "toToken");
178
+ },
179
+ setToTokenAmount(amount) {
180
+ state.toTokenAmount = amount ? react.NumberUtil.formatNumberToLocalString(amount, TO_AMOUNT_DECIMALS) : "";
181
+ },
182
+ async setTokenPrice(address, target) {
183
+ let price = state.tokensPriceMap[address] || 0;
184
+ if (!price) {
185
+ state.loadingPrices = true;
186
+ price = await SwapController.getAddressPrice(address);
187
+ }
188
+ if (target === "sourceToken") {
189
+ state.sourceTokenPriceInUSD = price;
190
+ } else if (target === "toToken") {
191
+ state.toTokenPriceInUSD = price;
192
+ }
193
+ if (state.loadingPrices) {
194
+ state.loadingPrices = false;
195
+ }
196
+ if (SwapController.getParams().availableToSwap) {
197
+ SwapController.swapTokens();
198
+ }
199
+ },
200
+ switchTokens() {
201
+ if (state.initializing || !state.initialized) {
202
+ return;
203
+ }
204
+ const newSourceToken = state.toToken ? { ...state.toToken } : void 0;
205
+ const newToToken = state.sourceToken ? { ...state.sourceToken } : void 0;
206
+ const newSourceTokenAmount = newSourceToken && state.toTokenAmount === "" ? "1" : state.toTokenAmount;
207
+ SwapController.setSourceToken(newSourceToken);
208
+ SwapController.setToToken(newToToken);
209
+ SwapController.setSourceTokenAmount(newSourceTokenAmount);
210
+ SwapController.setToTokenAmount("");
211
+ SwapController.swapTokens();
212
+ },
213
+ resetState() {
214
+ state.myTokensWithBalance = initialState.myTokensWithBalance;
215
+ state.tokensPriceMap = initialState.tokensPriceMap;
216
+ state.initialized = initialState.initialized;
217
+ state.sourceToken = initialState.sourceToken;
218
+ state.sourceTokenAmount = initialState.sourceTokenAmount;
219
+ state.sourceTokenPriceInUSD = initialState.sourceTokenPriceInUSD;
220
+ state.toToken = initialState.toToken;
221
+ state.toTokenAmount = initialState.toTokenAmount;
222
+ state.toTokenPriceInUSD = initialState.toTokenPriceInUSD;
223
+ state.networkPrice = initialState.networkPrice;
224
+ state.networkTokenSymbol = initialState.networkTokenSymbol;
225
+ state.networkBalanceInUSD = initialState.networkBalanceInUSD;
226
+ state.inputError = initialState.inputError;
227
+ state.myTokensWithBalance = initialState.myTokensWithBalance;
228
+ },
229
+ resetValues() {
230
+ var _a;
231
+ const { networkAddress } = SwapController.getParams();
232
+ const networkToken = (_a = state.tokens) == null ? void 0 : _a.find((token) => token.address === networkAddress);
233
+ SwapController.setSourceToken(networkToken);
234
+ SwapController.setToToken(void 0);
235
+ },
236
+ getApprovalLoadingState() {
237
+ return state.loadingApprovalTransaction;
238
+ },
239
+ clearError() {
240
+ state.transactionError = void 0;
241
+ },
242
+ async initializeState() {
243
+ if (state.initializing) {
244
+ return;
245
+ }
246
+ state.initializing = true;
247
+ if (!state.initialized) {
248
+ try {
249
+ await SwapController.fetchTokens();
250
+ state.initialized = true;
251
+ } catch (error) {
252
+ state.initialized = false;
253
+ react.SnackController.showError("Failed to initialize swap");
254
+ react.RouterController.goBack();
255
+ }
256
+ }
257
+ state.initializing = false;
258
+ },
259
+ async fetchTokens() {
260
+ var _a;
261
+ const { networkAddress } = SwapController.getParams();
262
+ await SwapController.getTokenList();
263
+ await SwapController.getNetworkTokenPrice();
264
+ await SwapController.getMyTokensWithBalance();
265
+ const networkToken = (_a = state.tokens) == null ? void 0 : _a.find((token) => token.address === networkAddress);
266
+ if (networkToken) {
267
+ state.networkTokenSymbol = networkToken.symbol;
268
+ SwapController.setSourceToken(networkToken);
269
+ SwapController.setSourceTokenAmount("1");
270
+ }
271
+ },
272
+ async getTokenList() {
273
+ const tokens = await react.SwapApiUtil.getTokenList();
274
+ state.tokens = tokens;
275
+ state.popularTokens = tokens.sort((aTokenInfo, bTokenInfo) => {
276
+ if (aTokenInfo.symbol < bTokenInfo.symbol) {
277
+ return -1;
278
+ }
279
+ if (aTokenInfo.symbol > bTokenInfo.symbol) {
280
+ return 1;
281
+ }
282
+ return 0;
283
+ });
284
+ state.suggestedTokens = tokens.filter((token) => {
285
+ if (react.ConstantsUtil.SWAP_SUGGESTED_TOKENS.includes(token.symbol)) {
286
+ return true;
287
+ }
288
+ return false;
289
+ }, {});
290
+ },
291
+ async getAddressPrice(address) {
292
+ var _a, _b;
293
+ const existPrice = state.tokensPriceMap[address];
294
+ if (existPrice) {
295
+ return existPrice;
296
+ }
297
+ const response = await react.BlockchainApiController.fetchTokenPrice({
298
+ addresses: [address]
299
+ });
300
+ const fungibles = (response == null ? void 0 : response.fungibles) || [];
301
+ const allTokens = [...state.tokens || [], ...state.myTokensWithBalance || []];
302
+ const symbol = (_a = allTokens == null ? void 0 : allTokens.find((token) => token.address === address)) == null ? void 0 : _a.symbol;
303
+ const price = ((_b = fungibles.find((p) => p.symbol.toLowerCase() === (symbol == null ? void 0 : symbol.toLowerCase()))) == null ? void 0 : _b.price) || 0;
304
+ const priceAsFloat = parseFloat(price.toString());
305
+ state.tokensPriceMap[address] = priceAsFloat;
306
+ return priceAsFloat;
307
+ },
308
+ async getNetworkTokenPrice() {
309
+ var _a;
310
+ const { networkAddress } = SwapController.getParams();
311
+ const response = await react.BlockchainApiController.fetchTokenPrice({
312
+ addresses: [networkAddress]
313
+ }).catch(() => {
314
+ react.SnackController.showError("Failed to fetch network token price");
315
+ return { fungibles: [] };
316
+ });
317
+ const token = (_a = response.fungibles) == null ? void 0 : _a[0];
318
+ const price = (token == null ? void 0 : token.price.toString()) || "0";
319
+ state.tokensPriceMap[networkAddress] = parseFloat(price);
320
+ state.networkTokenSymbol = (token == null ? void 0 : token.symbol) || "";
321
+ state.networkPrice = price;
322
+ },
323
+ async getMyTokensWithBalance(forceUpdate) {
324
+ const balances = await react.BalanceUtil.getMyTokensWithBalance(forceUpdate);
325
+ const swapBalances = react.SwapApiUtil.mapBalancesToSwapTokens(balances);
326
+ if (!swapBalances) {
327
+ return;
328
+ }
329
+ await SwapController.getInitialGasPrice();
330
+ SwapController.setBalances(swapBalances);
331
+ },
332
+ setBalances(balances) {
333
+ const { networkAddress } = SwapController.getParams();
334
+ const caipNetwork = react.ChainController.state.activeCaipNetwork;
335
+ if (!caipNetwork) {
336
+ return;
337
+ }
338
+ const networkToken = balances.find((token) => token.address === networkAddress);
339
+ balances.forEach((token) => {
340
+ state.tokensPriceMap[token.address] = token.price || 0;
341
+ });
342
+ state.myTokensWithBalance = balances.filter((token) => token.address.startsWith(caipNetwork.caipNetworkId));
343
+ state.networkBalanceInUSD = networkToken ? react.NumberUtil.multiply(networkToken.quantity.numeric, networkToken.price).toString() : "0";
344
+ },
345
+ async getInitialGasPrice() {
346
+ var _a, _b;
347
+ const res = await react.SwapApiUtil.fetchGasPrice();
348
+ if (!res) {
349
+ return { gasPrice: null, gasPriceInUSD: null };
350
+ }
351
+ switch ((_b = (_a = react.ChainController.state) == null ? void 0 : _a.activeCaipNetwork) == null ? void 0 : _b.chainNamespace) {
352
+ case "solana":
353
+ state.gasFee = res.standard ?? "0";
354
+ state.gasPriceInUSD = react.NumberUtil.multiply(res.standard, state.networkPrice).div(1e9).toNumber();
355
+ return {
356
+ gasPrice: BigInt(state.gasFee),
357
+ gasPriceInUSD: Number(state.gasPriceInUSD)
358
+ };
359
+ case "eip155":
360
+ default:
361
+ const value = res.standard ?? "0";
362
+ const gasFee = BigInt(value);
363
+ const gasLimit = BigInt(INITIAL_GAS_LIMIT);
364
+ const gasPrice = SwapCalculationUtil.getGasPriceInUSD(state.networkPrice, gasLimit, gasFee);
365
+ state.gasFee = value;
366
+ state.gasPriceInUSD = gasPrice;
367
+ return { gasPrice: gasFee, gasPriceInUSD: gasPrice };
368
+ }
369
+ },
370
+ // -- Swap -------------------------------------- //
371
+ async swapTokens() {
372
+ var _a, _b;
373
+ const address = react.AccountController.state.address;
374
+ const sourceToken = state.sourceToken;
375
+ const toToken = state.toToken;
376
+ const haveSourceTokenAmount = react.NumberUtil.bigNumber(state.sourceTokenAmount).gt(0);
377
+ if (!haveSourceTokenAmount) {
378
+ SwapController.setToTokenAmount("");
379
+ }
380
+ if (!toToken || !sourceToken || state.loadingPrices || !haveSourceTokenAmount) {
381
+ return;
382
+ }
383
+ state.loadingQuote = true;
384
+ const amountDecimal = react.NumberUtil.bigNumber(state.sourceTokenAmount).times(10 ** sourceToken.decimals).round(0);
385
+ try {
386
+ const quoteResponse = await react.BlockchainApiController.fetchSwapQuote({
387
+ userAddress: address,
388
+ from: sourceToken.address,
389
+ to: toToken.address,
390
+ gasPrice: state.gasFee,
391
+ amount: amountDecimal.toString()
392
+ });
393
+ state.loadingQuote = false;
394
+ const quoteToAmount = (_b = (_a = quoteResponse == null ? void 0 : quoteResponse.quotes) == null ? void 0 : _a[0]) == null ? void 0 : _b.toAmount;
395
+ if (!quoteToAmount) {
396
+ react.AlertController.open({
397
+ shortMessage: "Incorrect amount",
398
+ longMessage: "Please enter a valid amount"
399
+ }, "error");
400
+ return;
401
+ }
402
+ const toTokenAmount = react.NumberUtil.bigNumber(quoteToAmount).div(10 ** toToken.decimals).toString();
403
+ SwapController.setToTokenAmount(toTokenAmount);
404
+ const isInsufficientToken = SwapController.hasInsufficientToken(state.sourceTokenAmount, sourceToken.address);
405
+ if (isInsufficientToken) {
406
+ state.inputError = "Insufficient balance";
407
+ } else {
408
+ state.inputError = void 0;
409
+ SwapController.setTransactionDetails();
410
+ }
411
+ } catch (error) {
412
+ state.loadingQuote = false;
413
+ state.inputError = "Insufficient balance";
414
+ }
415
+ },
416
+ // -- Create Transactions -------------------------------------- //
417
+ async getTransaction() {
418
+ const { fromCaipAddress, availableToSwap } = SwapController.getParams();
419
+ const sourceToken = state.sourceToken;
420
+ const toToken = state.toToken;
421
+ if (!fromCaipAddress || !availableToSwap || !sourceToken || !toToken || state.loadingQuote) {
422
+ return void 0;
423
+ }
424
+ try {
425
+ state.loadingBuildTransaction = true;
426
+ const hasAllowance = await react.SwapApiUtil.fetchSwapAllowance({
427
+ userAddress: fromCaipAddress,
428
+ tokenAddress: sourceToken.address,
429
+ sourceTokenAmount: state.sourceTokenAmount,
430
+ sourceTokenDecimals: sourceToken.decimals
431
+ });
432
+ let transaction = void 0;
433
+ if (hasAllowance) {
434
+ transaction = await SwapController.createSwapTransaction();
435
+ } else {
436
+ transaction = await SwapController.createAllowanceTransaction();
437
+ }
438
+ state.loadingBuildTransaction = false;
439
+ state.fetchError = false;
440
+ return transaction;
441
+ } catch (error) {
442
+ react.RouterController.goBack();
443
+ react.SnackController.showError("Failed to check allowance");
444
+ state.loadingBuildTransaction = false;
445
+ state.approvalTransaction = void 0;
446
+ state.swapTransaction = void 0;
447
+ state.fetchError = true;
448
+ return void 0;
449
+ }
450
+ },
451
+ async createAllowanceTransaction() {
452
+ const { fromCaipAddress, sourceTokenAddress, toTokenAddress } = SwapController.getParams();
453
+ if (!fromCaipAddress || !toTokenAddress) {
454
+ return void 0;
455
+ }
456
+ if (!sourceTokenAddress) {
457
+ throw new Error("createAllowanceTransaction - No source token address found.");
458
+ }
459
+ try {
460
+ const response = await react.BlockchainApiController.generateApproveCalldata({
461
+ from: sourceTokenAddress,
462
+ to: toTokenAddress,
463
+ userAddress: fromCaipAddress
464
+ });
465
+ const transaction = {
466
+ data: response.tx.data,
467
+ to: react.CoreHelperUtil.getPlainAddress(response.tx.from),
468
+ gasPrice: BigInt(response.tx.eip155.gasPrice),
469
+ value: BigInt(response.tx.value),
470
+ toAmount: state.toTokenAmount
471
+ };
472
+ state.swapTransaction = void 0;
473
+ state.approvalTransaction = {
474
+ data: transaction.data,
475
+ to: transaction.to,
476
+ gasPrice: transaction.gasPrice,
477
+ value: transaction.value,
478
+ toAmount: transaction.toAmount
479
+ };
480
+ return {
481
+ data: transaction.data,
482
+ to: transaction.to,
483
+ gasPrice: transaction.gasPrice,
484
+ value: transaction.value,
485
+ toAmount: transaction.toAmount
486
+ };
487
+ } catch (error) {
488
+ react.RouterController.goBack();
489
+ react.SnackController.showError("Failed to create approval transaction");
490
+ state.approvalTransaction = void 0;
491
+ state.swapTransaction = void 0;
492
+ state.fetchError = true;
493
+ return void 0;
494
+ }
495
+ },
496
+ async createSwapTransaction() {
497
+ var _a;
498
+ const { networkAddress, fromCaipAddress, sourceTokenAmount } = SwapController.getParams();
499
+ const sourceToken = state.sourceToken;
500
+ const toToken = state.toToken;
501
+ if (!fromCaipAddress || !sourceTokenAmount || !sourceToken || !toToken) {
502
+ return void 0;
503
+ }
504
+ const amount = (_a = react.ConnectionController.parseUnits(sourceTokenAmount, sourceToken.decimals)) == null ? void 0 : _a.toString();
505
+ try {
506
+ const response = await react.BlockchainApiController.generateSwapCalldata({
507
+ userAddress: fromCaipAddress,
508
+ from: sourceToken.address,
509
+ to: toToken.address,
510
+ amount,
511
+ disableEstimate: true
512
+ });
513
+ const isSourceTokenIsNetworkToken = sourceToken.address === networkAddress;
514
+ const gas = BigInt(response.tx.eip155.gas);
515
+ const gasPrice = BigInt(response.tx.eip155.gasPrice);
516
+ const transaction = {
517
+ data: response.tx.data,
518
+ to: react.CoreHelperUtil.getPlainAddress(response.tx.to),
519
+ gas,
520
+ gasPrice,
521
+ value: isSourceTokenIsNetworkToken ? BigInt(amount ?? "0") : BigInt("0"),
522
+ toAmount: state.toTokenAmount
523
+ };
524
+ state.gasPriceInUSD = SwapCalculationUtil.getGasPriceInUSD(state.networkPrice, gas, gasPrice);
525
+ state.approvalTransaction = void 0;
526
+ state.swapTransaction = transaction;
527
+ return transaction;
528
+ } catch (error) {
529
+ react.RouterController.goBack();
530
+ react.SnackController.showError("Failed to create transaction");
531
+ state.approvalTransaction = void 0;
532
+ state.swapTransaction = void 0;
533
+ state.fetchError = true;
534
+ return void 0;
535
+ }
536
+ },
537
+ // -- Send Transactions --------------------------------- //
538
+ async sendTransactionForApproval(data) {
539
+ var _a, _b, _c;
540
+ const { fromAddress, isAuthConnector } = SwapController.getParams();
541
+ state.loadingApprovalTransaction = true;
542
+ const approveLimitMessage = `Approve limit increase in your wallet`;
543
+ if (isAuthConnector) {
544
+ react.RouterController.pushTransactionStack({
545
+ onSuccess() {
546
+ react.SnackController.showLoading(approveLimitMessage);
547
+ }
548
+ });
549
+ } else {
550
+ react.SnackController.showLoading(approveLimitMessage);
551
+ }
552
+ try {
553
+ await react.ConnectionController.sendTransaction({
554
+ address: fromAddress,
555
+ to: data.to,
556
+ data: data.data,
557
+ value: data.value,
558
+ chainNamespace: "eip155"
559
+ });
560
+ await SwapController.swapTokens();
561
+ await SwapController.getTransaction();
562
+ state.approvalTransaction = void 0;
563
+ state.loadingApprovalTransaction = false;
564
+ } catch (err) {
565
+ const error = err;
566
+ state.transactionError = error == null ? void 0 : error.shortMessage;
567
+ state.loadingApprovalTransaction = false;
568
+ react.SnackController.showError((error == null ? void 0 : error.shortMessage) || "Transaction error");
569
+ react.EventsController.sendEvent({
570
+ type: "track",
571
+ event: "SWAP_APPROVAL_ERROR",
572
+ properties: {
573
+ message: (error == null ? void 0 : error.shortMessage) || (error == null ? void 0 : error.message) || "Unknown",
574
+ network: ((_a = react.ChainController.state.activeCaipNetwork) == null ? void 0 : _a.caipNetworkId) || "",
575
+ swapFromToken: ((_b = SwapController.state.sourceToken) == null ? void 0 : _b.symbol) || "",
576
+ swapToToken: ((_c = SwapController.state.toToken) == null ? void 0 : _c.symbol) || "",
577
+ swapFromAmount: SwapController.state.sourceTokenAmount || "",
578
+ swapToAmount: SwapController.state.toTokenAmount || "",
579
+ isSmartAccount: react.getPreferredAccountType("eip155") === react.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
580
+ }
581
+ });
582
+ }
583
+ },
584
+ async sendTransactionForSwap(data) {
585
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
586
+ if (!data) {
587
+ return void 0;
588
+ }
589
+ const { fromAddress, toTokenAmount, isAuthConnector } = SwapController.getParams();
590
+ state.loadingTransaction = true;
591
+ const snackbarPendingMessage = `Swapping ${(_a = state.sourceToken) == null ? void 0 : _a.symbol} to ${react.NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${(_b = state.toToken) == null ? void 0 : _b.symbol}`;
592
+ const snackbarSuccessMessage = `Swapped ${(_c = state.sourceToken) == null ? void 0 : _c.symbol} to ${react.NumberUtil.formatNumberToLocalString(toTokenAmount, 3)} ${(_d = state.toToken) == null ? void 0 : _d.symbol}`;
593
+ if (isAuthConnector) {
594
+ react.RouterController.pushTransactionStack({
595
+ onSuccess() {
596
+ react.RouterController.replace("Account");
597
+ react.SnackController.showLoading(snackbarPendingMessage);
598
+ controller.resetState();
599
+ }
600
+ });
601
+ } else {
602
+ react.SnackController.showLoading("Confirm transaction in your wallet");
603
+ }
604
+ try {
605
+ const forceUpdateAddresses = [(_e = state.sourceToken) == null ? void 0 : _e.address, (_f = state.toToken) == null ? void 0 : _f.address].join(",");
606
+ const transactionHash = await react.ConnectionController.sendTransaction({
607
+ address: fromAddress,
608
+ to: data.to,
609
+ data: data.data,
610
+ value: data.value,
611
+ chainNamespace: "eip155"
612
+ });
613
+ state.loadingTransaction = false;
614
+ react.SnackController.showSuccess(snackbarSuccessMessage);
615
+ react.EventsController.sendEvent({
616
+ type: "track",
617
+ event: "SWAP_SUCCESS",
618
+ properties: {
619
+ network: ((_g = react.ChainController.state.activeCaipNetwork) == null ? void 0 : _g.caipNetworkId) || "",
620
+ swapFromToken: ((_h = SwapController.state.sourceToken) == null ? void 0 : _h.symbol) || "",
621
+ swapToToken: ((_i = SwapController.state.toToken) == null ? void 0 : _i.symbol) || "",
622
+ swapFromAmount: SwapController.state.sourceTokenAmount || "",
623
+ swapToAmount: SwapController.state.toTokenAmount || "",
624
+ isSmartAccount: react.getPreferredAccountType("eip155") === react.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
625
+ }
626
+ });
627
+ controller.resetState();
628
+ if (!isAuthConnector) {
629
+ react.RouterController.replace("Account");
630
+ }
631
+ controller.getMyTokensWithBalance(forceUpdateAddresses);
632
+ return transactionHash;
633
+ } catch (err) {
634
+ const error = err;
635
+ state.transactionError = error == null ? void 0 : error.shortMessage;
636
+ state.loadingTransaction = false;
637
+ react.SnackController.showError((error == null ? void 0 : error.shortMessage) || "Transaction error");
638
+ react.EventsController.sendEvent({
639
+ type: "track",
640
+ event: "SWAP_ERROR",
641
+ properties: {
642
+ message: (error == null ? void 0 : error.shortMessage) || (error == null ? void 0 : error.message) || "Unknown",
643
+ network: ((_j = react.ChainController.state.activeCaipNetwork) == null ? void 0 : _j.caipNetworkId) || "",
644
+ swapFromToken: ((_k = SwapController.state.sourceToken) == null ? void 0 : _k.symbol) || "",
645
+ swapToToken: ((_l = SwapController.state.toToken) == null ? void 0 : _l.symbol) || "",
646
+ swapFromAmount: SwapController.state.sourceTokenAmount || "",
647
+ swapToAmount: SwapController.state.toTokenAmount || "",
648
+ isSmartAccount: react.getPreferredAccountType("eip155") === react.W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT
649
+ }
650
+ });
651
+ return void 0;
652
+ }
653
+ },
654
+ // -- Checks -------------------------------------------- //
655
+ hasInsufficientToken(sourceTokenAmount, sourceTokenAddress) {
656
+ const isInsufficientSourceTokenForSwap = SwapCalculationUtil.isInsufficientSourceTokenForSwap(sourceTokenAmount, sourceTokenAddress, state.myTokensWithBalance);
657
+ return isInsufficientSourceTokenForSwap;
658
+ },
659
+ // -- Calculations -------------------------------------- //
660
+ setTransactionDetails() {
661
+ const { toTokenAddress, toTokenDecimals } = SwapController.getParams();
662
+ if (!toTokenAddress || !toTokenDecimals) {
663
+ return;
664
+ }
665
+ state.gasPriceInUSD = SwapCalculationUtil.getGasPriceInUSD(state.networkPrice, BigInt(state.gasFee), BigInt(INITIAL_GAS_LIMIT));
666
+ state.priceImpact = SwapCalculationUtil.getPriceImpact({
667
+ sourceTokenAmount: state.sourceTokenAmount,
668
+ sourceTokenPriceInUSD: state.sourceTokenPriceInUSD,
669
+ toTokenPriceInUSD: state.toTokenPriceInUSD,
670
+ toTokenAmount: state.toTokenAmount
671
+ });
672
+ state.maxSlippage = SwapCalculationUtil.getMaxSlippage(state.slippage, state.toTokenAmount);
673
+ state.providerFee = SwapCalculationUtil.getProviderFee(state.sourceTokenAmount);
674
+ }
675
+ };
676
+ const SwapController = react.withErrorBoundary(controller);
677
+ const styles = bitcoin.i`
678
+ :host {
679
+ display: block;
680
+ }
681
+
682
+ :host > button {
683
+ gap: var(--wui-spacing-xxs);
684
+ padding: var(--wui-spacing-xs);
685
+ padding-right: var(--wui-spacing-1xs);
686
+ height: 40px;
687
+ border-radius: var(--wui-border-radius-l);
688
+ background: var(--wui-color-gray-glass-002);
689
+ border-width: 0px;
690
+ box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-002);
691
+ }
692
+
693
+ :host > button wui-image {
694
+ width: 24px;
695
+ height: 24px;
696
+ border-radius: var(--wui-border-radius-s);
697
+ box-shadow: inset 0 0 0 1px var(--wui-color-gray-glass-010);
698
+ }
699
+ `;
700
+ var __decorate = function(decorators, target, key, desc) {
701
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
702
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
703
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
704
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
705
+ };
706
+ let WuiTokenButton = class WuiTokenButton2 extends bitcoin.i$1 {
707
+ constructor() {
708
+ super(...arguments);
709
+ this.text = "";
710
+ }
711
+ render() {
712
+ return bitcoin.x`
713
+ <button>
714
+ ${this.tokenTemplate()}
715
+ <wui-text variant="paragraph-600" color="fg-100">${this.text}</wui-text>
716
+ </button>
717
+ `;
718
+ }
719
+ tokenTemplate() {
720
+ if (this.imageSrc) {
721
+ return bitcoin.x`<wui-image src=${this.imageSrc}></wui-image>`;
722
+ }
723
+ return bitcoin.x`
724
+ <wui-icon-box
725
+ size="sm"
726
+ iconColor="fg-200"
727
+ backgroundColor="fg-300"
728
+ icon="networkPlaceholder"
729
+ ></wui-icon-box>
730
+ `;
731
+ }
732
+ };
733
+ WuiTokenButton.styles = [bitcoin.resetStyles, bitcoin.elementStyles, styles];
734
+ __decorate([
735
+ ifDefined.n()
736
+ ], WuiTokenButton.prototype, "imageSrc", void 0);
737
+ __decorate([
738
+ ifDefined.n()
739
+ ], WuiTokenButton.prototype, "text", void 0);
740
+ WuiTokenButton = __decorate([
741
+ ifDefined.customElement("wui-token-button")
742
+ ], WuiTokenButton);
743
+ exports.SwapController = SwapController;