@paywithglide/glide-react 0.0.9 → 0.0.10

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.
@@ -81,6 +81,7 @@ export type GlideDepositOptions = {
81
81
  amount?: string;
82
82
  preferGaslessPayment?: boolean;
83
83
  walletProvider?: GlideDepositWalletProvider;
84
+ onSuccess?: (hash: Hex) => void;
84
85
  baseUrl?: string;
85
86
  };
86
87
  export declare class GlideDeposit {
package/dist/glide.js CHANGED
@@ -1,12 +1,12 @@
1
- var P = Object.defineProperty;
2
- var D = (i, e, t) => e in i ? P(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var p = (i, e, t) => D(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { useMemo as v } from "react";
5
- class b {
6
- constructor(e) {
1
+ var E = Object.defineProperty;
2
+ var I = (i, t, e) => t in i ? E(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
3
+ var p = (i, t, e) => I(i, typeof t != "symbol" ? t + "" : t, e);
4
+ import { useMemo as P } from "react";
5
+ class D {
6
+ constructor(t) {
7
7
  p(this, "opts");
8
8
  p(this, "open", () => {
9
- var e, t, s, o;
9
+ var t, e, s, o;
10
10
  if (!document.body.classList.contains("glide-deposit-open")) {
11
11
  if (document.body.classList.add("glide-deposit-open"), this.opts.mode === "deposit" && !this.opts.recipient)
12
12
  throw new Error("recipient is required for deposit mode");
@@ -14,16 +14,19 @@ class b {
14
14
  throw new Error(
15
15
  "walletProvider.signTypedDataAsync is required when preferGaslessPayment=true"
16
16
  );
17
- const r = this.opts.recipient, n = (e = this.opts.walletProvider) == null ? void 0 : e.address, d = (t = this.opts.walletProvider) == null ? void 0 : t.availableChainIds, l = (s = this.opts.walletProvider) == null ? void 0 : s.currentChainId, c = this.opts.preferGaslessPayment || !!((o = this.opts.walletProvider) != null && o.signTypedDataAsync);
17
+ const r = this.opts.recipient, a = (t = this.opts.walletProvider) == null ? void 0 : t.address, d = (e = this.opts.walletProvider) == null ? void 0 : e.availableChainIds, l = (s = this.opts.walletProvider) == null ? void 0 : s.currentChainId, c = this.opts.preferGaslessPayment || !!((o = this.opts.walletProvider) != null && o.signTypedDataAsync);
18
18
  this.openUrl(
19
- `${this.baseUrl}${this.opts.app}?embed=true${r ? `&recipient=${r}` : ""}${n ? `&connectedWalletAddress=${n}` : ""}${l ? `&currentChainId=${l}` : ""}${d ? `&availableChainIds=${d.join(",")}` : ""}${c ? "&preferGaslessPayment=true" : ""}${this.opts.mode ? `&mode=${this.opts.mode}` : ""}${this.opts.amount ? `&amount=${this.opts.amount}` : ""}`
19
+ `${this.baseUrl}${this.opts.app}?embed=true${r ? `&recipient=${r}` : ""}${a ? `&connectedWalletAddress=${a}` : ""}${l ? `&currentChainId=${l}` : ""}${d ? `&availableChainIds=${d.join(",")}` : ""}${c ? "&preferGaslessPayment=true" : ""}${this.opts.mode ? `&mode=${this.opts.mode}` : ""}${this.opts.amount ? `&amount=${this.opts.amount}` : ""}`
20
20
  ), this.initialize();
21
21
  }
22
22
  });
23
- p(this, "iframeEventHandler", async (e) => {
24
- var s, o, r, n, d, l, c, h, m, y, w, u, f, g;
25
- const t = e.data;
26
- switch (t.type) {
23
+ p(this, "iframeEventHandler", async (t) => {
24
+ var s, o, r, a, d, l, c, h, m, y, w, u, f, g, v, b;
25
+ const e = t.data;
26
+ switch (e.type) {
27
+ case "success":
28
+ (o = (s = this.opts) == null ? void 0 : s.onSuccess) == null || o.call(s, e.hash);
29
+ break;
27
30
  case "close":
28
31
  this.removeIframe(), this.hideLoader(), this.destroy();
29
32
  break;
@@ -32,21 +35,21 @@ class b {
32
35
  throw new Error("walletProvider is not set");
33
36
  try {
34
37
  await this.opts.walletProvider.switchChainAsync({
35
- chainId: t.chainId
36
- }), (o = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || o.postMessage(
38
+ chainId: e.chainId
39
+ }), (a = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || a.postMessage(
37
40
  {
38
41
  type: "didSwitchChain",
39
42
  success: !0,
40
- chainId: t.chainId
43
+ chainId: e.chainId
41
44
  },
42
45
  this.baseUrl
43
46
  );
44
- } catch (a) {
45
- (n = (r = this.iframe) == null ? void 0 : r.contentWindow) == null || n.postMessage(
47
+ } catch (n) {
48
+ (l = (d = this.iframe) == null ? void 0 : d.contentWindow) == null || l.postMessage(
46
49
  {
47
50
  type: "didSwitchChain",
48
51
  success: !1,
49
- error: a
52
+ error: n
50
53
  },
51
54
  this.baseUrl
52
55
  );
@@ -57,23 +60,23 @@ class b {
57
60
  if (!this.opts.walletProvider)
58
61
  throw new Error("walletProvider is not set");
59
62
  try {
60
- const a = await this.opts.walletProvider.sendTransactionAsync(
61
- t.tx
63
+ const n = await this.opts.walletProvider.sendTransactionAsync(
64
+ e.tx
62
65
  );
63
- (l = (d = this.iframe) == null ? void 0 : d.contentWindow) == null || l.postMessage(
66
+ (h = (c = this.iframe) == null ? void 0 : c.contentWindow) == null || h.postMessage(
64
67
  {
65
68
  type: "didSendTransaction",
66
69
  success: !0,
67
- txHash: a
70
+ txHash: n
68
71
  },
69
72
  this.baseUrl
70
73
  );
71
- } catch (a) {
72
- (h = (c = this.iframe) == null ? void 0 : c.contentWindow) == null || h.postMessage(
74
+ } catch (n) {
75
+ (y = (m = this.iframe) == null ? void 0 : m.contentWindow) == null || y.postMessage(
73
76
  {
74
77
  type: "didSendTransaction",
75
78
  success: !1,
76
- error: a
79
+ error: n
77
80
  },
78
81
  this.baseUrl
79
82
  );
@@ -85,7 +88,7 @@ class b {
85
88
  if (!this.opts.walletProvider)
86
89
  throw new Error("walletProvider is not set");
87
90
  if (!this.opts.walletProvider.signTypedDataAsync) {
88
- (y = (m = this.iframe) == null ? void 0 : m.contentWindow) == null || y.postMessage(
91
+ (u = (w = this.iframe) == null ? void 0 : w.contentWindow) == null || u.postMessage(
89
92
  {
90
93
  type: "didSignTypedData",
91
94
  success: !1,
@@ -96,23 +99,23 @@ class b {
96
99
  return;
97
100
  }
98
101
  try {
99
- const a = await this.opts.walletProvider.signTypedDataAsync(
100
- t.data
102
+ const n = await this.opts.walletProvider.signTypedDataAsync(
103
+ e.data
101
104
  );
102
- (u = (w = this.iframe) == null ? void 0 : w.contentWindow) == null || u.postMessage(
105
+ (g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
103
106
  {
104
107
  type: "didSignTypedData",
105
108
  success: !0,
106
- signature: a
109
+ signature: n
107
110
  },
108
111
  this.baseUrl
109
112
  );
110
- } catch (a) {
111
- (g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
113
+ } catch (n) {
114
+ (b = (v = this.iframe) == null ? void 0 : v.contentWindow) == null || b.postMessage(
112
115
  {
113
116
  type: "didSignTypedData",
114
117
  success: !1,
115
- error: a
118
+ error: n
116
119
  },
117
120
  this.baseUrl
118
121
  );
@@ -121,7 +124,7 @@ class b {
121
124
  break;
122
125
  }
123
126
  });
124
- this.opts = e;
127
+ this.opts = t;
125
128
  }
126
129
  initialize() {
127
130
  window.addEventListener("message", this.iframeEventHandler);
@@ -135,73 +138,85 @@ class b {
135
138
  get iframe() {
136
139
  return document.getElementById("glide-deposit-iframe");
137
140
  }
138
- openUrl(e) {
139
- this.showLoader(), this.createIframe(e);
141
+ openUrl(t) {
142
+ this.showLoader(), this.createIframe(t);
140
143
  }
141
- createIframe(e) {
144
+ createIframe(t) {
142
145
  this.removeIframe();
143
- const t = document.createElement("iframe");
144
- t.id = "glide-deposit-iframe", t.setAttribute(
146
+ const e = document.createElement("iframe");
147
+ e.id = "glide-deposit-iframe", e.setAttribute(
145
148
  "style",
146
149
  "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%;"
147
- ), t.src = e, t.allow = "payment *; clipboard-write *", document.body.appendChild(t), window.setTimeout(() => {
150
+ ), e.src = t, e.allow = "payment *; clipboard-write *", document.body.appendChild(e), window.setTimeout(() => {
148
151
  var s;
149
- (s = t == null ? void 0 : t.contentWindow) == null || s.focus();
152
+ (s = e == null ? void 0 : e.contentWindow) == null || s.focus();
150
153
  }, 100);
151
154
  }
152
155
  removeIframe() {
153
- const e = document.getElementById("glide-deposit-iframe");
154
- e && (e.remove(), document.body.classList.remove("glide-deposit-open"));
156
+ const t = document.getElementById("glide-deposit-iframe");
157
+ t && (t.remove(), document.body.classList.remove("glide-deposit-open"));
155
158
  }
156
159
  showLoader() {
157
- const e = document.createElement("style");
158
- e.innerHTML = "@keyframes pulse { 0% { opacity: 1; transform: scale(0.1); } 100% { opacity: 0; transform: scale(1); } }", document.head.appendChild(e);
159
- const t = document.createElement("div");
160
- t.setAttribute("class", "glide-deposit-loader");
160
+ const t = document.createElement("style");
161
+ t.innerHTML = "@keyframes pulse { 0% { opacity: 1; transform: scale(0.1); } 100% { opacity: 0; transform: scale(1); } }", document.head.appendChild(t);
162
+ const e = document.createElement("div");
163
+ e.setAttribute("class", "glide-deposit-loader");
161
164
  const s = document.createElement("main");
162
165
  s.setAttribute(
163
166
  "style",
164
167
  "display: flex; align-items: center; justify-content: center; flex-direction: column; width: 100%; height: 100%;"
165
- ), t.appendChild(s), document.body.appendChild(t);
168
+ ), e.appendChild(s), document.body.appendChild(e);
166
169
  }
167
170
  hideLoader() {
168
- document.querySelectorAll(".glide-deposit-loader").forEach((e) => e.remove());
171
+ document.querySelectorAll(".glide-deposit-loader").forEach((t) => t.remove());
169
172
  }
170
173
  }
171
- const T = ({
174
+ const x = ({
172
175
  app: i,
173
- recipient: e,
174
- preferGaslessPayment: t,
176
+ recipient: t,
177
+ preferGaslessPayment: e,
175
178
  mode: s,
176
179
  walletProvider: o,
177
- baseUrl: r
180
+ onSuccess: r,
181
+ baseUrl: a
178
182
  }) => ({
179
- openGlideDeposit: v(() => new b({
183
+ openGlideDeposit: P(() => new D({
180
184
  app: i,
181
- recipient: e,
182
- preferGaslessPayment: t,
185
+ recipient: t,
186
+ preferGaslessPayment: e,
183
187
  mode: s,
184
188
  walletProvider: o,
185
- baseUrl: r
186
- }), [i, e, t, s, o, r]).open
187
- }), $ = ({
189
+ onSuccess: r,
190
+ baseUrl: a
191
+ }), [
192
+ i,
193
+ t,
194
+ e,
195
+ s,
196
+ o,
197
+ r,
198
+ a
199
+ ]).open
200
+ }), A = ({
188
201
  app: i,
189
- preferGaslessPayment: e,
190
- amount: t,
202
+ preferGaslessPayment: t,
203
+ amount: e,
191
204
  walletProvider: s,
192
- baseUrl: o
205
+ onSuccess: o,
206
+ baseUrl: r
193
207
  }) => ({
194
- openGlidePay: v(() => new b({
208
+ openGlidePay: P(() => new D({
195
209
  app: i,
196
- preferGaslessPayment: e,
210
+ preferGaslessPayment: t,
197
211
  mode: "pay",
198
- amount: t,
212
+ amount: e,
199
213
  walletProvider: s,
200
- baseUrl: o
201
- }), [i, e, s, o, t]).open
214
+ onSuccess: o,
215
+ baseUrl: r
216
+ }), [i, t, s, r, e, o]).open
202
217
  });
203
218
  export {
204
- b as GlideDeposit,
205
- T as useGlideDeposit,
206
- $ as useGlidePay
219
+ D as GlideDeposit,
220
+ x as useGlideDeposit,
221
+ A as useGlidePay
207
222
  };
@@ -5,9 +5,10 @@ interface UseGlideDepositProps {
5
5
  preferGaslessPayment?: boolean;
6
6
  mode?: "deposit" | "withdraw";
7
7
  walletProvider?: GlideDepositWalletProvider;
8
+ onSuccess?: (hash: Hex) => void;
8
9
  baseUrl?: string;
9
10
  }
10
- export declare const useGlideDeposit: ({ app, recipient, preferGaslessPayment, mode, walletProvider, baseUrl, }: UseGlideDepositProps) => {
11
+ export declare const useGlideDeposit: ({ app, recipient, preferGaslessPayment, mode, walletProvider, onSuccess, baseUrl, }: UseGlideDepositProps) => {
11
12
  openGlideDeposit: () => void;
12
13
  };
13
14
  export {};
@@ -1,12 +1,14 @@
1
1
  import { GlideDepositWalletProvider } from './GlideDeposit.ts';
2
+ import { Hex } from 'viem';
2
3
  interface UseGlidePayProps {
3
4
  app: string;
4
5
  preferGaslessPayment?: boolean;
5
6
  amount: string;
6
7
  walletProvider?: GlideDepositWalletProvider;
8
+ onSuccess?: (hash: Hex) => void;
7
9
  baseUrl?: string;
8
10
  }
9
- export declare const useGlidePay: ({ app, preferGaslessPayment, amount, walletProvider, baseUrl, }: UseGlidePayProps) => {
11
+ export declare const useGlidePay: ({ app, preferGaslessPayment, amount, walletProvider, onSuccess, baseUrl, }: UseGlidePayProps) => {
10
12
  openGlidePay: () => void;
11
13
  };
12
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paywithglide/glide-react",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"