@lnfi-network/nodeflow-sdk 1.0.0-alpha.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.
- package/README.md +276 -0
- package/dist/SwapController-C-2g6oSP.js +447 -0
- package/dist/add-DDBnz1-Q.js +19 -0
- package/dist/all-wallets-XTwjZKGg.js +10 -0
- package/dist/app-store-sCzhkWOo.js +21 -0
- package/dist/apple-C4IG4u61.js +22 -0
- package/dist/arrow-bottom-D5KjiSxX.js +12 -0
- package/dist/arrow-bottom-circle-BwWTHJky.js +15 -0
- package/dist/arrow-left-hn1Ftfvb.js +12 -0
- package/dist/arrow-right-CkV03q5Q.js +12 -0
- package/dist/arrow-top-BFm9X5g1.js +12 -0
- package/dist/bank-BUCrVHdo.js +18 -0
- package/dist/bin-BKleaahE.js +8 -0
- package/dist/bitcoin-C7iWQVuy.js +17 -0
- package/dist/browser-CpOtTIku.js +18 -0
- package/dist/build-info.json +1 -0
- package/dist/card-CJ3tg2Ri.js +18 -0
- package/dist/ccip-DyUNuvL1.js +239 -0
- package/dist/checkmark-CvSC6zeV.js +15 -0
- package/dist/checkmark-bold-DyZJqlJ7.js +12 -0
- package/dist/chevron-bottom-T9v1OvPA.js +12 -0
- package/dist/chevron-left-B4I8A8BR.js +12 -0
- package/dist/chevron-right-DGcVStvL.js +12 -0
- package/dist/chevron-top-BtD7BPVB.js +12 -0
- package/dist/chrome-store-BTKxY14m.js +65 -0
- package/dist/circle-DLLZtCBf.js +8 -0
- package/dist/clock-BNIDUPYZ.js +12 -0
- package/dist/close-BscNWH3j.js +12 -0
- package/dist/coinPlaceholder-JCYCAADZ.js +12 -0
- package/dist/compass-D7B-kHmZ.js +12 -0
- package/dist/copy-DHBc9gJO.js +19 -0
- package/dist/cursor-DKduK293.js +7 -0
- package/dist/cursor-transparent-8DkjrHTm.js +16 -0
- package/dist/desktop-ChlWl7Ma.js +13 -0
- package/dist/disconnect-CML_GEin.js +12 -0
- package/dist/discord-CgAM6i7H.js +21 -0
- package/dist/email-8mepCwp-.js +10 -0
- package/dist/embedded-wallet-scU49N5X.js +464 -0
- package/dist/ethereum-CA-_7cWX.js +14 -0
- package/dist/etherscan-B4h2i8Uc.js +10 -0
- package/dist/exclamation-triangle-ftOWMqSf.js +8 -0
- package/dist/extension-7iqlSonF.js +12 -0
- package/dist/external-link-DAvuMfW6.js +12 -0
- package/dist/facebook-CsyBIxMB.js +30 -0
- package/dist/farcaster-DfetCk1r.js +16 -0
- package/dist/filters-CsU-LYSd.js +12 -0
- package/dist/font/ClashDisplay-Variable.ttf +0 -0
- package/dist/font/ClashDisplay-Variable.woff +0 -0
- package/dist/font/ClashDisplay-Variable.woff2 +0 -0
- package/dist/github-DjxwfOOF.js +22 -0
- package/dist/google--g4VSi6h.js +22 -0
- package/dist/help-circle-BPA985E7.js +16 -0
- package/dist/id-BCUBMri8.js +16 -0
- package/dist/image-gYCDO7su.js +8 -0
- package/dist/index-B9q3HG5u.js +709 -0
- package/dist/index-BEm1bPeX.js +63547 -0
- package/dist/index-CCgAY-U4.js +70 -0
- package/dist/index-CRbuhHbe.js +33 -0
- package/dist/index-DYL5OPkx.js +1060 -0
- package/dist/info-CIaFQJ_e.js +7 -0
- package/dist/info-circle-BPz5hFQa.js +16 -0
- package/dist/lightbulb-BDmHvdbq.js +7 -0
- package/dist/mail-DQiXQ-4_.js +12 -0
- package/dist/mobile-CG_8sNWZ.js +13 -0
- package/dist/more-B1H_I3-I.js +15 -0
- package/dist/network-placeholder-1RWeD7Yp.js +18 -0
- package/dist/nftPlaceholder-Cg-f-eaw.js +12 -0
- package/dist/nodeflow-sdk.es.js +15 -0
- package/dist/off-DB-2L-AT.js +8 -0
- package/dist/onramp-DI5eQmAC.js +917 -0
- package/dist/play-store-DKJRWbqp.js +36 -0
- package/dist/plus-By1Ef8nV.js +17 -0
- package/dist/qr-code-DGuZgP-9.js +10 -0
- package/dist/receive-BEsZr88v.js +179 -0
- package/dist/recycle-horizontal-DubwRDbc.js +13 -0
- package/dist/refresh-Dwfvwy6t.js +12 -0
- package/dist/reown-logo-oDEjOrqY.js +16 -0
- package/dist/search-DX_QdW9h.js +12 -0
- package/dist/send-Bd5bwLNJ.js +1039 -0
- package/dist/send-Dq4B7ftm.js +19 -0
- package/dist/socials-BnnwB5_t.js +589 -0
- package/dist/solana-B7Ds9KBT.js +17 -0
- package/dist/swapHorizontal-CF6_7qU-.js +12 -0
- package/dist/swapHorizontalBold-C-YFgVbc.js +12 -0
- package/dist/swapHorizontalMedium-BGOdc8_e.js +20 -0
- package/dist/swapHorizontalRoundedBold-D_vYgwwO.js +12 -0
- package/dist/swapVertical-j2pWqia1.js +12 -0
- package/dist/swaps-Bh2kuHjL.js +1713 -0
- package/dist/telegram-bh_htnzP.js +20 -0
- package/dist/three-dots-B31D_Ocu.js +9 -0
- package/dist/transactions-Ch56TR3p.js +35 -0
- package/dist/twitch-DUloatpE.js +22 -0
- package/dist/twitterIcon-CNo6b91J.js +10 -0
- package/dist/ui-C7PJmqHY.js +812 -0
- package/dist/user-DqFnAlKR.js +7 -0
- package/dist/verify-BmaaygAV.js +12 -0
- package/dist/verify-filled-BwLeEdJj.js +12 -0
- package/dist/vite.svg +1 -0
- package/dist/w3m-modal-BijXCMl6.js +1041 -0
- package/dist/wallet-DyP6_6JN.js +12 -0
- package/dist/wallet-placeholder-BZC82rR0.js +18 -0
- package/dist/walletconnect-DT69luRK.js +36 -0
- package/dist/warning-circle-CGbg6QZn.js +16 -0
- package/dist/x-BfEtqtAc.js +16 -0
- package/dist/x-mark-CSmIdhvb.js +7 -0
- package/package.json +53 -0
|
@@ -0,0 +1,1060 @@
|
|
|
1
|
+
import { aA as q, aT as C, Y as O, V as y, P as g, aU as B, O as h, aV as j, M as z, Q as _, S as T, _ as A, R as Y, aH as x, a4 as X, a5 as J, E as W, J as F, K as m, a9 as v, aa as w, I as H, a8 as Z, a3 as G, a6 as Q } from "./index-BEm1bPeX.js";
|
|
2
|
+
const o = {
|
|
3
|
+
INVALID_PAYMENT_CONFIG: "INVALID_PAYMENT_CONFIG",
|
|
4
|
+
INVALID_RECIPIENT: "INVALID_RECIPIENT",
|
|
5
|
+
INVALID_ASSET: "INVALID_ASSET",
|
|
6
|
+
INVALID_AMOUNT: "INVALID_AMOUNT",
|
|
7
|
+
UNKNOWN_ERROR: "UNKNOWN_ERROR",
|
|
8
|
+
UNABLE_TO_INITIATE_PAYMENT: "UNABLE_TO_INITIATE_PAYMENT",
|
|
9
|
+
INVALID_CHAIN_NAMESPACE: "INVALID_CHAIN_NAMESPACE",
|
|
10
|
+
GENERIC_PAYMENT_ERROR: "GENERIC_PAYMENT_ERROR",
|
|
11
|
+
UNABLE_TO_GET_EXCHANGES: "UNABLE_TO_GET_EXCHANGES",
|
|
12
|
+
ASSET_NOT_SUPPORTED: "ASSET_NOT_SUPPORTED",
|
|
13
|
+
UNABLE_TO_GET_PAY_URL: "UNABLE_TO_GET_PAY_URL",
|
|
14
|
+
UNABLE_TO_GET_BUY_STATUS: "UNABLE_TO_GET_BUY_STATUS"
|
|
15
|
+
}, N = {
|
|
16
|
+
[o.INVALID_PAYMENT_CONFIG]: "Invalid payment configuration",
|
|
17
|
+
[o.INVALID_RECIPIENT]: "Invalid recipient address",
|
|
18
|
+
[o.INVALID_ASSET]: "Invalid asset specified",
|
|
19
|
+
[o.INVALID_AMOUNT]: "Invalid payment amount",
|
|
20
|
+
[o.UNKNOWN_ERROR]: "Unknown payment error occurred",
|
|
21
|
+
[o.UNABLE_TO_INITIATE_PAYMENT]: "Unable to initiate payment",
|
|
22
|
+
[o.INVALID_CHAIN_NAMESPACE]: "Invalid chain namespace",
|
|
23
|
+
[o.GENERIC_PAYMENT_ERROR]: "Unable to process payment",
|
|
24
|
+
[o.UNABLE_TO_GET_EXCHANGES]: "Unable to get exchanges",
|
|
25
|
+
[o.ASSET_NOT_SUPPORTED]: "Asset not supported by the selected exchange",
|
|
26
|
+
[o.UNABLE_TO_GET_PAY_URL]: "Unable to get payment URL",
|
|
27
|
+
[o.UNABLE_TO_GET_BUY_STATUS]: "Unable to get buy status"
|
|
28
|
+
};
|
|
29
|
+
class c extends Error {
|
|
30
|
+
get message() {
|
|
31
|
+
return N[this.code];
|
|
32
|
+
}
|
|
33
|
+
constructor(e, s) {
|
|
34
|
+
super(N[e]), this.name = "AppKitPayError", this.code = e, this.details = s, Error.captureStackTrace && Error.captureStackTrace(this, c);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const ee = "https://rpc.walletconnect.org/v1/json-rpc";
|
|
38
|
+
class te extends Error {
|
|
39
|
+
}
|
|
40
|
+
function ne() {
|
|
41
|
+
const t = q.getSnapshot().projectId;
|
|
42
|
+
return `${ee}?projectId=${t}`;
|
|
43
|
+
}
|
|
44
|
+
async function L(t, e) {
|
|
45
|
+
const s = ne(), i = await (await fetch(s, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
jsonrpc: "2.0",
|
|
49
|
+
id: 1,
|
|
50
|
+
method: t,
|
|
51
|
+
params: e
|
|
52
|
+
}),
|
|
53
|
+
headers: { "Content-Type": "application/json" }
|
|
54
|
+
})).json();
|
|
55
|
+
if (i.error)
|
|
56
|
+
throw new te(i.error.message);
|
|
57
|
+
return i;
|
|
58
|
+
}
|
|
59
|
+
async function V(t) {
|
|
60
|
+
return (await L("reown_getExchanges", t)).result;
|
|
61
|
+
}
|
|
62
|
+
async function se(t) {
|
|
63
|
+
return (await L("reown_getExchangePayUrl", t)).result;
|
|
64
|
+
}
|
|
65
|
+
async function ae(t) {
|
|
66
|
+
return (await L("reown_getExchangeBuyStatus", t)).result;
|
|
67
|
+
}
|
|
68
|
+
const re = ["eip155", "solana"], ie = {
|
|
69
|
+
eip155: {
|
|
70
|
+
native: { assetNamespace: "slip44", assetReference: "60" },
|
|
71
|
+
defaultTokenNamespace: "erc20"
|
|
72
|
+
},
|
|
73
|
+
solana: {
|
|
74
|
+
native: { assetNamespace: "slip44", assetReference: "501" },
|
|
75
|
+
defaultTokenNamespace: "token"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function R(t, e) {
|
|
79
|
+
const { chainNamespace: s, chainId: a } = C.parseCaipNetworkId(t), r = ie[s];
|
|
80
|
+
if (!r)
|
|
81
|
+
throw new Error(`Unsupported chain namespace for CAIP-19 formatting: ${s}`);
|
|
82
|
+
let i = r.native.assetNamespace, l = r.native.assetReference;
|
|
83
|
+
return e !== "native" && (i = r.defaultTokenNamespace, l = e), `${`${s}:${a}`}/${i}:${l}`;
|
|
84
|
+
}
|
|
85
|
+
function oe(t) {
|
|
86
|
+
const { chainNamespace: e } = C.parseCaipNetworkId(t);
|
|
87
|
+
return re.includes(e);
|
|
88
|
+
}
|
|
89
|
+
async function ce(t) {
|
|
90
|
+
const { paymentAssetNetwork: e, activeCaipNetwork: s, approvedCaipNetworkIds: a, requestedCaipNetworks: r } = t, l = O.sortRequestedNetworks(a, r).find((P) => P.caipNetworkId === e);
|
|
91
|
+
if (!l)
|
|
92
|
+
throw new c(o.INVALID_PAYMENT_CONFIG);
|
|
93
|
+
if (l.caipNetworkId === s.caipNetworkId)
|
|
94
|
+
return;
|
|
95
|
+
const d = y.getNetworkProp("supportsAllNetworks", l.chainNamespace);
|
|
96
|
+
if (!((a == null ? void 0 : a.includes(l.caipNetworkId)) || d))
|
|
97
|
+
throw new c(o.INVALID_PAYMENT_CONFIG);
|
|
98
|
+
try {
|
|
99
|
+
await y.switchActiveNetwork(l);
|
|
100
|
+
} catch (P) {
|
|
101
|
+
throw new c(o.GENERIC_PAYMENT_ERROR, P);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function le(t, e, s) {
|
|
105
|
+
var d;
|
|
106
|
+
if (e !== g.CHAIN.EVM)
|
|
107
|
+
throw new c(o.INVALID_CHAIN_NAMESPACE);
|
|
108
|
+
if (!s.fromAddress)
|
|
109
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, "fromAddress is required for native EVM payments.");
|
|
110
|
+
const a = typeof s.amount == "string" ? parseFloat(s.amount) : s.amount;
|
|
111
|
+
if (isNaN(a))
|
|
112
|
+
throw new c(o.INVALID_PAYMENT_CONFIG);
|
|
113
|
+
const r = ((d = t.metadata) == null ? void 0 : d.decimals) ?? 18, i = h.parseUnits(a.toString(), r);
|
|
114
|
+
if (typeof i != "bigint")
|
|
115
|
+
throw new c(o.GENERIC_PAYMENT_ERROR);
|
|
116
|
+
return await h.sendTransaction({
|
|
117
|
+
chainNamespace: e,
|
|
118
|
+
to: s.recipient,
|
|
119
|
+
address: s.fromAddress,
|
|
120
|
+
value: i,
|
|
121
|
+
data: "0x"
|
|
122
|
+
}) ?? void 0;
|
|
123
|
+
}
|
|
124
|
+
async function ue(t, e) {
|
|
125
|
+
if (!e.fromAddress)
|
|
126
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, "fromAddress is required for ERC20 EVM payments.");
|
|
127
|
+
const s = t.asset, a = e.recipient, r = Number(t.metadata.decimals), i = h.parseUnits(e.amount.toString(), r);
|
|
128
|
+
if (i === void 0)
|
|
129
|
+
throw new c(o.GENERIC_PAYMENT_ERROR);
|
|
130
|
+
return await h.writeContract({
|
|
131
|
+
fromAddress: e.fromAddress,
|
|
132
|
+
tokenAddress: s,
|
|
133
|
+
args: [a, i],
|
|
134
|
+
method: "transfer",
|
|
135
|
+
abi: j.getERC20Abi(s),
|
|
136
|
+
chainNamespace: g.CHAIN.EVM
|
|
137
|
+
}) ?? void 0;
|
|
138
|
+
}
|
|
139
|
+
async function de(t, e) {
|
|
140
|
+
if (t !== g.CHAIN.SOLANA)
|
|
141
|
+
throw new c(o.INVALID_CHAIN_NAMESPACE);
|
|
142
|
+
if (!e.fromAddress)
|
|
143
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, "fromAddress is required for Solana payments.");
|
|
144
|
+
const s = typeof e.amount == "string" ? parseFloat(e.amount) : e.amount;
|
|
145
|
+
if (isNaN(s) || s <= 0)
|
|
146
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, "Invalid payment amount.");
|
|
147
|
+
try {
|
|
148
|
+
if (!B.getProvider(t))
|
|
149
|
+
throw new c(o.GENERIC_PAYMENT_ERROR, "No Solana provider available.");
|
|
150
|
+
const r = await h.sendTransaction({
|
|
151
|
+
chainNamespace: g.CHAIN.SOLANA,
|
|
152
|
+
to: e.recipient,
|
|
153
|
+
value: s,
|
|
154
|
+
tokenMint: e.tokenMint
|
|
155
|
+
});
|
|
156
|
+
if (!r)
|
|
157
|
+
throw new c(o.GENERIC_PAYMENT_ERROR, "Transaction failed.");
|
|
158
|
+
return r;
|
|
159
|
+
} catch (a) {
|
|
160
|
+
throw a instanceof c ? a : new c(o.GENERIC_PAYMENT_ERROR, `Solana payment failed: ${a}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const $ = 0, k = "unknown", n = z({
|
|
164
|
+
paymentAsset: {
|
|
165
|
+
network: "eip155:1",
|
|
166
|
+
asset: "0x0",
|
|
167
|
+
metadata: {
|
|
168
|
+
name: "0x0",
|
|
169
|
+
symbol: "0x0",
|
|
170
|
+
decimals: 0
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
recipient: "0x0",
|
|
174
|
+
amount: 0,
|
|
175
|
+
isConfigured: !1,
|
|
176
|
+
error: null,
|
|
177
|
+
isPaymentInProgress: !1,
|
|
178
|
+
exchanges: [],
|
|
179
|
+
isLoading: !1,
|
|
180
|
+
openInNewTab: !0,
|
|
181
|
+
redirectUrl: void 0,
|
|
182
|
+
payWithExchange: void 0,
|
|
183
|
+
currentPayment: void 0,
|
|
184
|
+
analyticsSet: !1,
|
|
185
|
+
paymentId: void 0
|
|
186
|
+
}), u = {
|
|
187
|
+
state: n,
|
|
188
|
+
subscribe(t) {
|
|
189
|
+
return J(n, () => t(n));
|
|
190
|
+
},
|
|
191
|
+
subscribeKey(t, e) {
|
|
192
|
+
return X(n, t, e);
|
|
193
|
+
},
|
|
194
|
+
async handleOpenPay(t) {
|
|
195
|
+
this.resetState(), this.setPaymentConfig(t), this.subscribeEvents(), this.initializeAnalytics(), n.isConfigured = !0, _.sendEvent({
|
|
196
|
+
type: "track",
|
|
197
|
+
event: "PAY_MODAL_OPEN",
|
|
198
|
+
properties: {
|
|
199
|
+
exchanges: n.exchanges,
|
|
200
|
+
configuration: {
|
|
201
|
+
network: n.paymentAsset.network,
|
|
202
|
+
asset: n.paymentAsset.asset,
|
|
203
|
+
recipient: n.recipient,
|
|
204
|
+
amount: n.amount
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}), await x.open({
|
|
208
|
+
view: "Pay"
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
resetState() {
|
|
212
|
+
n.paymentAsset = {
|
|
213
|
+
network: "eip155:1",
|
|
214
|
+
asset: "0x0",
|
|
215
|
+
metadata: { name: "0x0", symbol: "0x0", decimals: 0 }
|
|
216
|
+
}, n.recipient = "0x0", n.amount = 0, n.isConfigured = !1, n.error = null, n.isPaymentInProgress = !1, n.isLoading = !1, n.currentPayment = void 0;
|
|
217
|
+
},
|
|
218
|
+
setPaymentConfig(t) {
|
|
219
|
+
if (!t.paymentAsset)
|
|
220
|
+
throw new c(o.INVALID_PAYMENT_CONFIG);
|
|
221
|
+
try {
|
|
222
|
+
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;
|
|
223
|
+
} catch (e) {
|
|
224
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, e.message);
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
getPaymentAsset() {
|
|
228
|
+
return n.paymentAsset;
|
|
229
|
+
},
|
|
230
|
+
getExchanges() {
|
|
231
|
+
return n.exchanges;
|
|
232
|
+
},
|
|
233
|
+
async fetchExchanges() {
|
|
234
|
+
try {
|
|
235
|
+
n.isLoading = !0;
|
|
236
|
+
const t = await V({
|
|
237
|
+
page: $,
|
|
238
|
+
asset: R(n.paymentAsset.network, n.paymentAsset.asset),
|
|
239
|
+
amount: n.amount.toString()
|
|
240
|
+
});
|
|
241
|
+
n.exchanges = t.exchanges.slice(0, 2);
|
|
242
|
+
} catch {
|
|
243
|
+
throw T.showError(N.UNABLE_TO_GET_EXCHANGES), new c(o.UNABLE_TO_GET_EXCHANGES);
|
|
244
|
+
} finally {
|
|
245
|
+
n.isLoading = !1;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
async getAvailableExchanges(t) {
|
|
249
|
+
var e;
|
|
250
|
+
try {
|
|
251
|
+
const s = t != null && t.asset && (t != null && t.network) ? R(t.network, t.asset) : void 0;
|
|
252
|
+
return await V({
|
|
253
|
+
page: (t == null ? void 0 : t.page) ?? $,
|
|
254
|
+
asset: s,
|
|
255
|
+
amount: (e = t == null ? void 0 : t.amount) == null ? void 0 : e.toString()
|
|
256
|
+
});
|
|
257
|
+
} catch {
|
|
258
|
+
throw new c(o.UNABLE_TO_GET_EXCHANGES);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
async getPayUrl(t, e, s = !1) {
|
|
262
|
+
try {
|
|
263
|
+
const a = Number(e.amount), r = await se({
|
|
264
|
+
exchangeId: t,
|
|
265
|
+
asset: R(e.network, e.asset),
|
|
266
|
+
amount: a.toString(),
|
|
267
|
+
recipient: `${e.network}:${e.recipient}`
|
|
268
|
+
});
|
|
269
|
+
return _.sendEvent({
|
|
270
|
+
type: "track",
|
|
271
|
+
event: "PAY_EXCHANGE_SELECTED",
|
|
272
|
+
properties: {
|
|
273
|
+
exchange: {
|
|
274
|
+
id: t
|
|
275
|
+
},
|
|
276
|
+
configuration: {
|
|
277
|
+
network: e.network,
|
|
278
|
+
asset: e.asset,
|
|
279
|
+
recipient: e.recipient,
|
|
280
|
+
amount: a
|
|
281
|
+
},
|
|
282
|
+
currentPayment: {
|
|
283
|
+
type: "exchange",
|
|
284
|
+
exchangeId: t
|
|
285
|
+
},
|
|
286
|
+
headless: s
|
|
287
|
+
}
|
|
288
|
+
}), s && (this.initiatePayment(), _.sendEvent({
|
|
289
|
+
type: "track",
|
|
290
|
+
event: "PAY_INITIATED",
|
|
291
|
+
properties: {
|
|
292
|
+
paymentId: n.paymentId || k,
|
|
293
|
+
configuration: {
|
|
294
|
+
network: e.network,
|
|
295
|
+
asset: e.asset,
|
|
296
|
+
recipient: e.recipient,
|
|
297
|
+
amount: a
|
|
298
|
+
},
|
|
299
|
+
currentPayment: {
|
|
300
|
+
type: "exchange",
|
|
301
|
+
exchangeId: t
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
})), r;
|
|
305
|
+
} catch (a) {
|
|
306
|
+
throw a instanceof Error && a.message.includes("is not supported") ? new c(o.ASSET_NOT_SUPPORTED) : new Error(a.message);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
async openPayUrl(t, e, s = !1) {
|
|
310
|
+
try {
|
|
311
|
+
const a = await this.getPayUrl(t.exchangeId, e, s);
|
|
312
|
+
if (!a)
|
|
313
|
+
throw new c(o.UNABLE_TO_GET_PAY_URL);
|
|
314
|
+
const i = t.openInNewTab ?? !0 ? "_blank" : "_self";
|
|
315
|
+
return O.openHref(a.url, i), a;
|
|
316
|
+
} catch (a) {
|
|
317
|
+
throw a instanceof c ? n.error = a.message : n.error = N.GENERIC_PAYMENT_ERROR, new c(o.UNABLE_TO_GET_PAY_URL);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
subscribeEvents() {
|
|
321
|
+
n.isConfigured || (h.subscribeKey("connections", (t) => {
|
|
322
|
+
t.size > 0 && this.handlePayment();
|
|
323
|
+
}), A.subscribeKey("caipAddress", (t) => {
|
|
324
|
+
const e = h.hasAnyConnection(g.CONNECTOR_ID.WALLET_CONNECT);
|
|
325
|
+
t && (e ? setTimeout(() => {
|
|
326
|
+
this.handlePayment();
|
|
327
|
+
}, 100) : this.handlePayment());
|
|
328
|
+
}));
|
|
329
|
+
},
|
|
330
|
+
async handlePayment() {
|
|
331
|
+
n.currentPayment = {
|
|
332
|
+
type: "wallet",
|
|
333
|
+
status: "IN_PROGRESS"
|
|
334
|
+
};
|
|
335
|
+
const t = A.state.caipAddress;
|
|
336
|
+
if (!t)
|
|
337
|
+
return;
|
|
338
|
+
const { chainId: e, address: s } = C.parseCaipAddress(t), a = y.state.activeChain;
|
|
339
|
+
if (!s || !e || !a || !B.getProvider(a))
|
|
340
|
+
return;
|
|
341
|
+
const i = y.state.activeCaipNetwork;
|
|
342
|
+
if (i && !n.isPaymentInProgress)
|
|
343
|
+
try {
|
|
344
|
+
this.initiatePayment();
|
|
345
|
+
const l = y.getAllRequestedCaipNetworks(), d = y.getAllApprovedCaipNetworkIds();
|
|
346
|
+
switch (await ce({
|
|
347
|
+
paymentAssetNetwork: n.paymentAsset.network,
|
|
348
|
+
activeCaipNetwork: i,
|
|
349
|
+
approvedCaipNetworkIds: d,
|
|
350
|
+
requestedCaipNetworks: l
|
|
351
|
+
}), await x.open({
|
|
352
|
+
view: "PayLoading"
|
|
353
|
+
}), a) {
|
|
354
|
+
case g.CHAIN.EVM:
|
|
355
|
+
n.paymentAsset.asset === "native" && (n.currentPayment.result = await le(n.paymentAsset, a, {
|
|
356
|
+
recipient: n.recipient,
|
|
357
|
+
amount: n.amount,
|
|
358
|
+
fromAddress: s
|
|
359
|
+
})), n.paymentAsset.asset.startsWith("0x") && (n.currentPayment.result = await ue(n.paymentAsset, {
|
|
360
|
+
recipient: n.recipient,
|
|
361
|
+
amount: n.amount,
|
|
362
|
+
fromAddress: s
|
|
363
|
+
})), n.currentPayment.status = "SUCCESS";
|
|
364
|
+
break;
|
|
365
|
+
case g.CHAIN.SOLANA:
|
|
366
|
+
n.currentPayment.result = await de(a, {
|
|
367
|
+
recipient: n.recipient,
|
|
368
|
+
amount: n.amount,
|
|
369
|
+
fromAddress: s,
|
|
370
|
+
tokenMint: n.paymentAsset.asset === "native" ? void 0 : n.paymentAsset.asset
|
|
371
|
+
}), n.currentPayment.status = "SUCCESS";
|
|
372
|
+
break;
|
|
373
|
+
default:
|
|
374
|
+
throw new c(o.INVALID_CHAIN_NAMESPACE);
|
|
375
|
+
}
|
|
376
|
+
} catch (l) {
|
|
377
|
+
l instanceof c ? n.error = l.message : n.error = N.GENERIC_PAYMENT_ERROR, n.currentPayment.status = "FAILED", T.showError(n.error);
|
|
378
|
+
} finally {
|
|
379
|
+
n.isPaymentInProgress = !1;
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
getExchangeById(t) {
|
|
383
|
+
return n.exchanges.find((e) => e.id === t);
|
|
384
|
+
},
|
|
385
|
+
validatePayConfig(t) {
|
|
386
|
+
const { paymentAsset: e, recipient: s, amount: a } = t;
|
|
387
|
+
if (!e)
|
|
388
|
+
throw new c(o.INVALID_PAYMENT_CONFIG);
|
|
389
|
+
if (!s)
|
|
390
|
+
throw new c(o.INVALID_RECIPIENT);
|
|
391
|
+
if (!e.asset)
|
|
392
|
+
throw new c(o.INVALID_ASSET);
|
|
393
|
+
if (a == null || a <= 0)
|
|
394
|
+
throw new c(o.INVALID_AMOUNT);
|
|
395
|
+
},
|
|
396
|
+
handlePayWithWallet() {
|
|
397
|
+
const t = A.state.caipAddress;
|
|
398
|
+
if (!t) {
|
|
399
|
+
Y.push("Connect");
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const { chainId: e, address: s } = C.parseCaipAddress(t), a = y.state.activeChain;
|
|
403
|
+
if (!s || !e || !a) {
|
|
404
|
+
Y.push("Connect");
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
this.handlePayment();
|
|
408
|
+
},
|
|
409
|
+
async handlePayWithExchange(t) {
|
|
410
|
+
try {
|
|
411
|
+
n.currentPayment = {
|
|
412
|
+
type: "exchange",
|
|
413
|
+
exchangeId: t
|
|
414
|
+
};
|
|
415
|
+
const { network: e, asset: s } = n.paymentAsset, a = {
|
|
416
|
+
network: e,
|
|
417
|
+
asset: s,
|
|
418
|
+
amount: n.amount,
|
|
419
|
+
recipient: n.recipient
|
|
420
|
+
}, r = await this.getPayUrl(t, a);
|
|
421
|
+
if (!r)
|
|
422
|
+
throw new c(o.UNABLE_TO_INITIATE_PAYMENT);
|
|
423
|
+
return n.currentPayment.sessionId = r.sessionId, n.currentPayment.status = "IN_PROGRESS", n.currentPayment.exchangeId = t, this.initiatePayment(), {
|
|
424
|
+
url: r.url,
|
|
425
|
+
openInNewTab: n.openInNewTab
|
|
426
|
+
};
|
|
427
|
+
} catch (e) {
|
|
428
|
+
return e instanceof c ? n.error = e.message : n.error = N.GENERIC_PAYMENT_ERROR, n.isPaymentInProgress = !1, T.showError(n.error), null;
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
async getBuyStatus(t, e) {
|
|
432
|
+
var s, a;
|
|
433
|
+
try {
|
|
434
|
+
const r = await ae({ sessionId: e, exchangeId: t });
|
|
435
|
+
return (r.status === "SUCCESS" || r.status === "FAILED") && _.sendEvent({
|
|
436
|
+
type: "track",
|
|
437
|
+
event: r.status === "SUCCESS" ? "PAY_SUCCESS" : "PAY_ERROR",
|
|
438
|
+
properties: {
|
|
439
|
+
paymentId: n.paymentId || k,
|
|
440
|
+
configuration: {
|
|
441
|
+
network: n.paymentAsset.network,
|
|
442
|
+
asset: n.paymentAsset.asset,
|
|
443
|
+
recipient: n.recipient,
|
|
444
|
+
amount: n.amount
|
|
445
|
+
},
|
|
446
|
+
currentPayment: {
|
|
447
|
+
type: "exchange",
|
|
448
|
+
exchangeId: (s = n.currentPayment) == null ? void 0 : s.exchangeId,
|
|
449
|
+
sessionId: (a = n.currentPayment) == null ? void 0 : a.sessionId,
|
|
450
|
+
result: r.txHash
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}), r;
|
|
454
|
+
} catch {
|
|
455
|
+
throw new c(o.UNABLE_TO_GET_BUY_STATUS);
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
async updateBuyStatus(t, e) {
|
|
459
|
+
try {
|
|
460
|
+
const s = await this.getBuyStatus(t, e);
|
|
461
|
+
n.currentPayment && (n.currentPayment.status = s.status, n.currentPayment.result = s.txHash), (s.status === "SUCCESS" || s.status === "FAILED") && (n.isPaymentInProgress = !1);
|
|
462
|
+
} catch {
|
|
463
|
+
throw new c(o.UNABLE_TO_GET_BUY_STATUS);
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
initiatePayment() {
|
|
467
|
+
n.isPaymentInProgress = !0, n.paymentId = crypto.randomUUID();
|
|
468
|
+
},
|
|
469
|
+
initializeAnalytics() {
|
|
470
|
+
n.analyticsSet || (n.analyticsSet = !0, this.subscribeKey("isPaymentInProgress", (t) => {
|
|
471
|
+
var e;
|
|
472
|
+
if ((e = n.currentPayment) != null && e.status && n.currentPayment.status !== "UNKNOWN") {
|
|
473
|
+
const s = {
|
|
474
|
+
IN_PROGRESS: "PAY_INITIATED",
|
|
475
|
+
SUCCESS: "PAY_SUCCESS",
|
|
476
|
+
FAILED: "PAY_ERROR"
|
|
477
|
+
}[n.currentPayment.status];
|
|
478
|
+
_.sendEvent({
|
|
479
|
+
type: "track",
|
|
480
|
+
event: s,
|
|
481
|
+
properties: {
|
|
482
|
+
paymentId: n.paymentId || k,
|
|
483
|
+
configuration: {
|
|
484
|
+
network: n.paymentAsset.network,
|
|
485
|
+
asset: n.paymentAsset.asset,
|
|
486
|
+
recipient: n.recipient,
|
|
487
|
+
amount: n.amount
|
|
488
|
+
},
|
|
489
|
+
currentPayment: {
|
|
490
|
+
type: n.currentPayment.type,
|
|
491
|
+
exchangeId: n.currentPayment.exchangeId,
|
|
492
|
+
sessionId: n.currentPayment.sessionId,
|
|
493
|
+
result: n.currentPayment.result
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}));
|
|
499
|
+
}
|
|
500
|
+
}, me = W`
|
|
501
|
+
wui-separator {
|
|
502
|
+
margin: var(--wui-spacing-m) calc(var(--wui-spacing-m) * -1) var(--wui-spacing-xs)
|
|
503
|
+
calc(var(--wui-spacing-m) * -1);
|
|
504
|
+
width: calc(100% + var(--wui-spacing-s) * 2);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
.token-display {
|
|
508
|
+
padding: var(--wui-spacing-s) var(--wui-spacing-m);
|
|
509
|
+
border-radius: var(--wui-border-radius-s);
|
|
510
|
+
background-color: var(--wui-color-bg-125);
|
|
511
|
+
margin-top: var(--wui-spacing-s);
|
|
512
|
+
margin-bottom: var(--wui-spacing-s);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.token-display wui-text {
|
|
516
|
+
text-transform: none;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
wui-loading-spinner {
|
|
520
|
+
padding: var(--wui-spacing-xs);
|
|
521
|
+
}
|
|
522
|
+
`;
|
|
523
|
+
var E = function(t, e, s, a) {
|
|
524
|
+
var r = arguments.length, i = r < 3 ? e : a === null ? a = Object.getOwnPropertyDescriptor(e, s) : a, l;
|
|
525
|
+
if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(t, e, s, a);
|
|
526
|
+
else for (var d = t.length - 1; d >= 0; d--) (l = t[d]) && (i = (r < 3 ? l(i) : r > 3 ? l(e, s, i) : l(e, s)) || i);
|
|
527
|
+
return r > 3 && i && Object.defineProperty(e, s, i), i;
|
|
528
|
+
};
|
|
529
|
+
let p = class extends F {
|
|
530
|
+
constructor() {
|
|
531
|
+
super(), this.unsubscribe = [], this.amount = "", this.tokenSymbol = "", this.networkName = "", this.exchanges = u.state.exchanges, this.isLoading = u.state.isLoading, this.loadingExchangeId = null, this.connectedWalletInfo = A.state.connectedWalletInfo, this.initializePaymentDetails(), this.unsubscribe.push(u.subscribeKey("exchanges", (e) => this.exchanges = e)), this.unsubscribe.push(u.subscribeKey("isLoading", (e) => this.isLoading = e)), this.unsubscribe.push(A.subscribe((e) => this.connectedWalletInfo = e.connectedWalletInfo)), u.fetchExchanges();
|
|
532
|
+
}
|
|
533
|
+
get isWalletConnected() {
|
|
534
|
+
return A.state.status === "connected";
|
|
535
|
+
}
|
|
536
|
+
render() {
|
|
537
|
+
return m`
|
|
538
|
+
<wui-flex flexDirection="column">
|
|
539
|
+
<wui-flex flexDirection="column" .padding=${["0", "l", "l", "l"]} gap="s">
|
|
540
|
+
${this.renderPaymentHeader()}
|
|
541
|
+
|
|
542
|
+
<wui-flex flexDirection="column" gap="s">
|
|
543
|
+
${this.renderPayWithWallet()} ${this.renderExchangeOptions()}
|
|
544
|
+
</wui-flex>
|
|
545
|
+
</wui-flex>
|
|
546
|
+
</wui-flex>
|
|
547
|
+
`;
|
|
548
|
+
}
|
|
549
|
+
initializePaymentDetails() {
|
|
550
|
+
const e = u.getPaymentAsset();
|
|
551
|
+
this.networkName = e.network, this.tokenSymbol = e.metadata.symbol, this.amount = u.state.amount.toString();
|
|
552
|
+
}
|
|
553
|
+
renderPayWithWallet() {
|
|
554
|
+
return oe(this.networkName) ? m`<wui-flex flexDirection="column" gap="s">
|
|
555
|
+
${this.isWalletConnected ? this.renderConnectedView() : this.renderDisconnectedView()}
|
|
556
|
+
</wui-flex>
|
|
557
|
+
<wui-separator text="or"></wui-separator>` : m``;
|
|
558
|
+
}
|
|
559
|
+
renderPaymentHeader() {
|
|
560
|
+
let e = this.networkName;
|
|
561
|
+
if (this.networkName) {
|
|
562
|
+
const a = y.getAllRequestedCaipNetworks().find((r) => r.caipNetworkId === this.networkName);
|
|
563
|
+
a && (e = a.name);
|
|
564
|
+
}
|
|
565
|
+
return m`
|
|
566
|
+
<wui-flex flexDirection="column" alignItems="center">
|
|
567
|
+
<wui-flex alignItems="center" gap="xs">
|
|
568
|
+
<wui-text variant="large-700" color="fg-100">${this.amount || "0.0000"}</wui-text>
|
|
569
|
+
<wui-flex class="token-display" alignItems="center" gap="xxs">
|
|
570
|
+
<wui-text variant="paragraph-600" color="fg-100">
|
|
571
|
+
${this.tokenSymbol || "Unknown Asset"}
|
|
572
|
+
</wui-text>
|
|
573
|
+
${e ? m`
|
|
574
|
+
<wui-text variant="small-500" color="fg-200"> on ${e} </wui-text>
|
|
575
|
+
` : ""}
|
|
576
|
+
</wui-flex>
|
|
577
|
+
</wui-flex>
|
|
578
|
+
</wui-flex>
|
|
579
|
+
`;
|
|
580
|
+
}
|
|
581
|
+
renderConnectedView() {
|
|
582
|
+
var s, a, r;
|
|
583
|
+
const e = ((s = this.connectedWalletInfo) == null ? void 0 : s.name) || "connected wallet";
|
|
584
|
+
return m`
|
|
585
|
+
<wui-list-item
|
|
586
|
+
@click=${this.onWalletPayment}
|
|
587
|
+
?chevron=${!0}
|
|
588
|
+
data-testid="wallet-payment-option"
|
|
589
|
+
>
|
|
590
|
+
<wui-flex alignItems="center" gap="s">
|
|
591
|
+
<wui-wallet-image
|
|
592
|
+
size="sm"
|
|
593
|
+
imageSrc=${v((a = this.connectedWalletInfo) == null ? void 0 : a.icon)}
|
|
594
|
+
name=${v((r = this.connectedWalletInfo) == null ? void 0 : r.name)}
|
|
595
|
+
></wui-wallet-image>
|
|
596
|
+
<wui-text variant="paragraph-500" color="inherit">Pay with ${e}</wui-text>
|
|
597
|
+
</wui-flex>
|
|
598
|
+
</wui-list-item>
|
|
599
|
+
|
|
600
|
+
<wui-list-item
|
|
601
|
+
variant="icon"
|
|
602
|
+
iconVariant="overlay"
|
|
603
|
+
icon="disconnect"
|
|
604
|
+
@click=${this.onDisconnect}
|
|
605
|
+
data-testid="disconnect-button"
|
|
606
|
+
?chevron=${!1}
|
|
607
|
+
>
|
|
608
|
+
<wui-text variant="paragraph-500" color="fg-200">Disconnect</wui-text>
|
|
609
|
+
</wui-list-item>
|
|
610
|
+
`;
|
|
611
|
+
}
|
|
612
|
+
renderDisconnectedView() {
|
|
613
|
+
return m`<wui-list-item
|
|
614
|
+
variant="icon"
|
|
615
|
+
iconVariant="overlay"
|
|
616
|
+
icon="walletPlaceholder"
|
|
617
|
+
@click=${this.onWalletPayment}
|
|
618
|
+
?chevron=${!0}
|
|
619
|
+
data-testid="wallet-payment-option"
|
|
620
|
+
>
|
|
621
|
+
<wui-text variant="paragraph-500" color="inherit">Pay from wallet</wui-text>
|
|
622
|
+
</wui-list-item>`;
|
|
623
|
+
}
|
|
624
|
+
renderExchangeOptions() {
|
|
625
|
+
return this.isLoading ? m`<wui-flex justifyContent="center" alignItems="center">
|
|
626
|
+
<wui-spinner size="md"></wui-spinner>
|
|
627
|
+
</wui-flex>` : this.exchanges.length === 0 ? m`<wui-flex justifyContent="center" alignItems="center">
|
|
628
|
+
<wui-text variant="paragraph-500" color="fg-100">No exchanges available</wui-text>
|
|
629
|
+
</wui-flex>` : this.exchanges.map((e) => m`
|
|
630
|
+
<wui-list-item
|
|
631
|
+
@click=${() => this.onExchangePayment(e.id)}
|
|
632
|
+
data-testid="exchange-option-${e.id}"
|
|
633
|
+
?chevron=${!0}
|
|
634
|
+
?disabled=${this.loadingExchangeId !== null}
|
|
635
|
+
>
|
|
636
|
+
<wui-flex alignItems="center" gap="s">
|
|
637
|
+
${this.loadingExchangeId === e.id ? m`<wui-loading-spinner color="accent-100" size="md"></wui-loading-spinner>` : m`<wui-wallet-image
|
|
638
|
+
size="sm"
|
|
639
|
+
imageSrc=${v(e.imageUrl)}
|
|
640
|
+
name=${e.name}
|
|
641
|
+
></wui-wallet-image>`}
|
|
642
|
+
<wui-text flexGrow="1" variant="paragraph-500" color="inherit"
|
|
643
|
+
>Pay with ${e.name} <wui-spinner size="sm" color="fg-200"></wui-spinner
|
|
644
|
+
></wui-text>
|
|
645
|
+
</wui-flex>
|
|
646
|
+
</wui-list-item>
|
|
647
|
+
`);
|
|
648
|
+
}
|
|
649
|
+
onWalletPayment() {
|
|
650
|
+
u.handlePayWithWallet();
|
|
651
|
+
}
|
|
652
|
+
async onExchangePayment(e) {
|
|
653
|
+
try {
|
|
654
|
+
this.loadingExchangeId = e;
|
|
655
|
+
const s = await u.handlePayWithExchange(e);
|
|
656
|
+
s && (await x.open({
|
|
657
|
+
view: "PayLoading"
|
|
658
|
+
}), O.openHref(s.url, s.openInNewTab ? "_blank" : "_self"));
|
|
659
|
+
} catch (s) {
|
|
660
|
+
console.error("Failed to pay with exchange", s), T.showError("Failed to pay with exchange");
|
|
661
|
+
} finally {
|
|
662
|
+
this.loadingExchangeId = null;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async onDisconnect(e) {
|
|
666
|
+
e.stopPropagation();
|
|
667
|
+
try {
|
|
668
|
+
await h.disconnect();
|
|
669
|
+
} catch {
|
|
670
|
+
console.error("Failed to disconnect"), T.showError("Failed to disconnect");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
disconnectedCallback() {
|
|
674
|
+
this.unsubscribe.forEach((e) => e());
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
p.styles = me;
|
|
678
|
+
E([
|
|
679
|
+
w()
|
|
680
|
+
], p.prototype, "amount", void 0);
|
|
681
|
+
E([
|
|
682
|
+
w()
|
|
683
|
+
], p.prototype, "tokenSymbol", void 0);
|
|
684
|
+
E([
|
|
685
|
+
w()
|
|
686
|
+
], p.prototype, "networkName", void 0);
|
|
687
|
+
E([
|
|
688
|
+
w()
|
|
689
|
+
], p.prototype, "exchanges", void 0);
|
|
690
|
+
E([
|
|
691
|
+
w()
|
|
692
|
+
], p.prototype, "isLoading", void 0);
|
|
693
|
+
E([
|
|
694
|
+
w()
|
|
695
|
+
], p.prototype, "loadingExchangeId", void 0);
|
|
696
|
+
E([
|
|
697
|
+
w()
|
|
698
|
+
], p.prototype, "connectedWalletInfo", void 0);
|
|
699
|
+
p = E([
|
|
700
|
+
H("w3m-pay-view")
|
|
701
|
+
], p);
|
|
702
|
+
const pe = W`
|
|
703
|
+
:host {
|
|
704
|
+
display: block;
|
|
705
|
+
height: 100%;
|
|
706
|
+
width: 100%;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
wui-flex:first-child:not(:only-child) {
|
|
710
|
+
position: relative;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
wui-loading-thumbnail {
|
|
714
|
+
position: absolute;
|
|
715
|
+
}
|
|
716
|
+
`;
|
|
717
|
+
var b = function(t, e, s, a) {
|
|
718
|
+
var r = arguments.length, i = r < 3 ? e : a === null ? a = Object.getOwnPropertyDescriptor(e, s) : a, l;
|
|
719
|
+
if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(t, e, s, a);
|
|
720
|
+
else for (var d = t.length - 1; d >= 0; d--) (l = t[d]) && (i = (r < 3 ? l(i) : r > 3 ? l(e, s, i) : l(e, s)) || i);
|
|
721
|
+
return r > 3 && i && Object.defineProperty(e, s, i), i;
|
|
722
|
+
};
|
|
723
|
+
const we = 4e3;
|
|
724
|
+
let I = class extends F {
|
|
725
|
+
constructor() {
|
|
726
|
+
super(), this.loadingMessage = "", this.subMessage = "", this.paymentState = "in-progress", this.paymentState = u.state.isPaymentInProgress ? "in-progress" : "completed", this.updateMessages(), this.setupSubscription(), this.setupExchangeSubscription();
|
|
727
|
+
}
|
|
728
|
+
disconnectedCallback() {
|
|
729
|
+
clearInterval(this.exchangeSubscription);
|
|
730
|
+
}
|
|
731
|
+
render() {
|
|
732
|
+
return m`
|
|
733
|
+
<wui-flex
|
|
734
|
+
flexDirection="column"
|
|
735
|
+
alignItems="center"
|
|
736
|
+
.padding=${["xl", "xl", "xl", "xl"]}
|
|
737
|
+
gap="xl"
|
|
738
|
+
>
|
|
739
|
+
<wui-flex justifyContent="center" alignItems="center"> ${this.getStateIcon()} </wui-flex>
|
|
740
|
+
<wui-flex flexDirection="column" alignItems="center" gap="xs">
|
|
741
|
+
<wui-text align="center" variant="paragraph-500" color="fg-100">
|
|
742
|
+
${this.loadingMessage}
|
|
743
|
+
</wui-text>
|
|
744
|
+
<wui-text align="center" variant="small-400" color="fg-200">
|
|
745
|
+
${this.subMessage}
|
|
746
|
+
</wui-text>
|
|
747
|
+
</wui-flex>
|
|
748
|
+
</wui-flex>
|
|
749
|
+
`;
|
|
750
|
+
}
|
|
751
|
+
updateMessages() {
|
|
752
|
+
var e;
|
|
753
|
+
switch (this.paymentState) {
|
|
754
|
+
case "completed":
|
|
755
|
+
this.loadingMessage = "Payment completed", this.subMessage = "Your transaction has been successfully processed";
|
|
756
|
+
break;
|
|
757
|
+
case "error":
|
|
758
|
+
this.loadingMessage = "Payment failed", this.subMessage = "There was an error processing your transaction";
|
|
759
|
+
break;
|
|
760
|
+
case "in-progress":
|
|
761
|
+
default:
|
|
762
|
+
((e = u.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");
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
getStateIcon() {
|
|
767
|
+
switch (this.paymentState) {
|
|
768
|
+
case "completed":
|
|
769
|
+
return this.successTemplate();
|
|
770
|
+
case "error":
|
|
771
|
+
return this.errorTemplate();
|
|
772
|
+
case "in-progress":
|
|
773
|
+
default:
|
|
774
|
+
return this.loaderTemplate();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
setupExchangeSubscription() {
|
|
778
|
+
var e;
|
|
779
|
+
((e = u.state.currentPayment) == null ? void 0 : e.type) === "exchange" && (this.exchangeSubscription = setInterval(async () => {
|
|
780
|
+
var r, i, l;
|
|
781
|
+
const s = (r = u.state.currentPayment) == null ? void 0 : r.exchangeId, a = (i = u.state.currentPayment) == null ? void 0 : i.sessionId;
|
|
782
|
+
s && a && (await u.updateBuyStatus(s, a), ((l = u.state.currentPayment) == null ? void 0 : l.status) === "SUCCESS" && clearInterval(this.exchangeSubscription));
|
|
783
|
+
}, we));
|
|
784
|
+
}
|
|
785
|
+
setupSubscription() {
|
|
786
|
+
u.subscribeKey("isPaymentInProgress", (e) => {
|
|
787
|
+
var s;
|
|
788
|
+
!e && this.paymentState === "in-progress" && (u.state.error || !((s = u.state.currentPayment) != null && s.result) ? this.paymentState = "error" : this.paymentState = "completed", this.updateMessages(), setTimeout(() => {
|
|
789
|
+
h.state.status !== "disconnected" && x.close();
|
|
790
|
+
}, 3e3));
|
|
791
|
+
}), u.subscribeKey("error", (e) => {
|
|
792
|
+
e && this.paymentState === "in-progress" && (this.paymentState = "error", this.updateMessages());
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
loaderTemplate() {
|
|
796
|
+
const e = Z.state.themeVariables["--w3m-border-radius-master"], s = e ? parseInt(e.replace("px", ""), 10) : 4, a = this.getPaymentIcon();
|
|
797
|
+
return m`
|
|
798
|
+
<wui-flex justifyContent="center" alignItems="center" style="position: relative;">
|
|
799
|
+
${a ? m`<wui-wallet-image size="lg" imageSrc=${a}></wui-wallet-image>` : null}
|
|
800
|
+
<wui-loading-thumbnail radius=${s * 9}></wui-loading-thumbnail>
|
|
801
|
+
</wui-flex>
|
|
802
|
+
`;
|
|
803
|
+
}
|
|
804
|
+
getPaymentIcon() {
|
|
805
|
+
var s;
|
|
806
|
+
const e = u.state.currentPayment;
|
|
807
|
+
if (e) {
|
|
808
|
+
if (e.type === "exchange") {
|
|
809
|
+
const a = e.exchangeId;
|
|
810
|
+
if (a) {
|
|
811
|
+
const r = u.getExchangeById(a);
|
|
812
|
+
return r == null ? void 0 : r.imageUrl;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (e.type === "wallet") {
|
|
816
|
+
const a = (s = A.state.connectedWalletInfo) == null ? void 0 : s.icon;
|
|
817
|
+
if (a)
|
|
818
|
+
return a;
|
|
819
|
+
const r = y.state.activeChain;
|
|
820
|
+
if (!r)
|
|
821
|
+
return;
|
|
822
|
+
const i = G.getConnectorId(r);
|
|
823
|
+
if (!i)
|
|
824
|
+
return;
|
|
825
|
+
const l = G.getConnectorById(i);
|
|
826
|
+
return l ? Q.getConnectorImage(l) : void 0;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
successTemplate() {
|
|
831
|
+
return m`<wui-icon size="xl" color="success-100" name="checkmark"></wui-icon>`;
|
|
832
|
+
}
|
|
833
|
+
errorTemplate() {
|
|
834
|
+
return m`<wui-icon size="xl" color="error-100" name="close"></wui-icon>`;
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
I.styles = pe;
|
|
838
|
+
b([
|
|
839
|
+
w()
|
|
840
|
+
], I.prototype, "loadingMessage", void 0);
|
|
841
|
+
b([
|
|
842
|
+
w()
|
|
843
|
+
], I.prototype, "subMessage", void 0);
|
|
844
|
+
b([
|
|
845
|
+
w()
|
|
846
|
+
], I.prototype, "paymentState", void 0);
|
|
847
|
+
I = b([
|
|
848
|
+
H("w3m-pay-loading-view")
|
|
849
|
+
], I);
|
|
850
|
+
const ye = 3e5;
|
|
851
|
+
async function he(t) {
|
|
852
|
+
return u.handleOpenPay(t);
|
|
853
|
+
}
|
|
854
|
+
async function Ne(t, e = ye) {
|
|
855
|
+
if (e <= 0)
|
|
856
|
+
throw new c(o.INVALID_PAYMENT_CONFIG, "Timeout must be greater than 0");
|
|
857
|
+
try {
|
|
858
|
+
await he(t);
|
|
859
|
+
} catch (s) {
|
|
860
|
+
throw s instanceof c ? s : new c(o.UNABLE_TO_INITIATE_PAYMENT, s.message);
|
|
861
|
+
}
|
|
862
|
+
return new Promise((s, a) => {
|
|
863
|
+
let r = !1;
|
|
864
|
+
const i = setTimeout(() => {
|
|
865
|
+
r || (r = !0, S(), a(new c(o.GENERIC_PAYMENT_ERROR, "Payment timeout")));
|
|
866
|
+
}, e);
|
|
867
|
+
function l() {
|
|
868
|
+
if (r)
|
|
869
|
+
return;
|
|
870
|
+
const f = u.state.currentPayment, U = u.state.error, K = u.state.isPaymentInProgress;
|
|
871
|
+
if ((f == null ? void 0 : f.status) === "SUCCESS") {
|
|
872
|
+
r = !0, S(), clearTimeout(i), s({
|
|
873
|
+
success: !0,
|
|
874
|
+
result: f.result
|
|
875
|
+
});
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
if ((f == null ? void 0 : f.status) === "FAILED") {
|
|
879
|
+
r = !0, S(), clearTimeout(i), s({
|
|
880
|
+
success: !1,
|
|
881
|
+
error: U || "Payment failed"
|
|
882
|
+
});
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
U && !K && !f && (r = !0, S(), clearTimeout(i), s({
|
|
886
|
+
success: !1,
|
|
887
|
+
error: U
|
|
888
|
+
}));
|
|
889
|
+
}
|
|
890
|
+
const d = D("currentPayment", l), M = D("error", l), P = D("isPaymentInProgress", l), S = fe([
|
|
891
|
+
d,
|
|
892
|
+
M,
|
|
893
|
+
P
|
|
894
|
+
]);
|
|
895
|
+
l();
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
function Ie() {
|
|
899
|
+
return u.getExchanges();
|
|
900
|
+
}
|
|
901
|
+
function Pe() {
|
|
902
|
+
var t;
|
|
903
|
+
return (t = u.state.currentPayment) == null ? void 0 : t.result;
|
|
904
|
+
}
|
|
905
|
+
function _e() {
|
|
906
|
+
return u.state.error;
|
|
907
|
+
}
|
|
908
|
+
function Te() {
|
|
909
|
+
return u.state.isPaymentInProgress;
|
|
910
|
+
}
|
|
911
|
+
function D(t, e) {
|
|
912
|
+
return u.subscribeKey(t, e);
|
|
913
|
+
}
|
|
914
|
+
function fe(t) {
|
|
915
|
+
return () => {
|
|
916
|
+
t.forEach((e) => {
|
|
917
|
+
try {
|
|
918
|
+
e();
|
|
919
|
+
} catch {
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
const Se = {
|
|
925
|
+
network: "eip155:8453",
|
|
926
|
+
asset: "native",
|
|
927
|
+
metadata: {
|
|
928
|
+
name: "Ethereum",
|
|
929
|
+
symbol: "ETH",
|
|
930
|
+
decimals: 18
|
|
931
|
+
}
|
|
932
|
+
}, Ce = {
|
|
933
|
+
network: "eip155:8453",
|
|
934
|
+
asset: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
935
|
+
metadata: {
|
|
936
|
+
name: "USD Coin",
|
|
937
|
+
symbol: "USDC",
|
|
938
|
+
decimals: 6
|
|
939
|
+
}
|
|
940
|
+
}, xe = {
|
|
941
|
+
network: "eip155:84532",
|
|
942
|
+
asset: "native",
|
|
943
|
+
metadata: {
|
|
944
|
+
name: "Ethereum",
|
|
945
|
+
symbol: "ETH",
|
|
946
|
+
decimals: 18
|
|
947
|
+
}
|
|
948
|
+
}, be = {
|
|
949
|
+
network: "eip155:1",
|
|
950
|
+
asset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
951
|
+
metadata: {
|
|
952
|
+
name: "USD Coin",
|
|
953
|
+
symbol: "USDC",
|
|
954
|
+
decimals: 6
|
|
955
|
+
}
|
|
956
|
+
}, Ue = {
|
|
957
|
+
network: "eip155:10",
|
|
958
|
+
asset: "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
|
|
959
|
+
metadata: {
|
|
960
|
+
name: "USD Coin",
|
|
961
|
+
symbol: "USDC",
|
|
962
|
+
decimals: 6
|
|
963
|
+
}
|
|
964
|
+
}, ve = {
|
|
965
|
+
network: "eip155:42161",
|
|
966
|
+
asset: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
967
|
+
metadata: {
|
|
968
|
+
name: "USD Coin",
|
|
969
|
+
symbol: "USDC",
|
|
970
|
+
decimals: 6
|
|
971
|
+
}
|
|
972
|
+
}, Re = {
|
|
973
|
+
network: "eip155:137",
|
|
974
|
+
asset: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
|
|
975
|
+
metadata: {
|
|
976
|
+
name: "USD Coin",
|
|
977
|
+
symbol: "USDC",
|
|
978
|
+
decimals: 6
|
|
979
|
+
}
|
|
980
|
+
}, ke = {
|
|
981
|
+
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
982
|
+
asset: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
983
|
+
metadata: {
|
|
984
|
+
name: "USD Coin",
|
|
985
|
+
symbol: "USDC",
|
|
986
|
+
decimals: 6
|
|
987
|
+
}
|
|
988
|
+
}, De = {
|
|
989
|
+
network: "eip155:1",
|
|
990
|
+
asset: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
991
|
+
metadata: {
|
|
992
|
+
name: "Tether USD",
|
|
993
|
+
symbol: "USDT",
|
|
994
|
+
decimals: 6
|
|
995
|
+
}
|
|
996
|
+
}, Oe = {
|
|
997
|
+
network: "eip155:10",
|
|
998
|
+
asset: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58",
|
|
999
|
+
metadata: {
|
|
1000
|
+
name: "Tether USD",
|
|
1001
|
+
symbol: "USDT",
|
|
1002
|
+
decimals: 6
|
|
1003
|
+
}
|
|
1004
|
+
}, Le = {
|
|
1005
|
+
network: "eip155:42161",
|
|
1006
|
+
asset: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
|
|
1007
|
+
metadata: {
|
|
1008
|
+
name: "Tether USD",
|
|
1009
|
+
symbol: "USDT",
|
|
1010
|
+
decimals: 6
|
|
1011
|
+
}
|
|
1012
|
+
}, Me = {
|
|
1013
|
+
network: "eip155:137",
|
|
1014
|
+
asset: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
|
|
1015
|
+
metadata: {
|
|
1016
|
+
name: "Tether USD",
|
|
1017
|
+
symbol: "USDT",
|
|
1018
|
+
decimals: 6
|
|
1019
|
+
}
|
|
1020
|
+
}, Ye = {
|
|
1021
|
+
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
1022
|
+
asset: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
1023
|
+
metadata: {
|
|
1024
|
+
name: "Tether USD",
|
|
1025
|
+
symbol: "USDT",
|
|
1026
|
+
decimals: 6
|
|
1027
|
+
}
|
|
1028
|
+
}, Ge = {
|
|
1029
|
+
network: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
1030
|
+
asset: "native",
|
|
1031
|
+
metadata: {
|
|
1032
|
+
name: "Solana",
|
|
1033
|
+
symbol: "SOL",
|
|
1034
|
+
decimals: 9
|
|
1035
|
+
}
|
|
1036
|
+
};
|
|
1037
|
+
export {
|
|
1038
|
+
I as W3mPayLoadingView,
|
|
1039
|
+
p as W3mPayView,
|
|
1040
|
+
ve as arbitrumUSDC,
|
|
1041
|
+
Le as arbitrumUSDT,
|
|
1042
|
+
Se as baseETH,
|
|
1043
|
+
xe as baseSepoliaETH,
|
|
1044
|
+
Ce as baseUSDC,
|
|
1045
|
+
be as ethereumUSDC,
|
|
1046
|
+
De as ethereumUSDT,
|
|
1047
|
+
Ie as getExchanges,
|
|
1048
|
+
Te as getIsPaymentInProgress,
|
|
1049
|
+
_e as getPayError,
|
|
1050
|
+
Pe as getPayResult,
|
|
1051
|
+
he as openPay,
|
|
1052
|
+
Ue as optimismUSDC,
|
|
1053
|
+
Oe as optimismUSDT,
|
|
1054
|
+
Ne as pay,
|
|
1055
|
+
Re as polygonUSDC,
|
|
1056
|
+
Me as polygonUSDT,
|
|
1057
|
+
Ge as solanaSOL,
|
|
1058
|
+
ke as solanaUSDC,
|
|
1059
|
+
Ye as solanaUSDT
|
|
1060
|
+
};
|