@paywithglide/glide-react 0.0.14 → 0.0.16

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.
@@ -77,7 +77,7 @@ export type GlideDepositWalletProvider = {
77
77
  };
78
78
  export type GlideDepositOptions = {
79
79
  app: string;
80
- recipient?: Hex;
80
+ recipient?: string;
81
81
  mode?: "deposit" | "withdraw" | "pay" | "call" | "buy";
82
82
  amount?: string;
83
83
  evm?: {
package/dist/glide.js CHANGED
@@ -1,17 +1,17 @@
1
- var k = Object.defineProperty;
2
- var C = (s, t, e) => t in s ? k(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var m = (s, t, e) => C(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { useMemo as f } from "react";
1
+ var M = Object.defineProperty;
2
+ var k = (s, t, e) => t in s ? M(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var g = (s, t, e) => k(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { useMemo as y } from "react";
5
5
  function G(s, { strict: t = !0 } = {}) {
6
6
  return !s || typeof s != "string" ? !1 : t ? /^0x[0-9a-fA-F]*$/.test(s) : s.startsWith("0x");
7
7
  }
8
8
  function U(s) {
9
9
  return G(s, { strict: !1 }) ? Math.ceil((s.length - 2) / 2) : s.length;
10
10
  }
11
- const D = "2.21.51";
12
- let h = {
11
+ const z = "2.21.51";
12
+ let m = {
13
13
  getDocsUrl: ({ docsBaseUrl: s, docsPath: t = "", docsSlug: e }) => t ? `${s ?? "https://viem.sh"}${t}${e ? `#${e}` : ""}` : void 0,
14
- version: `viem@${D}`
14
+ version: `viem@${z}`
15
15
  };
16
16
  class u extends Error {
17
17
  constructor(t, e = {}) {
@@ -19,13 +19,13 @@ class u extends Error {
19
19
  const i = (() => {
20
20
  var o;
21
21
  return e.cause instanceof u ? e.cause.details : (o = e.cause) != null && o.message ? e.cause.message : e.details;
22
- })(), n = e.cause instanceof u && e.cause.docsPath || e.docsPath, r = (a = h.getDocsUrl) == null ? void 0 : a.call(h, { ...e, docsPath: n }), d = [
22
+ })(), n = e.cause instanceof u && e.cause.docsPath || e.docsPath, r = (a = m.getDocsUrl) == null ? void 0 : a.call(m, { ...e, docsPath: n }), d = [
23
23
  t || "An error occurred.",
24
24
  "",
25
25
  ...e.metaMessages ? [...e.metaMessages, ""] : [],
26
26
  ...r ? [`Docs: ${r}`] : [],
27
27
  ...i ? [`Details: ${i}`] : [],
28
- ...h.version ? [`Version: ${h.version}`] : []
28
+ ...m.version ? [`Version: ${m.version}`] : []
29
29
  ].join(`
30
30
  `);
31
31
  super(d, e.cause ? { cause: e.cause } : void 0), Object.defineProperty(this, "details", {
@@ -58,7 +58,7 @@ class u extends Error {
58
58
  configurable: !0,
59
59
  writable: !0,
60
60
  value: "BaseError"
61
- }), this.details = i, this.docsPath = n, this.metaMessages = e.metaMessages, this.name = e.name ?? this.name, this.shortMessage = t, this.version = D;
61
+ }), this.details = i, this.docsPath = n, this.metaMessages = e.metaMessages, this.name = e.name ?? this.name, this.shortMessage = t, this.version = z;
62
62
  }
63
63
  walk(t) {
64
64
  return T(this, t);
@@ -67,20 +67,20 @@ class u extends Error {
67
67
  function T(s, t) {
68
68
  return t != null && t(s) ? s : s && typeof s == "object" && "cause" in s && s.cause !== void 0 ? T(s.cause, t) : t ? null : s;
69
69
  }
70
- class S extends u {
70
+ class D extends u {
71
71
  constructor({ size: t, targetSize: e, type: i }) {
72
72
  super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (${t}) exceeds padding size (${e}).`, { name: "SizeExceedsPaddingSizeError" });
73
73
  }
74
74
  }
75
- function y(s, { dir: t, size: e = 32 } = {}) {
76
- return typeof s == "string" ? W(s, { dir: t, size: e }) : H(s, { dir: t, size: e });
75
+ function b(s, { dir: t, size: e = 32 } = {}) {
76
+ return typeof s == "string" ? C(s, { dir: t, size: e }) : H(s, { dir: t, size: e });
77
77
  }
78
- function W(s, { dir: t, size: e = 32 } = {}) {
78
+ function C(s, { dir: t, size: e = 32 } = {}) {
79
79
  if (e === null)
80
80
  return s;
81
81
  const i = s.replace("0x", "");
82
82
  if (i.length > e * 2)
83
- throw new S({
83
+ throw new D({
84
84
  size: Math.ceil(i.length / 2),
85
85
  targetSize: e,
86
86
  type: "hex"
@@ -91,7 +91,7 @@ function H(s, { dir: t, size: e = 32 } = {}) {
91
91
  if (e === null)
92
92
  return s;
93
93
  if (s.length > e)
94
- throw new S({
94
+ throw new D({
95
95
  size: s.length,
96
96
  targetSize: e,
97
97
  type: "bytes"
@@ -108,32 +108,32 @@ class B extends u {
108
108
  super(`Number "${r}" is not in safe ${n ? `${n * 8}-bit ${i ? "signed" : "unsigned"} ` : ""}integer range ${t ? `(${e} to ${t})` : `(above ${e})`}`, { name: "IntegerOutOfRangeError" });
109
109
  }
110
110
  }
111
- class j extends u {
111
+ class W extends u {
112
112
  constructor({ givenSize: t, maxSize: e }) {
113
113
  super(`Size cannot exceed ${e} bytes. Given size: ${t} bytes.`, { name: "SizeOverflowError" });
114
114
  }
115
115
  }
116
- function A(s, { size: t }) {
116
+ function S(s, { size: t }) {
117
117
  if (U(s) > t)
118
- throw new j({
118
+ throw new W({
119
119
  givenSize: U(s),
120
120
  maxSize: t
121
121
  });
122
122
  }
123
123
  const O = /* @__PURE__ */ Array.from({ length: 256 }, (s, t) => t.toString(16).padStart(2, "0"));
124
- function z(s, t = {}) {
125
- return typeof s == "number" || typeof s == "bigint" ? N(s, t) : typeof s == "string" ? V(s, t) : typeof s == "boolean" ? L(s, t) : M(s, t);
124
+ function j(s, t = {}) {
125
+ return typeof s == "number" || typeof s == "bigint" ? N(s, t) : typeof s == "string" ? V(s, t) : typeof s == "boolean" ? L(s, t) : A(s, t);
126
126
  }
127
127
  function L(s, t = {}) {
128
128
  const e = `0x${Number(s)}`;
129
- return typeof t.size == "number" ? (A(e, { size: t.size }), y(e, { size: t.size })) : e;
129
+ return typeof t.size == "number" ? (S(e, { size: t.size }), b(e, { size: t.size })) : e;
130
130
  }
131
- function M(s, t = {}) {
131
+ function A(s, t = {}) {
132
132
  let e = "";
133
133
  for (let n = 0; n < s.length; n++)
134
134
  e += O[s[n]];
135
135
  const i = `0x${e}`;
136
- return typeof t.size == "number" ? (A(i, { size: t.size }), y(i, { dir: "right", size: t.size })) : i;
136
+ return typeof t.size == "number" ? (S(i, { size: t.size }), b(i, { dir: "right", size: t.size })) : i;
137
137
  }
138
138
  function N(s, t = {}) {
139
139
  const { signed: e, size: i } = t, n = BigInt(s);
@@ -151,32 +151,29 @@ function N(s, t = {}) {
151
151
  });
152
152
  }
153
153
  const a = `0x${(e && n < 0 ? (1n << BigInt(i * 8)) + BigInt(n) : n).toString(16)}`;
154
- return i ? y(a, { size: i }) : a;
154
+ return i ? b(a, { size: i }) : a;
155
155
  }
156
156
  const R = /* @__PURE__ */ new TextEncoder();
157
157
  function V(s, t = {}) {
158
158
  const e = R.encode(s);
159
- return M(e, t);
159
+ return A(e, t);
160
160
  }
161
- class g {
161
+ class w {
162
162
  constructor(t) {
163
- m(this, "opts");
164
- m(this, "open", () => {
165
- var d, a, o, c;
166
- if (document.body.classList.contains("glide-deposit-open")) return;
167
- if (document.body.classList.add("glide-deposit-open"), (this.opts.mode === "deposit" || this.opts.mode === "buy") && !this.opts.recipient)
168
- throw new Error("recipient is required for deposit/buy mode");
169
- if (this.opts.preferGaslessPayment && this.opts.walletProvider && !this.opts.walletProvider.signTypedDataAsync)
170
- throw new Error(
171
- "walletProvider.signTypedDataAsync is required when preferGaslessPayment=true"
172
- );
173
- const t = this.opts.recipient, e = (d = this.opts.walletProvider) == null ? void 0 : d.address, i = (a = this.opts.walletProvider) == null ? void 0 : a.availableChainIds, n = (o = this.opts.walletProvider) == null ? void 0 : o.currentChainId, r = this.opts.preferGaslessPayment || !!((c = this.opts.walletProvider) != null && c.signTypedDataAsync);
174
- this.openUrl(
175
- `${this.baseUrl}${this.opts.app}?embed=true${t ? `&recipient=${t}` : ""}${e ? `&connectedWalletAddress=${e}` : ""}${n ? `&currentChainId=${n}` : ""}${i ? `&availableChainIds=${i.join(",")}` : ""}${r ? "&preferGaslessPayment=true" : ""}${this.opts.mode ? `&mode=${this.opts.mode}` : ""}${this.opts.amount ? `&amount=${this.opts.amount}` : ""}${this.opts.evm ? `&evm.chainId=${this.opts.evm.chainId}&evm.to=${this.opts.evm.to}&evm.data=${this.opts.evm.data || "0x0"}&evm.value=${z(this.opts.evm.value || 0n)}` : ""}${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" : ""}`
176
- ), this.initialize();
163
+ g(this, "opts");
164
+ g(this, "open", () => {
165
+ if (!document.body.classList.contains("glide-deposit-open")) {
166
+ if (document.body.classList.add("glide-deposit-open"), (this.opts.mode === "deposit" || this.opts.mode === "buy") && !this.opts.recipient)
167
+ throw new Error("recipient is required for deposit/buy mode");
168
+ if (this.opts.preferGaslessPayment && this.opts.walletProvider && !this.opts.walletProvider.signTypedDataAsync)
169
+ throw new Error(
170
+ "walletProvider.signTypedDataAsync is required when preferGaslessPayment=true"
171
+ );
172
+ this.openUrl(`${this.baseUrl}${this.opts.app}?init=true&embed=true`), this.initialize();
173
+ }
177
174
  });
178
- m(this, "iframeEventHandler", async (t) => {
179
- var i, n, r, d, a, o, c, l, $, w, v, b, x, P, I, E;
175
+ g(this, "iframeEventHandler", async (t) => {
176
+ var i, n, r, d, a, o, c, l, h, f, v, $, x, P, E, I;
180
177
  const e = t.data;
181
178
  switch (e.type) {
182
179
  case "success":
@@ -227,7 +224,7 @@ class g {
227
224
  this.baseUrl
228
225
  );
229
226
  } catch (p) {
230
- (w = ($ = this.iframe) == null ? void 0 : $.contentWindow) == null || w.postMessage(
227
+ (f = (h = this.iframe) == null ? void 0 : h.contentWindow) == null || f.postMessage(
231
228
  {
232
229
  type: "didSendTransaction",
233
230
  success: !1,
@@ -243,7 +240,7 @@ class g {
243
240
  if (!this.opts.walletProvider)
244
241
  throw new Error("walletProvider is not set");
245
242
  if (!this.opts.walletProvider.signTypedDataAsync) {
246
- (b = (v = this.iframe) == null ? void 0 : v.contentWindow) == null || b.postMessage(
243
+ ($ = (v = this.iframe) == null ? void 0 : v.contentWindow) == null || $.postMessage(
247
244
  {
248
245
  type: "didSignTypedData",
249
246
  success: !1,
@@ -266,7 +263,7 @@ class g {
266
263
  this.baseUrl
267
264
  );
268
265
  } catch (p) {
269
- (E = (I = this.iframe) == null ? void 0 : I.contentWindow) == null || E.postMessage(
266
+ (I = (E = this.iframe) == null ? void 0 : E.contentWindow) == null || I.postMessage(
270
267
  {
271
268
  type: "didSignTypedData",
272
269
  success: !1,
@@ -282,7 +279,7 @@ class g {
282
279
  this.opts = t;
283
280
  }
284
281
  get externalUrl() {
285
- 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.evm ? `&evm.chainId=${this.opts.evm.chainId}&evm.to=${this.opts.evm.to}&evm.data=${this.opts.evm.data || "0x0"}&evm.value=${z(this.opts.evm.value || 0n)}` : ""}${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" : ""}`;
282
+ 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.evm ? `&evm.chainId=${this.opts.evm.chainId}&evm.to=${this.opts.evm.to}&evm.data=${this.opts.evm.data || "0x0"}&evm.value=${j(this.opts.evm.value || 0n)}` : ""}${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" : ""}`;
286
283
  }
287
284
  initialize() {
288
285
  window.addEventListener("message", this.iframeEventHandler);
@@ -306,14 +303,29 @@ class g {
306
303
  "style",
307
304
  "z-index: 2147483647; 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;"
308
305
  ), e.onload = () => {
309
- var i, n;
310
- e.style.opacity = "1", (i = e == null ? void 0 : e.contentWindow) == null || i.focus(), (n = e == null ? void 0 : e.contentWindow) == null || n.postMessage(
311
- {
312
- type: "updateTheme",
313
- theme: this.opts.theme
314
- },
315
- this.baseUrl
316
- );
306
+ var o, c, l, h;
307
+ const i = this.opts.recipient, n = (o = this.opts.walletProvider) == null ? void 0 : o.address, r = (c = this.opts.walletProvider) == null ? void 0 : c.availableChainIds, d = (l = this.opts.walletProvider) == null ? void 0 : l.currentChainId, a = this.opts.preferGaslessPayment || !!((h = this.opts.walletProvider) != null && h.signTypedDataAsync);
308
+ e.style.opacity = "1", setTimeout(() => {
309
+ var f;
310
+ (f = e == null ? void 0 : e.contentWindow) == null || f.postMessage(
311
+ {
312
+ type: "initialize",
313
+ recipient: i,
314
+ connectedWalletAddress: n,
315
+ availableChainIds: r,
316
+ currentChainId: d,
317
+ preferGaslessPayment: a,
318
+ mode: this.opts.mode,
319
+ amount: this.opts.amount,
320
+ evmTx: this.opts.evm,
321
+ tokenApproval: this.opts.approval,
322
+ sessionMetadata: this.opts.sessionMetadata,
323
+ autoCloseOnSuccess: this.opts.autoCloseOnSuccess,
324
+ theme: this.opts.theme
325
+ },
326
+ new URL(this.baseUrl).origin
327
+ );
328
+ }, 10);
317
329
  }, e.src = t, e.allow = "payment *; clipboard-write *", document.body.appendChild(e);
318
330
  }
319
331
  removeIframe() {
@@ -333,7 +345,7 @@ const X = ({
333
345
  autoCloseOnSuccess: o,
334
346
  baseUrl: c
335
347
  }) => {
336
- const l = f(() => new g({
348
+ const l = y(() => new w({
337
349
  app: s,
338
350
  recipient: t,
339
351
  preferGaslessPayment: e,
@@ -372,7 +384,7 @@ const X = ({
372
384
  autoCloseOnSuccess: a,
373
385
  baseUrl: o
374
386
  }) => {
375
- const c = f(() => new g({
387
+ const c = y(() => new w({
376
388
  app: s,
377
389
  preferGaslessPayment: t,
378
390
  mode: "pay",
@@ -411,7 +423,7 @@ const X = ({
411
423
  autoCloseOnSuccess: o,
412
424
  baseUrl: c
413
425
  }) => {
414
- const l = f(() => new g({
426
+ const l = y(() => new w({
415
427
  app: s,
416
428
  evm: t,
417
429
  approval: e,
@@ -451,7 +463,7 @@ const X = ({
451
463
  autoCloseOnSuccess: a,
452
464
  baseUrl: o
453
465
  }) => {
454
- const c = f(() => new g({
466
+ const c = y(() => new w({
455
467
  app: s,
456
468
  recipient: t,
457
469
  preferGaslessPayment: e,
@@ -480,7 +492,7 @@ const X = ({
480
492
  };
481
493
  };
482
494
  export {
483
- g as GlideDeposit,
495
+ w as GlideDeposit,
484
496
  Q as useGlideBuy,
485
497
  K as useGlideCall,
486
498
  X as useGlideDeposit,
@@ -2,7 +2,7 @@ import { GlideDepositWalletProvider, Hex } from './GlideDeposit.ts';
2
2
  import { GlideWidgetTheme } from './theme.ts';
3
3
  interface UseGlideBuyProps {
4
4
  app: string;
5
- recipient?: Hex;
5
+ recipient?: string;
6
6
  preferGaslessPayment?: boolean;
7
7
  sessionMetadata?: string;
8
8
  theme?: GlideWidgetTheme;
@@ -1,8 +1,8 @@
1
- import { GlideDepositWalletProvider, Hex } from './GlideDeposit.ts';
1
+ import { GlideDepositWalletProvider } from './GlideDeposit.ts';
2
2
  import { GlideWidgetTheme } from './theme.ts';
3
3
  interface UseGlideDepositProps {
4
4
  app: string;
5
- recipient?: Hex;
5
+ recipient?: string;
6
6
  preferGaslessPayment?: boolean;
7
7
  mode?: "deposit" | "withdraw";
8
8
  sessionMetadata?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paywithglide/glide-react",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"