@paywithglide/glide-react 0.0.3 → 0.0.4

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,6 +77,7 @@ export type GlideDepositWalletProvider = {
77
77
  export type GlideDepositOptions = {
78
78
  app: string;
79
79
  recipient?: Hex;
80
+ mode: "deposit" | "withdraw";
80
81
  walletProvider?: GlideDepositWalletProvider;
81
82
  baseUrl?: string;
82
83
  };
package/dist/glide.js CHANGED
@@ -1,24 +1,24 @@
1
1
  var v = Object.defineProperty;
2
- var b = (r, e, t) => e in r ? v(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var c = (r, e, t) => b(r, typeof e != "symbol" ? e + "" : e, t);
2
+ var b = (o, e, t) => e in o ? v(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var l = (o, e, t) => b(o, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { useMemo as I, useEffect as E } from "react";
5
5
  class P {
6
6
  constructor(e) {
7
- c(this, "opts");
8
- c(this, "didInit", !1);
9
- c(this, "open", () => {
10
- var e, t, s, i;
7
+ l(this, "opts");
8
+ l(this, "didInit", !1);
9
+ l(this, "open", () => {
10
+ var e, t, s, a;
11
11
  if (!document.body.classList.contains("glide-deposit-open")) {
12
- if (document.body.classList.add("glide-deposit-open"), !this.opts.recipient)
13
- throw new Error("recipient is required");
14
- const l = this.opts.recipient, n = (e = this.opts.walletProvider) == null ? void 0 : e.address, o = (t = this.opts.walletProvider) == null ? void 0 : t.availableChainIds, d = (s = this.opts.walletProvider) == null ? void 0 : s.currentChainId, p = !!((i = this.opts.walletProvider) != null && i.signTypedDataAsync);
12
+ if (document.body.classList.add("glide-deposit-open"), this.opts.mode === "deposit" && !this.opts.recipient)
13
+ throw new Error("recipient is required for deposit mode");
14
+ const i = this.opts.recipient, n = (e = this.opts.walletProvider) == null ? void 0 : e.address, d = (t = this.opts.walletProvider) == null ? void 0 : t.availableChainIds, c = (s = this.opts.walletProvider) == null ? void 0 : s.currentChainId, p = !!((a = this.opts.walletProvider) != null && a.signTypedDataAsync);
15
15
  this.openUrl(
16
- `${this.baseUrl}${this.opts.app}?recipient=${l}&embed=true${n ? `&connectedWalletAddress=${n}` : ""}${d ? `&currentChainId=${d}` : ""}${o ? `&availableChainIds=${o.join(",")}` : ""}${p ? "&preferGaslessPayment=true" : ""}`
16
+ `${this.baseUrl}${this.opts.app}?embed=true${i ? `&recipient=${i}` : ""}${n ? `&connectedWalletAddress=${n}` : ""}${c ? `&currentChainId=${c}` : ""}${d ? `&availableChainIds=${d.join(",")}` : ""}${p ? "&preferGaslessPayment=true" : ""}&mode=${this.opts.mode}`
17
17
  );
18
18
  }
19
19
  });
20
- c(this, "iframeEventHandler", async (e) => {
21
- var s, i, l, n, o, d, p, h, m, y, u, w, f, g;
20
+ l(this, "iframeEventHandler", async (e) => {
21
+ var s, a, i, n, d, c, p, h, m, y, u, w, f, g;
22
22
  const t = e.data;
23
23
  switch (t.type) {
24
24
  case "close":
@@ -30,7 +30,7 @@ class P {
30
30
  try {
31
31
  await this.opts.walletProvider.switchChainAsync({
32
32
  chainId: t.chainId
33
- }), (i = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || i.postMessage(
33
+ }), (a = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || a.postMessage(
34
34
  {
35
35
  type: "didSwitchChain",
36
36
  success: !0,
@@ -38,12 +38,12 @@ class P {
38
38
  },
39
39
  this.baseUrl
40
40
  );
41
- } catch (a) {
42
- (n = (l = this.iframe) == null ? void 0 : l.contentWindow) == null || n.postMessage(
41
+ } catch (r) {
42
+ (n = (i = this.iframe) == null ? void 0 : i.contentWindow) == null || n.postMessage(
43
43
  {
44
44
  type: "didSwitchChain",
45
45
  success: !1,
46
- error: a
46
+ error: r
47
47
  },
48
48
  this.baseUrl
49
49
  );
@@ -54,23 +54,23 @@ class P {
54
54
  if (!this.opts.walletProvider)
55
55
  throw new Error("walletProvider is not set");
56
56
  try {
57
- const a = await this.opts.walletProvider.sendTransactionAsync(
57
+ const r = await this.opts.walletProvider.sendTransactionAsync(
58
58
  t.tx
59
59
  );
60
- (d = (o = this.iframe) == null ? void 0 : o.contentWindow) == null || d.postMessage(
60
+ (c = (d = this.iframe) == null ? void 0 : d.contentWindow) == null || c.postMessage(
61
61
  {
62
62
  type: "didSendTransaction",
63
63
  success: !0,
64
- txHash: a
64
+ txHash: r
65
65
  },
66
66
  this.baseUrl
67
67
  );
68
- } catch (a) {
68
+ } catch (r) {
69
69
  (h = (p = this.iframe) == null ? void 0 : p.contentWindow) == null || h.postMessage(
70
70
  {
71
71
  type: "didSendTransaction",
72
72
  success: !1,
73
- error: a
73
+ error: r
74
74
  },
75
75
  this.baseUrl
76
76
  );
@@ -93,23 +93,23 @@ class P {
93
93
  return;
94
94
  }
95
95
  try {
96
- const a = await this.opts.walletProvider.signTypedDataAsync(
96
+ const r = await this.opts.walletProvider.signTypedDataAsync(
97
97
  t.data
98
98
  );
99
99
  (w = (u = this.iframe) == null ? void 0 : u.contentWindow) == null || w.postMessage(
100
100
  {
101
101
  type: "didSignTypedData",
102
102
  success: !0,
103
- signature: a
103
+ signature: r
104
104
  },
105
105
  this.baseUrl
106
106
  );
107
- } catch (a) {
107
+ } catch (r) {
108
108
  (g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
109
109
  {
110
110
  type: "didSignTypedData",
111
111
  success: !1,
112
- error: a
112
+ error: r
113
113
  },
114
114
  this.baseUrl
115
115
  );
@@ -166,17 +166,19 @@ class P {
166
166
  }
167
167
  }
168
168
  const T = ({
169
- app: r,
169
+ app: o,
170
170
  recipient: e,
171
- walletProvider: t,
172
- baseUrl: s
171
+ mode: t = "deposit",
172
+ walletProvider: s,
173
+ baseUrl: a
173
174
  }) => {
174
175
  const i = I(() => new P({
175
- app: r,
176
+ app: o,
176
177
  recipient: e,
177
- walletProvider: t,
178
- baseUrl: s
179
- }), [r, e, t, s]);
178
+ mode: t,
179
+ walletProvider: s,
180
+ baseUrl: a
181
+ }), [o, e, t, s, a]);
180
182
  return E(() => (i.initialize(), () => {
181
183
  i.destroy();
182
184
  }), [i]), {
@@ -2,10 +2,11 @@ import { GlideDepositWalletProvider, Hex } from './GlideDeposit.ts';
2
2
  interface UseGlideDepositProps {
3
3
  app: string;
4
4
  recipient?: Hex;
5
+ mode?: "deposit" | "withdraw";
5
6
  walletProvider: GlideDepositWalletProvider;
6
7
  baseUrl?: string;
7
8
  }
8
- export declare const useGlideDeposit: ({ app, recipient, walletProvider, baseUrl, }: UseGlideDepositProps) => {
9
+ export declare const useGlideDeposit: ({ app, recipient, mode, walletProvider, baseUrl, }: UseGlideDepositProps) => {
9
10
  openGlideDeposit: () => void;
10
11
  };
11
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paywithglide/glide-react",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -23,6 +23,7 @@
23
23
  "prepublishOnly": "npm run build"
24
24
  },
25
25
  "dependencies": {
26
+ "@paywithglide/glide-js": "^0.9.33",
26
27
  "@tanstack/react-query": "^5.61.5",
27
28
  "react": "^18.3.1",
28
29
  "react-dom": "^18.3.1",