@paywithglide/glide-react 0.0.2 → 0.0.3

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.
@@ -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,6 +72,7 @@ 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;
package/dist/glide.js CHANGED
@@ -1,24 +1,24 @@
1
- var m = Object.defineProperty;
2
- var u = (s, e, t) => e in s ? m(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var c = (s, e, t) => u(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { useMemo as w, useEffect as f } from "react";
5
- class y {
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);
4
+ import { useMemo as I, useEffect as E } from "react";
5
+ class P {
6
6
  constructor(e) {
7
7
  c(this, "opts");
8
8
  c(this, "didInit", !1);
9
9
  c(this, "open", () => {
10
- var e, t, i;
10
+ var e, t, s, i;
11
11
  if (!document.body.classList.contains("glide-deposit-open")) {
12
12
  if (document.body.classList.add("glide-deposit-open"), !this.opts.recipient)
13
13
  throw new Error("recipient is required");
14
- const o = this.opts.recipient, n = (e = this.opts.walletProvider) == null ? void 0 : e.address, r = (t = this.opts.walletProvider) == null ? void 0 : t.availableChainIds, a = (i = this.opts.walletProvider) == null ? void 0 : i.currentChainId;
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);
15
15
  this.openUrl(
16
- `${this.baseUrl}${this.opts.app}?recipient=${o}&embed=true${n ? `&connectedWalletAddress=${n}` : ""}${a ? `&currentChainId=${a}` : ""}${r ? `&availableChainIds=${r.join(",")}` : ""}`
16
+ `${this.baseUrl}${this.opts.app}?recipient=${l}&embed=true${n ? `&connectedWalletAddress=${n}` : ""}${d ? `&currentChainId=${d}` : ""}${o ? `&availableChainIds=${o.join(",")}` : ""}${p ? "&preferGaslessPayment=true" : ""}`
17
17
  );
18
18
  }
19
19
  });
20
20
  c(this, "iframeEventHandler", async (e) => {
21
- var i, o, n, r, a, l, h, p;
21
+ var s, i, l, n, o, d, 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
- }), (o = (i = this.iframe) == null ? void 0 : i.contentWindow) == null || o.postMessage(
33
+ }), (i = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || i.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 (d) {
42
- (r = (n = this.iframe) == null ? void 0 : n.contentWindow) == null || r.postMessage(
41
+ } catch (a) {
42
+ (n = (l = this.iframe) == null ? void 0 : l.contentWindow) == null || n.postMessage(
43
43
  {
44
44
  type: "didSwitchChain",
45
45
  success: !1,
46
- error: d
46
+ error: a
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 d = await this.opts.walletProvider.sendTransactionAsync(
57
+ const a = await this.opts.walletProvider.sendTransactionAsync(
58
58
  t.tx
59
59
  );
60
- (l = (a = this.iframe) == null ? void 0 : a.contentWindow) == null || l.postMessage(
60
+ (d = (o = this.iframe) == null ? void 0 : o.contentWindow) == null || d.postMessage(
61
61
  {
62
62
  type: "didSendTransaction",
63
63
  success: !0,
64
- txHash: d
64
+ txHash: a
65
65
  },
66
66
  this.baseUrl
67
67
  );
68
- } catch (d) {
69
- (p = (h = this.iframe) == null ? void 0 : h.contentWindow) == null || p.postMessage(
68
+ } catch (a) {
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: d
73
+ error: a
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 a = 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: a
104
+ },
105
+ this.baseUrl
106
+ );
107
+ } catch (a) {
108
+ (g = (f = this.iframe) == null ? void 0 : f.contentWindow) == null || g.postMessage(
109
+ {
110
+ type: "didSignTypedData",
111
+ success: !1,
112
+ error: a
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 i;
107
- (i = t == null ? void 0 : t.contentWindow) == null || i.focus();
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,35 @@ 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 i = document.createElement("main");
120
- i.setAttribute(
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(i), document.body.appendChild(t);
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 b = ({
130
- app: s,
168
+ const T = ({
169
+ app: r,
131
170
  recipient: e,
132
171
  walletProvider: t,
133
- baseUrl: i
172
+ baseUrl: s
134
173
  }) => {
135
- const o = w(() => new y({
136
- app: s,
174
+ const i = I(() => new P({
175
+ app: r,
137
176
  recipient: e,
138
177
  walletProvider: t,
139
- baseUrl: i
140
- }), [s, e, t, i]);
141
- return f(() => (o.initialize(), () => {
142
- o.destroy();
143
- }), [o]), {
144
- openGlideDeposit: o.open
178
+ baseUrl: s
179
+ }), [r, e, t, s]);
180
+ return E(() => (i.initialize(), () => {
181
+ i.destroy();
182
+ }), [i]), {
183
+ openGlideDeposit: i.open
145
184
  };
146
185
  };
147
186
  export {
148
- y as GlideDeposit,
149
- b as useGlideDeposit
187
+ P as GlideDeposit,
188
+ T as useGlideDeposit
150
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paywithglide/glide-react",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"