@directcryptopay/sdk 0.1.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 (141) hide show
  1. package/README.md +357 -0
  2. package/dist/ConstantsUtil-B-_-u8aQ.js +6 -0
  3. package/dist/add-KF4m4jFK.js +19 -0
  4. package/dist/all-wallets-D6NAjQgX.js +10 -0
  5. package/dist/app-store-D7TTn-EO.js +21 -0
  6. package/dist/apple-DjX2E2hE.js +22 -0
  7. package/dist/arrow-bottom-C0YrNJYB.js +12 -0
  8. package/dist/arrow-bottom-circle-Dlxvx_XG.js +15 -0
  9. package/dist/arrow-left-x8_-lUyK.js +12 -0
  10. package/dist/arrow-right-BTZybj80.js +12 -0
  11. package/dist/arrow-top-LzH7iLCp.js +12 -0
  12. package/dist/bank-23jp-IV_.js +18 -0
  13. package/dist/browser-EjoorDid.js +18 -0
  14. package/dist/card-DGgWwtwC.js +18 -0
  15. package/dist/ccip-BMANewTU.js +150 -0
  16. package/dist/checkmark-B1qcQhBo.js +15 -0
  17. package/dist/checkmark-bold-Cyc4IEEJ.js +12 -0
  18. package/dist/chevron-bottom-ClHs08rB.js +12 -0
  19. package/dist/chevron-left-O8h_551_.js +12 -0
  20. package/dist/chevron-right-DP3xpyIA.js +12 -0
  21. package/dist/chevron-top-CuwkBUs9.js +12 -0
  22. package/dist/chrome-store-zfT_aJ3R.js +65 -0
  23. package/dist/clock-DHZqivIS.js +12 -0
  24. package/dist/close-Cp9rNAw4.js +12 -0
  25. package/dist/coinPlaceholder-U7-T1KKQ.js +12 -0
  26. package/dist/compass-Ds5-PRSR.js +12 -0
  27. package/dist/copy-Jg4HdIMf.js +19 -0
  28. package/dist/core/api.d.ts +30 -0
  29. package/dist/core/config.d.ts +59 -0
  30. package/dist/core/logic.d.ts +2 -0
  31. package/dist/core/wallet.d.ts +34 -0
  32. package/dist/cursor-DmMevduB.js +7 -0
  33. package/dist/cursor-transparent-Dn9-1SV8.js +16 -0
  34. package/dist/dcp-sdk.umd.js +12000 -0
  35. package/dist/dcp.d.ts +10 -0
  36. package/dist/desktop-C4udXXlZ.js +13 -0
  37. package/dist/disconnect-wd1BYLxt.js +12 -0
  38. package/dist/discord-DthxuCAP.js +21 -0
  39. package/dist/email-B3jSnUFE.js +696 -0
  40. package/dist/embedded-wallet-CJHmoBI2.js +468 -0
  41. package/dist/etherscan-Cjp4xfMW.js +10 -0
  42. package/dist/exclamation-triangle-CRNR5WOy.js +8 -0
  43. package/dist/extension-Cydk0mZt.js +12 -0
  44. package/dist/external-link-CuPTAoq9.js +12 -0
  45. package/dist/facebook-CghqXmdf.js +30 -0
  46. package/dist/farcaster-BREqMX4y.js +16 -0
  47. package/dist/filters-Dn_Ys7ew.js +12 -0
  48. package/dist/github-C-A7JmIY.js +22 -0
  49. package/dist/google-CCdM_naE.js +22 -0
  50. package/dist/hashTypedData-D2Qmzscs.js +197 -0
  51. package/dist/help-circle-DIH4vyj3.js +16 -0
  52. package/dist/id-DkJ0gBuy.js +16 -0
  53. package/dist/if-defined-BciplFKz.js +744 -0
  54. package/dist/image-qMjyiXM0.js +8 -0
  55. package/dist/index--3Zp0jAb.js +45 -0
  56. package/dist/index-1adX-Fit.js +65 -0
  57. package/dist/index-AvC0IGDl.js +7864 -0
  58. package/dist/index-B2-vKLd8.js +276 -0
  59. package/dist/index-B2iDt0TJ.js +146 -0
  60. package/dist/index-B5zkXsLJ.js +320 -0
  61. package/dist/index-B7K86vWu.js +1742 -0
  62. package/dist/index-BBkcvSiY.js +511 -0
  63. package/dist/index-BdjxQs66.js +181 -0
  64. package/dist/index-Bijd4_Ns.js +294 -0
  65. package/dist/index-BpXOsxzU.js +387 -0
  66. package/dist/index-C1QEJL-2.js +572 -0
  67. package/dist/index-C27dwOyE.js +243 -0
  68. package/dist/index-C4BX3QW8.js +58 -0
  69. package/dist/index-CMPIqsB1.js +170 -0
  70. package/dist/index-CTYngdl0.js +21991 -0
  71. package/dist/index-CUdQyyFn.js +51 -0
  72. package/dist/index-CX60z_g2.js +573 -0
  73. package/dist/index-CppCc1n8.js +65 -0
  74. package/dist/index-CqVegmN4.js +559 -0
  75. package/dist/index-CuiyMA8F.js +78 -0
  76. package/dist/index-CwB_qRfM.js +305 -0
  77. package/dist/index-CxOF7GqE.js +265 -0
  78. package/dist/index-D-IzHD_8.js +54 -0
  79. package/dist/index-DRNiFv9I.js +218 -0
  80. package/dist/index-Da8oZh8H.js +838 -0
  81. package/dist/index-DiHImG4L.js +44236 -0
  82. package/dist/index-DmOMXRG1.js +181 -0
  83. package/dist/index-DoSYqTQg.js +199 -0
  84. package/dist/index-DpHXq5_E.js +603 -0
  85. package/dist/index-DtCsAVBg.js +78 -0
  86. package/dist/index-Ij6XA6_4.js +77 -0
  87. package/dist/index-SzyBYfzA.js +8490 -0
  88. package/dist/index-eW8y-mXH.js +257 -0
  89. package/dist/index-fxzIDZsb.js +75 -0
  90. package/dist/index-lbhz9evJ.js +97 -0
  91. package/dist/index.d.ts +3 -0
  92. package/dist/index.js +4 -0
  93. package/dist/info-DMIGgjkL.js +7 -0
  94. package/dist/info-circle-CJuIKZSx.js +16 -0
  95. package/dist/lightbulb-qFT6WEWV.js +7 -0
  96. package/dist/localBatchGatewayRequest-CsMVMFBc.js +91 -0
  97. package/dist/mail-DoYgQvOt.js +12 -0
  98. package/dist/mobile-URtsh7o-.js +13 -0
  99. package/dist/more-DoQd10TF.js +15 -0
  100. package/dist/network-placeholder-BBA2Ue6C.js +18 -0
  101. package/dist/nftPlaceholder-C9RXWz9k.js +12 -0
  102. package/dist/off-YcuDQczT.js +12 -0
  103. package/dist/onramp-BfqDIx4o.js +1279 -0
  104. package/dist/parseSignature-280HB24T.js +3560 -0
  105. package/dist/play-store-sFaloG_r.js +36 -0
  106. package/dist/plus-l0wekSht.js +17 -0
  107. package/dist/qr-code-CihrUU4G.js +10 -0
  108. package/dist/receive-dfY1Cu-g.js +186 -0
  109. package/dist/recycle-horizontal-nXu6YaPw.js +13 -0
  110. package/dist/ref-huAzXCX0.js +41 -0
  111. package/dist/refresh-D2ZbVeNC.js +12 -0
  112. package/dist/reown-logo-BMaTMJmc.js +16 -0
  113. package/dist/search-YVM9q3J-.js +12 -0
  114. package/dist/secp256k1-BrysY3Sv.js +1302 -0
  115. package/dist/secp256k1-DPQgTBwQ.js +1510 -0
  116. package/dist/send-BwQZPKxI.js +19 -0
  117. package/dist/send-GyetMVu1.js +1038 -0
  118. package/dist/socials-B0W91J9k.js +574 -0
  119. package/dist/swapHorizontal-Dy_oQEkp.js +12 -0
  120. package/dist/swapHorizontalBold-C4JpaMpc.js +12 -0
  121. package/dist/swapHorizontalMedium-D5NuVZFh.js +20 -0
  122. package/dist/swapHorizontalRoundedBold-Bq4P2MCj.js +12 -0
  123. package/dist/swapVertical-CVQ8Mg03.js +12 -0
  124. package/dist/swaps-CA04SSdK.js +1637 -0
  125. package/dist/telegram-BP4SgW_L.js +20 -0
  126. package/dist/three-dots-BJYGJ-dQ.js +9 -0
  127. package/dist/transactions-Bq-98Tsg.js +37 -0
  128. package/dist/twitch-DTATWo9M.js +22 -0
  129. package/dist/twitterIcon-D5UWPInb.js +10 -0
  130. package/dist/types.d.ts +128 -0
  131. package/dist/ui/Modal.d.ts +9 -0
  132. package/dist/ui/index.d.ts +6 -0
  133. package/dist/verify-Byvj8Wi1.js +12 -0
  134. package/dist/verify-filled-B40taNm0.js +12 -0
  135. package/dist/w3m-modal-HV6SE74G.js +1037 -0
  136. package/dist/wallet-Cp-6Kk88.js +12 -0
  137. package/dist/wallet-placeholder-C3juwA9o.js +18 -0
  138. package/dist/walletconnect-CRkIiLCx.js +36 -0
  139. package/dist/warning-circle-DtvCLwG4.js +16 -0
  140. package/dist/x-Cqyx5eCt.js +16 -0
  141. package/package.json +70 -0
@@ -0,0 +1,838 @@
1
+ import { dd as Y, dE as _, cY as R, cT as h, d8 as U, d1 as f, dF as $, cP as W, d3 as A, cU as I, cS as E, cE as O, dG as S, cN as P, cQ as B, cR as H, cz as M, cA as G, cB as d, cW as F } from "./index-DiHImG4L.js";
2
+ import { o as C, r as w, c as V } from "./if-defined-BciplFKz.js";
3
+ import "./index-Bijd4_Ns.js";
4
+ import "./index-B5zkXsLJ.js";
5
+ import "./index-1adX-Fit.js";
6
+ import "./index-CUdQyyFn.js";
7
+ import "./index-BdjxQs66.js";
8
+ import "./index-lbhz9evJ.js";
9
+ import "./index--3Zp0jAb.js";
10
+ import "./index-CppCc1n8.js";
11
+ const o = {
12
+ INVALID_PAYMENT_CONFIG: "INVALID_PAYMENT_CONFIG",
13
+ INVALID_RECIPIENT: "INVALID_RECIPIENT",
14
+ INVALID_ASSET: "INVALID_ASSET",
15
+ INVALID_AMOUNT: "INVALID_AMOUNT",
16
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
17
+ UNABLE_TO_INITIATE_PAYMENT: "UNABLE_TO_INITIATE_PAYMENT",
18
+ INVALID_CHAIN_NAMESPACE: "INVALID_CHAIN_NAMESPACE",
19
+ GENERIC_PAYMENT_ERROR: "GENERIC_PAYMENT_ERROR",
20
+ UNABLE_TO_GET_EXCHANGES: "UNABLE_TO_GET_EXCHANGES",
21
+ ASSET_NOT_SUPPORTED: "ASSET_NOT_SUPPORTED",
22
+ UNABLE_TO_GET_PAY_URL: "UNABLE_TO_GET_PAY_URL",
23
+ UNABLE_TO_GET_BUY_STATUS: "UNABLE_TO_GET_BUY_STATUS"
24
+ }, g = {
25
+ [o.INVALID_PAYMENT_CONFIG]: "Invalid payment configuration",
26
+ [o.INVALID_RECIPIENT]: "Invalid recipient address",
27
+ [o.INVALID_ASSET]: "Invalid asset specified",
28
+ [o.INVALID_AMOUNT]: "Invalid payment amount",
29
+ [o.UNKNOWN_ERROR]: "Unknown payment error occurred",
30
+ [o.UNABLE_TO_INITIATE_PAYMENT]: "Unable to initiate payment",
31
+ [o.INVALID_CHAIN_NAMESPACE]: "Invalid chain namespace",
32
+ [o.GENERIC_PAYMENT_ERROR]: "Unable to process payment",
33
+ [o.UNABLE_TO_GET_EXCHANGES]: "Unable to get exchanges",
34
+ [o.ASSET_NOT_SUPPORTED]: "Asset not supported by the selected exchange",
35
+ [o.UNABLE_TO_GET_PAY_URL]: "Unable to get payment URL",
36
+ [o.UNABLE_TO_GET_BUY_STATUS]: "Unable to get buy status"
37
+ };
38
+ class c extends Error {
39
+ get message() {
40
+ return g[this.code];
41
+ }
42
+ constructor(e, s) {
43
+ super(g[e]), this.name = "AppKitPayError", this.code = e, this.details = s, Error.captureStackTrace && Error.captureStackTrace(this, c);
44
+ }
45
+ }
46
+ const j = "https://rpc.walletconnect.org/v1/json-rpc";
47
+ class K extends Error {
48
+ }
49
+ function z() {
50
+ const t = Y.getSnapshot().projectId;
51
+ return `${j}?projectId=${t}`;
52
+ }
53
+ async function k(t, e) {
54
+ const s = z(), i = await (await fetch(s, {
55
+ method: "POST",
56
+ body: JSON.stringify({
57
+ jsonrpc: "2.0",
58
+ id: 1,
59
+ method: t,
60
+ params: e
61
+ }),
62
+ headers: { "Content-Type": "application/json" }
63
+ })).json();
64
+ if (i.error)
65
+ throw new K(i.error.message);
66
+ return i;
67
+ }
68
+ async function L(t) {
69
+ return (await k("reown_getExchanges", t)).result;
70
+ }
71
+ async function q(t) {
72
+ return (await k("reown_getExchangePayUrl", t)).result;
73
+ }
74
+ async function X(t) {
75
+ return (await k("reown_getExchangeBuyStatus", t)).result;
76
+ }
77
+ const J = ["eip155"], Q = {
78
+ eip155: {
79
+ native: { assetNamespace: "slip44", assetReference: "60" },
80
+ defaultTokenNamespace: "erc20"
81
+ },
82
+ solana: {
83
+ native: { assetNamespace: "slip44", assetReference: "501" },
84
+ defaultTokenNamespace: "token"
85
+ }
86
+ };
87
+ function b(t, e) {
88
+ const { chainNamespace: s, chainId: a } = _.parseCaipNetworkId(t), r = Q[s];
89
+ if (!r)
90
+ throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${s}`);
91
+ let i = r.native.assetNamespace, u = r.native.assetReference;
92
+ return e !== "native" && (i = r.defaultTokenNamespace, u = e), `${`${s}:${a}`}/${i}:${u}`;
93
+ }
94
+ function Z(t) {
95
+ const { chainNamespace: e } = _.parseCaipNetworkId(t);
96
+ return J.includes(e);
97
+ }
98
+ async function ee(t) {
99
+ const { paymentAssetNetwork: e, activeCaipNetwork: s, approvedCaipNetworkIds: a, requestedCaipNetworks: r } = t, u = R.sortRequestedNetworks(a, r).find((T) => T.caipNetworkId === e);
100
+ if (!u)
101
+ throw new c(o.INVALID_PAYMENT_CONFIG);
102
+ if (u.caipNetworkId === s.caipNetworkId)
103
+ return;
104
+ const p = h.getNetworkProp("supportsAllNetworks", u.chainNamespace);
105
+ if (!((a == null ? void 0 : a.includes(u.caipNetworkId)) || p))
106
+ throw new c(o.INVALID_PAYMENT_CONFIG);
107
+ try {
108
+ await h.switchActiveNetwork(u);
109
+ } catch (T) {
110
+ throw new c(o.GENERIC_PAYMENT_ERROR, T);
111
+ }
112
+ }
113
+ async function te(t, e, s) {
114
+ var p;
115
+ if (e !== U.CHAIN.EVM)
116
+ throw new c(o.INVALID_CHAIN_NAMESPACE);
117
+ if (!s.fromAddress)
118
+ throw new c(o.INVALID_PAYMENT_CONFIG, "fromAddress is required for native EVM payments.");
119
+ const a = typeof s.amount == "string" ? parseFloat(s.amount) : s.amount;
120
+ if (isNaN(a))
121
+ throw new c(o.INVALID_PAYMENT_CONFIG);
122
+ const r = ((p = t.metadata) == null ? void 0 : p.decimals) ?? 18, i = f.parseUnits(a.toString(), r);
123
+ if (typeof i != "bigint")
124
+ throw new c(o.GENERIC_PAYMENT_ERROR);
125
+ return await f.sendTransaction({
126
+ chainNamespace: e,
127
+ to: s.recipient,
128
+ address: s.fromAddress,
129
+ value: i,
130
+ data: "0x"
131
+ }) ?? void 0;
132
+ }
133
+ async function ne(t, e) {
134
+ if (!e.fromAddress)
135
+ throw new c(o.INVALID_PAYMENT_CONFIG, "fromAddress is required for ERC20 EVM payments.");
136
+ const s = t.asset, a = e.recipient, r = Number(t.metadata.decimals), i = f.parseUnits(e.amount.toString(), r);
137
+ if (i === void 0)
138
+ throw new c(o.GENERIC_PAYMENT_ERROR);
139
+ return await f.writeContract({
140
+ fromAddress: e.fromAddress,
141
+ tokenAddress: s,
142
+ args: [a, i],
143
+ method: "transfer",
144
+ abi: $.getERC20Abi(s),
145
+ chainNamespace: U.CHAIN.EVM
146
+ }) ?? void 0;
147
+ }
148
+ const D = 0, v = "unknown", n = W({
149
+ paymentAsset: {
150
+ network: "eip155:1",
151
+ asset: "0x0",
152
+ metadata: {
153
+ name: "0x0",
154
+ symbol: "0x0",
155
+ decimals: 0
156
+ }
157
+ },
158
+ recipient: "0x0",
159
+ amount: 0,
160
+ isConfigured: !1,
161
+ error: null,
162
+ isPaymentInProgress: !1,
163
+ exchanges: [],
164
+ isLoading: !1,
165
+ openInNewTab: !0,
166
+ redirectUrl: void 0,
167
+ payWithExchange: void 0,
168
+ currentPayment: void 0,
169
+ analyticsSet: !1,
170
+ paymentId: void 0
171
+ }), l = {
172
+ state: n,
173
+ subscribe(t) {
174
+ return H(n, () => t(n));
175
+ },
176
+ subscribeKey(t, e) {
177
+ return B(n, t, e);
178
+ },
179
+ async handleOpenPay(t) {
180
+ this.resetState(), this.setPaymentConfig(t), this.subscribeEvents(), this.initializeAnalytics(), n.isConfigured = !0, A.sendEvent({
181
+ type: "track",
182
+ event: "PAY_MODAL_OPEN",
183
+ properties: {
184
+ exchanges: n.exchanges,
185
+ configuration: {
186
+ network: n.paymentAsset.network,
187
+ asset: n.paymentAsset.asset,
188
+ recipient: n.recipient,
189
+ amount: n.amount
190
+ }
191
+ }
192
+ }), await P.open({
193
+ view: "Pay"
194
+ });
195
+ },
196
+ resetState() {
197
+ n.paymentAsset = {
198
+ network: "eip155:1",
199
+ asset: "0x0",
200
+ metadata: { name: "0x0", symbol: "0x0", decimals: 0 }
201
+ }, n.recipient = "0x0", n.amount = 0, n.isConfigured = !1, n.error = null, n.isPaymentInProgress = !1, n.isLoading = !1, n.currentPayment = void 0;
202
+ },
203
+ setPaymentConfig(t) {
204
+ if (!t.paymentAsset)
205
+ throw new c(o.INVALID_PAYMENT_CONFIG);
206
+ try {
207
+ n.paymentAsset = t.paymentAsset, n.recipient = t.recipient, n.amount = t.amount, n.openInNewTab = t.openInNewTab ?? !0, n.redirectUrl = t.redirectUrl, n.payWithExchange = t.payWithExchange, n.error = null;
208
+ } catch (e) {
209
+ throw new c(o.INVALID_PAYMENT_CONFIG, e.message);
210
+ }
211
+ },
212
+ getPaymentAsset() {
213
+ return n.paymentAsset;
214
+ },
215
+ getExchanges() {
216
+ return n.exchanges;
217
+ },
218
+ async fetchExchanges() {
219
+ try {
220
+ n.isLoading = !0;
221
+ const t = await L({
222
+ page: D,
223
+ asset: b(n.paymentAsset.network, n.paymentAsset.asset),
224
+ amount: n.amount.toString()
225
+ });
226
+ n.exchanges = t.exchanges.slice(0, 2);
227
+ } catch {
228
+ throw I.showError(g.UNABLE_TO_GET_EXCHANGES), new c(o.UNABLE_TO_GET_EXCHANGES);
229
+ } finally {
230
+ n.isLoading = !1;
231
+ }
232
+ },
233
+ async getAvailableExchanges(t) {
234
+ var e;
235
+ try {
236
+ const s = t != null && t.asset && (t != null && t.network) ? b(t.network, t.asset) : void 0;
237
+ return await L({
238
+ page: (t == null ? void 0 : t.page) ?? D,
239
+ asset: s,
240
+ amount: (e = t == null ? void 0 : t.amount) == null ? void 0 : e.toString()
241
+ });
242
+ } catch {
243
+ throw new c(o.UNABLE_TO_GET_EXCHANGES);
244
+ }
245
+ },
246
+ async getPayUrl(t, e, s = !1) {
247
+ try {
248
+ const a = Number(e.amount), r = await q({
249
+ exchangeId: t,
250
+ asset: b(e.network, e.asset),
251
+ amount: a.toString(),
252
+ recipient: `${e.network}:${e.recipient}`
253
+ });
254
+ return A.sendEvent({
255
+ type: "track",
256
+ event: "PAY_EXCHANGE_SELECTED",
257
+ properties: {
258
+ exchange: {
259
+ id: t
260
+ },
261
+ configuration: {
262
+ network: e.network,
263
+ asset: e.asset,
264
+ recipient: e.recipient,
265
+ amount: a
266
+ },
267
+ currentPayment: {
268
+ type: "exchange",
269
+ exchangeId: t
270
+ },
271
+ headless: s
272
+ }
273
+ }), s && (this.initiatePayment(), A.sendEvent({
274
+ type: "track",
275
+ event: "PAY_INITIATED",
276
+ properties: {
277
+ paymentId: n.paymentId || v,
278
+ configuration: {
279
+ network: e.network,
280
+ asset: e.asset,
281
+ recipient: e.recipient,
282
+ amount: a
283
+ },
284
+ currentPayment: {
285
+ type: "exchange",
286
+ exchangeId: t
287
+ }
288
+ }
289
+ })), r;
290
+ } catch (a) {
291
+ throw a instanceof Error && a.message.includes("is not supported") ? new c(o.ASSET_NOT_SUPPORTED) : new Error(a.message);
292
+ }
293
+ },
294
+ async openPayUrl(t, e, s = !1) {
295
+ try {
296
+ const a = await this.getPayUrl(t.exchangeId, e, s);
297
+ if (!a)
298
+ throw new c(o.UNABLE_TO_GET_PAY_URL);
299
+ const i = t.openInNewTab ?? !0 ? "_blank" : "_self";
300
+ return R.openHref(a.url, i), a;
301
+ } catch (a) {
302
+ throw a instanceof c ? n.error = a.message : n.error = g.GENERIC_PAYMENT_ERROR, new c(o.UNABLE_TO_GET_PAY_URL);
303
+ }
304
+ },
305
+ subscribeEvents() {
306
+ n.isConfigured || (S.subscribeProviders(async (t) => {
307
+ const e = h.state.activeChain;
308
+ S.getProvider(e) && await this.handlePayment();
309
+ }), E.subscribeKey("caipAddress", async (t) => {
310
+ t && await this.handlePayment();
311
+ }));
312
+ },
313
+ async handlePayment() {
314
+ n.currentPayment = {
315
+ type: "wallet",
316
+ status: "IN_PROGRESS"
317
+ };
318
+ const t = E.state.caipAddress;
319
+ if (!t)
320
+ return;
321
+ const { chainId: e, address: s } = _.parseCaipAddress(t), a = h.state.activeChain;
322
+ if (!s || !e || !a || !S.getProvider(a))
323
+ return;
324
+ const i = h.state.activeCaipNetwork;
325
+ if (i && !n.isPaymentInProgress)
326
+ try {
327
+ this.initiatePayment();
328
+ const u = h.getAllRequestedCaipNetworks(), p = h.getAllApprovedCaipNetworkIds();
329
+ switch (await ee({
330
+ paymentAssetNetwork: n.paymentAsset.network,
331
+ activeCaipNetwork: i,
332
+ approvedCaipNetworkIds: p,
333
+ requestedCaipNetworks: u
334
+ }), await P.open({
335
+ view: "PayLoading"
336
+ }), a) {
337
+ case U.CHAIN.EVM:
338
+ n.paymentAsset.asset === "native" && (n.currentPayment.result = await te(n.paymentAsset, a, {
339
+ recipient: n.recipient,
340
+ amount: n.amount,
341
+ fromAddress: s
342
+ })), n.paymentAsset.asset.startsWith("0x") && (n.currentPayment.result = await ne(n.paymentAsset, {
343
+ recipient: n.recipient,
344
+ amount: n.amount,
345
+ fromAddress: s
346
+ })), n.currentPayment.status = "SUCCESS";
347
+ break;
348
+ default:
349
+ throw new c(o.INVALID_CHAIN_NAMESPACE);
350
+ }
351
+ } catch (u) {
352
+ u instanceof c ? n.error = u.message : n.error = g.GENERIC_PAYMENT_ERROR, n.currentPayment.status = "FAILED", I.showError(n.error);
353
+ } finally {
354
+ n.isPaymentInProgress = !1;
355
+ }
356
+ },
357
+ getExchangeById(t) {
358
+ return n.exchanges.find((e) => e.id === t);
359
+ },
360
+ validatePayConfig(t) {
361
+ const { paymentAsset: e, recipient: s, amount: a } = t;
362
+ if (!e)
363
+ throw new c(o.INVALID_PAYMENT_CONFIG);
364
+ if (!s)
365
+ throw new c(o.INVALID_RECIPIENT);
366
+ if (!e.asset)
367
+ throw new c(o.INVALID_ASSET);
368
+ if (a == null || a <= 0)
369
+ throw new c(o.INVALID_AMOUNT);
370
+ },
371
+ handlePayWithWallet() {
372
+ const t = E.state.caipAddress;
373
+ if (!t) {
374
+ O.push("Connect");
375
+ return;
376
+ }
377
+ const { chainId: e, address: s } = _.parseCaipAddress(t), a = h.state.activeChain;
378
+ if (!s || !e || !a) {
379
+ O.push("Connect");
380
+ return;
381
+ }
382
+ this.handlePayment();
383
+ },
384
+ async handlePayWithExchange(t) {
385
+ try {
386
+ n.currentPayment = {
387
+ type: "exchange",
388
+ exchangeId: t
389
+ };
390
+ const { network: e, asset: s } = n.paymentAsset, a = {
391
+ network: e,
392
+ asset: s,
393
+ amount: n.amount,
394
+ recipient: n.recipient
395
+ }, r = await this.getPayUrl(t, a);
396
+ if (!r)
397
+ throw new c(o.UNABLE_TO_INITIATE_PAYMENT);
398
+ return n.currentPayment.sessionId = r.sessionId, n.currentPayment.status = "IN_PROGRESS", n.currentPayment.exchangeId = t, this.initiatePayment(), {
399
+ url: r.url,
400
+ openInNewTab: n.openInNewTab
401
+ };
402
+ } catch (e) {
403
+ return e instanceof c ? n.error = e.message : n.error = g.GENERIC_PAYMENT_ERROR, n.isPaymentInProgress = !1, I.showError(n.error), null;
404
+ }
405
+ },
406
+ async getBuyStatus(t, e) {
407
+ var s, a;
408
+ try {
409
+ const r = await X({ sessionId: e, exchangeId: t });
410
+ return (r.status === "SUCCESS" || r.status === "FAILED") && A.sendEvent({
411
+ type: "track",
412
+ event: r.status === "SUCCESS" ? "PAY_SUCCESS" : "PAY_ERROR",
413
+ properties: {
414
+ paymentId: n.paymentId || v,
415
+ configuration: {
416
+ network: n.paymentAsset.network,
417
+ asset: n.paymentAsset.asset,
418
+ recipient: n.recipient,
419
+ amount: n.amount
420
+ },
421
+ currentPayment: {
422
+ type: "exchange",
423
+ exchangeId: (s = n.currentPayment) == null ? void 0 : s.exchangeId,
424
+ sessionId: (a = n.currentPayment) == null ? void 0 : a.sessionId,
425
+ result: r.txHash
426
+ }
427
+ }
428
+ }), r;
429
+ } catch {
430
+ throw new c(o.UNABLE_TO_GET_BUY_STATUS);
431
+ }
432
+ },
433
+ async updateBuyStatus(t, e) {
434
+ try {
435
+ const s = await this.getBuyStatus(t, e);
436
+ n.currentPayment && (n.currentPayment.status = s.status, n.currentPayment.result = s.txHash), (s.status === "SUCCESS" || s.status === "FAILED") && (n.isPaymentInProgress = !1);
437
+ } catch {
438
+ throw new c(o.UNABLE_TO_GET_BUY_STATUS);
439
+ }
440
+ },
441
+ initiatePayment() {
442
+ n.isPaymentInProgress = !0, n.paymentId = crypto.randomUUID();
443
+ },
444
+ initializeAnalytics() {
445
+ n.analyticsSet || (n.analyticsSet = !0, this.subscribeKey("isPaymentInProgress", (t) => {
446
+ var e;
447
+ if ((e = n.currentPayment) != null && e.status && n.currentPayment.status !== "UNKNOWN") {
448
+ const s = {
449
+ IN_PROGRESS: "PAY_INITIATED",
450
+ SUCCESS: "PAY_SUCCESS",
451
+ FAILED: "PAY_ERROR"
452
+ }[n.currentPayment.status];
453
+ A.sendEvent({
454
+ type: "track",
455
+ event: s,
456
+ properties: {
457
+ paymentId: n.paymentId || v,
458
+ configuration: {
459
+ network: n.paymentAsset.network,
460
+ asset: n.paymentAsset.asset,
461
+ recipient: n.recipient,
462
+ amount: n.amount
463
+ },
464
+ currentPayment: {
465
+ type: n.currentPayment.type,
466
+ exchangeId: n.currentPayment.exchangeId,
467
+ sessionId: n.currentPayment.sessionId,
468
+ result: n.currentPayment.result
469
+ }
470
+ }
471
+ });
472
+ }
473
+ }));
474
+ }
475
+ }, se = M`
476
+ wui-separator {
477
+ margin: var(--wui-spacing-m) calc(var(--wui-spacing-m) * -1) var(--wui-spacing-xs)
478
+ calc(var(--wui-spacing-m) * -1);
479
+ width: calc(100% + var(--wui-spacing-s) * 2);
480
+ }
481
+
482
+ .token-display {
483
+ padding: var(--wui-spacing-s) var(--wui-spacing-m);
484
+ border-radius: var(--wui-border-radius-s);
485
+ background-color: var(--wui-color-bg-125);
486
+ margin-top: var(--wui-spacing-s);
487
+ margin-bottom: var(--wui-spacing-s);
488
+ }
489
+
490
+ .token-display wui-text {
491
+ text-transform: none;
492
+ }
493
+
494
+ wui-loading-spinner {
495
+ padding: var(--wui-spacing-xs);
496
+ }
497
+ `;
498
+ var y = function(t, e, s, a) {
499
+ var r = arguments.length, i = r < 3 ? e : a === null ? a = Object.getOwnPropertyDescriptor(e, s) : a, u;
500
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(t, e, s, a);
501
+ else for (var p = t.length - 1; p >= 0; p--) (u = t[p]) && (i = (r < 3 ? u(i) : r > 3 ? u(e, s, i) : u(e, s)) || i);
502
+ return r > 3 && i && Object.defineProperty(e, s, i), i;
503
+ };
504
+ let m = class extends G {
505
+ constructor() {
506
+ super(), this.unsubscribe = [], this.amount = "", this.tokenSymbol = "", this.networkName = "", this.exchanges = l.state.exchanges, this.isLoading = l.state.isLoading, this.loadingExchangeId = null, this.connectedWalletInfo = E.state.connectedWalletInfo, this.initializePaymentDetails(), this.unsubscribe.push(l.subscribeKey("exchanges", (e) => this.exchanges = e)), this.unsubscribe.push(l.subscribeKey("isLoading", (e) => this.isLoading = e)), this.unsubscribe.push(E.subscribe((e) => this.connectedWalletInfo = e.connectedWalletInfo)), l.fetchExchanges();
507
+ }
508
+ get isWalletConnected() {
509
+ return E.state.status === "connected";
510
+ }
511
+ render() {
512
+ return d`
513
+ <wui-flex flexDirection="column">
514
+ <wui-flex flexDirection="column" .padding=${["0", "l", "l", "l"]} gap="s">
515
+ ${this.renderPaymentHeader()}
516
+
517
+ <wui-flex flexDirection="column" gap="s">
518
+ ${this.renderPayWithWallet()} ${this.renderExchangeOptions()}
519
+ </wui-flex>
520
+ </wui-flex>
521
+ </wui-flex>
522
+ `;
523
+ }
524
+ initializePaymentDetails() {
525
+ const e = l.getPaymentAsset();
526
+ this.networkName = e.network, this.tokenSymbol = e.metadata.symbol, this.amount = l.state.amount.toString();
527
+ }
528
+ renderPayWithWallet() {
529
+ return Z(this.networkName) ? d`<wui-flex flexDirection="column" gap="s">
530
+ ${this.isWalletConnected ? this.renderConnectedView() : this.renderDisconnectedView()}
531
+ </wui-flex>
532
+ <wui-separator text="or"></wui-separator>` : d``;
533
+ }
534
+ renderPaymentHeader() {
535
+ let e = this.networkName;
536
+ if (this.networkName) {
537
+ const a = h.getAllRequestedCaipNetworks().find((r) => r.caipNetworkId === this.networkName);
538
+ a && (e = a.name);
539
+ }
540
+ return d`
541
+ <wui-flex flexDirection="column" alignItems="center">
542
+ <wui-flex alignItems="center" gap="xs">
543
+ <wui-text variant="large-700" color="fg-100">${this.amount || "0.0000"}</wui-text>
544
+ <wui-flex class="token-display" alignItems="center" gap="xxs">
545
+ <wui-text variant="paragraph-600" color="fg-100">
546
+ ${this.tokenSymbol || "Unknown Asset"}
547
+ </wui-text>
548
+ ${e ? d`
549
+ <wui-text variant="small-500" color="fg-200"> on ${e} </wui-text>
550
+ ` : ""}
551
+ </wui-flex>
552
+ </wui-flex>
553
+ </wui-flex>
554
+ `;
555
+ }
556
+ renderConnectedView() {
557
+ var s, a, r;
558
+ const e = ((s = this.connectedWalletInfo) == null ? void 0 : s.name) || "connected wallet";
559
+ return d`
560
+ <wui-list-item
561
+ @click=${this.onWalletPayment}
562
+ ?chevron=${!0}
563
+ data-testid="wallet-payment-option"
564
+ >
565
+ <wui-flex alignItems="center" gap="s">
566
+ <wui-wallet-image
567
+ size="sm"
568
+ imageSrc=${C((a = this.connectedWalletInfo) == null ? void 0 : a.icon)}
569
+ name=${C((r = this.connectedWalletInfo) == null ? void 0 : r.name)}
570
+ ></wui-wallet-image>
571
+ <wui-text variant="paragraph-500" color="inherit">Pay with ${e}</wui-text>
572
+ </wui-flex>
573
+ </wui-list-item>
574
+
575
+ <wui-list-item
576
+ variant="icon"
577
+ iconVariant="overlay"
578
+ icon="disconnect"
579
+ @click=${this.onDisconnect}
580
+ data-testid="disconnect-button"
581
+ ?chevron=${!1}
582
+ >
583
+ <wui-text variant="paragraph-500" color="fg-200">Disconnect</wui-text>
584
+ </wui-list-item>
585
+ `;
586
+ }
587
+ renderDisconnectedView() {
588
+ return d`<wui-list-item
589
+ variant="icon"
590
+ iconVariant="overlay"
591
+ icon="walletPlaceholder"
592
+ @click=${this.onWalletPayment}
593
+ ?chevron=${!0}
594
+ data-testid="wallet-payment-option"
595
+ >
596
+ <wui-text variant="paragraph-500" color="inherit">Pay from wallet</wui-text>
597
+ </wui-list-item>`;
598
+ }
599
+ renderExchangeOptions() {
600
+ return this.isLoading ? d`<wui-flex justifyContent="center" alignItems="center">
601
+ <wui-spinner size="md"></wui-spinner>
602
+ </wui-flex>` : this.exchanges.length === 0 ? d`<wui-flex justifyContent="center" alignItems="center">
603
+ <wui-text variant="paragraph-500" color="fg-100">No exchanges available</wui-text>
604
+ </wui-flex>` : this.exchanges.map((e) => d`
605
+ <wui-list-item
606
+ @click=${() => this.onExchangePayment(e.id)}
607
+ data-testid="exchange-option-${e.id}"
608
+ ?chevron=${!0}
609
+ ?disabled=${this.loadingExchangeId !== null}
610
+ >
611
+ <wui-flex alignItems="center" gap="s">
612
+ ${this.loadingExchangeId === e.id ? d`<wui-loading-spinner color="accent-100" size="md"></wui-loading-spinner>` : d`<wui-wallet-image
613
+ size="sm"
614
+ imageSrc=${C(e.imageUrl)}
615
+ name=${e.name}
616
+ ></wui-wallet-image>`}
617
+ <wui-text flexGrow="1" variant="paragraph-500" color="inherit"
618
+ >Pay with ${e.name} <wui-spinner size="sm" color="fg-200"></wui-spinner
619
+ ></wui-text>
620
+ </wui-flex>
621
+ </wui-list-item>
622
+ `);
623
+ }
624
+ onWalletPayment() {
625
+ l.handlePayWithWallet();
626
+ }
627
+ async onExchangePayment(e) {
628
+ try {
629
+ this.loadingExchangeId = e;
630
+ const s = await l.handlePayWithExchange(e);
631
+ s && (await P.open({
632
+ view: "PayLoading"
633
+ }), R.openHref(s.url, s.openInNewTab ? "_blank" : "_self"));
634
+ } catch (s) {
635
+ console.error("Failed to pay with exchange", s), I.showError("Failed to pay with exchange");
636
+ } finally {
637
+ this.loadingExchangeId = null;
638
+ }
639
+ }
640
+ async onDisconnect(e) {
641
+ e.stopPropagation();
642
+ try {
643
+ await f.disconnect(), P.close();
644
+ } catch {
645
+ console.error("Failed to disconnect"), I.showError("Failed to disconnect");
646
+ }
647
+ }
648
+ disconnectedCallback() {
649
+ this.unsubscribe.forEach((e) => e());
650
+ }
651
+ };
652
+ m.styles = se;
653
+ y([
654
+ w()
655
+ ], m.prototype, "amount", void 0);
656
+ y([
657
+ w()
658
+ ], m.prototype, "tokenSymbol", void 0);
659
+ y([
660
+ w()
661
+ ], m.prototype, "networkName", void 0);
662
+ y([
663
+ w()
664
+ ], m.prototype, "exchanges", void 0);
665
+ y([
666
+ w()
667
+ ], m.prototype, "isLoading", void 0);
668
+ y([
669
+ w()
670
+ ], m.prototype, "loadingExchangeId", void 0);
671
+ y([
672
+ w()
673
+ ], m.prototype, "connectedWalletInfo", void 0);
674
+ m = y([
675
+ V("w3m-pay-view")
676
+ ], m);
677
+ const ae = M`
678
+ :host {
679
+ display: block;
680
+ height: 100%;
681
+ width: 100%;
682
+ }
683
+ `;
684
+ var x = function(t, e, s, a) {
685
+ var r = arguments.length, i = r < 3 ? e : a === null ? a = Object.getOwnPropertyDescriptor(e, s) : a, u;
686
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(t, e, s, a);
687
+ else for (var p = t.length - 1; p >= 0; p--) (u = t[p]) && (i = (r < 3 ? u(i) : r > 3 ? u(e, s, i) : u(e, s)) || i);
688
+ return r > 3 && i && Object.defineProperty(e, s, i), i;
689
+ };
690
+ const re = 4e3;
691
+ let N = class extends G {
692
+ constructor() {
693
+ super(), this.loadingMessage = "", this.subMessage = "", this.paymentState = "in-progress", this.paymentState = l.state.isPaymentInProgress ? "in-progress" : "completed", this.updateMessages(), this.setupSubscription(), this.setupExchangeSubscription();
694
+ }
695
+ disconnectedCallback() {
696
+ clearInterval(this.exchangeSubscription);
697
+ }
698
+ render() {
699
+ return d`
700
+ <wui-flex
701
+ flexDirection="column"
702
+ alignItems="center"
703
+ .padding=${["xl", "xl", "xl", "xl"]}
704
+ gap="xl"
705
+ >
706
+ <wui-flex justifyContent="center" alignItems="center"> ${this.getStateIcon()} </wui-flex>
707
+ <wui-flex flexDirection="column" alignItems="center" gap="xs">
708
+ <wui-text align="center" variant="paragraph-500" color="fg-100">
709
+ ${this.loadingMessage}
710
+ </wui-text>
711
+ <wui-text align="center" variant="small-400" color="fg-200">
712
+ ${this.subMessage}
713
+ </wui-text>
714
+ </wui-flex>
715
+ </wui-flex>
716
+ `;
717
+ }
718
+ updateMessages() {
719
+ var e;
720
+ switch (this.paymentState) {
721
+ case "completed":
722
+ this.loadingMessage = "Payment completed", this.subMessage = "Your transaction has been successfully processed";
723
+ break;
724
+ case "error":
725
+ this.loadingMessage = "Payment failed", this.subMessage = "There was an error processing your transaction";
726
+ break;
727
+ case "in-progress":
728
+ default:
729
+ ((e = l.state.currentPayment) == null ? void 0 : e.type) === "exchange" ? (this.loadingMessage = "Payment initiated", this.subMessage = "Please complete the payment on the exchange") : (this.loadingMessage = "Awaiting payment confirmation", this.subMessage = "Please confirm the payment transaction in your wallet");
730
+ break;
731
+ }
732
+ }
733
+ getStateIcon() {
734
+ switch (this.paymentState) {
735
+ case "completed":
736
+ return this.successTemplate();
737
+ case "error":
738
+ return this.errorTemplate();
739
+ case "in-progress":
740
+ default:
741
+ return this.loaderTemplate();
742
+ }
743
+ }
744
+ setupExchangeSubscription() {
745
+ var e;
746
+ ((e = l.state.currentPayment) == null ? void 0 : e.type) === "exchange" && (this.exchangeSubscription = setInterval(async () => {
747
+ var r, i, u;
748
+ const s = (r = l.state.currentPayment) == null ? void 0 : r.exchangeId, a = (i = l.state.currentPayment) == null ? void 0 : i.sessionId;
749
+ s && a && (await l.updateBuyStatus(s, a), ((u = l.state.currentPayment) == null ? void 0 : u.status) === "SUCCESS" && clearInterval(this.exchangeSubscription));
750
+ }, re));
751
+ }
752
+ setupSubscription() {
753
+ l.subscribeKey("isPaymentInProgress", (e) => {
754
+ var s;
755
+ !e && this.paymentState === "in-progress" && (l.state.error || !((s = l.state.currentPayment) != null && s.result) ? this.paymentState = "error" : this.paymentState = "completed", this.updateMessages(), setTimeout(() => {
756
+ f.state.status !== "disconnected" && P.close();
757
+ }, 3e3));
758
+ }), l.subscribeKey("error", (e) => {
759
+ e && this.paymentState === "in-progress" && (this.paymentState = "error", this.updateMessages());
760
+ });
761
+ }
762
+ loaderTemplate() {
763
+ const e = F.state.themeVariables["--w3m-border-radius-master"], s = e ? parseInt(e.replace("px", ""), 10) : 4;
764
+ return d`<wui-loading-thumbnail radius=${s * 9}></wui-loading-thumbnail>`;
765
+ }
766
+ successTemplate() {
767
+ return d`<wui-icon size="xl" color="success-100" name="checkmark"></wui-icon>`;
768
+ }
769
+ errorTemplate() {
770
+ return d`<wui-icon size="xl" color="error-100" name="close"></wui-icon>`;
771
+ }
772
+ };
773
+ N.styles = ae;
774
+ x([
775
+ w()
776
+ ], N.prototype, "loadingMessage", void 0);
777
+ x([
778
+ w()
779
+ ], N.prototype, "subMessage", void 0);
780
+ x([
781
+ w()
782
+ ], N.prototype, "paymentState", void 0);
783
+ N = x([
784
+ V("w3m-pay-loading-view")
785
+ ], N);
786
+ async function fe(t) {
787
+ return l.handleOpenPay(t);
788
+ }
789
+ function Ne() {
790
+ return l.getExchanges();
791
+ }
792
+ function Ae() {
793
+ var t;
794
+ return (t = l.state.currentPayment) == null ? void 0 : t.result;
795
+ }
796
+ function Ie() {
797
+ return l.state.error;
798
+ }
799
+ function Pe() {
800
+ return l.state.isPaymentInProgress;
801
+ }
802
+ const _e = {
803
+ network: "eip155:8453",
804
+ asset: "native",
805
+ metadata: {
806
+ name: "Ethereum",
807
+ symbol: "ETH",
808
+ decimals: 18
809
+ }
810
+ }, xe = {
811
+ network: "eip155:8453",
812
+ asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
813
+ metadata: {
814
+ name: "USD Coin",
815
+ symbol: "USDC",
816
+ decimals: 6
817
+ }
818
+ }, Te = {
819
+ network: "eip155:84532",
820
+ asset: "native",
821
+ metadata: {
822
+ name: "Ethereum",
823
+ symbol: "ETH",
824
+ decimals: 18
825
+ }
826
+ };
827
+ export {
828
+ N as W3mPayLoadingView,
829
+ m as W3mPayView,
830
+ _e as baseETH,
831
+ Te as baseSepoliaETH,
832
+ xe as baseUSDC,
833
+ Ne as getExchanges,
834
+ Pe as getIsPaymentInProgress,
835
+ Ie as getPayError,
836
+ Ae as getPayResult,
837
+ fe as openPay
838
+ };