@paywithglide/glide-react 0.0.46 → 0.0.47
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 +40 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +741 -0
- package/dist/glide.js +350 -929
- package/dist/pkg/GlideDeposit.d.ts +20 -1
- package/dist/pkg/analytics.d.ts +220 -0
- package/dist/pkg/core.d.ts +5 -0
- package/dist/pkg/index.d.ts +1 -0
- package/package.json +6 -2
- /package/dist/{index.d.ts → glide.d.ts} +0 -0
package/dist/core.js
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
var ee = Object.defineProperty;
|
|
2
|
+
var te = (s, e, t) => e in s ? ee(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var w = (s, e, t) => te(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
function se(s, { strict: e = !0 } = {}) {
|
|
5
|
+
return !s || typeof s != "string" ? !1 : e ? /^0x[0-9a-fA-F]*$/.test(s) : s.startsWith("0x");
|
|
6
|
+
}
|
|
7
|
+
function _(s) {
|
|
8
|
+
return se(s, { strict: !1 }) ? Math.ceil((s.length - 2) / 2) : s.length;
|
|
9
|
+
}
|
|
10
|
+
const q = "2.21.51";
|
|
11
|
+
let b = {
|
|
12
|
+
getDocsUrl: ({ docsBaseUrl: s, docsPath: e = "", docsSlug: t }) => e ? `${s ?? "https://viem.sh"}${e}${t ? `#${t}` : ""}` : void 0,
|
|
13
|
+
version: `viem@${q}`
|
|
14
|
+
};
|
|
15
|
+
class v extends Error {
|
|
16
|
+
constructor(e, t = {}) {
|
|
17
|
+
var d;
|
|
18
|
+
const i = (() => {
|
|
19
|
+
var a;
|
|
20
|
+
return t.cause instanceof v ? t.cause.details : (a = t.cause) != null && a.message ? t.cause.message : t.details;
|
|
21
|
+
})(), o = t.cause instanceof v && t.cause.docsPath || t.docsPath, n = (d = b.getDocsUrl) == null ? void 0 : d.call(b, { ...t, docsPath: o }), c = [
|
|
22
|
+
e || "An error occurred.",
|
|
23
|
+
"",
|
|
24
|
+
...t.metaMessages ? [...t.metaMessages, ""] : [],
|
|
25
|
+
...n ? [`Docs: ${n}`] : [],
|
|
26
|
+
...i ? [`Details: ${i}`] : [],
|
|
27
|
+
...b.version ? [`Version: ${b.version}`] : []
|
|
28
|
+
].join(`
|
|
29
|
+
`);
|
|
30
|
+
super(c, t.cause ? { cause: t.cause } : void 0), Object.defineProperty(this, "details", {
|
|
31
|
+
enumerable: !0,
|
|
32
|
+
configurable: !0,
|
|
33
|
+
writable: !0,
|
|
34
|
+
value: void 0
|
|
35
|
+
}), Object.defineProperty(this, "docsPath", {
|
|
36
|
+
enumerable: !0,
|
|
37
|
+
configurable: !0,
|
|
38
|
+
writable: !0,
|
|
39
|
+
value: void 0
|
|
40
|
+
}), Object.defineProperty(this, "metaMessages", {
|
|
41
|
+
enumerable: !0,
|
|
42
|
+
configurable: !0,
|
|
43
|
+
writable: !0,
|
|
44
|
+
value: void 0
|
|
45
|
+
}), Object.defineProperty(this, "shortMessage", {
|
|
46
|
+
enumerable: !0,
|
|
47
|
+
configurable: !0,
|
|
48
|
+
writable: !0,
|
|
49
|
+
value: void 0
|
|
50
|
+
}), Object.defineProperty(this, "version", {
|
|
51
|
+
enumerable: !0,
|
|
52
|
+
configurable: !0,
|
|
53
|
+
writable: !0,
|
|
54
|
+
value: void 0
|
|
55
|
+
}), Object.defineProperty(this, "name", {
|
|
56
|
+
enumerable: !0,
|
|
57
|
+
configurable: !0,
|
|
58
|
+
writable: !0,
|
|
59
|
+
value: "BaseError"
|
|
60
|
+
}), this.details = i, this.docsPath = o, this.metaMessages = t.metaMessages, this.name = t.name ?? this.name, this.shortMessage = e, this.version = q;
|
|
61
|
+
}
|
|
62
|
+
walk(e) {
|
|
63
|
+
return K(this, e);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function K(s, e) {
|
|
67
|
+
return e != null && e(s) ? s : s && typeof s == "object" && "cause" in s && s.cause !== void 0 ? K(s.cause, e) : e ? null : s;
|
|
68
|
+
}
|
|
69
|
+
class N extends v {
|
|
70
|
+
constructor({ size: e, targetSize: t, type: i }) {
|
|
71
|
+
super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`, { name: "SizeExceedsPaddingSizeError" });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function I(s, { dir: e, size: t = 32 } = {}) {
|
|
75
|
+
return typeof s == "string" ? ie(s, { dir: e, size: t }) : oe(s, { dir: e, size: t });
|
|
76
|
+
}
|
|
77
|
+
function ie(s, { dir: e, size: t = 32 } = {}) {
|
|
78
|
+
if (t === null)
|
|
79
|
+
return s;
|
|
80
|
+
const i = s.replace("0x", "");
|
|
81
|
+
if (i.length > t * 2)
|
|
82
|
+
throw new N({
|
|
83
|
+
size: Math.ceil(i.length / 2),
|
|
84
|
+
targetSize: t,
|
|
85
|
+
type: "hex"
|
|
86
|
+
});
|
|
87
|
+
return `0x${i[e === "right" ? "padEnd" : "padStart"](t * 2, "0")}`;
|
|
88
|
+
}
|
|
89
|
+
function oe(s, { dir: e, size: t = 32 } = {}) {
|
|
90
|
+
if (t === null)
|
|
91
|
+
return s;
|
|
92
|
+
if (s.length > t)
|
|
93
|
+
throw new N({
|
|
94
|
+
size: s.length,
|
|
95
|
+
targetSize: t,
|
|
96
|
+
type: "bytes"
|
|
97
|
+
});
|
|
98
|
+
const i = new Uint8Array(t);
|
|
99
|
+
for (let o = 0; o < t; o++) {
|
|
100
|
+
const n = e === "right";
|
|
101
|
+
i[n ? o : t - o - 1] = s[n ? o : s.length - o - 1];
|
|
102
|
+
}
|
|
103
|
+
return i;
|
|
104
|
+
}
|
|
105
|
+
class ne extends v {
|
|
106
|
+
constructor({ max: e, min: t, signed: i, size: o, value: n }) {
|
|
107
|
+
super(`Number "${n}" is not in safe ${o ? `${o * 8}-bit ${i ? "signed" : "unsigned"} ` : ""}integer range ${e ? `(${t} to ${e})` : `(above ${t})`}`, { name: "IntegerOutOfRangeError" });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
class re extends v {
|
|
111
|
+
constructor({ givenSize: e, maxSize: t }) {
|
|
112
|
+
super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`, { name: "SizeOverflowError" });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function V(s, { size: e }) {
|
|
116
|
+
if (_(s) > e)
|
|
117
|
+
throw new re({
|
|
118
|
+
givenSize: _(s),
|
|
119
|
+
maxSize: e
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const ae = /* @__PURE__ */ Array.from({ length: 256 }, (s, e) => e.toString(16).padStart(2, "0"));
|
|
123
|
+
function de(s, e = {}) {
|
|
124
|
+
return typeof s == "number" || typeof s == "bigint" ? pe(s, e) : typeof s == "string" ? ue(s, e) : typeof s == "boolean" ? ce(s, e) : J(s, e);
|
|
125
|
+
}
|
|
126
|
+
function ce(s, e = {}) {
|
|
127
|
+
const t = `0x${Number(s)}`;
|
|
128
|
+
return typeof e.size == "number" ? (V(t, { size: e.size }), I(t, { size: e.size })) : t;
|
|
129
|
+
}
|
|
130
|
+
function J(s, e = {}) {
|
|
131
|
+
let t = "";
|
|
132
|
+
for (let o = 0; o < s.length; o++)
|
|
133
|
+
t += ae[s[o]];
|
|
134
|
+
const i = `0x${t}`;
|
|
135
|
+
return typeof e.size == "number" ? (V(i, { size: e.size }), I(i, { dir: "right", size: e.size })) : i;
|
|
136
|
+
}
|
|
137
|
+
function pe(s, e = {}) {
|
|
138
|
+
const { signed: t, size: i } = e, o = BigInt(s);
|
|
139
|
+
let n;
|
|
140
|
+
i ? t ? n = (1n << BigInt(i) * 8n - 1n) - 1n : n = 2n ** (BigInt(i) * 8n) - 1n : typeof s == "number" && (n = BigInt(Number.MAX_SAFE_INTEGER));
|
|
141
|
+
const c = typeof n == "bigint" && t ? -n - 1n : 0;
|
|
142
|
+
if (n && o > n || o < c) {
|
|
143
|
+
const a = typeof s == "bigint" ? "n" : "";
|
|
144
|
+
throw new ne({
|
|
145
|
+
max: n ? `${n}${a}` : void 0,
|
|
146
|
+
min: `${c}${a}`,
|
|
147
|
+
signed: t,
|
|
148
|
+
size: i,
|
|
149
|
+
value: `${s}${a}`
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
const d = `0x${(t && o < 0 ? (1n << BigInt(i * 8)) + BigInt(o) : o).toString(16)}`;
|
|
153
|
+
return i ? I(d, { size: i }) : d;
|
|
154
|
+
}
|
|
155
|
+
const le = /* @__PURE__ */ new TextEncoder();
|
|
156
|
+
function ue(s, e = {}) {
|
|
157
|
+
const t = le.encode(s);
|
|
158
|
+
return J(t, e);
|
|
159
|
+
}
|
|
160
|
+
function he(s) {
|
|
161
|
+
return s instanceof Error;
|
|
162
|
+
}
|
|
163
|
+
let F = !1;
|
|
164
|
+
function me(s) {
|
|
165
|
+
if (F)
|
|
166
|
+
return;
|
|
167
|
+
F = !0;
|
|
168
|
+
const e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), o = (c) => {
|
|
169
|
+
const d = c.detail;
|
|
170
|
+
e.has(d.info.uuid) || e.set(d.info.uuid, d);
|
|
171
|
+
};
|
|
172
|
+
window.addEventListener("eip6963:announceProvider", o), window.dispatchEvent(new Event("eip6963:requestProvider")), window.addEventListener("message", async (c) => {
|
|
173
|
+
var y;
|
|
174
|
+
if (c.origin !== s) return;
|
|
175
|
+
const { type: d, data: a } = c.data;
|
|
176
|
+
switch (d) {
|
|
177
|
+
case "glide:getProviders": {
|
|
178
|
+
const p = Array.from(e.values()).map(
|
|
179
|
+
({ info: u, provider: l }) => ({
|
|
180
|
+
info: u,
|
|
181
|
+
isConnected: typeof l.isConnected == "boolean" ? l.isConnected : void 0,
|
|
182
|
+
chainId: l.chainId,
|
|
183
|
+
selectedAddress: l.selectedAddress
|
|
184
|
+
})
|
|
185
|
+
), r = document.getElementById(
|
|
186
|
+
"glide-deposit-iframe"
|
|
187
|
+
);
|
|
188
|
+
r != null && r.contentWindow && r.contentWindow.postMessage(
|
|
189
|
+
{
|
|
190
|
+
type: "glide:providers",
|
|
191
|
+
providers: p
|
|
192
|
+
},
|
|
193
|
+
s
|
|
194
|
+
);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "glide:providerRequest": {
|
|
198
|
+
const { uuid: p, requestId: r, method: u, params: l } = a;
|
|
199
|
+
if (i.has(r))
|
|
200
|
+
return;
|
|
201
|
+
i.set(r, !0);
|
|
202
|
+
const g = e.get(p);
|
|
203
|
+
if (!g) {
|
|
204
|
+
i.delete(r), n(r, { error: "Provider not found" });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const h = await g.provider.request({
|
|
209
|
+
method: u,
|
|
210
|
+
params: l
|
|
211
|
+
});
|
|
212
|
+
i.delete(r), n(r, { result: h });
|
|
213
|
+
} catch (h) {
|
|
214
|
+
i.delete(r), he(h) ? n(r, {
|
|
215
|
+
error: h.message || String(h),
|
|
216
|
+
code: h.code,
|
|
217
|
+
data: h.data
|
|
218
|
+
}) : n(r, {
|
|
219
|
+
error: String(h)
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "glide:addEventListener": {
|
|
225
|
+
const { uuid: p, requestId: r, eventName: u } = a, l = e.get(p);
|
|
226
|
+
if (!l || !l.provider.on) {
|
|
227
|
+
n(r, { error: "Provider or method not found" });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const g = (...h) => {
|
|
231
|
+
const f = document.getElementById(
|
|
232
|
+
"glide-deposit-iframe"
|
|
233
|
+
);
|
|
234
|
+
f != null && f.contentWindow && f.contentWindow.postMessage(
|
|
235
|
+
{
|
|
236
|
+
type: "glide:providerEvent",
|
|
237
|
+
uuid: p,
|
|
238
|
+
eventName: u,
|
|
239
|
+
args: h
|
|
240
|
+
},
|
|
241
|
+
s
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
t.has(p) || t.set(p, /* @__PURE__ */ new Map()), t.get(p).has(u) || t.get(p).set(u, /* @__PURE__ */ new Set()), t.get(p).get(u).add(g), l.provider.on(u, g), n(r, { result: !0 });
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case "glide:removeEventListener": {
|
|
248
|
+
const { uuid: p, requestId: r, eventName: u } = a, l = e.get(p);
|
|
249
|
+
if (!l || !l.provider.removeListener) {
|
|
250
|
+
n(r, { error: "Provider or method not found" });
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const g = (y = t.get(p)) == null ? void 0 : y.get(u);
|
|
254
|
+
g && (g.forEach((h) => {
|
|
255
|
+
l.provider.removeListener(u, h);
|
|
256
|
+
}), g.clear()), n(r, { result: !0 });
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
function n(c, d) {
|
|
262
|
+
const a = document.getElementById(
|
|
263
|
+
"glide-deposit-iframe"
|
|
264
|
+
);
|
|
265
|
+
a != null && a.contentWindow && a.contentWindow.postMessage(
|
|
266
|
+
{
|
|
267
|
+
type: "glide:providerResponse",
|
|
268
|
+
requestId: c,
|
|
269
|
+
...d
|
|
270
|
+
},
|
|
271
|
+
s
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
const ge = "@paywithglide/glide-react", fe = "0.0.47", ye = "module", we = ["dist"], ve = "dist/glide.js", be = "dist/index.d.ts", $e = { ".": { types: "./dist/index.d.ts", default: "./dist/glide.js" }, "./core": { types: "./dist/core.d.ts", default: "./dist/core.js" }, "./package.json": "./package.json" }, Se = !1, Ie = { dev: "vite", build: "bun run lint && vite build", "build-web": "tsc --p ./tsconfig.build.json && vite build --mode web", "build-chromeext": "tsc --p ./tsconfig.build.json && vite build --mode chromeext:popup && vite build --mode chromeext:content && vite build --mode chromeext:background", lint: "prettier --check . && eslint . --max-warnings 0 && tsc --p ./tsconfig.build.json", preview: "vite preview", prepublishOnly: "bun run build" }, xe = { "@paywithglide/glide-js": "0.13.32" }, Pe = { "@antiwork/shortest": "^0.2.1", "@eslint/js": "^9.15.0", "@tanstack/react-query": "^5.61.5", "@types/chrome": "^0.0.299", "@types/react": "^18.3.12", "@types/react-dom": "^18.3.1", "@vitejs/plugin-react": "^4.3.4", eslint: "^9.15.0", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.14", globals: "^15.12.0", prettier: "^3.6.2", react: "^18.3.1", "react-dom": "^18.3.1", typescript: "~5.6.2", "typescript-eslint": "^8.15.0", viem: "^2.21.51", vite: "^6.0.1", "vite-plugin-dts": "^4.3.0", "vite-plugin-static-copy": "^2.2.0", wagmi: "^2.13.0" }, ke = {
|
|
276
|
+
name: ge,
|
|
277
|
+
version: fe,
|
|
278
|
+
type: ye,
|
|
279
|
+
files: we,
|
|
280
|
+
module: ve,
|
|
281
|
+
types: be,
|
|
282
|
+
exports: $e,
|
|
283
|
+
sideEffects: Se,
|
|
284
|
+
scripts: Ie,
|
|
285
|
+
dependencies: xe,
|
|
286
|
+
devDependencies: Pe
|
|
287
|
+
}, G = ke.version;
|
|
288
|
+
function Ee() {
|
|
289
|
+
var t;
|
|
290
|
+
if (typeof navigator > "u") return "unknown";
|
|
291
|
+
const s = navigator.userAgent.toLowerCase(), e = ((t = navigator.platform) == null ? void 0 : t.toLowerCase()) || "";
|
|
292
|
+
return /iphone|ipad|ipod/.test(s) || e === "macintel" && navigator.maxTouchPoints > 1 ? "ios" : /android/.test(s) ? "android" : /win/.test(e) || /windows/.test(s) ? "windows" : /mac/.test(e) && !/iphone|ipad|ipod/.test(s) ? "macos" : /linux/.test(e) || /linux/.test(s) ? "linux" : "unknown";
|
|
293
|
+
}
|
|
294
|
+
function Ce() {
|
|
295
|
+
if (typeof navigator > "u") return "unknown";
|
|
296
|
+
const s = navigator.userAgent;
|
|
297
|
+
return s.includes("Firefox") ? "firefox" : s.includes("Edg") ? "edge" : s.includes("Chrome") ? "chrome" : s.includes("Safari") ? "safari" : s.includes("Opera") || s.includes("OPR") ? "opera" : "unknown";
|
|
298
|
+
}
|
|
299
|
+
function Ae() {
|
|
300
|
+
if (typeof navigator > "u") return !1;
|
|
301
|
+
const s = navigator.userAgent.toLowerCase();
|
|
302
|
+
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile/.test(
|
|
303
|
+
s
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
const H = 999999;
|
|
307
|
+
class Te {
|
|
308
|
+
constructor(e) {
|
|
309
|
+
w(this, "opts");
|
|
310
|
+
w(this, "open", () => {
|
|
311
|
+
if (!(!this.opts.container && document.body.classList.contains("glide-deposit-open"))) {
|
|
312
|
+
if (this.opts.container || document.body.classList.add("glide-deposit-open"), (this.opts.mode === "deposit" || this.opts.mode === "buy") && !this.opts.recipient)
|
|
313
|
+
throw new Error("recipient is required for deposit/buy mode");
|
|
314
|
+
if (this.opts.preferGaslessPayment && this.opts.walletProvider && !this.opts.walletProvider.signTypedDataAsync)
|
|
315
|
+
throw new Error(
|
|
316
|
+
"walletProvider.signTypedDataAsync is required when preferGaslessPayment=true"
|
|
317
|
+
);
|
|
318
|
+
this.openUrl(`${this.baseUrl}${this.opts.app}?init=true&embed=true`), this.initialize();
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
w(this, "iframeEventHandler", async (e) => {
|
|
322
|
+
var i, o, n, c, d, a, y, p, r, u, l, g, h, f, x, $, P, S, k, E, C, A, M, D, T, U, O, j, z, R, L, B, W;
|
|
323
|
+
const t = e.data;
|
|
324
|
+
switch (t.type) {
|
|
325
|
+
case "sendInit": {
|
|
326
|
+
const m = this.opts.recipient, X = (i = this.opts.walletProvider) == null ? void 0 : i.address, Z = (o = this.opts.walletProvider) == null ? void 0 : o.availableChainIds, Q = (n = this.opts.walletProvider) == null ? void 0 : n.currentChainId, Y = this.opts.preferGaslessPayment || !!((c = this.opts.walletProvider) != null && c.signTypedDataAsync);
|
|
327
|
+
(y = (d = this.iframe) == null ? void 0 : d.contentWindow) == null || y.postMessage(
|
|
328
|
+
{
|
|
329
|
+
type: "initialize",
|
|
330
|
+
// Analytics context - project identification
|
|
331
|
+
projectId: this.opts.projectId,
|
|
332
|
+
appSlug: this.opts.app,
|
|
333
|
+
sessionId: this.opts.sessionId,
|
|
334
|
+
recipient: m,
|
|
335
|
+
connectedWalletAddress: X,
|
|
336
|
+
availableChainIds: Z,
|
|
337
|
+
currentChainId: Q,
|
|
338
|
+
preferGaslessPayment: Y,
|
|
339
|
+
chainIds: this.opts.chainIds,
|
|
340
|
+
excludeChainIds: this.opts.excludeChainIds,
|
|
341
|
+
excludeCurrencyTiers: this.opts.excludeCurrencyTiers,
|
|
342
|
+
excludeFundingSources: this.opts.excludeFundingSources,
|
|
343
|
+
fundingSources: this.opts.fundingSources,
|
|
344
|
+
allowedPaymentCurrencies: this.opts.allowedPaymentCurrencies,
|
|
345
|
+
appMetadata: this.opts.appMetadata,
|
|
346
|
+
enableRefundEmails: this.opts.enableRefundEmails,
|
|
347
|
+
payerEmail: this.opts.payerEmail,
|
|
348
|
+
mode: this.opts.mode,
|
|
349
|
+
amount: this.opts.amount,
|
|
350
|
+
chainId: this.opts.chainId,
|
|
351
|
+
currencyId: this.opts.currencyId,
|
|
352
|
+
evmTx: this.opts.evm,
|
|
353
|
+
tokenApproval: this.opts.approval,
|
|
354
|
+
sessionMetadata: this.opts.sessionMetadata,
|
|
355
|
+
autoCloseOnSuccess: this.opts.autoCloseOnSuccess,
|
|
356
|
+
disableWithdrawToSelfSuggestion: this.opts.disableWithdrawToSelfSuggestion,
|
|
357
|
+
hideSettlementCopy: this.opts.hideSettlementCopy,
|
|
358
|
+
showAppLogo: this.opts.showAppLogo,
|
|
359
|
+
showOnrampFirst: this.opts.showOnrampFirst,
|
|
360
|
+
debitCardAlias: this.opts.debitCardAlias,
|
|
361
|
+
copyOverrides: this.opts.copyOverrides,
|
|
362
|
+
stableDepositAddressKey: this.opts.stableDepositAddressKey,
|
|
363
|
+
theme: {
|
|
364
|
+
...this.opts.theme || {},
|
|
365
|
+
colorScheme: ((a = this.opts.theme) == null ? void 0 : a.colorScheme) || getComputedStyle(document.documentElement).colorScheme || "",
|
|
366
|
+
safeInsetBottom: this.getSafeInsetBottom()
|
|
367
|
+
},
|
|
368
|
+
didProvideLocalStorage: !!this.opts.localStorageProvider,
|
|
369
|
+
debug: this.opts.debug,
|
|
370
|
+
popupsBlocked: this.opts.popupsBlocked,
|
|
371
|
+
gasRefuelAmountPerChain: this.opts.gasRefuelAmountPerChain,
|
|
372
|
+
sdkVersion: G,
|
|
373
|
+
referrerDomain: typeof window < "u" ? window.location.origin : void 0,
|
|
374
|
+
hasAnalyticsCallback: !!this.opts.onAnalyticsEvent
|
|
375
|
+
},
|
|
376
|
+
new URL(this.baseUrl).origin
|
|
377
|
+
);
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case "didOpen": {
|
|
381
|
+
this.iframe.style.opacity = "1", (r = (p = this.opts).onOpen) == null || r.call(p), this.trackEvent({
|
|
382
|
+
type: "modal_opened",
|
|
383
|
+
timestamp: Date.now()
|
|
384
|
+
});
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
case "analyticsEvent":
|
|
388
|
+
this.opts.onAnalyticsEvent && t.event && this.opts.onAnalyticsEvent(t.event);
|
|
389
|
+
break;
|
|
390
|
+
case "localStorage.getKeys": {
|
|
391
|
+
if (!this.opts.localStorageProvider)
|
|
392
|
+
throw new Error("localStorageProvider is not set");
|
|
393
|
+
const m = await this.opts.localStorageProvider.getKeys();
|
|
394
|
+
(l = (u = this.iframe) == null ? void 0 : u.contentWindow) == null || l.postMessage(
|
|
395
|
+
{
|
|
396
|
+
type: "localStorage.didGetKeys",
|
|
397
|
+
keys: m
|
|
398
|
+
},
|
|
399
|
+
this.baseUrl
|
|
400
|
+
);
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
case "localStorage.setItem":
|
|
404
|
+
if (!this.opts.localStorageProvider)
|
|
405
|
+
throw new Error("localStorageProvider is not set");
|
|
406
|
+
await this.opts.localStorageProvider.setItem(
|
|
407
|
+
t.key,
|
|
408
|
+
t.value
|
|
409
|
+
);
|
|
410
|
+
break;
|
|
411
|
+
case "localStorage.removeItem":
|
|
412
|
+
if (!this.opts.localStorageProvider)
|
|
413
|
+
throw new Error("localStorageProvider is not set");
|
|
414
|
+
await this.opts.localStorageProvider.removeItem(t.key);
|
|
415
|
+
break;
|
|
416
|
+
case "localStorage.getItem": {
|
|
417
|
+
if (!this.opts.localStorageProvider)
|
|
418
|
+
throw new Error("localStorageProvider is not set");
|
|
419
|
+
const m = await this.opts.localStorageProvider.getItem(t.key);
|
|
420
|
+
(h = (g = this.iframe) == null ? void 0 : g.contentWindow) == null || h.postMessage(
|
|
421
|
+
{
|
|
422
|
+
type: "localStorage.didGetItem",
|
|
423
|
+
key: t.key,
|
|
424
|
+
value: m
|
|
425
|
+
},
|
|
426
|
+
this.baseUrl
|
|
427
|
+
);
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case "success":
|
|
431
|
+
(x = (f = this.opts) == null ? void 0 : f.onSuccess) == null || x.call(f, t.hash, t.session), this.trackEvent({
|
|
432
|
+
type: "modal_closed",
|
|
433
|
+
timestamp: Date.now(),
|
|
434
|
+
completedTransaction: !0
|
|
435
|
+
});
|
|
436
|
+
break;
|
|
437
|
+
case "close":
|
|
438
|
+
this.removeIframe(), this.destroy(), this.trackEvent({
|
|
439
|
+
type: "modal_closed",
|
|
440
|
+
timestamp: Date.now(),
|
|
441
|
+
completedTransaction: !1
|
|
442
|
+
}), (P = ($ = this.opts) == null ? void 0 : $.onClose) == null || P.call($);
|
|
443
|
+
break;
|
|
444
|
+
case "setMode":
|
|
445
|
+
(k = (S = this.opts) == null ? void 0 : S.onSetMode) == null || k.call(S, t.mode);
|
|
446
|
+
break;
|
|
447
|
+
case "switchChain":
|
|
448
|
+
if (!this.opts.walletProvider)
|
|
449
|
+
throw new Error("walletProvider is not set");
|
|
450
|
+
try {
|
|
451
|
+
await this.opts.walletProvider.switchChainAsync({
|
|
452
|
+
chainId: t.chainId
|
|
453
|
+
}), (C = (E = this.iframe) == null ? void 0 : E.contentWindow) == null || C.postMessage(
|
|
454
|
+
{
|
|
455
|
+
type: "didSwitchChain",
|
|
456
|
+
success: !0,
|
|
457
|
+
chainId: t.chainId
|
|
458
|
+
},
|
|
459
|
+
this.baseUrl
|
|
460
|
+
);
|
|
461
|
+
} catch (m) {
|
|
462
|
+
(M = (A = this.iframe) == null ? void 0 : A.contentWindow) == null || M.postMessage(
|
|
463
|
+
{
|
|
464
|
+
type: "didSwitchChain",
|
|
465
|
+
success: !1,
|
|
466
|
+
error: m
|
|
467
|
+
},
|
|
468
|
+
this.baseUrl
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
case "sendTransaction":
|
|
473
|
+
{
|
|
474
|
+
if (!this.opts.walletProvider)
|
|
475
|
+
throw new Error("walletProvider is not set");
|
|
476
|
+
try {
|
|
477
|
+
const m = await this.opts.walletProvider.sendTransactionAsync(
|
|
478
|
+
t.tx
|
|
479
|
+
);
|
|
480
|
+
(T = (D = this.iframe) == null ? void 0 : D.contentWindow) == null || T.postMessage(
|
|
481
|
+
{
|
|
482
|
+
type: "didSendTransaction",
|
|
483
|
+
success: !0,
|
|
484
|
+
txHash: m
|
|
485
|
+
},
|
|
486
|
+
this.baseUrl
|
|
487
|
+
);
|
|
488
|
+
} catch (m) {
|
|
489
|
+
(O = (U = this.iframe) == null ? void 0 : U.contentWindow) == null || O.postMessage(
|
|
490
|
+
{
|
|
491
|
+
type: "didSendTransaction",
|
|
492
|
+
success: !1,
|
|
493
|
+
error: m
|
|
494
|
+
},
|
|
495
|
+
this.baseUrl
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
500
|
+
case "signTypedData":
|
|
501
|
+
{
|
|
502
|
+
if (!this.opts.walletProvider)
|
|
503
|
+
throw new Error("walletProvider is not set");
|
|
504
|
+
if (!this.opts.walletProvider.signTypedDataAsync) {
|
|
505
|
+
(z = (j = this.iframe) == null ? void 0 : j.contentWindow) == null || z.postMessage(
|
|
506
|
+
{
|
|
507
|
+
type: "didSignTypedData",
|
|
508
|
+
success: !1,
|
|
509
|
+
error: "signTypedDataAsync_not_implemented"
|
|
510
|
+
},
|
|
511
|
+
this.baseUrl
|
|
512
|
+
);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
const m = await this.opts.walletProvider.signTypedDataAsync(
|
|
517
|
+
t.data
|
|
518
|
+
);
|
|
519
|
+
(L = (R = this.iframe) == null ? void 0 : R.contentWindow) == null || L.postMessage(
|
|
520
|
+
{
|
|
521
|
+
type: "didSignTypedData",
|
|
522
|
+
success: !0,
|
|
523
|
+
signature: m
|
|
524
|
+
},
|
|
525
|
+
this.baseUrl
|
|
526
|
+
);
|
|
527
|
+
} catch (m) {
|
|
528
|
+
(W = (B = this.iframe) == null ? void 0 : B.contentWindow) == null || W.postMessage(
|
|
529
|
+
{
|
|
530
|
+
type: "didSignTypedData",
|
|
531
|
+
success: !1,
|
|
532
|
+
error: m
|
|
533
|
+
},
|
|
534
|
+
this.baseUrl
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
this.opts = e;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Get analytics context for events tracked directly in SDK
|
|
545
|
+
*/
|
|
546
|
+
getAnalyticsContext() {
|
|
547
|
+
var e;
|
|
548
|
+
return {
|
|
549
|
+
projectId: this.opts.projectId,
|
|
550
|
+
appSlug: this.opts.app,
|
|
551
|
+
sdkVersion: G,
|
|
552
|
+
referrerDomain: typeof window < "u" ? window.location.origin : void 0,
|
|
553
|
+
walletAddress: (e = this.opts.walletProvider) == null ? void 0 : e.address,
|
|
554
|
+
device: {
|
|
555
|
+
isMobile: Ae(),
|
|
556
|
+
platform: Ee(),
|
|
557
|
+
browser: Ce()
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Track an analytics event with context
|
|
563
|
+
*/
|
|
564
|
+
trackEvent(e) {
|
|
565
|
+
if (!this.opts.onAnalyticsEvent) return;
|
|
566
|
+
const t = {
|
|
567
|
+
...e,
|
|
568
|
+
...this.getAnalyticsContext()
|
|
569
|
+
};
|
|
570
|
+
this.opts.onAnalyticsEvent(t);
|
|
571
|
+
}
|
|
572
|
+
get externalUrl() {
|
|
573
|
+
var e, t, i, o, n, c, d, a, y;
|
|
574
|
+
return `${this.baseUrl}${this.opts.app}?${this.opts.recipient ? `&recipient=${this.opts.recipient}` : ""}${this.opts.preferGaslessPayment ? "&preferGaslessPayment=true" : ""}${this.opts.mode ? `&mode=${this.opts.mode}` : ""}${this.opts.amount ? `&amount=${this.opts.amount}` : ""}${this.opts.chainId ? `&chainId=${this.opts.chainId}` : ""}${this.opts.currencyId ? `¤cyId=${this.opts.currencyId}` : ""}${this.opts.evm ? `&evm.chainId=${this.opts.evm.chainId}&evm.to=${this.opts.evm.to}&evm.data=${this.opts.evm.data || "0x0"}&evm.value=${de(
|
|
575
|
+
this.opts.evm.value || 0n
|
|
576
|
+
)}` : ""}${this.opts.approval ? `&approval.token=${this.opts.approval.token}&approval.amount=${this.opts.approval.amount}` : ""}${this.opts.sessionMetadata ? `&metadata=${this.opts.sessionMetadata}` : ""}${this.opts.autoCloseOnSuccess ? "&autoCloseOnSuccess=true" : ""}${this.opts.sessionId ? `&sessionId=${this.opts.sessionId}` : ""}${(e = this.opts.chainIds) != null && e.length ? `&chainIds=${this.opts.chainIds.join(",")}` : ""}${(t = this.opts.excludeChainIds) != null && t.length ? `&excludeChainIds=${this.opts.excludeChainIds.join(",")}` : ""}${(i = this.opts.excludeCurrencyTiers) != null && i.length ? `&excludeCurrencyTiers=${this.opts.excludeCurrencyTiers.join(",")}` : ""}${(o = this.opts.excludeFundingSources) != null && o.length ? `&excludeFundingSources=${this.opts.excludeFundingSources.join(",")}` : ""}${(n = this.opts.fundingSources) != null && n.length ? `&fundingSources=${this.opts.fundingSources.join(",")}` : ""}${(c = this.opts.allowedPaymentCurrencies) != null && c.length ? `&allowedPaymentCurrencies=${this.opts.allowedPaymentCurrencies.join(",")}` : ""}${(d = this.opts.appMetadata) != null && d.name ? `&appMetadata.name=${encodeURIComponent(this.opts.appMetadata.name)}` : ""}${(a = this.opts.appMetadata) != null && a.logoUrl ? `&appMetadata.logoUrl=${encodeURIComponent(this.opts.appMetadata.logoUrl)}` : ""}${(y = this.opts.appMetadata) != null && y.faviconUrl ? `&appMetadata.faviconUrl=${encodeURIComponent(this.opts.appMetadata.faviconUrl)}` : ""}${this.opts.enableRefundEmails ? "&enableRefundEmails=true" : ""}${this.opts.payerEmail ? `&payerEmail=${encodeURIComponent(this.opts.payerEmail)}` : ""}${this.opts.debug ? "&debug=true" : ""}${this.opts.popupsBlocked ? "&popupsBlocked=true" : ""}${this.opts.disableWithdrawToSelfSuggestion ? "&disableWithdrawToSelfSuggestion=true" : ""}${this.opts.hideSettlementCopy ? "&hideSettlementCopy=true" : ""}${this.opts.showAppLogo ? `&showAppLogo=${this.opts.showAppLogo}` : ""}${this.opts.showOnrampFirst ? "&showOnrampFirst=true" : ""}${this.opts.debitCardAlias ? `&debitCardAlias=${this.opts.debitCardAlias}` : ""}${this.opts.copyOverrides ? `©Overrides=${encodeURIComponent(JSON.stringify(this.opts.copyOverrides))}` : ""}${this.opts.stableDepositAddressKey ? `&stableDepositAddressKey=${encodeURIComponent(this.opts.stableDepositAddressKey)}` : ""}${this.opts.gasRefuelAmountPerChain ? `&gasRefuelAmountPerChain=${encodeURIComponent(JSON.stringify(this.opts.gasRefuelAmountPerChain))}` : ""}`;
|
|
577
|
+
}
|
|
578
|
+
initialize() {
|
|
579
|
+
window.addEventListener("message", this.iframeEventHandler);
|
|
580
|
+
const e = new URL(this.baseUrl).origin;
|
|
581
|
+
me(e);
|
|
582
|
+
}
|
|
583
|
+
destroy() {
|
|
584
|
+
window.removeEventListener("message", this.iframeEventHandler);
|
|
585
|
+
}
|
|
586
|
+
get baseUrl() {
|
|
587
|
+
return this.opts.baseUrl || "https://deposit.paywithglide.xyz/";
|
|
588
|
+
}
|
|
589
|
+
get iframe() {
|
|
590
|
+
return document.getElementById("glide-deposit-iframe");
|
|
591
|
+
}
|
|
592
|
+
getSafeInsetBottom() {
|
|
593
|
+
if (typeof window > "u" || typeof document > "u")
|
|
594
|
+
return 0;
|
|
595
|
+
try {
|
|
596
|
+
const e = document.createElement("div");
|
|
597
|
+
e.style.cssText = "position: fixed; bottom: 0; left: 0; width: 1px; height: 1px; padding: 0; margin: 0; padding-bottom: env(safe-area-inset-bottom, 0px); visibility: hidden; pointer-events: none; z-index: -1;", document.body.appendChild(e);
|
|
598
|
+
const t = window.getComputedStyle(e).paddingBottom;
|
|
599
|
+
return document.body.removeChild(e), parseFloat(t) || 0;
|
|
600
|
+
} catch {
|
|
601
|
+
return 0;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
openUrl(e) {
|
|
605
|
+
this.createIframe(e);
|
|
606
|
+
}
|
|
607
|
+
createIframe(e) {
|
|
608
|
+
this.removeIframe();
|
|
609
|
+
const t = document.createElement("iframe");
|
|
610
|
+
t.id = "glide-deposit-iframe";
|
|
611
|
+
const i = this.opts.container, o = i ? `z-index: ${H}; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: relative; width: 100%; height: 100%; opacity: 0;` : `z-index: ${H}; display: block; background-color: transparent; border: 0px none transparent; overflow-x: hidden; overflow-y: auto; visibility: visible; margin: 0px; padding: 0px; -webkit-tap-highlight-color: transparent; position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; opacity: 0;`;
|
|
612
|
+
t.setAttribute("style", o), t.src = e, t.allow = "payment *; clipboard-write *", i ? i.appendChild(t) : document.body.appendChild(t);
|
|
613
|
+
}
|
|
614
|
+
removeIframe() {
|
|
615
|
+
const e = document.getElementById("glide-deposit-iframe");
|
|
616
|
+
e && (e.remove(), document.body.classList.remove("glide-deposit-open"));
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
const Ue = Object.freeze({
|
|
620
|
+
getItem: (s) => new Promise((e, t) => {
|
|
621
|
+
try {
|
|
622
|
+
const i = localStorage.getItem(s);
|
|
623
|
+
e(i);
|
|
624
|
+
} catch (i) {
|
|
625
|
+
t(i);
|
|
626
|
+
}
|
|
627
|
+
}),
|
|
628
|
+
setItem: (s, e) => new Promise((t, i) => {
|
|
629
|
+
try {
|
|
630
|
+
localStorage.setItem(s, e), t();
|
|
631
|
+
} catch (o) {
|
|
632
|
+
i(o);
|
|
633
|
+
}
|
|
634
|
+
}),
|
|
635
|
+
removeItem: (s) => new Promise((e, t) => {
|
|
636
|
+
try {
|
|
637
|
+
localStorage.removeItem(s), e();
|
|
638
|
+
} catch (i) {
|
|
639
|
+
t(i);
|
|
640
|
+
}
|
|
641
|
+
}),
|
|
642
|
+
getKeys: () => new Promise((s, e) => {
|
|
643
|
+
try {
|
|
644
|
+
const t = Object.keys(localStorage);
|
|
645
|
+
s(t);
|
|
646
|
+
} catch (t) {
|
|
647
|
+
e(t);
|
|
648
|
+
}
|
|
649
|
+
})
|
|
650
|
+
});
|
|
651
|
+
class Me {
|
|
652
|
+
constructor(e) {
|
|
653
|
+
w(this, "callback");
|
|
654
|
+
w(this, "startTime");
|
|
655
|
+
w(this, "currentStep");
|
|
656
|
+
this.callback = e;
|
|
657
|
+
}
|
|
658
|
+
setCallback(e) {
|
|
659
|
+
this.callback = e;
|
|
660
|
+
}
|
|
661
|
+
track(e) {
|
|
662
|
+
if (this.callback)
|
|
663
|
+
try {
|
|
664
|
+
this.callback(e);
|
|
665
|
+
} catch (t) {
|
|
666
|
+
console.error("Error in analytics callback:", t);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
// Convenience methods for common events
|
|
670
|
+
modalOpened() {
|
|
671
|
+
this.startTime = Date.now(), this.track({
|
|
672
|
+
type: "modal_opened",
|
|
673
|
+
timestamp: Date.now()
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
modalClosed(e) {
|
|
677
|
+
this.track({
|
|
678
|
+
type: "modal_closed",
|
|
679
|
+
timestamp: Date.now(),
|
|
680
|
+
completedTransaction: e
|
|
681
|
+
}), this.startTime = void 0, this.currentStep = void 0;
|
|
682
|
+
}
|
|
683
|
+
stepViewed(e) {
|
|
684
|
+
this.currentStep = e, this.track({
|
|
685
|
+
type: "step_viewed",
|
|
686
|
+
step: e,
|
|
687
|
+
timestamp: Date.now()
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
stepExited(e, t) {
|
|
691
|
+
this.track({
|
|
692
|
+
type: "step_exited",
|
|
693
|
+
step: e,
|
|
694
|
+
timestamp: Date.now(),
|
|
695
|
+
direction: t
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
paymentMethodSelected(e) {
|
|
699
|
+
this.track({
|
|
700
|
+
type: "payment_method_selected",
|
|
701
|
+
paymentMethod: e,
|
|
702
|
+
timestamp: Date.now()
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
transactionCompleted(e, t, i, o) {
|
|
706
|
+
const n = this.startTime ? Date.now() - this.startTime : 0;
|
|
707
|
+
this.track({
|
|
708
|
+
type: "transaction_completed",
|
|
709
|
+
sessionId: e,
|
|
710
|
+
txHash: t,
|
|
711
|
+
paymentMethod: i,
|
|
712
|
+
success: !0,
|
|
713
|
+
amountUSD: o,
|
|
714
|
+
timestamp: Date.now()
|
|
715
|
+
}), this.track({
|
|
716
|
+
type: "conversion_completed",
|
|
717
|
+
sessionId: e,
|
|
718
|
+
paymentMethod: i,
|
|
719
|
+
amountUSD: o,
|
|
720
|
+
duration: n,
|
|
721
|
+
timestamp: Date.now()
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
errorOccurred(e, t, i) {
|
|
725
|
+
this.track({
|
|
726
|
+
type: "error_occurred",
|
|
727
|
+
errorType: e,
|
|
728
|
+
errorMessage: t,
|
|
729
|
+
step: i || this.currentStep,
|
|
730
|
+
timestamp: Date.now()
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const Oe = new Me();
|
|
735
|
+
export {
|
|
736
|
+
Me as GlideAnalytics,
|
|
737
|
+
Te as GlideDeposit,
|
|
738
|
+
Ue as browserLocalStorageProvider,
|
|
739
|
+
Oe as glideAnalytics,
|
|
740
|
+
me as initializeParentBridge
|
|
741
|
+
};
|