@paywithglide/glide-react 0.0.3 → 0.0.5
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 +4 -3
- package/dist/glide.js +52 -50
- package/dist/useGlideDeposit.d.ts +4 -2
- package/package.json +2 -1
package/dist/GlideDeposit.d.ts
CHANGED
|
@@ -77,16 +77,17 @@ export type GlideDepositWalletProvider = {
|
|
|
77
77
|
export type GlideDepositOptions = {
|
|
78
78
|
app: string;
|
|
79
79
|
recipient?: Hex;
|
|
80
|
+
mode?: "deposit" | "withdraw";
|
|
81
|
+
preferGaslessPayment?: boolean;
|
|
80
82
|
walletProvider?: GlideDepositWalletProvider;
|
|
81
83
|
baseUrl?: string;
|
|
82
84
|
};
|
|
83
85
|
export declare class GlideDeposit {
|
|
84
86
|
opts: GlideDepositOptions;
|
|
85
87
|
constructor(opts: GlideDepositOptions);
|
|
86
|
-
private didInit;
|
|
87
|
-
initialize(): void;
|
|
88
|
-
destroy(): void;
|
|
89
88
|
open: () => void;
|
|
89
|
+
private initialize;
|
|
90
|
+
private destroy;
|
|
90
91
|
private get baseUrl();
|
|
91
92
|
private get iframe();
|
|
92
93
|
private iframeEventHandler;
|
package/dist/glide.js
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
var v = Object.defineProperty;
|
|
2
|
-
var b = (
|
|
3
|
-
var
|
|
4
|
-
import { useMemo as
|
|
5
|
-
class
|
|
2
|
+
var b = (i, e, t) => e in i ? v(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var p = (i, e, t) => b(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { useMemo as P } from "react";
|
|
5
|
+
class E {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var e, t, s, i;
|
|
7
|
+
p(this, "opts");
|
|
8
|
+
p(this, "open", () => {
|
|
9
|
+
var e, t, s, o;
|
|
11
10
|
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
|
-
|
|
11
|
+
if (document.body.classList.add("glide-deposit-open"), this.opts.mode === "deposit" && !this.opts.recipient)
|
|
12
|
+
throw new Error("recipient is required for deposit mode");
|
|
13
|
+
if (this.opts.preferGaslessPayment && this.opts.walletProvider && !this.opts.walletProvider.signTypedDataAsync)
|
|
14
|
+
throw new Error(
|
|
15
|
+
"walletProvider.signTypedDataAsync is required when preferGaslessPayment=true"
|
|
16
|
+
);
|
|
17
|
+
const a = 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);
|
|
15
18
|
this.openUrl(
|
|
16
|
-
`${this.baseUrl}${this.opts.app}?recipient=${
|
|
17
|
-
);
|
|
19
|
+
`${this.baseUrl}${this.opts.app}?embed=true${a ? `&recipient=${a}` : ""}${n ? `&connectedWalletAddress=${n}` : ""}${l ? `¤tChainId=${l}` : ""}${d ? `&availableChainIds=${d.join(",")}` : ""}${c ? "&preferGaslessPayment=true" : ""}${this.opts.mode ? `&mode=${this.opts.mode}` : ""}`
|
|
20
|
+
), this.initialize();
|
|
18
21
|
}
|
|
19
22
|
});
|
|
20
|
-
|
|
21
|
-
var s,
|
|
23
|
+
p(this, "iframeEventHandler", async (e) => {
|
|
24
|
+
var s, o, a, n, d, l, c, h, m, y, w, u, f, g;
|
|
22
25
|
const t = e.data;
|
|
23
26
|
switch (t.type) {
|
|
24
27
|
case "close":
|
|
25
|
-
this.removeIframe(), this.hideLoader();
|
|
28
|
+
this.removeIframe(), this.hideLoader(), this.destroy();
|
|
26
29
|
break;
|
|
27
30
|
case "switchChain":
|
|
28
31
|
if (!this.opts.walletProvider)
|
|
@@ -30,7 +33,7 @@ class P {
|
|
|
30
33
|
try {
|
|
31
34
|
await this.opts.walletProvider.switchChainAsync({
|
|
32
35
|
chainId: t.chainId
|
|
33
|
-
}), (
|
|
36
|
+
}), (o = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || o.postMessage(
|
|
34
37
|
{
|
|
35
38
|
type: "didSwitchChain",
|
|
36
39
|
success: !0,
|
|
@@ -38,12 +41,12 @@ class P {
|
|
|
38
41
|
},
|
|
39
42
|
this.baseUrl
|
|
40
43
|
);
|
|
41
|
-
} catch (
|
|
42
|
-
(n = (
|
|
44
|
+
} catch (r) {
|
|
45
|
+
(n = (a = this.iframe) == null ? void 0 : a.contentWindow) == null || n.postMessage(
|
|
43
46
|
{
|
|
44
47
|
type: "didSwitchChain",
|
|
45
48
|
success: !1,
|
|
46
|
-
error:
|
|
49
|
+
error: r
|
|
47
50
|
},
|
|
48
51
|
this.baseUrl
|
|
49
52
|
);
|
|
@@ -54,23 +57,23 @@ class P {
|
|
|
54
57
|
if (!this.opts.walletProvider)
|
|
55
58
|
throw new Error("walletProvider is not set");
|
|
56
59
|
try {
|
|
57
|
-
const
|
|
60
|
+
const r = await this.opts.walletProvider.sendTransactionAsync(
|
|
58
61
|
t.tx
|
|
59
62
|
);
|
|
60
|
-
(
|
|
63
|
+
(l = (d = this.iframe) == null ? void 0 : d.contentWindow) == null || l.postMessage(
|
|
61
64
|
{
|
|
62
65
|
type: "didSendTransaction",
|
|
63
66
|
success: !0,
|
|
64
|
-
txHash:
|
|
67
|
+
txHash: r
|
|
65
68
|
},
|
|
66
69
|
this.baseUrl
|
|
67
70
|
);
|
|
68
|
-
} catch (
|
|
69
|
-
(h = (
|
|
71
|
+
} catch (r) {
|
|
72
|
+
(h = (c = this.iframe) == null ? void 0 : c.contentWindow) == null || h.postMessage(
|
|
70
73
|
{
|
|
71
74
|
type: "didSendTransaction",
|
|
72
75
|
success: !1,
|
|
73
|
-
error:
|
|
76
|
+
error: r
|
|
74
77
|
},
|
|
75
78
|
this.baseUrl
|
|
76
79
|
);
|
|
@@ -93,23 +96,23 @@ class P {
|
|
|
93
96
|
return;
|
|
94
97
|
}
|
|
95
98
|
try {
|
|
96
|
-
const
|
|
99
|
+
const r = await this.opts.walletProvider.signTypedDataAsync(
|
|
97
100
|
t.data
|
|
98
101
|
);
|
|
99
|
-
(
|
|
102
|
+
(u = (w = this.iframe) == null ? void 0 : w.contentWindow) == null || u.postMessage(
|
|
100
103
|
{
|
|
101
104
|
type: "didSignTypedData",
|
|
102
105
|
success: !0,
|
|
103
|
-
signature:
|
|
106
|
+
signature: r
|
|
104
107
|
},
|
|
105
108
|
this.baseUrl
|
|
106
109
|
);
|
|
107
|
-
} catch (
|
|
110
|
+
} catch (r) {
|
|
108
111
|
(g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
|
|
109
112
|
{
|
|
110
113
|
type: "didSignTypedData",
|
|
111
114
|
success: !1,
|
|
112
|
-
error:
|
|
115
|
+
error: r
|
|
113
116
|
},
|
|
114
117
|
this.baseUrl
|
|
115
118
|
);
|
|
@@ -121,7 +124,7 @@ class P {
|
|
|
121
124
|
this.opts = e;
|
|
122
125
|
}
|
|
123
126
|
initialize() {
|
|
124
|
-
|
|
127
|
+
window.addEventListener("message", this.iframeEventHandler);
|
|
125
128
|
}
|
|
126
129
|
destroy() {
|
|
127
130
|
window.removeEventListener("message", this.iframeEventHandler);
|
|
@@ -165,25 +168,24 @@ class P {
|
|
|
165
168
|
document.querySelectorAll(".glide-deposit-loader").forEach((e) => e.remove());
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
|
-
const
|
|
169
|
-
app:
|
|
171
|
+
const D = ({
|
|
172
|
+
app: i,
|
|
170
173
|
recipient: e,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
preferGaslessPayment: t,
|
|
175
|
+
mode: s,
|
|
176
|
+
walletProvider: o,
|
|
177
|
+
baseUrl: a
|
|
178
|
+
}) => ({
|
|
179
|
+
openGlideDeposit: P(() => new E({
|
|
180
|
+
app: i,
|
|
176
181
|
recipient: e,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
openGlideDeposit: i.open
|
|
184
|
-
};
|
|
185
|
-
};
|
|
182
|
+
preferGaslessPayment: t,
|
|
183
|
+
mode: s,
|
|
184
|
+
walletProvider: o,
|
|
185
|
+
baseUrl: a
|
|
186
|
+
}), [i, e, t, s, o, a]).open
|
|
187
|
+
});
|
|
186
188
|
export {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
E as GlideDeposit,
|
|
190
|
+
D as useGlideDeposit
|
|
189
191
|
};
|
|
@@ -2,10 +2,12 @@ import { GlideDepositWalletProvider, Hex } from './GlideDeposit.ts';
|
|
|
2
2
|
interface UseGlideDepositProps {
|
|
3
3
|
app: string;
|
|
4
4
|
recipient?: Hex;
|
|
5
|
-
|
|
5
|
+
preferGaslessPayment?: boolean;
|
|
6
|
+
mode?: "deposit" | "withdraw";
|
|
7
|
+
walletProvider?: GlideDepositWalletProvider;
|
|
6
8
|
baseUrl?: string;
|
|
7
9
|
}
|
|
8
|
-
export declare const useGlideDeposit: ({ app, recipient, walletProvider, baseUrl, }: UseGlideDepositProps) => {
|
|
10
|
+
export declare const useGlideDeposit: ({ app, recipient, preferGaslessPayment, mode, walletProvider, baseUrl, }: UseGlideDepositProps) => {
|
|
9
11
|
openGlideDeposit: () => void;
|
|
10
12
|
};
|
|
11
13
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paywithglide/glide-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
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",
|