@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.
- package/dist/GlideDeposit.d.ts +1 -0
- package/dist/glide.js +86 -71
- package/dist/useGlideDeposit.d.ts +2 -1
- package/dist/useGlidePay.d.ts +3 -1
- package/package.json +1 -1
package/dist/GlideDeposit.d.ts
CHANGED
package/dist/glide.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var p = (i,
|
|
4
|
-
import { useMemo as
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
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
|
|
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,
|
|
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}` : ""}${
|
|
19
|
+
`${this.baseUrl}${this.opts.app}?embed=true${r ? `&recipient=${r}` : ""}${a ? `&connectedWalletAddress=${a}` : ""}${l ? `¤tChainId=${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 (
|
|
24
|
-
var s, o, r,
|
|
25
|
-
const
|
|
26
|
-
switch (
|
|
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:
|
|
36
|
-
}), (
|
|
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:
|
|
43
|
+
chainId: e.chainId
|
|
41
44
|
},
|
|
42
45
|
this.baseUrl
|
|
43
46
|
);
|
|
44
|
-
} catch (
|
|
45
|
-
(
|
|
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:
|
|
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
|
|
61
|
-
|
|
63
|
+
const n = await this.opts.walletProvider.sendTransactionAsync(
|
|
64
|
+
e.tx
|
|
62
65
|
);
|
|
63
|
-
(
|
|
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:
|
|
70
|
+
txHash: n
|
|
68
71
|
},
|
|
69
72
|
this.baseUrl
|
|
70
73
|
);
|
|
71
|
-
} catch (
|
|
72
|
-
(
|
|
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:
|
|
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
|
-
(
|
|
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
|
|
100
|
-
|
|
102
|
+
const n = await this.opts.walletProvider.signTypedDataAsync(
|
|
103
|
+
e.data
|
|
101
104
|
);
|
|
102
|
-
(
|
|
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:
|
|
109
|
+
signature: n
|
|
107
110
|
},
|
|
108
111
|
this.baseUrl
|
|
109
112
|
);
|
|
110
|
-
} catch (
|
|
111
|
-
(
|
|
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:
|
|
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 =
|
|
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(
|
|
139
|
-
this.showLoader(), this.createIframe(
|
|
141
|
+
openUrl(t) {
|
|
142
|
+
this.showLoader(), this.createIframe(t);
|
|
140
143
|
}
|
|
141
|
-
createIframe(
|
|
144
|
+
createIframe(t) {
|
|
142
145
|
this.removeIframe();
|
|
143
|
-
const
|
|
144
|
-
|
|
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
|
-
),
|
|
150
|
+
), e.src = t, e.allow = "payment *; clipboard-write *", document.body.appendChild(e), window.setTimeout(() => {
|
|
148
151
|
var s;
|
|
149
|
-
(s =
|
|
152
|
+
(s = e == null ? void 0 : e.contentWindow) == null || s.focus();
|
|
150
153
|
}, 100);
|
|
151
154
|
}
|
|
152
155
|
removeIframe() {
|
|
153
|
-
const
|
|
154
|
-
|
|
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
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
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
|
-
),
|
|
168
|
+
), e.appendChild(s), document.body.appendChild(e);
|
|
166
169
|
}
|
|
167
170
|
hideLoader() {
|
|
168
|
-
document.querySelectorAll(".glide-deposit-loader").forEach((
|
|
171
|
+
document.querySelectorAll(".glide-deposit-loader").forEach((t) => t.remove());
|
|
169
172
|
}
|
|
170
173
|
}
|
|
171
|
-
const
|
|
174
|
+
const x = ({
|
|
172
175
|
app: i,
|
|
173
|
-
recipient:
|
|
174
|
-
preferGaslessPayment:
|
|
176
|
+
recipient: t,
|
|
177
|
+
preferGaslessPayment: e,
|
|
175
178
|
mode: s,
|
|
176
179
|
walletProvider: o,
|
|
177
|
-
|
|
180
|
+
onSuccess: r,
|
|
181
|
+
baseUrl: a
|
|
178
182
|
}) => ({
|
|
179
|
-
openGlideDeposit:
|
|
183
|
+
openGlideDeposit: P(() => new D({
|
|
180
184
|
app: i,
|
|
181
|
-
recipient:
|
|
182
|
-
preferGaslessPayment:
|
|
185
|
+
recipient: t,
|
|
186
|
+
preferGaslessPayment: e,
|
|
183
187
|
mode: s,
|
|
184
188
|
walletProvider: o,
|
|
185
|
-
|
|
186
|
-
|
|
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:
|
|
190
|
-
amount:
|
|
202
|
+
preferGaslessPayment: t,
|
|
203
|
+
amount: e,
|
|
191
204
|
walletProvider: s,
|
|
192
|
-
|
|
205
|
+
onSuccess: o,
|
|
206
|
+
baseUrl: r
|
|
193
207
|
}) => ({
|
|
194
|
-
openGlidePay:
|
|
208
|
+
openGlidePay: P(() => new D({
|
|
195
209
|
app: i,
|
|
196
|
-
preferGaslessPayment:
|
|
210
|
+
preferGaslessPayment: t,
|
|
197
211
|
mode: "pay",
|
|
198
|
-
amount:
|
|
212
|
+
amount: e,
|
|
199
213
|
walletProvider: s,
|
|
200
|
-
|
|
201
|
-
|
|
214
|
+
onSuccess: o,
|
|
215
|
+
baseUrl: r
|
|
216
|
+
}), [i, t, s, r, e, o]).open
|
|
202
217
|
});
|
|
203
218
|
export {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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 {};
|
package/dist/useGlidePay.d.ts
CHANGED
|
@@ -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 {};
|