@directcryptopay/sdk 0.2.2 → 0.2.4

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 (228) hide show
  1. package/dist/ExchangeController-CbO41bcH.js +217 -0
  2. package/dist/HelpersUtil-DHm6EVSE.js +120 -0
  3. package/dist/NavigationUtil-kj9LEOOd.js +8 -0
  4. package/dist/PhArrowCircleDown-lsK25DCk.js +73 -0
  5. package/dist/PhArrowClockwise-NeKHZ1co.js +73 -0
  6. package/dist/PhArrowDown-C9AkNvLs.js +73 -0
  7. package/dist/PhArrowLeft-RNfIQP1X.js +73 -0
  8. package/dist/PhArrowRight-DM1tna0G.js +73 -0
  9. package/dist/PhArrowSquareOut-S5XYbAZj.js +73 -0
  10. package/dist/PhArrowUp-DmktzOWy.js +73 -0
  11. package/dist/PhArrowUpRight-BkNeW_5i.js +73 -0
  12. package/dist/PhArrowsClockwise-CQ4pG76b.js +73 -0
  13. package/dist/PhArrowsDownUp-H6gxaNM6.js +73 -0
  14. package/dist/PhArrowsLeftRight-DZSsfMR6.js +73 -0
  15. package/dist/PhBank-4_9QzqIB.js +73 -0
  16. package/dist/PhBrowser-B-JSznId.js +73 -0
  17. package/dist/PhCaretDown-vV5oHMNi.js +73 -0
  18. package/dist/PhCaretLeft-BLo6Y_f4.js +73 -0
  19. package/dist/PhCaretRight-CqQN4TT3.js +73 -0
  20. package/dist/PhCaretUp-Df7UCAHy.js +73 -0
  21. package/dist/PhCheck-gtpfK4ed.js +73 -0
  22. package/dist/PhCircleHalf-Uq7dwDYw.js +73 -0
  23. package/dist/PhClock-SDCW-NmF.js +73 -0
  24. package/dist/PhCompass-B7hgtdx-.js +73 -0
  25. package/dist/PhCopy-BcnhyXCy.js +73 -0
  26. package/dist/PhCreditCard-BJjByVgu.js +73 -0
  27. package/dist/PhCurrencyDollar-B7ZXqXBy.js +73 -0
  28. package/dist/PhDesktop-B3VKPuJx.js +73 -0
  29. package/dist/PhDeviceMobile-Bnd0TYEH.js +73 -0
  30. package/dist/PhDotsThree-yyMWyZ-R.js +73 -0
  31. package/dist/PhEnvelope-67uzHbI9.js +73 -0
  32. package/dist/PhFunnelSimple-B-DCsloI.js +73 -0
  33. package/dist/PhGlobe-TMm_6qGk.js +73 -0
  34. package/dist/PhIdentificationCard-CePPD2xc.js +73 -0
  35. package/dist/PhImage-gY96WtHR.js +73 -0
  36. package/dist/PhInfo-DRQM_ZDP.js +73 -0
  37. package/dist/PhLightbulb-B0TxPfZ1.js +73 -0
  38. package/dist/PhMagnifyingGlass-B8si5_6W.js +73 -0
  39. package/dist/PhPaperPlaneRight-DVu5PLYd.js +73 -0
  40. package/dist/PhPlus-BfTsQnUz.js +73 -0
  41. package/dist/PhPower-CxYUGOWn.js +73 -0
  42. package/dist/PhPuzzlePiece-CQ4wh0gV.js +73 -0
  43. package/dist/PhQrCode-BuJ97NYJ.js +73 -0
  44. package/dist/PhQuestion-kJoP8Mja.js +73 -0
  45. package/dist/PhQuestionMark-C46ZkFpu.js +73 -0
  46. package/dist/PhSealCheck-Eh8jVqSN.js +73 -0
  47. package/dist/PhSignOut-jk97OSVt.js +73 -0
  48. package/dist/PhSpinner-CiYOhwMg.js +73 -0
  49. package/dist/PhTrash-pxerMqzd.js +73 -0
  50. package/dist/PhUser-BMg0VV4A.js +73 -0
  51. package/dist/PhVault-DYQvx5A-.js +73 -0
  52. package/dist/PhWarning-NLC5Mj87.js +73 -0
  53. package/dist/PhWarningCircle-Ch2jU9fA.js +73 -0
  54. package/dist/PhX-Bx4wpwm3.js +73 -0
  55. package/dist/SwapController-Ch0FFTEt.js +457 -0
  56. package/dist/{ccip-BIGqktC1.js → ccip-BrGhNXIM.js} +4 -4
  57. package/dist/data-capture-CpafmuCb.js +490 -0
  58. package/dist/dcp-sdk.umd.js +7400 -6589
  59. package/dist/email-Dcg4jlai.js +344 -0
  60. package/dist/embedded-wallet-DeoRdAPw.js +820 -0
  61. package/dist/features-B9Nde43h.js +274 -0
  62. package/dist/{hashTypedData-ZH9ZnWu3.js → hashTypedData-a7b8tdkO.js} +6 -6
  63. package/dist/if-defined-k21LutCn.js +10 -0
  64. package/dist/index-9vLw53Xl.js +228 -0
  65. package/dist/index-B5wUyynz.js +107 -0
  66. package/dist/index-B8LkUrww.js +86 -0
  67. package/dist/{index-CPTcEPbD.js → index-BA0VwKg0.js} +296 -298
  68. package/dist/index-BB9JJ24N.js +125 -0
  69. package/dist/index-BCkEvPQ6.js +172 -0
  70. package/dist/index-BDeO_csr.js +171 -0
  71. package/dist/index-Bb7babLF.js +1281 -0
  72. package/dist/index-BjOhprVS.js +199 -0
  73. package/dist/{index-Dy4NyE6l.js → index-BjyMgZsf.js} +7 -7
  74. package/dist/index-BkThIDLX.js +159 -0
  75. package/dist/index-BmFs6nb7.js +209 -0
  76. package/dist/{index-5mp7WkhV.js → index-C4qc4PdD.js} +2 -2
  77. package/dist/{index-BdSIrl-R.js → index-CAPvUh14.js} +578 -570
  78. package/dist/index-CBMU3PTE.js +65 -0
  79. package/dist/index-CGwPkJLF.js +355 -0
  80. package/dist/index-CNGEqX3D.js +153 -0
  81. package/dist/index-CRlCq6IB.js +7981 -0
  82. package/dist/index-Cg_o-i9X.js +118 -0
  83. package/dist/index-D1BvhCbI.js +62 -0
  84. package/dist/index-DFi8TiHc.js +128 -0
  85. package/dist/index-DLwuveL9.js +555 -0
  86. package/dist/index-DMn7ktUQ.js +56 -0
  87. package/dist/index-DOXwtuwa.js +117 -0
  88. package/dist/index-DPPOW_Tp.js +118 -0
  89. package/dist/{index-f3LXSfM5.js → index-DQpzHpW-.js} +56 -142
  90. package/dist/{index-D6h-qfpt.js → index-DXHg5C-W.js} +5 -5
  91. package/dist/index-DcYjZV4H.js +110 -0
  92. package/dist/{index-BJ7cbG3N.js → index-DeL88Lwc.js} +36769 -40177
  93. package/dist/index-DrWVlf8b.js +46 -0
  94. package/dist/index-Dsfuc4rB.js +123 -0
  95. package/dist/index-DuTny38n.js +1175 -0
  96. package/dist/{index-D5r0iSq4.js → index-Nfjb6bV0.js} +1 -1
  97. package/dist/index-WwwdQSN2.js +85 -0
  98. package/dist/index-Yha9Afch.js +174 -0
  99. package/dist/index-cbQHN7GC.js +100 -0
  100. package/dist/{index-DobBVPe4.js → index-hyG3cYsv.js} +481 -236
  101. package/dist/index-qLxmmPaL.js +257 -0
  102. package/dist/index.js +1 -1
  103. package/dist/{localBatchGatewayRequest-CjGcn5nM.js → localBatchGatewayRequest-vfcvRH0G.js} +1 -1
  104. package/dist/onramp-BSiyOX4L.js +855 -0
  105. package/dist/{parseSignature-S8VEpRHC.js → parseSignature-CdCMAPZN.js} +2312 -2313
  106. package/dist/pay-with-exchange-CduNoMEz.js +525 -0
  107. package/dist/property-Bd8U3_QP.js +618 -0
  108. package/dist/receive-CrmptJlq.js +232 -0
  109. package/dist/ref-SOwYtCZb.js +107 -0
  110. package/dist/send-oMcHMEr6.js +1166 -0
  111. package/dist/socials-C0A4-FbY.js +620 -0
  112. package/dist/swaps-CbJJ9Ciu.js +1760 -0
  113. package/dist/{transactions-DujFkB-M.js → transactions-BDfCoBS5.js} +10 -10
  114. package/dist/w3m-modal-BjsTkny7.js +1706 -0
  115. package/package.json +3 -3
  116. package/dist/ConstantsUtil-B-_-u8aQ.js +0 -6
  117. package/dist/add-sji6scSD.js +0 -19
  118. package/dist/all-wallets-B4H-890E.js +0 -10
  119. package/dist/app-store-Z433s97G.js +0 -21
  120. package/dist/apple-b8Lxj7nb.js +0 -22
  121. package/dist/arrow-bottom-M9oWWo_9.js +0 -12
  122. package/dist/arrow-bottom-circle-N9c4CXY1.js +0 -15
  123. package/dist/arrow-left-Dw8AKfwf.js +0 -12
  124. package/dist/arrow-right-DwLQZSC_.js +0 -12
  125. package/dist/arrow-top-zhUjkBe1.js +0 -12
  126. package/dist/bank-CbQdnILK.js +0 -18
  127. package/dist/browser-xAqNwt7z.js +0 -18
  128. package/dist/card-Dr1QBmWp.js +0 -18
  129. package/dist/checkmark-BhT1dTgG.js +0 -15
  130. package/dist/checkmark-bold-CPB29wqQ.js +0 -12
  131. package/dist/chevron-bottom-BhNyx2II.js +0 -12
  132. package/dist/chevron-left-CGuEjQlY.js +0 -12
  133. package/dist/chevron-right-CvIRRsqZ.js +0 -12
  134. package/dist/chevron-top-RSzCqjBd.js +0 -12
  135. package/dist/chrome-store-Cs8dAgs0.js +0 -65
  136. package/dist/clock-fhZO5otC.js +0 -12
  137. package/dist/close-BPuztrdR.js +0 -12
  138. package/dist/coinPlaceholder-C8X2i7Kh.js +0 -12
  139. package/dist/compass-WMc5huk0.js +0 -12
  140. package/dist/copy-DVAeT17y.js +0 -19
  141. package/dist/cursor-BJ4YLXfy.js +0 -7
  142. package/dist/cursor-transparent-DN2fLQN4.js +0 -16
  143. package/dist/desktop-6avxisBw.js +0 -13
  144. package/dist/disconnect-AReVI8Gk.js +0 -12
  145. package/dist/discord-CxrI30BZ.js +0 -21
  146. package/dist/email-B8dIIaay.js +0 -696
  147. package/dist/embedded-wallet-C_5hF7rM.js +0 -468
  148. package/dist/etherscan-BnAy8cIF.js +0 -10
  149. package/dist/exclamation-triangle-Bu7nHwx9.js +0 -8
  150. package/dist/extension-F0LIhvcf.js +0 -12
  151. package/dist/external-link-CP6phyaM.js +0 -12
  152. package/dist/facebook-BtQ-Io2y.js +0 -30
  153. package/dist/farcaster-BmaN1ugd.js +0 -16
  154. package/dist/filters-DpEwoOmy.js +0 -12
  155. package/dist/github-q7qO9V-b.js +0 -22
  156. package/dist/google-DH_ZE8bW.js +0 -22
  157. package/dist/help-circle-BAQVmKas.js +0 -16
  158. package/dist/id-Cj68Zwgo.js +0 -16
  159. package/dist/if-defined-CNte9B3N.js +0 -744
  160. package/dist/image-BKJDw6N-.js +0 -8
  161. package/dist/index-7toZMdtG.js +0 -573
  162. package/dist/index-B1uKzdvN.js +0 -170
  163. package/dist/index-BHFZVF-b.js +0 -257
  164. package/dist/index-BKwa5JSA.js +0 -559
  165. package/dist/index-BP4B9VUt.js +0 -54
  166. package/dist/index-BVdzXHpO.js +0 -181
  167. package/dist/index-BYND0GJ9.js +0 -146
  168. package/dist/index-BaJ0zEbh.js +0 -97
  169. package/dist/index-Bh0MPFwP.js +0 -58
  170. package/dist/index-Bsh7_qTp.js +0 -511
  171. package/dist/index-BwnXTNNg.js +0 -199
  172. package/dist/index-C0kPDbg_.js +0 -77
  173. package/dist/index-CKikVKe2.js +0 -75
  174. package/dist/index-ChVh0Hkp.js +0 -243
  175. package/dist/index-Cle_NnnS.js +0 -305
  176. package/dist/index-CmWdvIFT.js +0 -51
  177. package/dist/index-D2AMA8Bu.js +0 -65
  178. package/dist/index-DAUM8CO4.js +0 -65
  179. package/dist/index-DGjZW6uR.js +0 -78
  180. package/dist/index-DQe94z7X.js +0 -265
  181. package/dist/index-DTo6w99t.js +0 -7864
  182. package/dist/index-DYdXjap2.js +0 -320
  183. package/dist/index-DceCxNV5.js +0 -181
  184. package/dist/index-Uw9cSw0q.js +0 -294
  185. package/dist/index-qiuyrukh.js +0 -45
  186. package/dist/index-zddvaohA.js +0 -78
  187. package/dist/info-RfPsmroW.js +0 -7
  188. package/dist/info-circle-DFKHB_ZN.js +0 -16
  189. package/dist/lightbulb-B-Bykj9X.js +0 -7
  190. package/dist/mail-mBAgGuw5.js +0 -12
  191. package/dist/mobile-Dhh3ndkf.js +0 -13
  192. package/dist/more-D1h7UTvg.js +0 -15
  193. package/dist/network-placeholder-Dqynvc-t.js +0 -18
  194. package/dist/nftPlaceholder-Df7MW4MM.js +0 -12
  195. package/dist/off-BmG3cHTX.js +0 -12
  196. package/dist/onramp-C401Aenb.js +0 -1279
  197. package/dist/play-store-4q1fzL_P.js +0 -36
  198. package/dist/plus-603Gs3yG.js +0 -17
  199. package/dist/qr-code-Dgwhf6M1.js +0 -10
  200. package/dist/receive-CYXbbEUR.js +0 -186
  201. package/dist/recycle-horizontal-Bu8zZ563.js +0 -13
  202. package/dist/ref-DpmKRWBK.js +0 -41
  203. package/dist/refresh-BMZFu0mu.js +0 -12
  204. package/dist/reown-logo-BXph7ThY.js +0 -16
  205. package/dist/search-Cm_V42Y_.js +0 -12
  206. package/dist/secp256k1-C0iX1TUr.js +0 -1510
  207. package/dist/secp256k1-DOQBqE4Z.js +0 -1302
  208. package/dist/send-BSMYxDuP.js +0 -19
  209. package/dist/send-C8EeIzRB.js +0 -1038
  210. package/dist/socials-DQrHQajs.js +0 -574
  211. package/dist/swapHorizontal-98rnJewS.js +0 -12
  212. package/dist/swapHorizontalBold-C299FjEt.js +0 -12
  213. package/dist/swapHorizontalMedium-Cqm6i4WJ.js +0 -20
  214. package/dist/swapHorizontalRoundedBold-De7hFfqZ.js +0 -12
  215. package/dist/swapVertical-DSL75l8L.js +0 -12
  216. package/dist/swaps-BuTNp65Y.js +0 -1637
  217. package/dist/telegram-cJP7hgUb.js +0 -20
  218. package/dist/three-dots-DHnEh28O.js +0 -9
  219. package/dist/twitch-CR2iGcBo.js +0 -22
  220. package/dist/twitterIcon-E5TAQjOn.js +0 -10
  221. package/dist/verify-DEukUJp0.js +0 -12
  222. package/dist/verify-filled-BXsx1i_p.js +0 -12
  223. package/dist/w3m-modal-Bm7BqVng.js +0 -1037
  224. package/dist/wallet-CzyyvdrT.js +0 -12
  225. package/dist/wallet-placeholder-BrcmyGEe.js +0 -18
  226. package/dist/walletconnect-BSYogWiE.js +0 -36
  227. package/dist/warning-circle-Cgp2BW3m.js +0 -16
  228. package/dist/x-BJinLpTw.js +0 -16
@@ -0,0 +1,457 @@
1
+ import { cN as T, c$ as W, cC as x, d0 as A, cH as g, d1 as B, d2 as P, cF as D, d3 as M, d4 as F, cE as w, cP as v, cG as L, d5 as N, d6 as z, d7 as R, cL as _, cO as H, d8 as V, cR as $, cS as q } from "./index-DeL88Lwc.js";
2
+ const I = {
3
+ getGasPriceInEther(n, t) {
4
+ const o = t * n;
5
+ return Number(o) / 1e18;
6
+ },
7
+ getGasPriceInUSD(n, t, o) {
8
+ const s = I.getGasPriceInEther(t, o);
9
+ return T.bigNumber(n).times(s).toNumber();
10
+ },
11
+ getPriceImpact({ sourceTokenAmount: n, sourceTokenPriceInUSD: t, toTokenPriceInUSD: o, toTokenAmount: s }) {
12
+ const c = T.bigNumber(n).times(t), r = T.bigNumber(s).times(o);
13
+ return c.minus(r).div(c).times(100).toNumber();
14
+ },
15
+ getMaxSlippage(n, t) {
16
+ const o = T.bigNumber(n).div(100);
17
+ return T.multiply(t, o).toNumber();
18
+ },
19
+ getProviderFee(n, t = 85e-4) {
20
+ return T.bigNumber(n).times(t).toString();
21
+ },
22
+ isInsufficientNetworkTokenForGas(n, t) {
23
+ const o = t || "0";
24
+ return T.bigNumber(n).eq(0) ? !0 : T.bigNumber(T.bigNumber(o)).gt(n);
25
+ },
26
+ isInsufficientSourceTokenForSwap(n, t, o) {
27
+ var r, d;
28
+ const s = (d = (r = o == null ? void 0 : o.find((l) => l.address === t)) == null ? void 0 : r.quantity) == null ? void 0 : d.numeric;
29
+ return T.bigNumber(s || "0").lt(n);
30
+ }
31
+ }, O = 15e4, Q = 6, k = {
32
+ // Loading states
33
+ initializing: !1,
34
+ initialized: !1,
35
+ loadingPrices: !1,
36
+ loadingQuote: !1,
37
+ loadingApprovalTransaction: !1,
38
+ loadingBuildTransaction: !1,
39
+ loadingTransaction: !1,
40
+ // Control states
41
+ switchingTokens: !1,
42
+ // Error states
43
+ fetchError: !1,
44
+ // Approval & Swap transaction states
45
+ approvalTransaction: void 0,
46
+ swapTransaction: void 0,
47
+ transactionError: void 0,
48
+ // Input values
49
+ sourceToken: void 0,
50
+ sourceTokenAmount: "",
51
+ sourceTokenPriceInUSD: 0,
52
+ toToken: void 0,
53
+ toTokenAmount: "",
54
+ toTokenPriceInUSD: 0,
55
+ networkPrice: "0",
56
+ networkBalanceInUSD: "0",
57
+ networkTokenSymbol: "",
58
+ inputError: void 0,
59
+ // Request values
60
+ slippage: _.CONVERT_SLIPPAGE_TOLERANCE,
61
+ // Tokens
62
+ tokens: void 0,
63
+ popularTokens: void 0,
64
+ suggestedTokens: void 0,
65
+ foundTokens: void 0,
66
+ myTokensWithBalance: void 0,
67
+ tokensPriceMap: {},
68
+ // Calculations
69
+ gasFee: "0",
70
+ gasPriceInUSD: 0,
71
+ priceImpact: void 0,
72
+ maxSlippage: void 0,
73
+ providerFee: void 0
74
+ }, e = x({ ...k }), E = {
75
+ state: e,
76
+ subscribe(n) {
77
+ return q(e, () => n(e));
78
+ },
79
+ subscribeKey(n, t) {
80
+ return $(e, n, t);
81
+ },
82
+ getParams() {
83
+ var i, u, p, f, S, h, y, b, C;
84
+ const n = w.state.activeChain, t = ((i = w.getAccountData(n)) == null ? void 0 : i.caipAddress) ?? w.state.activeCaipAddress, o = L.getPlainAddress(t), s = H(), c = V.getConnectorId(w.state.activeChain);
85
+ if (!o)
86
+ throw new Error("No address found to swap the tokens from.");
87
+ const r = !((u = e.toToken) != null && u.address) || !((p = e.toToken) != null && p.decimals), d = !((f = e.sourceToken) != null && f.address) || !((S = e.sourceToken) != null && S.decimals) || !T.bigNumber(e.sourceTokenAmount).gt(0), l = !e.sourceTokenAmount;
88
+ return {
89
+ networkAddress: s,
90
+ fromAddress: o,
91
+ fromCaipAddress: t,
92
+ sourceTokenAddress: (h = e.sourceToken) == null ? void 0 : h.address,
93
+ toTokenAddress: (y = e.toToken) == null ? void 0 : y.address,
94
+ toTokenAmount: e.toTokenAmount,
95
+ toTokenDecimals: (b = e.toToken) == null ? void 0 : b.decimals,
96
+ sourceTokenAmount: e.sourceTokenAmount,
97
+ sourceTokenDecimals: (C = e.sourceToken) == null ? void 0 : C.decimals,
98
+ invalidToToken: r,
99
+ invalidSourceToken: d,
100
+ invalidSourceTokenAmount: l,
101
+ availableToSwap: t && !r && !d && !l,
102
+ isAuthConnector: c === P.CONNECTOR_ID.AUTH
103
+ };
104
+ },
105
+ async setSourceToken(n) {
106
+ if (!n) {
107
+ e.sourceToken = n, e.sourceTokenAmount = "", e.sourceTokenPriceInUSD = 0;
108
+ return;
109
+ }
110
+ e.sourceToken = n, await a.setTokenPrice(n.address, "sourceToken");
111
+ },
112
+ setSourceTokenAmount(n) {
113
+ e.sourceTokenAmount = n;
114
+ },
115
+ async setToToken(n) {
116
+ if (!n) {
117
+ e.toToken = n, e.toTokenAmount = "", e.toTokenPriceInUSD = 0;
118
+ return;
119
+ }
120
+ e.toToken = n, await a.setTokenPrice(n.address, "toToken");
121
+ },
122
+ setToTokenAmount(n) {
123
+ e.toTokenAmount = n ? T.toFixed(n, Q) : "";
124
+ },
125
+ async setTokenPrice(n, t) {
126
+ let o = e.tokensPriceMap[n] || 0;
127
+ o || (e.loadingPrices = !0, o = await a.getAddressPrice(n)), t === "sourceToken" ? e.sourceTokenPriceInUSD = o : t === "toToken" && (e.toTokenPriceInUSD = o), e.loadingPrices && (e.loadingPrices = !1), a.getParams().availableToSwap && !e.switchingTokens && a.swapTokens();
128
+ },
129
+ async switchTokens() {
130
+ if (!(e.initializing || !e.initialized || e.switchingTokens)) {
131
+ e.switchingTokens = !0;
132
+ try {
133
+ const n = e.toToken ? { ...e.toToken } : void 0, t = e.sourceToken ? { ...e.sourceToken } : void 0, o = n && e.toTokenAmount === "" ? "1" : e.toTokenAmount;
134
+ a.setSourceTokenAmount(o), a.setToTokenAmount(""), await a.setSourceToken(n), await a.setToToken(t), e.switchingTokens = !1, a.swapTokens();
135
+ } catch (n) {
136
+ throw e.switchingTokens = !1, n;
137
+ }
138
+ }
139
+ },
140
+ resetState() {
141
+ e.myTokensWithBalance = k.myTokensWithBalance, e.tokensPriceMap = k.tokensPriceMap, e.initialized = k.initialized, e.initializing = k.initializing, e.switchingTokens = k.switchingTokens, e.sourceToken = k.sourceToken, e.sourceTokenAmount = k.sourceTokenAmount, e.sourceTokenPriceInUSD = k.sourceTokenPriceInUSD, e.toToken = k.toToken, e.toTokenAmount = k.toTokenAmount, e.toTokenPriceInUSD = k.toTokenPriceInUSD, e.networkPrice = k.networkPrice, e.networkTokenSymbol = k.networkTokenSymbol, e.networkBalanceInUSD = k.networkBalanceInUSD, e.inputError = k.inputError;
142
+ },
143
+ resetValues() {
144
+ var o;
145
+ const { networkAddress: n } = a.getParams(), t = (o = e.tokens) == null ? void 0 : o.find((s) => s.address === n);
146
+ a.setSourceToken(t), a.setToToken(void 0);
147
+ },
148
+ getApprovalLoadingState() {
149
+ return e.loadingApprovalTransaction;
150
+ },
151
+ clearError() {
152
+ e.transactionError = void 0;
153
+ },
154
+ async initializeState() {
155
+ if (!e.initializing) {
156
+ if (e.initializing = !0, !e.initialized)
157
+ try {
158
+ await a.fetchTokens(), e.initialized = !0;
159
+ } catch {
160
+ e.initialized = !1, g.showError("Failed to initialize swap"), A.goBack();
161
+ }
162
+ e.initializing = !1;
163
+ }
164
+ },
165
+ async fetchTokens() {
166
+ var o;
167
+ const { networkAddress: n } = a.getParams();
168
+ await a.getNetworkTokenPrice(), await a.getMyTokensWithBalance();
169
+ const t = (o = e.myTokensWithBalance) == null ? void 0 : o.find((s) => s.address === n);
170
+ t && (e.networkTokenSymbol = t.symbol, a.setSourceToken(t), a.setSourceTokenAmount("0"));
171
+ },
172
+ async getTokenList() {
173
+ var t, o;
174
+ const n = (t = w.state.activeCaipNetwork) == null ? void 0 : t.caipNetworkId;
175
+ if (!(e.caipNetworkId === n && e.tokens))
176
+ try {
177
+ e.tokensLoading = !0;
178
+ const s = await N.getTokenList(n);
179
+ e.tokens = s, e.caipNetworkId = n, e.popularTokens = s.sort((i, u) => i.symbol < u.symbol ? -1 : i.symbol > u.symbol ? 1 : 0);
180
+ const r = (n && ((o = _.SUGGESTED_TOKENS_BY_CHAIN) == null ? void 0 : o[n]) || []).map((i) => s.find((u) => u.symbol === i)).filter((i) => !!i), l = (_.SWAP_SUGGESTED_TOKENS || []).map((i) => s.find((u) => u.symbol === i)).filter((i) => !!i).filter((i) => !r.some((u) => u.address === i.address));
181
+ e.suggestedTokens = [...r, ...l];
182
+ } catch {
183
+ e.tokens = [], e.popularTokens = [], e.suggestedTokens = [];
184
+ } finally {
185
+ e.tokensLoading = !1;
186
+ }
187
+ },
188
+ async getAddressPrice(n) {
189
+ var i, u;
190
+ const t = e.tokensPriceMap[n];
191
+ if (t)
192
+ return t;
193
+ const o = await v.fetchTokenPrice({
194
+ addresses: [n]
195
+ }), s = (o == null ? void 0 : o.fungibles) || [], c = [...e.tokens || [], ...e.myTokensWithBalance || []], r = (i = c == null ? void 0 : c.find((p) => p.address === n)) == null ? void 0 : i.symbol, d = ((u = s.find((p) => p.symbol.toLowerCase() === (r == null ? void 0 : r.toLowerCase()))) == null ? void 0 : u.price) || 0, l = parseFloat(d.toString());
196
+ return e.tokensPriceMap[n] = l, l;
197
+ },
198
+ async getNetworkTokenPrice() {
199
+ var c;
200
+ const { networkAddress: n } = a.getParams(), o = (c = (await v.fetchTokenPrice({
201
+ addresses: [n]
202
+ }).catch(() => (g.showError("Failed to fetch network token price"), { fungibles: [] }))).fungibles) == null ? void 0 : c[0], s = (o == null ? void 0 : o.price.toString()) || "0";
203
+ e.tokensPriceMap[n] = parseFloat(s), e.networkTokenSymbol = (o == null ? void 0 : o.symbol) || "", e.networkPrice = s;
204
+ },
205
+ async getMyTokensWithBalance(n) {
206
+ const t = await R.getMyTokensWithBalance(n), o = N.mapBalancesToSwapTokens(t);
207
+ o && (await a.getInitialGasPrice(), a.setBalances(o));
208
+ },
209
+ setBalances(n) {
210
+ const { networkAddress: t } = a.getParams(), o = w.state.activeCaipNetwork;
211
+ if (!o)
212
+ return;
213
+ const s = n.find((c) => c.address === t);
214
+ n.forEach((c) => {
215
+ e.tokensPriceMap[c.address] = c.price || 0;
216
+ }), e.myTokensWithBalance = n.filter((c) => c.address.startsWith(o.caipNetworkId)), e.networkBalanceInUSD = s ? T.multiply(s.quantity.numeric, s.price).toString() : "0";
217
+ },
218
+ async getInitialGasPrice() {
219
+ var t, o;
220
+ const n = await N.fetchGasPrice();
221
+ if (!n)
222
+ return { gasPrice: null, gasPriceInUSD: null };
223
+ switch ((o = (t = w.state) == null ? void 0 : t.activeCaipNetwork) == null ? void 0 : o.chainNamespace) {
224
+ case P.CHAIN.SOLANA:
225
+ return e.gasFee = n.standard ?? "0", e.gasPriceInUSD = T.multiply(n.standard, e.networkPrice).div(1e9).toNumber(), {
226
+ gasPrice: BigInt(e.gasFee),
227
+ gasPriceInUSD: Number(e.gasPriceInUSD)
228
+ };
229
+ case P.CHAIN.EVM:
230
+ default:
231
+ const s = n.standard ?? "0", c = BigInt(s), r = BigInt(O), d = I.getGasPriceInUSD(e.networkPrice, r, c);
232
+ return e.gasFee = s, e.gasPriceInUSD = d, { gasPrice: c, gasPriceInUSD: d };
233
+ }
234
+ },
235
+ // -- Swap -------------------------------------- //
236
+ async swapTokens() {
237
+ var r, d, l;
238
+ const n = (r = w.getAccountData()) == null ? void 0 : r.address, t = e.sourceToken, o = e.toToken, s = T.bigNumber(e.sourceTokenAmount).gt(0);
239
+ if (s || a.setToTokenAmount(""), !o || !t || e.loadingPrices || !s || !n)
240
+ return;
241
+ e.loadingQuote = !0;
242
+ const c = T.bigNumber(e.sourceTokenAmount).times(10 ** t.decimals).round(0);
243
+ try {
244
+ const i = await v.fetchSwapQuote({
245
+ userAddress: n,
246
+ from: t.address,
247
+ to: o.address,
248
+ gasPrice: e.gasFee,
249
+ amount: c.toString()
250
+ });
251
+ e.loadingQuote = !1;
252
+ const u = (l = (d = i == null ? void 0 : i.quotes) == null ? void 0 : d[0]) == null ? void 0 : l.toAmount;
253
+ if (!u) {
254
+ z.open({
255
+ displayMessage: "Incorrect amount",
256
+ debugMessage: "Please enter a valid amount"
257
+ }, "error");
258
+ return;
259
+ }
260
+ const p = T.bigNumber(u).div(10 ** o.decimals).toString();
261
+ a.setToTokenAmount(p), a.hasInsufficientToken(e.sourceTokenAmount, t.address) ? e.inputError = "Insufficient balance" : (e.inputError = void 0, a.setTransactionDetails());
262
+ } catch (i) {
263
+ const u = await N.handleSwapError(i);
264
+ e.loadingQuote = !1, e.inputError = u || "Insufficient balance";
265
+ }
266
+ },
267
+ // -- Create Transactions -------------------------------------- //
268
+ async getTransaction() {
269
+ const { fromCaipAddress: n, availableToSwap: t } = a.getParams(), o = e.sourceToken, s = e.toToken;
270
+ if (!(!n || !t || !o || !s || e.loadingQuote))
271
+ try {
272
+ e.loadingBuildTransaction = !0;
273
+ const c = await N.fetchSwapAllowance({
274
+ userAddress: n,
275
+ tokenAddress: o.address,
276
+ sourceTokenAmount: e.sourceTokenAmount,
277
+ sourceTokenDecimals: o.decimals
278
+ });
279
+ let r;
280
+ return c ? r = await a.createSwapTransaction() : r = await a.createAllowanceTransaction(), e.loadingBuildTransaction = !1, e.fetchError = !1, r;
281
+ } catch {
282
+ A.goBack(), g.showError("Failed to check allowance"), e.loadingBuildTransaction = !1, e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
283
+ return;
284
+ }
285
+ },
286
+ async createAllowanceTransaction() {
287
+ const { fromCaipAddress: n, sourceTokenAddress: t, toTokenAddress: o } = a.getParams();
288
+ if (!(!n || !o)) {
289
+ if (!t)
290
+ throw new Error("createAllowanceTransaction - No source token address found.");
291
+ try {
292
+ const s = await v.generateApproveCalldata({
293
+ from: t,
294
+ to: o,
295
+ userAddress: n
296
+ }), c = L.getPlainAddress(s.tx.from);
297
+ if (!c)
298
+ throw new Error("SwapController:createAllowanceTransaction - address is required");
299
+ const r = {
300
+ data: s.tx.data,
301
+ to: c,
302
+ gasPrice: BigInt(s.tx.eip155.gasPrice),
303
+ value: BigInt(s.tx.value),
304
+ toAmount: e.toTokenAmount
305
+ };
306
+ return e.swapTransaction = void 0, e.approvalTransaction = {
307
+ data: r.data,
308
+ to: r.to,
309
+ gasPrice: r.gasPrice,
310
+ value: r.value,
311
+ toAmount: r.toAmount
312
+ }, {
313
+ data: r.data,
314
+ to: r.to,
315
+ gasPrice: r.gasPrice,
316
+ value: r.value,
317
+ toAmount: r.toAmount
318
+ };
319
+ } catch {
320
+ A.goBack(), g.showError("Failed to create approval transaction"), e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
321
+ return;
322
+ }
323
+ }
324
+ },
325
+ async createSwapTransaction() {
326
+ var d;
327
+ const { networkAddress: n, fromCaipAddress: t, sourceTokenAmount: o } = a.getParams(), s = e.sourceToken, c = e.toToken;
328
+ if (!t || !o || !s || !c)
329
+ return;
330
+ const r = (d = B.parseUnits(o, s.decimals)) == null ? void 0 : d.toString();
331
+ try {
332
+ const l = await v.generateSwapCalldata({
333
+ userAddress: t,
334
+ from: s.address,
335
+ to: c.address,
336
+ amount: r,
337
+ disableEstimate: !0
338
+ }), i = s.address === n, u = BigInt(l.tx.eip155.gas), p = BigInt(l.tx.eip155.gasPrice), f = L.getPlainAddress(l.tx.to);
339
+ if (!f)
340
+ throw new Error("SwapController:createSwapTransaction - address is required");
341
+ const S = {
342
+ data: l.tx.data,
343
+ to: f,
344
+ gas: u,
345
+ gasPrice: p,
346
+ value: BigInt(i ? r ?? "0" : "0"),
347
+ toAmount: e.toTokenAmount
348
+ };
349
+ return e.gasPriceInUSD = I.getGasPriceInUSD(e.networkPrice, u, p), e.approvalTransaction = void 0, e.swapTransaction = S, S;
350
+ } catch {
351
+ A.goBack(), g.showError("Failed to create transaction"), e.approvalTransaction = void 0, e.swapTransaction = void 0, e.fetchError = !0;
352
+ return;
353
+ }
354
+ },
355
+ onEmbeddedWalletApprovalSuccess() {
356
+ g.showLoading("Approve limit increase in your wallet"), A.replace("SwapPreview");
357
+ },
358
+ // -- Send Transactions --------------------------------- //
359
+ async sendTransactionForApproval(n) {
360
+ var c, r, d;
361
+ const { fromAddress: t, isAuthConnector: o } = a.getParams();
362
+ e.loadingApprovalTransaction = !0, o ? A.pushTransactionStack({
363
+ onSuccess: a.onEmbeddedWalletApprovalSuccess
364
+ }) : g.showLoading("Approve limit increase in your wallet");
365
+ try {
366
+ await B.sendTransaction({
367
+ address: t,
368
+ to: n.to,
369
+ data: n.data,
370
+ value: n.value,
371
+ chainNamespace: P.CHAIN.EVM
372
+ }), await a.swapTokens(), await a.getTransaction(), e.approvalTransaction = void 0, e.loadingApprovalTransaction = !1;
373
+ } catch (l) {
374
+ const i = l;
375
+ e.transactionError = i == null ? void 0 : i.displayMessage, e.loadingApprovalTransaction = !1, g.showError((i == null ? void 0 : i.displayMessage) || "Transaction error"), D.sendEvent({
376
+ type: "track",
377
+ event: "SWAP_APPROVAL_ERROR",
378
+ properties: {
379
+ message: (i == null ? void 0 : i.displayMessage) || (i == null ? void 0 : i.message) || "Unknown",
380
+ network: ((c = w.state.activeCaipNetwork) == null ? void 0 : c.caipNetworkId) || "",
381
+ swapFromToken: ((r = a.state.sourceToken) == null ? void 0 : r.symbol) || "",
382
+ swapToToken: ((d = a.state.toToken) == null ? void 0 : d.symbol) || "",
383
+ swapFromAmount: a.state.sourceTokenAmount || "",
384
+ swapToAmount: a.state.toTokenAmount || "",
385
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
386
+ }
387
+ });
388
+ }
389
+ },
390
+ async sendTransactionForSwap(n) {
391
+ var d, l, i, u, p, f, S, h, y, b, C, G;
392
+ if (!n)
393
+ return;
394
+ const { fromAddress: t, toTokenAmount: o, isAuthConnector: s } = a.getParams();
395
+ e.loadingTransaction = !0;
396
+ const c = `Swapping ${(d = e.sourceToken) == null ? void 0 : d.symbol} to ${T.formatNumberToLocalString(o, 3)} ${(l = e.toToken) == null ? void 0 : l.symbol}`, r = `Swapped ${(i = e.sourceToken) == null ? void 0 : i.symbol} to ${T.formatNumberToLocalString(o, 3)} ${(u = e.toToken) == null ? void 0 : u.symbol}`;
397
+ s ? A.pushTransactionStack({
398
+ onSuccess() {
399
+ A.replace("Account"), g.showLoading(c), E.resetState();
400
+ }
401
+ }) : g.showLoading("Confirm transaction in your wallet");
402
+ try {
403
+ const U = [(p = e.sourceToken) == null ? void 0 : p.address, (f = e.toToken) == null ? void 0 : f.address].join(","), m = await B.sendTransaction({
404
+ address: t,
405
+ to: n.to,
406
+ data: n.data,
407
+ value: n.value,
408
+ chainNamespace: P.CHAIN.EVM
409
+ });
410
+ return e.loadingTransaction = !1, g.showSuccess(r), D.sendEvent({
411
+ type: "track",
412
+ event: "SWAP_SUCCESS",
413
+ properties: {
414
+ network: ((S = w.state.activeCaipNetwork) == null ? void 0 : S.caipNetworkId) || "",
415
+ swapFromToken: ((h = a.state.sourceToken) == null ? void 0 : h.symbol) || "",
416
+ swapToToken: ((y = a.state.toToken) == null ? void 0 : y.symbol) || "",
417
+ swapFromAmount: a.state.sourceTokenAmount || "",
418
+ swapToAmount: a.state.toTokenAmount || "",
419
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
420
+ }
421
+ }), E.resetState(), s || A.replace("Account"), E.getMyTokensWithBalance(U), m;
422
+ } catch (U) {
423
+ const m = U;
424
+ e.transactionError = m == null ? void 0 : m.displayMessage, e.loadingTransaction = !1, g.showError((m == null ? void 0 : m.displayMessage) || "Transaction error"), D.sendEvent({
425
+ type: "track",
426
+ event: "SWAP_ERROR",
427
+ properties: {
428
+ message: (m == null ? void 0 : m.displayMessage) || (m == null ? void 0 : m.message) || "Unknown",
429
+ network: ((b = w.state.activeCaipNetwork) == null ? void 0 : b.caipNetworkId) || "",
430
+ swapFromToken: ((C = a.state.sourceToken) == null ? void 0 : C.symbol) || "",
431
+ swapToToken: ((G = a.state.toToken) == null ? void 0 : G.symbol) || "",
432
+ swapFromAmount: a.state.sourceTokenAmount || "",
433
+ swapToAmount: a.state.toTokenAmount || "",
434
+ isSmartAccount: M(P.CHAIN.EVM) === F.ACCOUNT_TYPES.SMART_ACCOUNT
435
+ }
436
+ });
437
+ return;
438
+ }
439
+ },
440
+ // -- Checks -------------------------------------------- //
441
+ hasInsufficientToken(n, t) {
442
+ return I.isInsufficientSourceTokenForSwap(n, t, e.myTokensWithBalance);
443
+ },
444
+ // -- Calculations -------------------------------------- //
445
+ setTransactionDetails() {
446
+ const { toTokenAddress: n, toTokenDecimals: t } = a.getParams();
447
+ !n || !t || (e.gasPriceInUSD = I.getGasPriceInUSD(e.networkPrice, BigInt(e.gasFee), BigInt(O)), e.priceImpact = I.getPriceImpact({
448
+ sourceTokenAmount: e.sourceTokenAmount,
449
+ sourceTokenPriceInUSD: e.sourceTokenPriceInUSD,
450
+ toTokenPriceInUSD: e.toTokenPriceInUSD,
451
+ toTokenAmount: e.toTokenAmount
452
+ }), e.maxSlippage = I.getMaxSlippage(e.slippage, e.toTokenAmount), e.providerFee = I.getProviderFee(e.sourceTokenAmount));
453
+ }
454
+ }, a = W(E);
455
+ export {
456
+ a as S
457
+ };
@@ -1,5 +1,5 @@
1
- import { a1 as p, cQ as y, cq as w, bf as g, br as k, cR as E, bB as L, bi as O, aA as m, bE as R } from "./index-BJ7cbG3N.js";
2
- import { l as x, b as M } from "./localBatchGatewayRequest-CjGcn5nM.js";
1
+ import { a1 as p, dd as y, cq as w, bf as g, br as k, de as E, bB as L, bi as O, aA as m, bE as x } from "./index-DeL88Lwc.js";
2
+ import { l as R, b as M } from "./localBatchGatewayRequest-vfcvRH0G.js";
3
3
  class q extends p {
4
4
  constructor({ callbackSelector: r, cause: a, data: n, extraData: i, sender: f, urls: t }) {
5
5
  var o;
@@ -78,7 +78,7 @@ async function B(c, { blockNumber: r, blockTag: a, data: n, to: i }) {
78
78
  try {
79
79
  if (!k(i, t))
80
80
  throw new $({ sender: t, to: i });
81
- const u = o.includes(x) ? await M({
81
+ const u = o.includes(R) ? await M({
82
82
  data: d,
83
83
  ccipRequest: h
84
84
  }) : await h({ data: d, sender: t, urls: o }), { data: b } = await E(c, {
@@ -124,7 +124,7 @@ async function A({ data: c, sender: r, urls: a }) {
124
124
  });
125
125
  continue;
126
126
  }
127
- if (!R(e)) {
127
+ if (!x(e)) {
128
128
  n = new S({
129
129
  result: e,
130
130
  url: t