@paywithglide/glide-react 0.0.2 → 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.
- package/dist/GlideDeposit.d.ts +60 -0
- package/dist/glide.js +86 -45
- package/dist/useGlideDeposit.d.ts +2 -1
- package/package.json +2 -1
package/dist/GlideDeposit.d.ts
CHANGED
|
@@ -6,6 +6,64 @@ export type EVMTransaction = {
|
|
|
6
6
|
data?: Hex;
|
|
7
7
|
value?: bigint;
|
|
8
8
|
};
|
|
9
|
+
export type PermitTypedData<ChainId extends Hex | bigint> = {
|
|
10
|
+
types: {
|
|
11
|
+
EIP712Domain: [
|
|
12
|
+
{
|
|
13
|
+
name: "name";
|
|
14
|
+
type: "string";
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "version";
|
|
18
|
+
type: "string";
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "chainId";
|
|
22
|
+
type: "uint256";
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "verifyingContract";
|
|
26
|
+
type: "address";
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
Permit: [
|
|
30
|
+
{
|
|
31
|
+
name: "owner";
|
|
32
|
+
type: "address";
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "spender";
|
|
36
|
+
type: "address";
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "value";
|
|
40
|
+
type: "uint256";
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "nonce";
|
|
44
|
+
type: "uint256";
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "deadline";
|
|
48
|
+
type: "uint256";
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
};
|
|
52
|
+
primaryType: "Permit";
|
|
53
|
+
domain: {
|
|
54
|
+
name: string;
|
|
55
|
+
version: string;
|
|
56
|
+
chainId: ChainId;
|
|
57
|
+
verifyingContract: Hex;
|
|
58
|
+
};
|
|
59
|
+
message: {
|
|
60
|
+
deadline: bigint;
|
|
61
|
+
nonce: bigint;
|
|
62
|
+
owner: Hex;
|
|
63
|
+
spender: Hex;
|
|
64
|
+
value: bigint;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
9
67
|
export type GlideDepositWalletProvider = {
|
|
10
68
|
address: Hex | undefined;
|
|
11
69
|
availableChainIds: number[] | undefined;
|
|
@@ -14,10 +72,12 @@ export type GlideDepositWalletProvider = {
|
|
|
14
72
|
chainId: number;
|
|
15
73
|
}) => Promise<unknown>;
|
|
16
74
|
sendTransactionAsync: (tx: EVMTransaction) => Promise<Hex>;
|
|
75
|
+
signTypedDataAsync?: (args: PermitTypedData<bigint>) => Promise<Hex>;
|
|
17
76
|
};
|
|
18
77
|
export type GlideDepositOptions = {
|
|
19
78
|
app: string;
|
|
20
79
|
recipient?: Hex;
|
|
80
|
+
mode: "deposit" | "withdraw";
|
|
21
81
|
walletProvider?: GlideDepositWalletProvider;
|
|
22
82
|
baseUrl?: string;
|
|
23
83
|
};
|
package/dist/glide.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { useMemo as
|
|
5
|
-
class
|
|
1
|
+
var v = Object.defineProperty;
|
|
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
|
+
import { useMemo as I, useEffect as E } from "react";
|
|
5
|
+
class P {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var e, t,
|
|
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
|
|
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=${
|
|
16
|
+
`${this.baseUrl}${this.opts.app}?embed=true${i ? `&recipient=${i}` : ""}${n ? `&connectedWalletAddress=${n}` : ""}${c ? `¤tChainId=${c}` : ""}${d ? `&availableChainIds=${d.join(",")}` : ""}${p ? "&preferGaslessPayment=true" : ""}&mode=${this.opts.mode}`
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
var
|
|
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 y {
|
|
|
30
30
|
try {
|
|
31
31
|
await this.opts.walletProvider.switchChainAsync({
|
|
32
32
|
chainId: t.chainId
|
|
33
|
-
}), (
|
|
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 y {
|
|
|
38
38
|
},
|
|
39
39
|
this.baseUrl
|
|
40
40
|
);
|
|
41
|
-
} catch (
|
|
42
|
-
(
|
|
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:
|
|
46
|
+
error: r
|
|
47
47
|
},
|
|
48
48
|
this.baseUrl
|
|
49
49
|
);
|
|
@@ -54,23 +54,62 @@ class y {
|
|
|
54
54
|
if (!this.opts.walletProvider)
|
|
55
55
|
throw new Error("walletProvider is not set");
|
|
56
56
|
try {
|
|
57
|
-
const
|
|
57
|
+
const r = await this.opts.walletProvider.sendTransactionAsync(
|
|
58
58
|
t.tx
|
|
59
59
|
);
|
|
60
|
-
(
|
|
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:
|
|
64
|
+
txHash: r
|
|
65
65
|
},
|
|
66
66
|
this.baseUrl
|
|
67
67
|
);
|
|
68
|
-
} catch (
|
|
69
|
-
(
|
|
68
|
+
} catch (r) {
|
|
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:
|
|
73
|
+
error: r
|
|
74
|
+
},
|
|
75
|
+
this.baseUrl
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
case "signTypedData":
|
|
81
|
+
{
|
|
82
|
+
if (!this.opts.walletProvider)
|
|
83
|
+
throw new Error("walletProvider is not set");
|
|
84
|
+
if (!this.opts.walletProvider.signTypedDataAsync) {
|
|
85
|
+
(y = (m = this.iframe) == null ? void 0 : m.contentWindow) == null || y.postMessage(
|
|
86
|
+
{
|
|
87
|
+
type: "didSignTypedData",
|
|
88
|
+
success: !1,
|
|
89
|
+
error: "signTypedDataAsync_not_implemented"
|
|
90
|
+
},
|
|
91
|
+
this.baseUrl
|
|
92
|
+
);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const r = await this.opts.walletProvider.signTypedDataAsync(
|
|
97
|
+
t.data
|
|
98
|
+
);
|
|
99
|
+
(w = (u = this.iframe) == null ? void 0 : u.contentWindow) == null || w.postMessage(
|
|
100
|
+
{
|
|
101
|
+
type: "didSignTypedData",
|
|
102
|
+
success: !0,
|
|
103
|
+
signature: r
|
|
104
|
+
},
|
|
105
|
+
this.baseUrl
|
|
106
|
+
);
|
|
107
|
+
} catch (r) {
|
|
108
|
+
(g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
|
|
109
|
+
{
|
|
110
|
+
type: "didSignTypedData",
|
|
111
|
+
success: !1,
|
|
112
|
+
error: r
|
|
74
113
|
},
|
|
75
114
|
this.baseUrl
|
|
76
115
|
);
|
|
@@ -103,8 +142,8 @@ class y {
|
|
|
103
142
|
"style",
|
|
104
143
|
"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%;"
|
|
105
144
|
), t.src = e, t.allow = "payment", document.body.appendChild(t), window.setTimeout(() => {
|
|
106
|
-
var
|
|
107
|
-
(
|
|
145
|
+
var s;
|
|
146
|
+
(s = t == null ? void 0 : t.contentWindow) == null || s.focus();
|
|
108
147
|
}, 100);
|
|
109
148
|
}
|
|
110
149
|
removeIframe() {
|
|
@@ -116,35 +155,37 @@ class y {
|
|
|
116
155
|
e.innerHTML = "@keyframes pulse { 0% { opacity: 1; transform: scale(0.1); } 100% { opacity: 0; transform: scale(1); } }", document.head.appendChild(e);
|
|
117
156
|
const t = document.createElement("div");
|
|
118
157
|
t.setAttribute("class", "glide-deposit-loader");
|
|
119
|
-
const
|
|
120
|
-
|
|
158
|
+
const s = document.createElement("main");
|
|
159
|
+
s.setAttribute(
|
|
121
160
|
"style",
|
|
122
161
|
"display: flex; align-items: center; justify-content: center; flex-direction: column; width: 100%; height: 100%;"
|
|
123
|
-
), t.appendChild(
|
|
162
|
+
), t.appendChild(s), document.body.appendChild(t);
|
|
124
163
|
}
|
|
125
164
|
hideLoader() {
|
|
126
165
|
document.querySelectorAll(".glide-deposit-loader").forEach((e) => e.remove());
|
|
127
166
|
}
|
|
128
167
|
}
|
|
129
|
-
const
|
|
130
|
-
app:
|
|
168
|
+
const T = ({
|
|
169
|
+
app: o,
|
|
131
170
|
recipient: e,
|
|
132
|
-
|
|
133
|
-
|
|
171
|
+
mode: t = "deposit",
|
|
172
|
+
walletProvider: s,
|
|
173
|
+
baseUrl: a
|
|
134
174
|
}) => {
|
|
135
|
-
const
|
|
136
|
-
app:
|
|
175
|
+
const i = I(() => new P({
|
|
176
|
+
app: o,
|
|
137
177
|
recipient: e,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
178
|
+
mode: t,
|
|
179
|
+
walletProvider: s,
|
|
180
|
+
baseUrl: a
|
|
181
|
+
}), [o, e, t, s, a]);
|
|
182
|
+
return E(() => (i.initialize(), () => {
|
|
183
|
+
i.destroy();
|
|
184
|
+
}), [i]), {
|
|
185
|
+
openGlideDeposit: i.open
|
|
145
186
|
};
|
|
146
187
|
};
|
|
147
188
|
export {
|
|
148
|
-
|
|
149
|
-
|
|
189
|
+
P as GlideDeposit,
|
|
190
|
+
T as useGlideDeposit
|
|
150
191
|
};
|
|
@@ -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
|
+
"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",
|