@chainrails/react 0.0.14 → 0.0.15
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/dist/chainrails-sdk.es.js +129 -117
- package/dist/chainrails-sdk.es.mjs +129 -117
- package/dist/chainrails-sdk.umd.js +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as L, useRef as W, useEffect as G } from "react";
|
|
2
2
|
import { jsxs as O, jsx as w } from "react/jsx-runtime";
|
|
3
3
|
import './index.css';function B(t) {
|
|
4
4
|
var e, s, r = "";
|
|
@@ -18,8 +18,8 @@ class C extends Error {
|
|
|
18
18
|
request;
|
|
19
19
|
options;
|
|
20
20
|
constructor(e, s, r) {
|
|
21
|
-
const n = e.status || e.status === 0 ? e.status : "", o = e.statusText ?? "", i = `${n} ${o}`.trim(),
|
|
22
|
-
super(`Request failed with ${
|
|
21
|
+
const n = e.status || e.status === 0 ? e.status : "", o = e.statusText ?? "", i = `${n} ${o}`.trim(), c = i ? `status code ${i}` : "an unknown error";
|
|
22
|
+
super(`Request failed with ${c}: ${s.method} ${s.url}`), this.name = "HTTPError", this.response = e, this.request = s, this.options = r;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
class D extends Error {
|
|
@@ -63,7 +63,7 @@ const I = (() => {
|
|
|
63
63
|
throw n;
|
|
64
64
|
}
|
|
65
65
|
return t && !e;
|
|
66
|
-
})(), Z = typeof globalThis.AbortController == "function", H = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", Y = typeof globalThis.ReadableStream == "function", Q = typeof globalThis.FormData == "function",
|
|
66
|
+
})(), Z = typeof globalThis.AbortController == "function", H = typeof globalThis.AbortSignal == "function" && typeof globalThis.AbortSignal.any == "function", Y = typeof globalThis.ReadableStream == "function", Q = typeof globalThis.FormData == "function", $ = ["get", "post", "put", "patch", "head", "delete"], ee = {
|
|
67
67
|
json: "application/json",
|
|
68
68
|
text: "text/*",
|
|
69
69
|
formData: "multipart/form-data",
|
|
@@ -72,14 +72,14 @@ const I = (() => {
|
|
|
72
72
|
// Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
|
|
73
73
|
// We still feature-check at runtime before exposing the shortcut.
|
|
74
74
|
bytes: "*/*"
|
|
75
|
-
}, A = 2147483647, te = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length,
|
|
76
|
-
class
|
|
75
|
+
}, A = 2147483647, te = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length, F = Symbol("stop");
|
|
76
|
+
class z {
|
|
77
77
|
options;
|
|
78
78
|
constructor(e) {
|
|
79
79
|
this.options = e;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
const se = (t) => new
|
|
82
|
+
const se = (t) => new z(t), re = {
|
|
83
83
|
json: !0,
|
|
84
84
|
parseJson: !0,
|
|
85
85
|
stringifyJson: !0,
|
|
@@ -138,14 +138,14 @@ const se = (t) => new F(t), re = {
|
|
|
138
138
|
return 0;
|
|
139
139
|
}
|
|
140
140
|
return 0;
|
|
141
|
-
},
|
|
141
|
+
}, J = (t, e, s) => {
|
|
142
142
|
let r, n = 0;
|
|
143
143
|
return t.pipeThrough(new TransformStream({
|
|
144
144
|
transform(o, i) {
|
|
145
145
|
if (i.enqueue(o), r) {
|
|
146
146
|
n += r.byteLength;
|
|
147
|
-
let
|
|
148
|
-
|
|
147
|
+
let c = e === 0 ? 0 : n / e;
|
|
148
|
+
c >= 1 && (c = 1 - Number.EPSILON), s?.({ percent: c, totalBytes: Math.max(e, n), transferredBytes: n }, r);
|
|
149
149
|
}
|
|
150
150
|
r = o;
|
|
151
151
|
},
|
|
@@ -163,26 +163,26 @@ const se = (t) => new F(t), re = {
|
|
|
163
163
|
headers: t.headers
|
|
164
164
|
});
|
|
165
165
|
const s = Math.max(0, Number(t.headers.get("content-length")) || 0);
|
|
166
|
-
return new Response(
|
|
166
|
+
return new Response(J(t.body, s, e), {
|
|
167
167
|
status: t.status,
|
|
168
168
|
statusText: t.statusText,
|
|
169
169
|
headers: t.headers
|
|
170
170
|
});
|
|
171
|
-
},
|
|
171
|
+
}, ce = (t, e, s) => {
|
|
172
172
|
if (!t.body)
|
|
173
173
|
return t;
|
|
174
174
|
const r = ie(s ?? t.body);
|
|
175
175
|
return new Request(t, {
|
|
176
176
|
// @ts-expect-error - Types are outdated.
|
|
177
177
|
duplex: "half",
|
|
178
|
-
body:
|
|
178
|
+
body: J(t.body, r, e)
|
|
179
179
|
});
|
|
180
180
|
}, f = (t) => t !== null && typeof t == "object", b = (...t) => {
|
|
181
181
|
for (const e of t)
|
|
182
182
|
if ((!f(e) || Array.isArray(e)) && e !== void 0)
|
|
183
183
|
throw new TypeError("The `options` argument must be an object");
|
|
184
184
|
return j({}, ...t);
|
|
185
|
-
},
|
|
185
|
+
}, K = (t = {}, e = {}) => {
|
|
186
186
|
const s = new globalThis.Headers(t), r = e instanceof globalThis.Headers, n = new globalThis.Headers(e);
|
|
187
187
|
for (const [o, i] of n.entries())
|
|
188
188
|
r && i === "undefined" || i === void 0 ? s.delete(o) : s.set(o, i);
|
|
@@ -191,12 +191,12 @@ const se = (t) => new F(t), re = {
|
|
|
191
191
|
function T(t, e, s) {
|
|
192
192
|
return Object.hasOwn(e, s) && e[s] === void 0 ? [] : j(t[s] ?? [], e[s] ?? []);
|
|
193
193
|
}
|
|
194
|
-
const
|
|
194
|
+
const _ = (t = {}, e = {}) => ({
|
|
195
195
|
beforeRequest: T(t, e, "beforeRequest"),
|
|
196
196
|
beforeRetry: T(t, e, "beforeRetry"),
|
|
197
197
|
afterResponse: T(t, e, "afterResponse"),
|
|
198
198
|
beforeError: T(t, e, "beforeError")
|
|
199
|
-
}),
|
|
199
|
+
}), ue = (t, e) => {
|
|
200
200
|
const s = new URLSearchParams();
|
|
201
201
|
for (const r of [t, e])
|
|
202
202
|
if (r !== void 0)
|
|
@@ -225,12 +225,12 @@ const K = (t = {}, e = {}) => ({
|
|
|
225
225
|
if (Array.isArray(i))
|
|
226
226
|
Array.isArray(e) || (e = []), e = [...e, ...i];
|
|
227
227
|
else if (f(i)) {
|
|
228
|
-
for (let [
|
|
229
|
-
if (
|
|
228
|
+
for (let [c, a] of Object.entries(i)) {
|
|
229
|
+
if (c === "signal" && a instanceof globalThis.AbortSignal) {
|
|
230
230
|
o.push(a);
|
|
231
231
|
continue;
|
|
232
232
|
}
|
|
233
|
-
if (
|
|
233
|
+
if (c === "context") {
|
|
234
234
|
if (a != null && (!f(a) || Array.isArray(a)))
|
|
235
235
|
throw new TypeError("The `context` option must be an object");
|
|
236
236
|
e = {
|
|
@@ -239,18 +239,18 @@ const K = (t = {}, e = {}) => ({
|
|
|
239
239
|
};
|
|
240
240
|
continue;
|
|
241
241
|
}
|
|
242
|
-
if (
|
|
243
|
-
a == null ? n = void 0 : n = n === void 0 ? a :
|
|
242
|
+
if (c === "searchParams") {
|
|
243
|
+
a == null ? n = void 0 : n = n === void 0 ? a : ue(n, a);
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
|
-
f(a) &&
|
|
246
|
+
f(a) && c in e && (a = j(e[c], a)), e = { ...e, [c]: a };
|
|
247
247
|
}
|
|
248
|
-
f(i.hooks) && (r =
|
|
248
|
+
f(i.hooks) && (r = _(r, i.hooks), e.hooks = r), f(i.headers) && (s = K(s, i.headers), e.headers = s);
|
|
249
249
|
}
|
|
250
250
|
return n !== void 0 && (e.searchParams = n), o.length > 0 && (o.length === 1 ? e.signal = o[0] : H ? e.signal = AbortSignal.any(o) : e.signal = o.at(-1)), e.context === void 0 && (e.context = {}), e;
|
|
251
|
-
},
|
|
251
|
+
}, le = (t) => $.includes(t) ? t.toUpperCase() : t, he = ["get", "put", "head", "delete", "options", "trace"], fe = [408, 413, 429, 500, 502, 503, 504], de = [413, 429, 503], M = {
|
|
252
252
|
limit: 2,
|
|
253
|
-
methods:
|
|
253
|
+
methods: he,
|
|
254
254
|
statusCodes: fe,
|
|
255
255
|
afterStatusCodes: de,
|
|
256
256
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
@@ -261,7 +261,7 @@ const K = (t = {}, e = {}) => ({
|
|
|
261
261
|
}, pe = (t = {}) => {
|
|
262
262
|
if (typeof t == "number")
|
|
263
263
|
return {
|
|
264
|
-
...
|
|
264
|
+
...M,
|
|
265
265
|
limit: t
|
|
266
266
|
};
|
|
267
267
|
if (t.methods && !Array.isArray(t.methods))
|
|
@@ -269,7 +269,7 @@ const K = (t = {}, e = {}) => ({
|
|
|
269
269
|
if (t.statusCodes && !Array.isArray(t.statusCodes))
|
|
270
270
|
throw new Error("retry.statusCodes must be an array");
|
|
271
271
|
return {
|
|
272
|
-
...
|
|
272
|
+
...M,
|
|
273
273
|
...t
|
|
274
274
|
};
|
|
275
275
|
};
|
|
@@ -319,19 +319,19 @@ class p {
|
|
|
319
319
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${A}`);
|
|
320
320
|
await Promise.resolve();
|
|
321
321
|
let i = await r.#y();
|
|
322
|
-
for (const
|
|
323
|
-
const a = r.#
|
|
324
|
-
if (
|
|
322
|
+
for (const c of r.#e.hooks.afterResponse) {
|
|
323
|
+
const a = r.#l(i.clone()), h = await c(r.request, r.#a(), a, { retryCount: r.#s });
|
|
324
|
+
if (h instanceof globalThis.Response && (i = h), h instanceof z)
|
|
325
325
|
throw await Promise.all([
|
|
326
326
|
a.body?.cancel(),
|
|
327
327
|
i.body?.cancel()
|
|
328
|
-
]), new S(
|
|
328
|
+
]), new S(h.options);
|
|
329
329
|
}
|
|
330
|
-
if (r.#
|
|
331
|
-
let
|
|
330
|
+
if (r.#l(i), !i.ok && (typeof r.#e.throwHttpErrors == "function" ? r.#e.throwHttpErrors(i.status) : r.#e.throwHttpErrors)) {
|
|
331
|
+
let c = new C(i, r.request, r.#a());
|
|
332
332
|
for (const a of r.#e.hooks.beforeError)
|
|
333
|
-
|
|
334
|
-
throw
|
|
333
|
+
c = await a(c, { retryCount: r.#s });
|
|
334
|
+
throw c;
|
|
335
335
|
}
|
|
336
336
|
if (r.#e.onDownloadProgress) {
|
|
337
337
|
if (typeof r.#e.onDownloadProgress != "function")
|
|
@@ -341,19 +341,19 @@ class p {
|
|
|
341
341
|
return ae(i.clone(), r.#e.onDownloadProgress);
|
|
342
342
|
}
|
|
343
343
|
return i;
|
|
344
|
-
}, o = r.#
|
|
345
|
-
const i = r.#o,
|
|
346
|
-
i && !i.bodyUsed &&
|
|
344
|
+
}, o = r.#h(n).finally(async () => {
|
|
345
|
+
const i = r.#o, c = [];
|
|
346
|
+
i && !i.bodyUsed && c.push(i.body?.cancel()), r.request.bodyUsed || c.push(r.request.body?.cancel()), await Promise.all(c);
|
|
347
347
|
});
|
|
348
|
-
for (const [i,
|
|
348
|
+
for (const [i, c] of Object.entries(ee))
|
|
349
349
|
i === "bytes" && typeof globalThis.Response?.prototype?.bytes != "function" || (o[i] = async () => {
|
|
350
|
-
r.request.headers.set("accept", r.request.headers.get("accept") ||
|
|
350
|
+
r.request.headers.set("accept", r.request.headers.get("accept") || c);
|
|
351
351
|
const a = await o;
|
|
352
352
|
if (i === "json") {
|
|
353
353
|
if (a.status === 204)
|
|
354
354
|
return "";
|
|
355
|
-
const
|
|
356
|
-
return
|
|
355
|
+
const h = await a.text();
|
|
356
|
+
return h === "" ? "" : s.parseJson ? s.parseJson(h) : JSON.parse(h);
|
|
357
357
|
}
|
|
358
358
|
return a[i]();
|
|
359
359
|
});
|
|
@@ -376,14 +376,14 @@ class p {
|
|
|
376
376
|
constructor(e, s = {}) {
|
|
377
377
|
if (this.#t = e, this.#e = {
|
|
378
378
|
...s,
|
|
379
|
-
headers:
|
|
380
|
-
hooks:
|
|
379
|
+
headers: K(this.#t.headers, s.headers),
|
|
380
|
+
hooks: _({
|
|
381
381
|
beforeRequest: [],
|
|
382
382
|
beforeRetry: [],
|
|
383
383
|
beforeError: [],
|
|
384
384
|
afterResponse: []
|
|
385
385
|
}, s.hooks),
|
|
386
|
-
method:
|
|
386
|
+
method: le(s.method ?? this.#t.method ?? "GET"),
|
|
387
387
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
388
388
|
prefixUrl: String(s.prefixUrl || ""),
|
|
389
389
|
retry: pe(s.retry),
|
|
@@ -412,7 +412,7 @@ class p {
|
|
|
412
412
|
this.request = this.#f(this.request, this.#e.body ?? void 0);
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
|
-
#
|
|
415
|
+
#c() {
|
|
416
416
|
const e = this.#e.retry.delay(this.#s);
|
|
417
417
|
let s = e;
|
|
418
418
|
return this.#e.retry.jitter === !0 ? s = Math.random() * e : typeof this.#e.retry.jitter == "function" && (s = this.#e.retry.jitter(e), (!Number.isFinite(s) || s < 0) && (s = e)), Math.min(this.#e.retry.backoffLimit, s);
|
|
@@ -422,7 +422,7 @@ class p {
|
|
|
422
422
|
throw e;
|
|
423
423
|
const s = e instanceof Error ? e : new D(e);
|
|
424
424
|
if (s instanceof S)
|
|
425
|
-
return s.customDelay ?? this.#
|
|
425
|
+
return s.customDelay ?? this.#c();
|
|
426
426
|
if (!this.#e.retry.methods.includes(this.request.method.toLowerCase()))
|
|
427
427
|
throw e;
|
|
428
428
|
if (this.#e.retry.shouldRetry !== void 0) {
|
|
@@ -430,7 +430,7 @@ class p {
|
|
|
430
430
|
if (r === !1)
|
|
431
431
|
throw e;
|
|
432
432
|
if (r === !0)
|
|
433
|
-
return this.#
|
|
433
|
+
return this.#c();
|
|
434
434
|
}
|
|
435
435
|
if (Te(e) && !this.#e.retry.retryOnTimeout)
|
|
436
436
|
throw e;
|
|
@@ -447,12 +447,12 @@ class p {
|
|
|
447
447
|
if (e.response.status === 413)
|
|
448
448
|
throw e;
|
|
449
449
|
}
|
|
450
|
-
return this.#
|
|
450
|
+
return this.#c();
|
|
451
451
|
}
|
|
452
|
-
#
|
|
452
|
+
#l(e) {
|
|
453
453
|
return this.#e.parseJson && (e.json = async () => this.#e.parseJson(await e.text())), e;
|
|
454
454
|
}
|
|
455
|
-
async #
|
|
455
|
+
async #h(e) {
|
|
456
456
|
try {
|
|
457
457
|
return await e();
|
|
458
458
|
} catch (s) {
|
|
@@ -461,7 +461,7 @@ class p {
|
|
|
461
461
|
throw s;
|
|
462
462
|
if (await ge(r, this.#n ? { signal: this.#n } : {}), s instanceof S && s.customRequest) {
|
|
463
463
|
const n = this.#e.signal ? new globalThis.Request(s.customRequest, { signal: this.#e.signal }) : new globalThis.Request(s.customRequest);
|
|
464
|
-
this.#
|
|
464
|
+
this.#u(n);
|
|
465
465
|
}
|
|
466
466
|
for (const n of this.#e.hooks.beforeRetry) {
|
|
467
467
|
const o = await n({
|
|
@@ -471,15 +471,15 @@ class p {
|
|
|
471
471
|
retryCount: this.#s
|
|
472
472
|
});
|
|
473
473
|
if (o instanceof globalThis.Request) {
|
|
474
|
-
this.#
|
|
474
|
+
this.#u(o);
|
|
475
475
|
break;
|
|
476
476
|
}
|
|
477
477
|
if (o instanceof globalThis.Response)
|
|
478
478
|
return o;
|
|
479
|
-
if (o ===
|
|
479
|
+
if (o === F)
|
|
480
480
|
return;
|
|
481
481
|
}
|
|
482
|
-
return this.#
|
|
482
|
+
return this.#h(e);
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
485
|
async #y() {
|
|
@@ -489,7 +489,7 @@ class p {
|
|
|
489
489
|
if (r instanceof Response)
|
|
490
490
|
return r;
|
|
491
491
|
if (r instanceof globalThis.Request) {
|
|
492
|
-
this.#
|
|
492
|
+
this.#u(r);
|
|
493
493
|
break;
|
|
494
494
|
}
|
|
495
495
|
}
|
|
@@ -503,38 +503,42 @@ class p {
|
|
|
503
503
|
}
|
|
504
504
|
return this.#i;
|
|
505
505
|
}
|
|
506
|
-
#
|
|
506
|
+
#u(e) {
|
|
507
507
|
this.#i = void 0, this.request = this.#f(e);
|
|
508
508
|
}
|
|
509
509
|
#f(e, s) {
|
|
510
|
-
return !this.#e.onUploadProgress || !e.body ? e :
|
|
510
|
+
return !this.#e.onUploadProgress || !e.body ? e : ce(e, this.#e.onUploadProgress, s ?? this.#e.body ?? void 0);
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
513
|
/*! MIT License © Sindre Sorhus */
|
|
514
514
|
const x = (t) => {
|
|
515
515
|
const e = (s, r) => p.create(s, b(t, r));
|
|
516
|
-
for (const s of
|
|
516
|
+
for (const s of $)
|
|
517
517
|
e[s] = (r, n) => p.create(r, b(t, n, { method: s }));
|
|
518
|
-
return e.create = (s) => x(b(s)), e.extend = (s) => (typeof s == "function" && (s = s(t ?? {})), x(b(t, s))), e.stop =
|
|
518
|
+
return e.create = (s) => x(b(s)), e.extend = (s) => (typeof s == "function" && (s = s(t ?? {})), x(b(t, s))), e.stop = F, e.retry = se, e;
|
|
519
519
|
}, Re = x();
|
|
520
|
-
var Ee = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(Ee || {}), Se = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(Se || {}),
|
|
521
|
-
class
|
|
520
|
+
var Ee = /* @__PURE__ */ ((t) => (t.ARBITRUM = "ARBITRUM_MAINNET", t.ARBITRUM_TESTNET = "ARBITRUM_TESTNET", t.AVALANCHE = "AVALANCHE_MAINNET", t.AVALANCHE_TESTNET = "AVALANCHE_TESTNET", t.BASE = "BASE_MAINNET", t.BASE_TESTNET = "BASE_TESTNET", t.BSC = "BSC_MAINNET", t.ETHEREUM = "ETHEREUM_MAINNET", t.ETHEREUM_TESTNET = "ETHEREUM_TESTNET", t.STARKNET = "STARKNET_MAINNET", t))(Ee || {}), Se = /* @__PURE__ */ ((t) => (t.USDC = "USDC", t))(Se || {}), v = /* @__PURE__ */ ((t) => (t.PRODUCTION = "production", t.STAGING = "staging", t))(v || {});
|
|
521
|
+
class u {
|
|
522
522
|
constructor({ api_key: e, env: s }) {
|
|
523
|
-
this.api_key = e, this.jwt = "", this.env = s ??
|
|
523
|
+
this.api_key = e, this.jwt = "", this.env = s ?? v.PRODUCTION;
|
|
524
524
|
}
|
|
525
525
|
static config(e) {
|
|
526
|
-
if (!
|
|
526
|
+
if (!u.app) {
|
|
527
527
|
if (!e)
|
|
528
528
|
throw new Error("Please provide an api_key");
|
|
529
|
-
|
|
529
|
+
u.app = new u(e);
|
|
530
530
|
}
|
|
531
|
-
return e && (
|
|
531
|
+
return e && (u.app.api_key = e.api_key, e.env !== void 0 && (u.app.env = e.env), this.updateJWT(), setInterval(this.updateJWT.bind(this), 1500 * 1e3)), u.app;
|
|
532
532
|
}
|
|
533
533
|
static async updateJWT() {
|
|
534
534
|
try {
|
|
535
535
|
const e = await (await fetch(this.getBaseUrl() + "/client/api-keys/session-token", {
|
|
536
|
+
method: "POST",
|
|
537
|
+
// headers: {
|
|
538
|
+
// Authorization: `Bearer ${Chainrails.app.api_key}`,
|
|
539
|
+
// },
|
|
536
540
|
body: JSON.stringify({
|
|
537
|
-
apiKey:
|
|
541
|
+
apiKey: u.app.api_key
|
|
538
542
|
})
|
|
539
543
|
})).json();
|
|
540
544
|
this.app.jwt = e.token;
|
|
@@ -542,42 +546,50 @@ class c {
|
|
|
542
546
|
}
|
|
543
547
|
}
|
|
544
548
|
static getApiKey() {
|
|
545
|
-
if (!
|
|
549
|
+
if (!u.app)
|
|
546
550
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
547
|
-
return
|
|
551
|
+
return u.app.api_key;
|
|
548
552
|
}
|
|
549
553
|
static getSessionKey() {
|
|
550
|
-
return
|
|
554
|
+
return u.app.jwt;
|
|
551
555
|
}
|
|
552
556
|
static getEnv() {
|
|
553
|
-
if (!
|
|
557
|
+
if (!u.app)
|
|
554
558
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
555
|
-
return
|
|
559
|
+
return u.app.env === "internal" ? "staging" : u.app.env;
|
|
556
560
|
}
|
|
557
561
|
static getBaseUrl() {
|
|
558
|
-
if (!
|
|
562
|
+
if (!u.app)
|
|
559
563
|
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
560
|
-
switch (
|
|
564
|
+
switch (u.app.env) {
|
|
561
565
|
case "production":
|
|
562
566
|
return "https://api.chainrails.io/api/v1";
|
|
563
567
|
case "staging":
|
|
564
568
|
return "https://dev.chainrails.io/api/v1";
|
|
569
|
+
case "internal":
|
|
570
|
+
return "https://dev.chainrails.io/api/v1";
|
|
565
571
|
default:
|
|
566
572
|
return "https://api.chainrails.io/api/v1";
|
|
567
573
|
}
|
|
568
574
|
}
|
|
575
|
+
static getPayModalUrl(e, s, r, n) {
|
|
576
|
+
if (!u.app)
|
|
577
|
+
throw new Error("Chainrails SDK not configured. Please call Chainrails.config() first.");
|
|
578
|
+
const o = u.app.env === "internal" ? "https://chainrails-frontend-git-staging-horus-labs.vercel.app/pay/" : "https://app.chainrails.io/pay/", i = `${e}/_token_/${s}/_to_/${r}/_amount_/${n * 100}`;
|
|
579
|
+
return o + i;
|
|
580
|
+
}
|
|
569
581
|
}
|
|
570
582
|
let q = null;
|
|
571
583
|
function Ae() {
|
|
572
584
|
q = Re.create({
|
|
573
|
-
prefixUrl:
|
|
585
|
+
prefixUrl: u.getBaseUrl(),
|
|
574
586
|
headers: {
|
|
575
587
|
"Content-Type": "application/json"
|
|
576
588
|
},
|
|
577
589
|
hooks: {
|
|
578
590
|
beforeRequest: [
|
|
579
591
|
(t) => {
|
|
580
|
-
const e =
|
|
592
|
+
const e = u.getSessionKey();
|
|
581
593
|
t.headers.set("Authorization", `Bearer ${e}`);
|
|
582
594
|
}
|
|
583
595
|
],
|
|
@@ -588,71 +600,71 @@ function Ae() {
|
|
|
588
600
|
}
|
|
589
601
|
});
|
|
590
602
|
}
|
|
591
|
-
function
|
|
603
|
+
function l() {
|
|
592
604
|
return q || Ae(), q;
|
|
593
605
|
}
|
|
594
606
|
class Ce {
|
|
595
607
|
async getById(e) {
|
|
596
|
-
return await
|
|
608
|
+
return await l().get("intents/" + e).json();
|
|
597
609
|
}
|
|
598
610
|
async getForSender(e) {
|
|
599
|
-
return await
|
|
611
|
+
return await l().get("intents/user/" + e).json();
|
|
600
612
|
}
|
|
601
613
|
async getForAddress(e) {
|
|
602
|
-
return await
|
|
614
|
+
return await l().get("intents/address/" + e).json();
|
|
603
615
|
}
|
|
604
616
|
async getAll(e) {
|
|
605
|
-
return await
|
|
617
|
+
return await l().get("intents", { searchParams: e }).json();
|
|
606
618
|
}
|
|
607
619
|
async create(e) {
|
|
608
|
-
return await
|
|
620
|
+
return await l().post("intents", { json: e }).json();
|
|
609
621
|
}
|
|
610
622
|
async update(e, s) {
|
|
611
|
-
return await
|
|
623
|
+
return await l().post("intents", { json: s }).json();
|
|
612
624
|
}
|
|
613
625
|
async triggerProcessing(e) {
|
|
614
|
-
return await
|
|
626
|
+
return await l().post(`intents/${e}/trigger-processing`).json();
|
|
615
627
|
}
|
|
616
628
|
}
|
|
617
629
|
class Pe {
|
|
618
630
|
async getFromSpecificBridge(e) {
|
|
619
|
-
return await
|
|
631
|
+
return await l().get("quotes/single", { searchParams: e }).json();
|
|
620
632
|
}
|
|
621
633
|
async getFromAllBridges(e) {
|
|
622
|
-
return await
|
|
634
|
+
return await l().get("quotes/multiple", { searchParams: e }).json();
|
|
623
635
|
}
|
|
624
636
|
async getBestAcrossBridges(e) {
|
|
625
|
-
return await
|
|
637
|
+
return await l().get("quotes/best", { searchParams: e }).json();
|
|
626
638
|
}
|
|
627
639
|
async getAll(e) {
|
|
628
|
-
return await
|
|
640
|
+
return await l().get("quotes/multi-source", { searchParams: e }).json();
|
|
629
641
|
}
|
|
630
642
|
}
|
|
631
643
|
class xe {
|
|
632
644
|
async getOptimalRoutes(e) {
|
|
633
|
-
return await
|
|
645
|
+
return await l().get("router/optimal-route", { searchParams: e }).json();
|
|
634
646
|
}
|
|
635
647
|
async getAllSupportedBridges() {
|
|
636
|
-
return await
|
|
648
|
+
return await l().get("router/supported-bridges/all").json();
|
|
637
649
|
}
|
|
638
650
|
async getSupportedBridges(e) {
|
|
639
|
-
return await
|
|
651
|
+
return await l().get("router/supported-bridges/route", { searchParams: e }).json();
|
|
640
652
|
}
|
|
641
653
|
async getSupportedRoutes(e, s) {
|
|
642
|
-
return await
|
|
654
|
+
return await l().get("router/supported-bridges/bridge/" + e, { searchParams: s }).json();
|
|
643
655
|
}
|
|
644
656
|
}
|
|
645
657
|
class qe {
|
|
646
658
|
async getSupported(e) {
|
|
647
|
-
return await
|
|
659
|
+
return await l().get("chains", { searchParams: e }).json();
|
|
648
660
|
}
|
|
649
661
|
}
|
|
650
662
|
class je {
|
|
651
663
|
async getClientInfo() {
|
|
652
|
-
return await
|
|
664
|
+
return await l().get("client/auth/client-info").json();
|
|
653
665
|
}
|
|
654
666
|
}
|
|
655
|
-
const
|
|
667
|
+
const ke = {
|
|
656
668
|
router: new xe(),
|
|
657
669
|
quotes: new Pe(),
|
|
658
670
|
intents: new Ce(),
|
|
@@ -667,33 +679,33 @@ function Ue(t) {
|
|
|
667
679
|
amount: n,
|
|
668
680
|
isOpen: o,
|
|
669
681
|
close: i,
|
|
670
|
-
complete:
|
|
682
|
+
complete: c,
|
|
671
683
|
cancel: a,
|
|
672
|
-
chainSelected:
|
|
684
|
+
chainSelected: h,
|
|
673
685
|
intentCreated: y,
|
|
674
686
|
...R
|
|
675
|
-
} = t, [d, E] =
|
|
687
|
+
} = t, [d, E] = L(!0), N = W(null);
|
|
676
688
|
G(() => {
|
|
677
|
-
|
|
689
|
+
k();
|
|
678
690
|
const g = document.body.style.overflow;
|
|
679
691
|
o ? (document.body.style.overflow = "hidden", document.body.style.overflow = "hidden") : document.body.style.overflow = g || "";
|
|
680
692
|
const U = (m) => {
|
|
681
|
-
m.data === "closed" && a(), m.data === "completed" &&
|
|
693
|
+
m.data === "closed" && a(), m.data === "completed" && c(), m.data === "chainSelected" && h(), m.data === "intentCreated" && y();
|
|
682
694
|
};
|
|
683
695
|
return window.addEventListener("message", U), () => {
|
|
684
696
|
document.body.style.overflow = g || "", window.removeEventListener("message", U);
|
|
685
697
|
};
|
|
686
|
-
}, [o, a,
|
|
698
|
+
}, [o, a, c, h, y]);
|
|
687
699
|
function V() {
|
|
688
|
-
E(!1),
|
|
700
|
+
E(!1), k();
|
|
689
701
|
}
|
|
690
|
-
function
|
|
702
|
+
function k() {
|
|
691
703
|
const g = {
|
|
692
704
|
type: "apiKey",
|
|
693
|
-
apiKey:
|
|
694
|
-
environment:
|
|
705
|
+
apiKey: u.getApiKey(),
|
|
706
|
+
environment: u.getEnv() || v.PRODUCTION
|
|
695
707
|
};
|
|
696
|
-
|
|
708
|
+
N.current?.contentWindow?.postMessage(g, "https://app.chainrails.io");
|
|
697
709
|
}
|
|
698
710
|
return /* @__PURE__ */ O("div", {
|
|
699
711
|
...R,
|
|
@@ -717,10 +729,10 @@ function Ue(t) {
|
|
|
717
729
|
})
|
|
718
730
|
}), /* @__PURE__ */ w("iframe", {
|
|
719
731
|
allow: "clipboard-read *; clipboard-write *",
|
|
720
|
-
src:
|
|
732
|
+
src: u.getPayModalUrl(r, s, e, n),
|
|
721
733
|
onLoad: V,
|
|
722
734
|
className: `payment-modal ${d ? "invisible" : "visible"}`,
|
|
723
|
-
ref:
|
|
735
|
+
ref: N
|
|
724
736
|
})]
|
|
725
737
|
});
|
|
726
738
|
}
|
|
@@ -731,18 +743,18 @@ function Oe(t) {
|
|
|
731
743
|
onChainSelect: r,
|
|
732
744
|
onIntentCreate: n,
|
|
733
745
|
...o
|
|
734
|
-
} = t, [i,
|
|
746
|
+
} = t, [i, c] = L(!1);
|
|
735
747
|
function a() {
|
|
736
|
-
|
|
748
|
+
c(!0);
|
|
737
749
|
}
|
|
738
|
-
function
|
|
739
|
-
|
|
750
|
+
function h() {
|
|
751
|
+
c(!1);
|
|
740
752
|
}
|
|
741
753
|
function y() {
|
|
742
|
-
|
|
754
|
+
h(), e?.();
|
|
743
755
|
}
|
|
744
756
|
function R() {
|
|
745
|
-
window.setTimeout(
|
|
757
|
+
window.setTimeout(h, 2e3), s?.();
|
|
746
758
|
}
|
|
747
759
|
function d() {
|
|
748
760
|
r?.();
|
|
@@ -752,7 +764,7 @@ function Oe(t) {
|
|
|
752
764
|
}
|
|
753
765
|
return {
|
|
754
766
|
open: a,
|
|
755
|
-
close:
|
|
767
|
+
close: h,
|
|
756
768
|
complete: R,
|
|
757
769
|
cancel: y,
|
|
758
770
|
chainSelected: d,
|
|
@@ -762,10 +774,10 @@ function Oe(t) {
|
|
|
762
774
|
};
|
|
763
775
|
}
|
|
764
776
|
export {
|
|
765
|
-
|
|
777
|
+
u as Chainrails,
|
|
766
778
|
Ue as PaymentModal,
|
|
767
779
|
Ee as chains,
|
|
768
|
-
|
|
780
|
+
ke as crapi,
|
|
769
781
|
Se as tokens,
|
|
770
782
|
Oe as usePaymentModal
|
|
771
783
|
};
|