@chainrails/react 0.0.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 +16 -0
- package/dist/PaymentModal/index.d.ts +17 -0
- package/dist/PaymentModal/index.d.ts.map +1 -0
- package/dist/chainrails-sdk.es.js +722 -0
- package/dist/chainrails-sdk.es.mjs +722 -0
- package/dist/chainrails-sdk.umd.js +1 -0
- package/dist/hooks/usePaymentModal.d.ts +25 -0
- package/dist/hooks/usePaymentModal.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/react.css +1 -0
- package/dist/store.d.ts +8 -0
- package/dist/store.d.ts.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
import { useState as U, useEffect as z } from "react";
|
|
2
|
+
import { jsxs as N, jsx as w } from "react/jsx-runtime";
|
|
3
|
+
class C extends Error {
|
|
4
|
+
response;
|
|
5
|
+
request;
|
|
6
|
+
options;
|
|
7
|
+
constructor(e, r, s) {
|
|
8
|
+
const n = e.status || e.status === 0 ? e.status : "", o = e.statusText ?? "", i = `${n} ${o}`.trim(), u = i ? `status code ${i}` : "an unknown error";
|
|
9
|
+
super(`Request failed with ${u}: ${r.method} ${r.url}`), this.name = "HTTPError", this.response = e, this.request = r, this.options = s;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class L extends Error {
|
|
13
|
+
name = "NonError";
|
|
14
|
+
value;
|
|
15
|
+
constructor(e) {
|
|
16
|
+
let r = "Non-error value was thrown";
|
|
17
|
+
try {
|
|
18
|
+
typeof e == "string" ? r = e : e && typeof e == "object" && "message" in e && typeof e.message == "string" && (r = e.message);
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
super(r), this.value = e;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class A extends Error {
|
|
25
|
+
name = "ForceRetryError";
|
|
26
|
+
customDelay;
|
|
27
|
+
code;
|
|
28
|
+
customRequest;
|
|
29
|
+
constructor(e) {
|
|
30
|
+
const r = e?.cause ? e.cause instanceof Error ? e.cause : new L(e.cause) : void 0;
|
|
31
|
+
super(e?.code ? `Forced retry: ${e.code}` : "Forced retry", r ? { cause: r } : void 0), this.customDelay = e?.delay, this.code = e?.code, this.customRequest = e?.request;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const v = (() => {
|
|
35
|
+
let t = !1, e = !1;
|
|
36
|
+
const r = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
|
|
37
|
+
if (r && s)
|
|
38
|
+
try {
|
|
39
|
+
e = new globalThis.Request("https://empty.invalid", {
|
|
40
|
+
body: new globalThis.ReadableStream(),
|
|
41
|
+
method: "POST",
|
|
42
|
+
// @ts-expect-error - Types are outdated.
|
|
43
|
+
get duplex() {
|
|
44
|
+
return t = !0, "half";
|
|
45
|
+
}
|
|
46
|
+
}).headers.has("Content-Type");
|
|
47
|
+
} catch (n) {
|
|
48
|
+
if (n instanceof Error && n.message === "unsupported BodyInit type")
|
|
49
|
+
return !1;
|
|
50
|
+
throw n;
|
|
51
|
+
}
|
|
52
|
+
return t && !e;
|
|
53
|
+
})(), J = typeof globalThis.AbortController == "function", I = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", V = typeof globalThis.ReadableStream == "function", K = typeof globalThis.FormData == "function", _ = ["get", "post", "put", "patch", "head", "delete"], W = {
|
|
54
|
+
json: "application/json",
|
|
55
|
+
text: "text/*",
|
|
56
|
+
formData: "multipart/form-data",
|
|
57
|
+
arrayBuffer: "*/*",
|
|
58
|
+
blob: "*/*",
|
|
59
|
+
// Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
|
|
60
|
+
// We still feature-check at runtime before exposing the shortcut.
|
|
61
|
+
bytes: "*/*"
|
|
62
|
+
}, E = 2147483647, X = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length, M = Symbol("stop");
|
|
63
|
+
class B {
|
|
64
|
+
options;
|
|
65
|
+
constructor(e) {
|
|
66
|
+
this.options = e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const Z = (t) => new B(t), Y = {
|
|
70
|
+
json: !0,
|
|
71
|
+
parseJson: !0,
|
|
72
|
+
stringifyJson: !0,
|
|
73
|
+
searchParams: !0,
|
|
74
|
+
prefixUrl: !0,
|
|
75
|
+
retry: !0,
|
|
76
|
+
timeout: !0,
|
|
77
|
+
hooks: !0,
|
|
78
|
+
throwHttpErrors: !0,
|
|
79
|
+
onDownloadProgress: !0,
|
|
80
|
+
onUploadProgress: !0,
|
|
81
|
+
fetch: !0,
|
|
82
|
+
context: !0
|
|
83
|
+
}, G = {
|
|
84
|
+
next: !0
|
|
85
|
+
// Next.js cache revalidation (revalidate, tags)
|
|
86
|
+
}, Q = {
|
|
87
|
+
method: !0,
|
|
88
|
+
headers: !0,
|
|
89
|
+
body: !0,
|
|
90
|
+
mode: !0,
|
|
91
|
+
credentials: !0,
|
|
92
|
+
cache: !0,
|
|
93
|
+
redirect: !0,
|
|
94
|
+
referrer: !0,
|
|
95
|
+
referrerPolicy: !0,
|
|
96
|
+
integrity: !0,
|
|
97
|
+
keepalive: !0,
|
|
98
|
+
signal: !0,
|
|
99
|
+
window: !0,
|
|
100
|
+
duplex: !0
|
|
101
|
+
}, ee = (t) => {
|
|
102
|
+
if (!t)
|
|
103
|
+
return 0;
|
|
104
|
+
if (t instanceof FormData) {
|
|
105
|
+
let e = 0;
|
|
106
|
+
for (const [r, s] of t)
|
|
107
|
+
e += X, e += new TextEncoder().encode(`Content-Disposition: form-data; name="${r}"`).length, e += typeof s == "string" ? new TextEncoder().encode(s).length : s.size;
|
|
108
|
+
return e;
|
|
109
|
+
}
|
|
110
|
+
if (t instanceof Blob)
|
|
111
|
+
return t.size;
|
|
112
|
+
if (t instanceof ArrayBuffer)
|
|
113
|
+
return t.byteLength;
|
|
114
|
+
if (typeof t == "string")
|
|
115
|
+
return new TextEncoder().encode(t).length;
|
|
116
|
+
if (t instanceof URLSearchParams)
|
|
117
|
+
return new TextEncoder().encode(t.toString()).length;
|
|
118
|
+
if ("byteLength" in t)
|
|
119
|
+
return t.byteLength;
|
|
120
|
+
if (typeof t == "object" && t !== null)
|
|
121
|
+
try {
|
|
122
|
+
const e = JSON.stringify(t);
|
|
123
|
+
return new TextEncoder().encode(e).length;
|
|
124
|
+
} catch {
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
return 0;
|
|
128
|
+
}, H = (t, e, r) => {
|
|
129
|
+
let s, n = 0;
|
|
130
|
+
return t.pipeThrough(new TransformStream({
|
|
131
|
+
transform(o, i) {
|
|
132
|
+
if (i.enqueue(o), s) {
|
|
133
|
+
n += s.byteLength;
|
|
134
|
+
let u = e === 0 ? 0 : n / e;
|
|
135
|
+
u >= 1 && (u = 1 - Number.EPSILON), r?.({ percent: u, totalBytes: Math.max(e, n), transferredBytes: n }, s);
|
|
136
|
+
}
|
|
137
|
+
s = o;
|
|
138
|
+
},
|
|
139
|
+
flush() {
|
|
140
|
+
s && (n += s.byteLength, r?.({ percent: 1, totalBytes: Math.max(e, n), transferredBytes: n }, s));
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
}, te = (t, e) => {
|
|
144
|
+
if (!t.body)
|
|
145
|
+
return t;
|
|
146
|
+
if (t.status === 204)
|
|
147
|
+
return new Response(null, {
|
|
148
|
+
status: t.status,
|
|
149
|
+
statusText: t.statusText,
|
|
150
|
+
headers: t.headers
|
|
151
|
+
});
|
|
152
|
+
const r = Math.max(0, Number(t.headers.get("content-length")) || 0);
|
|
153
|
+
return new Response(H(t.body, r, e), {
|
|
154
|
+
status: t.status,
|
|
155
|
+
statusText: t.statusText,
|
|
156
|
+
headers: t.headers
|
|
157
|
+
});
|
|
158
|
+
}, re = (t, e, r) => {
|
|
159
|
+
if (!t.body)
|
|
160
|
+
return t;
|
|
161
|
+
const s = ee(r ?? t.body);
|
|
162
|
+
return new Request(t, {
|
|
163
|
+
// @ts-expect-error - Types are outdated.
|
|
164
|
+
duplex: "half",
|
|
165
|
+
body: H(t.body, s, e)
|
|
166
|
+
});
|
|
167
|
+
}, l = (t) => t !== null && typeof t == "object", b = (...t) => {
|
|
168
|
+
for (const e of t)
|
|
169
|
+
if ((!l(e) || Array.isArray(e)) && e !== void 0)
|
|
170
|
+
throw new TypeError("The `options` argument must be an object");
|
|
171
|
+
return k({}, ...t);
|
|
172
|
+
}, D = (t = {}, e = {}) => {
|
|
173
|
+
const r = new globalThis.Headers(t), s = e instanceof globalThis.Headers, n = new globalThis.Headers(e);
|
|
174
|
+
for (const [o, i] of n.entries())
|
|
175
|
+
s && i === "undefined" || i === void 0 ? r.delete(o) : r.set(o, i);
|
|
176
|
+
return r;
|
|
177
|
+
};
|
|
178
|
+
function R(t, e, r) {
|
|
179
|
+
return Object.hasOwn(e, r) && e[r] === void 0 ? [] : k(t[r] ?? [], e[r] ?? []);
|
|
180
|
+
}
|
|
181
|
+
const $ = (t = {}, e = {}) => ({
|
|
182
|
+
beforeRequest: R(t, e, "beforeRequest"),
|
|
183
|
+
beforeRetry: R(t, e, "beforeRetry"),
|
|
184
|
+
afterResponse: R(t, e, "afterResponse"),
|
|
185
|
+
beforeError: R(t, e, "beforeError")
|
|
186
|
+
}), se = (t, e) => {
|
|
187
|
+
const r = new URLSearchParams();
|
|
188
|
+
for (const s of [t, e])
|
|
189
|
+
if (s !== void 0)
|
|
190
|
+
if (s instanceof URLSearchParams)
|
|
191
|
+
for (const [n, o] of s.entries())
|
|
192
|
+
r.append(n, o);
|
|
193
|
+
else if (Array.isArray(s))
|
|
194
|
+
for (const n of s) {
|
|
195
|
+
if (!Array.isArray(n) || n.length !== 2)
|
|
196
|
+
throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
|
|
197
|
+
r.append(String(n[0]), String(n[1]));
|
|
198
|
+
}
|
|
199
|
+
else if (l(s))
|
|
200
|
+
for (const [n, o] of Object.entries(s))
|
|
201
|
+
o !== void 0 && r.append(n, String(o));
|
|
202
|
+
else {
|
|
203
|
+
const n = new URLSearchParams(s);
|
|
204
|
+
for (const [o, i] of n.entries())
|
|
205
|
+
r.append(o, i);
|
|
206
|
+
}
|
|
207
|
+
return r;
|
|
208
|
+
}, k = (...t) => {
|
|
209
|
+
let e = {}, r = {}, s = {}, n;
|
|
210
|
+
const o = [];
|
|
211
|
+
for (const i of t)
|
|
212
|
+
if (Array.isArray(i))
|
|
213
|
+
Array.isArray(e) || (e = []), e = [...e, ...i];
|
|
214
|
+
else if (l(i)) {
|
|
215
|
+
for (let [u, a] of Object.entries(i)) {
|
|
216
|
+
if (u === "signal" && a instanceof globalThis.AbortSignal) {
|
|
217
|
+
o.push(a);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (u === "context") {
|
|
221
|
+
if (a != null && (!l(a) || Array.isArray(a)))
|
|
222
|
+
throw new TypeError("The `context` option must be an object");
|
|
223
|
+
e = {
|
|
224
|
+
...e,
|
|
225
|
+
context: a == null ? {} : { ...e.context, ...a }
|
|
226
|
+
};
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (u === "searchParams") {
|
|
230
|
+
a == null ? n = void 0 : n = n === void 0 ? a : se(n, a);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
l(a) && u in e && (a = k(e[u], a)), e = { ...e, [u]: a };
|
|
234
|
+
}
|
|
235
|
+
l(i.hooks) && (s = $(s, i.hooks), e.hooks = s), l(i.headers) && (r = D(r, i.headers), e.headers = r);
|
|
236
|
+
}
|
|
237
|
+
return n !== void 0 && (e.searchParams = n), o.length > 0 && (o.length === 1 ? e.signal = o[0] : I ? e.signal = AbortSignal.any(o) : e.signal = o.at(-1)), e.context === void 0 && (e.context = {}), e;
|
|
238
|
+
}, ne = (t) => _.includes(t) ? t.toUpperCase() : t, oe = ["get", "put", "head", "delete", "options", "trace"], ie = [408, 413, 429, 500, 502, 503, 504], ae = [413, 429, 503], O = {
|
|
239
|
+
limit: 2,
|
|
240
|
+
methods: oe,
|
|
241
|
+
statusCodes: ie,
|
|
242
|
+
afterStatusCodes: ae,
|
|
243
|
+
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
244
|
+
backoffLimit: Number.POSITIVE_INFINITY,
|
|
245
|
+
delay: (t) => 0.3 * 2 ** (t - 1) * 1e3,
|
|
246
|
+
jitter: void 0,
|
|
247
|
+
retryOnTimeout: !1
|
|
248
|
+
}, ue = (t = {}) => {
|
|
249
|
+
if (typeof t == "number")
|
|
250
|
+
return {
|
|
251
|
+
...O,
|
|
252
|
+
limit: t
|
|
253
|
+
};
|
|
254
|
+
if (t.methods && !Array.isArray(t.methods))
|
|
255
|
+
throw new Error("retry.methods must be an array");
|
|
256
|
+
if (t.statusCodes && !Array.isArray(t.statusCodes))
|
|
257
|
+
throw new Error("retry.statusCodes must be an array");
|
|
258
|
+
return {
|
|
259
|
+
...O,
|
|
260
|
+
...t
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
class x extends Error {
|
|
264
|
+
request;
|
|
265
|
+
constructor(e) {
|
|
266
|
+
super(`Request timed out: ${e.method} ${e.url}`), this.name = "TimeoutError", this.request = e;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async function ce(t, e, r, s) {
|
|
270
|
+
return new Promise((n, o) => {
|
|
271
|
+
const i = setTimeout(() => {
|
|
272
|
+
r && r.abort(), o(new x(t));
|
|
273
|
+
}, s.timeout);
|
|
274
|
+
s.fetch(t, e).then(n).catch(o).then(() => {
|
|
275
|
+
clearTimeout(i);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
async function he(t, { signal: e }) {
|
|
280
|
+
return new Promise((r, s) => {
|
|
281
|
+
e && (e.throwIfAborted(), e.addEventListener("abort", n, { once: !0 }));
|
|
282
|
+
function n() {
|
|
283
|
+
clearTimeout(o), s(e.reason);
|
|
284
|
+
}
|
|
285
|
+
const o = setTimeout(() => {
|
|
286
|
+
e?.removeEventListener("abort", n), r();
|
|
287
|
+
}, t);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const le = (t, e) => {
|
|
291
|
+
const r = {};
|
|
292
|
+
for (const s in e)
|
|
293
|
+
Object.hasOwn(e, s) && !(s in Q) && !(s in Y) && (!(s in t) || s in G) && (r[s] = e[s]);
|
|
294
|
+
return r;
|
|
295
|
+
}, fe = (t) => t === void 0 ? !1 : Array.isArray(t) ? t.length > 0 : t instanceof URLSearchParams ? t.size > 0 : typeof t == "object" ? Object.keys(t).length > 0 : typeof t == "string" ? t.trim().length > 0 : !!t;
|
|
296
|
+
function de(t) {
|
|
297
|
+
return t instanceof C || t?.name === C.name;
|
|
298
|
+
}
|
|
299
|
+
function pe(t) {
|
|
300
|
+
return t instanceof x || t?.name === x.name;
|
|
301
|
+
}
|
|
302
|
+
class y {
|
|
303
|
+
static create(e, r) {
|
|
304
|
+
const s = new y(e, r), n = async () => {
|
|
305
|
+
if (typeof s.#e.timeout == "number" && s.#e.timeout > E)
|
|
306
|
+
throw new RangeError(`The \`timeout\` option cannot be greater than ${E}`);
|
|
307
|
+
await Promise.resolve();
|
|
308
|
+
let i = await s.#y();
|
|
309
|
+
for (const u of s.#e.hooks.afterResponse) {
|
|
310
|
+
const a = s.#h(i.clone()), c = await u(s.request, s.#a(), a, { retryCount: s.#r });
|
|
311
|
+
if (c instanceof globalThis.Response && (i = c), c instanceof B)
|
|
312
|
+
throw await Promise.all([
|
|
313
|
+
a.body?.cancel(),
|
|
314
|
+
i.body?.cancel()
|
|
315
|
+
]), new A(c.options);
|
|
316
|
+
}
|
|
317
|
+
if (s.#h(i), !i.ok && (typeof s.#e.throwHttpErrors == "function" ? s.#e.throwHttpErrors(i.status) : s.#e.throwHttpErrors)) {
|
|
318
|
+
let u = new C(i, s.request, s.#a());
|
|
319
|
+
for (const a of s.#e.hooks.beforeError)
|
|
320
|
+
u = await a(u, { retryCount: s.#r });
|
|
321
|
+
throw u;
|
|
322
|
+
}
|
|
323
|
+
if (s.#e.onDownloadProgress) {
|
|
324
|
+
if (typeof s.#e.onDownloadProgress != "function")
|
|
325
|
+
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
326
|
+
if (!V)
|
|
327
|
+
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
328
|
+
return te(i.clone(), s.#e.onDownloadProgress);
|
|
329
|
+
}
|
|
330
|
+
return i;
|
|
331
|
+
}, o = s.#l(n).finally(async () => {
|
|
332
|
+
const i = s.#o, u = [];
|
|
333
|
+
i && !i.bodyUsed && u.push(i.body?.cancel()), s.request.bodyUsed || u.push(s.request.body?.cancel()), await Promise.all(u);
|
|
334
|
+
});
|
|
335
|
+
for (const [i, u] of Object.entries(W))
|
|
336
|
+
i === "bytes" && typeof globalThis.Response?.prototype?.bytes != "function" || (o[i] = async () => {
|
|
337
|
+
s.request.headers.set("accept", s.request.headers.get("accept") || u);
|
|
338
|
+
const a = await o;
|
|
339
|
+
if (i === "json") {
|
|
340
|
+
if (a.status === 204)
|
|
341
|
+
return "";
|
|
342
|
+
const c = await a.text();
|
|
343
|
+
return c === "" ? "" : r.parseJson ? r.parseJson(c) : JSON.parse(c);
|
|
344
|
+
}
|
|
345
|
+
return a[i]();
|
|
346
|
+
});
|
|
347
|
+
return o;
|
|
348
|
+
}
|
|
349
|
+
// eslint-disable-next-line unicorn/prevent-abbreviations
|
|
350
|
+
static #d(e) {
|
|
351
|
+
return e && typeof e == "object" && !Array.isArray(e) && !(e instanceof URLSearchParams) ? Object.fromEntries(Object.entries(e).filter(([, r]) => r !== void 0)) : e;
|
|
352
|
+
}
|
|
353
|
+
request;
|
|
354
|
+
#s;
|
|
355
|
+
#r = 0;
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly -- False positive: #input is reassigned on line 202
|
|
357
|
+
#t;
|
|
358
|
+
#e;
|
|
359
|
+
#o;
|
|
360
|
+
#n;
|
|
361
|
+
#i;
|
|
362
|
+
// eslint-disable-next-line complexity
|
|
363
|
+
constructor(e, r = {}) {
|
|
364
|
+
if (this.#t = e, this.#e = {
|
|
365
|
+
...r,
|
|
366
|
+
headers: D(this.#t.headers, r.headers),
|
|
367
|
+
hooks: $({
|
|
368
|
+
beforeRequest: [],
|
|
369
|
+
beforeRetry: [],
|
|
370
|
+
beforeError: [],
|
|
371
|
+
afterResponse: []
|
|
372
|
+
}, r.hooks),
|
|
373
|
+
method: ne(r.method ?? this.#t.method ?? "GET"),
|
|
374
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
375
|
+
prefixUrl: String(r.prefixUrl || ""),
|
|
376
|
+
retry: ue(r.retry),
|
|
377
|
+
throwHttpErrors: r.throwHttpErrors ?? !0,
|
|
378
|
+
timeout: r.timeout ?? 1e4,
|
|
379
|
+
fetch: r.fetch ?? globalThis.fetch.bind(globalThis),
|
|
380
|
+
context: r.context ?? {}
|
|
381
|
+
}, typeof this.#t != "string" && !(this.#t instanceof URL || this.#t instanceof globalThis.Request))
|
|
382
|
+
throw new TypeError("`input` must be a string, URL, or Request");
|
|
383
|
+
if (this.#e.prefixUrl && typeof this.#t == "string") {
|
|
384
|
+
if (this.#t.startsWith("/"))
|
|
385
|
+
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
386
|
+
this.#e.prefixUrl.endsWith("/") || (this.#e.prefixUrl += "/"), this.#t = this.#e.prefixUrl + this.#t;
|
|
387
|
+
}
|
|
388
|
+
J && I && (this.#n = this.#e.signal ?? this.#t.signal, this.#s = new globalThis.AbortController(), this.#e.signal = this.#n ? AbortSignal.any([this.#n, this.#s.signal]) : this.#s.signal), v && (this.#e.duplex = "half"), this.#e.json !== void 0 && (this.#e.body = this.#e.stringifyJson?.(this.#e.json) ?? JSON.stringify(this.#e.json), this.#e.headers.set("content-type", this.#e.headers.get("content-type") ?? "application/json"));
|
|
389
|
+
const s = r.headers && new globalThis.Headers(r.headers).has("content-type");
|
|
390
|
+
if (this.#t instanceof globalThis.Request && (K && this.#e.body instanceof globalThis.FormData || this.#e.body instanceof URLSearchParams) && !s && this.#e.headers.delete("content-type"), this.request = new globalThis.Request(this.#t, this.#e), fe(this.#e.searchParams)) {
|
|
391
|
+
const o = "?" + (typeof this.#e.searchParams == "string" ? this.#e.searchParams.replace(/^\?/, "") : new URLSearchParams(y.#d(this.#e.searchParams)).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, o);
|
|
392
|
+
this.request = new globalThis.Request(i, this.#e);
|
|
393
|
+
}
|
|
394
|
+
if (this.#e.onUploadProgress) {
|
|
395
|
+
if (typeof this.#e.onUploadProgress != "function")
|
|
396
|
+
throw new TypeError("The `onUploadProgress` option must be a function");
|
|
397
|
+
if (!v)
|
|
398
|
+
throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
|
|
399
|
+
this.request = this.#f(this.request, this.#e.body ?? void 0);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
#u() {
|
|
403
|
+
const e = this.#e.retry.delay(this.#r);
|
|
404
|
+
let r = e;
|
|
405
|
+
return this.#e.retry.jitter === !0 ? r = Math.random() * e : typeof this.#e.retry.jitter == "function" && (r = this.#e.retry.jitter(e), (!Number.isFinite(r) || r < 0) && (r = e)), Math.min(this.#e.retry.backoffLimit, r);
|
|
406
|
+
}
|
|
407
|
+
async #p(e) {
|
|
408
|
+
if (this.#r++, this.#r > this.#e.retry.limit)
|
|
409
|
+
throw e;
|
|
410
|
+
const r = e instanceof Error ? e : new L(e);
|
|
411
|
+
if (r instanceof A)
|
|
412
|
+
return r.customDelay ?? this.#u();
|
|
413
|
+
if (!this.#e.retry.methods.includes(this.request.method.toLowerCase()))
|
|
414
|
+
throw e;
|
|
415
|
+
if (this.#e.retry.shouldRetry !== void 0) {
|
|
416
|
+
const s = await this.#e.retry.shouldRetry({ error: r, retryCount: this.#r });
|
|
417
|
+
if (s === !1)
|
|
418
|
+
throw e;
|
|
419
|
+
if (s === !0)
|
|
420
|
+
return this.#u();
|
|
421
|
+
}
|
|
422
|
+
if (pe(e) && !this.#e.retry.retryOnTimeout)
|
|
423
|
+
throw e;
|
|
424
|
+
if (de(e)) {
|
|
425
|
+
if (!this.#e.retry.statusCodes.includes(e.response.status))
|
|
426
|
+
throw e;
|
|
427
|
+
const s = e.response.headers.get("Retry-After") ?? e.response.headers.get("RateLimit-Reset") ?? e.response.headers.get("X-RateLimit-Retry-After") ?? e.response.headers.get("X-RateLimit-Reset") ?? e.response.headers.get("X-Rate-Limit-Reset");
|
|
428
|
+
if (s && this.#e.retry.afterStatusCodes.includes(e.response.status)) {
|
|
429
|
+
let n = Number(s) * 1e3;
|
|
430
|
+
Number.isNaN(n) ? n = Date.parse(s) - Date.now() : n >= Date.parse("2024-01-01") && (n -= Date.now());
|
|
431
|
+
const o = this.#e.retry.maxRetryAfter ?? n;
|
|
432
|
+
return n < o ? n : o;
|
|
433
|
+
}
|
|
434
|
+
if (e.response.status === 413)
|
|
435
|
+
throw e;
|
|
436
|
+
}
|
|
437
|
+
return this.#u();
|
|
438
|
+
}
|
|
439
|
+
#h(e) {
|
|
440
|
+
return this.#e.parseJson && (e.json = async () => this.#e.parseJson(await e.text())), e;
|
|
441
|
+
}
|
|
442
|
+
async #l(e) {
|
|
443
|
+
try {
|
|
444
|
+
return await e();
|
|
445
|
+
} catch (r) {
|
|
446
|
+
const s = Math.min(await this.#p(r), E);
|
|
447
|
+
if (this.#r < 1)
|
|
448
|
+
throw r;
|
|
449
|
+
if (await he(s, this.#n ? { signal: this.#n } : {}), r instanceof A && r.customRequest) {
|
|
450
|
+
const n = this.#e.signal ? new globalThis.Request(r.customRequest, { signal: this.#e.signal }) : new globalThis.Request(r.customRequest);
|
|
451
|
+
this.#c(n);
|
|
452
|
+
}
|
|
453
|
+
for (const n of this.#e.hooks.beforeRetry) {
|
|
454
|
+
const o = await n({
|
|
455
|
+
request: this.request,
|
|
456
|
+
options: this.#a(),
|
|
457
|
+
error: r,
|
|
458
|
+
retryCount: this.#r
|
|
459
|
+
});
|
|
460
|
+
if (o instanceof globalThis.Request) {
|
|
461
|
+
this.#c(o);
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
if (o instanceof globalThis.Response)
|
|
465
|
+
return o;
|
|
466
|
+
if (o === M)
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
return this.#l(e);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
async #y() {
|
|
473
|
+
this.#s?.signal.aborted && (this.#s = new globalThis.AbortController(), this.#e.signal = this.#n ? AbortSignal.any([this.#n, this.#s.signal]) : this.#s.signal, this.request = new globalThis.Request(this.request, { signal: this.#e.signal }));
|
|
474
|
+
for (const r of this.#e.hooks.beforeRequest) {
|
|
475
|
+
const s = await r(this.request, this.#a(), { retryCount: this.#r });
|
|
476
|
+
if (s instanceof Response)
|
|
477
|
+
return s;
|
|
478
|
+
if (s instanceof globalThis.Request) {
|
|
479
|
+
this.#c(s);
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const e = le(this.request, this.#e);
|
|
484
|
+
return this.#o = this.request, this.request = this.#o.clone(), this.#e.timeout === !1 ? this.#e.fetch(this.#o, e) : ce(this.#o, e, this.#s, this.#e);
|
|
485
|
+
}
|
|
486
|
+
#a() {
|
|
487
|
+
if (!this.#i) {
|
|
488
|
+
const { hooks: e, ...r } = this.#e;
|
|
489
|
+
this.#i = Object.freeze(r);
|
|
490
|
+
}
|
|
491
|
+
return this.#i;
|
|
492
|
+
}
|
|
493
|
+
#c(e) {
|
|
494
|
+
this.#i = void 0, this.request = this.#f(e);
|
|
495
|
+
}
|
|
496
|
+
#f(e, r) {
|
|
497
|
+
return !this.#e.onUploadProgress || !e.body ? e : re(e, this.#e.onUploadProgress, r ?? this.#e.body ?? void 0);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/*! MIT License © Sindre Sorhus */
|
|
501
|
+
const P = (t) => {
|
|
502
|
+
const e = (r, s) => y.create(r, b(t, s));
|
|
503
|
+
for (const r of _)
|
|
504
|
+
e[r] = (s, n) => y.create(s, b(t, n, { method: r }));
|
|
505
|
+
return e.create = (r) => P(b(r)), e.extend = (r) => (typeof r == "function" && (r = r(t ?? {})), P(b(t, r))), e.stop = M, e.retry = Z, e;
|
|
506
|
+
}, ye = P();
|
|
507
|
+
let me = class d {
|
|
508
|
+
constructor({ api_key: e }) {
|
|
509
|
+
this.api_key = e;
|
|
510
|
+
}
|
|
511
|
+
static config(e) {
|
|
512
|
+
if (!d.app) {
|
|
513
|
+
if (!e)
|
|
514
|
+
throw new Error("Please provide an api_key");
|
|
515
|
+
d.app = new d(e);
|
|
516
|
+
}
|
|
517
|
+
return e && (this.app.api_key = e.api_key), d.app;
|
|
518
|
+
}
|
|
519
|
+
static getApiKey() {
|
|
520
|
+
return d.app.api_key;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const h = ye.create({
|
|
524
|
+
prefixUrl: "https://dev.chainrails.io/api/v1",
|
|
525
|
+
headers: {
|
|
526
|
+
"Content-Type": "application/json"
|
|
527
|
+
},
|
|
528
|
+
hooks: {
|
|
529
|
+
beforeRequest: [
|
|
530
|
+
(t) => {
|
|
531
|
+
const e = me.getApiKey();
|
|
532
|
+
t.headers.set("Authorization", `Bearer ${e}`);
|
|
533
|
+
}
|
|
534
|
+
],
|
|
535
|
+
afterResponse: [(t, e, r) => r]
|
|
536
|
+
},
|
|
537
|
+
retry: {
|
|
538
|
+
limit: 2
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
class ge {
|
|
542
|
+
async getClientInfo() {
|
|
543
|
+
return await h.get("client/auth/client-info").json();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
class we {
|
|
547
|
+
async getById(e) {
|
|
548
|
+
return await h.get("intents/" + e).json();
|
|
549
|
+
}
|
|
550
|
+
async getForSender(e) {
|
|
551
|
+
return await h.get("intents/user/" + e).json();
|
|
552
|
+
}
|
|
553
|
+
async getForAddress(e) {
|
|
554
|
+
return await h.get("intents/address/" + e).json();
|
|
555
|
+
}
|
|
556
|
+
async getAll(e) {
|
|
557
|
+
return await h.get("intents", { searchParams: e }).json();
|
|
558
|
+
}
|
|
559
|
+
async create(e) {
|
|
560
|
+
return await h.post("intents", { json: e }).json();
|
|
561
|
+
}
|
|
562
|
+
async update(e, r) {
|
|
563
|
+
return await h.post("intents", { json: r }).json();
|
|
564
|
+
}
|
|
565
|
+
//Calculate Destination
|
|
566
|
+
}
|
|
567
|
+
class be {
|
|
568
|
+
async getAll(e) {
|
|
569
|
+
return await h.get("quotes/multi-source", { searchParams: e }).json();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class Re {
|
|
573
|
+
async getOptimalRoutes(e) {
|
|
574
|
+
return await h.get("router/optimal-route", { searchParams: e }).json();
|
|
575
|
+
}
|
|
576
|
+
async getAllSupportedBridges() {
|
|
577
|
+
return await h.get("router/supported-bridges/all").json();
|
|
578
|
+
}
|
|
579
|
+
async getSupportedBridges(e) {
|
|
580
|
+
return await h.get("router/supported-bridges/route", { searchParams: e }).json();
|
|
581
|
+
}
|
|
582
|
+
async getSupportedRoutes(e, r) {
|
|
583
|
+
return await h.get("router/supported-bridges/bridge/" + e, { searchParams: r }).json();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
const Te = {
|
|
587
|
+
router: new Re(),
|
|
588
|
+
quotes: new be(),
|
|
589
|
+
intents: new we(),
|
|
590
|
+
client: new ge()
|
|
591
|
+
}, Pe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
592
|
+
__proto__: null,
|
|
593
|
+
CRAPI: Te
|
|
594
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
595
|
+
function F(t) {
|
|
596
|
+
var e, r, s = "";
|
|
597
|
+
if (typeof t == "string" || typeof t == "number") s += t;
|
|
598
|
+
else if (typeof t == "object") if (Array.isArray(t)) {
|
|
599
|
+
var n = t.length;
|
|
600
|
+
for (e = 0; e < n; e++) t[e] && (r = F(t[e])) && (s && (s += " "), s += r);
|
|
601
|
+
} else for (r in t) t[r] && (s && (s += " "), s += r);
|
|
602
|
+
return s;
|
|
603
|
+
}
|
|
604
|
+
function Se() {
|
|
605
|
+
for (var t, e, r = 0, s = "", n = arguments.length; r < n; r++) (t = arguments[r]) && (e = F(t)) && (s && (s += " "), s += e);
|
|
606
|
+
return s;
|
|
607
|
+
}
|
|
608
|
+
var Ae = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t))(Ae || {}), Ee = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(Ee || {});
|
|
609
|
+
class f {
|
|
610
|
+
constructor({ api_key: e }) {
|
|
611
|
+
this.api_key = e;
|
|
612
|
+
}
|
|
613
|
+
static config(e) {
|
|
614
|
+
if (!f.app) {
|
|
615
|
+
if (!e)
|
|
616
|
+
throw new Error("Please provide an api_key");
|
|
617
|
+
f.app = new f(e);
|
|
618
|
+
}
|
|
619
|
+
return e && (this.app.api_key = e.api_key), f.app;
|
|
620
|
+
}
|
|
621
|
+
static getApiKey() {
|
|
622
|
+
return f.app.api_key;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function ke(t) {
|
|
626
|
+
const {
|
|
627
|
+
to: e,
|
|
628
|
+
token: r,
|
|
629
|
+
chain: s,
|
|
630
|
+
amount: n,
|
|
631
|
+
isOpen: o,
|
|
632
|
+
close: i,
|
|
633
|
+
complete: u,
|
|
634
|
+
cancel: a,
|
|
635
|
+
chainSelected: c,
|
|
636
|
+
intentCreated: m,
|
|
637
|
+
...T
|
|
638
|
+
} = t, [p, S] = U(!0);
|
|
639
|
+
return z(() => {
|
|
640
|
+
const q = document.body.style.overflow;
|
|
641
|
+
o ? document.body.style.overflow = "hidden" : document.body.style.overflow = q || "";
|
|
642
|
+
const j = (g) => {
|
|
643
|
+
g.data === "closed" && a(), g.data === "completed" && u(), g.data === "chainSelected" && c(), g.data === "intentCreated" && m();
|
|
644
|
+
};
|
|
645
|
+
return window.addEventListener("message", j), () => {
|
|
646
|
+
document.body.style.overflow = q || "", window.removeEventListener("message", j);
|
|
647
|
+
};
|
|
648
|
+
}, [o, a, u, c, m]), /* @__PURE__ */ N("div", {
|
|
649
|
+
...T,
|
|
650
|
+
className: Se("payment-modal-wrapper", p ? "loading" : "not-loading", o ? "open" : "closed"),
|
|
651
|
+
children: [p && /* @__PURE__ */ w("div", {
|
|
652
|
+
role: "status",
|
|
653
|
+
className: "payment-modal-loader",
|
|
654
|
+
children: /* @__PURE__ */ N("svg", {
|
|
655
|
+
"aria-hidden": "true",
|
|
656
|
+
className: "icon",
|
|
657
|
+
viewBox: "0 0 100 101",
|
|
658
|
+
fill: "none",
|
|
659
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
660
|
+
children: [/* @__PURE__ */ w("path", {
|
|
661
|
+
d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
|
|
662
|
+
fill: "currentColor"
|
|
663
|
+
}), /* @__PURE__ */ w("path", {
|
|
664
|
+
d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
|
|
665
|
+
fill: "currentFill"
|
|
666
|
+
})]
|
|
667
|
+
})
|
|
668
|
+
}), /* @__PURE__ */ w("iframe", {
|
|
669
|
+
allow: "clipboard-read *; clipboard-write *",
|
|
670
|
+
src: `https://chainrails-frontend.vercel.app/pay/_chain_/${s}/_token_/${r}/_to_/${e}/_amount_/${n * 100}?id=${f.getApiKey()}`,
|
|
671
|
+
onLoad: () => {
|
|
672
|
+
S(!1);
|
|
673
|
+
},
|
|
674
|
+
className: `payment-modal ${p ? "invisible" : "visible"}`
|
|
675
|
+
})]
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
function qe(t) {
|
|
679
|
+
const {
|
|
680
|
+
onCancel: e,
|
|
681
|
+
onSuccess: r,
|
|
682
|
+
onChainSelect: s,
|
|
683
|
+
onIntentCreate: n,
|
|
684
|
+
...o
|
|
685
|
+
} = t, [i, u] = U(!1);
|
|
686
|
+
function a() {
|
|
687
|
+
u(!0);
|
|
688
|
+
}
|
|
689
|
+
function c() {
|
|
690
|
+
u(!1);
|
|
691
|
+
}
|
|
692
|
+
function m() {
|
|
693
|
+
c(), e?.();
|
|
694
|
+
}
|
|
695
|
+
function T() {
|
|
696
|
+
window.setTimeout(c, 2e3), r?.();
|
|
697
|
+
}
|
|
698
|
+
function p() {
|
|
699
|
+
s?.();
|
|
700
|
+
}
|
|
701
|
+
function S() {
|
|
702
|
+
n?.();
|
|
703
|
+
}
|
|
704
|
+
return {
|
|
705
|
+
open: a,
|
|
706
|
+
close: c,
|
|
707
|
+
complete: T,
|
|
708
|
+
cancel: m,
|
|
709
|
+
chainSelected: p,
|
|
710
|
+
intentCreated: S,
|
|
711
|
+
isOpen: i,
|
|
712
|
+
...o
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
export {
|
|
716
|
+
Pe as CRAPI,
|
|
717
|
+
f as ChainRails,
|
|
718
|
+
ke as PaymentModal,
|
|
719
|
+
Ae as chains,
|
|
720
|
+
Ee as tokens,
|
|
721
|
+
qe as usePaymentModal
|
|
722
|
+
};
|