@use-glyph/sdk-react 1.0.29 → 1.1.0

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.
Files changed (31) hide show
  1. package/dist/EIP1193Strategy.js +92 -93
  2. package/dist/PrivyStrategy.js +70 -77
  3. package/dist/assets/sdk-react.css +1 -1
  4. package/dist/glyph-widget.umd.js +55 -63
  5. package/dist/index.js +8516 -8716
  6. package/dist/types/assets/svg/ActivityIcon.d.ts +1 -1
  7. package/dist/types/assets/svg/ApecoinIcon.d.ts +1 -1
  8. package/dist/types/assets/svg/BackIcon.d.ts +1 -1
  9. package/dist/types/assets/svg/CaretDownIcon.d.ts +1 -1
  10. package/dist/types/assets/svg/CopyIcon.d.ts +1 -1
  11. package/dist/types/assets/svg/EditIcon.d.ts +1 -1
  12. package/dist/types/assets/svg/Ellipse.d.ts +1 -1
  13. package/dist/types/assets/svg/FailureIcon.d.ts +1 -1
  14. package/dist/types/assets/svg/GlyphIcon.d.ts +1 -1
  15. package/dist/types/assets/svg/HelpIcon.d.ts +1 -1
  16. package/dist/types/assets/svg/HomeIcon.d.ts +1 -1
  17. package/dist/types/assets/svg/InfoIcon.d.ts +1 -1
  18. package/dist/types/assets/svg/LinkIcon.d.ts +1 -1
  19. package/dist/types/assets/svg/LinkedNFTChip.d.ts +1 -1
  20. package/dist/types/assets/svg/LoadingCircleIcon..d.ts +1 -1
  21. package/dist/types/assets/svg/NFTsIcon.d.ts +1 -1
  22. package/dist/types/assets/svg/PlusSign.d.ts +1 -1
  23. package/dist/types/assets/svg/ProfileViewPattern.d.ts +1 -1
  24. package/dist/types/assets/svg/QRIcon.d.ts +1 -1
  25. package/dist/types/assets/svg/SuccessIcon.d.ts +1 -1
  26. package/dist/types/assets/svg/SuccessViewPattern.d.ts +1 -1
  27. package/dist/types/assets/svg/TokensIcon.d.ts +1 -1
  28. package/dist/types/assets/svg/TxSendIcon.d.ts +1 -1
  29. package/dist/types/assets/svg/WalletsTabFilledIcon.d.ts +1 -1
  30. package/dist/types/assets/svg/WalletsTabOutlinedIcon.d.ts +1 -1
  31. package/package.json +39 -39
@@ -1,149 +1,148 @@
1
- import { c as J, W as C, b as q, d as z, j as H, a as Q } from "./index.js";
2
- import { useState as g, useEffect as p, useCallback as u } from "react";
3
- import { useAccount as V, useDisconnect as X, useSignMessage as Z, useSendTransaction as L, useAccountEffect as U } from "wagmi";
4
- const T = "__glyph-widget-token__", k = "__glyph-widget-nonce__", r = J("EIP1193Strategy"), ee = ({
5
- children: O,
6
- glyphUrl: o,
7
- onLogin: E,
8
- onLogout: S,
9
- askForSignature: A = !0
1
+ import { c as R, W as S, b as Y, d as B, j as J, a as q } from "./index.js";
2
+ import { useState as g, useEffect as y, useCallback as l } from "react";
3
+ import { useAccount as z, useDisconnect as H, useSignMessage as Q, useSendTransaction as V, useAccountEffect as X } from "wagmi";
4
+ const A = "__glyph-widget-token__", I = "__glyph-widget-nonce__", r = R("EIP1193Strategy"), Z = ({
5
+ children: P,
6
+ glyphUrl: a,
7
+ onLogin: j,
8
+ onLogout: M,
9
+ askForSignature: h = !0
10
10
  }) => {
11
- const [$, c] = g(!1), [D, h] = g(null), { address: e, isConnected: s, chainId: b } = V(), { disconnectAsync: x } = X(), { signMessageAsync: m } = Z(), { sendTransactionAsync: N } = L();
12
- r.log({ address: e, isConnected: s });
13
- const [i, I] = g(() => {
11
+ const [W, c] = g(!1), [L, d] = g(null), { address: t, isConnected: o, chainId: _ } = z(), { disconnectAsync: v } = H(), { signMessageAsync: f } = Q(), { sendTransactionAsync: C } = V();
12
+ r.log({ address: t, isConnected: o });
13
+ const [i, m] = g(() => {
14
14
  if (typeof window > "u")
15
15
  return null;
16
16
  try {
17
- return localStorage.getItem(T);
18
- } catch (t) {
19
- return r.warn("Error reading session token", t), null;
17
+ return localStorage.getItem(A);
18
+ } catch (e) {
19
+ return r.warn("Error reading session token", e), null;
20
20
  }
21
- }), [d, F] = g(null), [n, _] = g(() => {
21
+ }), [u, O] = g(null), [n, w] = g(() => {
22
22
  if (typeof window > "u")
23
23
  return null;
24
24
  try {
25
- return localStorage.getItem(k);
26
- } catch (t) {
27
- return r.warn("Error reading session nonce", t), null;
25
+ return localStorage.getItem(I);
26
+ } catch (e) {
27
+ return r.warn("Error reading session nonce", e), null;
28
28
  }
29
29
  });
30
- p(() => {
30
+ y(() => {
31
31
  try {
32
- !i || !n ? (localStorage.removeItem(T), localStorage.removeItem(k)) : (localStorage.setItem(T, i), localStorage.setItem(k, n));
33
- } catch (t) {
34
- r.error("Error saving session token", t);
32
+ !i || !n ? (localStorage.removeItem(A), localStorage.removeItem(I)) : (localStorage.setItem(A, i), localStorage.setItem(I, n));
33
+ } catch (e) {
34
+ r.error("Error saving session token", e);
35
35
  }
36
36
  }, [n, i]);
37
- const P = u(
38
- async (t) => {
37
+ const T = l(
38
+ async (e) => {
39
39
  try {
40
40
  return await fetch(
41
- `${o || C}/api/widget/auth/message/${t}`
42
- ).then((f) => f.json());
43
- } catch (a) {
44
- throw r.error("Can't fetch message to sign", a), new Error("Failed to fetch the message to sign.");
41
+ `${a || S}/api/widget/auth/message/${e}`
42
+ ).then((E) => E.json());
43
+ } catch (s) {
44
+ throw r.error("Can't fetch message to sign", s), new Error("Failed to fetch the message to sign.");
45
45
  }
46
46
  },
47
- [o]
48
- ), j = u(
49
- async (t, a, f) => {
47
+ [a]
48
+ ), k = l(
49
+ async (e, s, E) => {
50
50
  try {
51
- return await fetch(`${o || C}/api/widget/auth/verify/${t}`, {
51
+ return await fetch(`${a || S}/api/widget/auth/verify/${e}`, {
52
52
  method: "POST",
53
- body: JSON.stringify({ signature: a, nonce: f })
54
- }).then((w) => w.json());
55
- } catch (y) {
56
- throw r.error("Can't verify signature", y), new Error("Signature verification failed.");
53
+ body: JSON.stringify({ signature: s, nonce: E })
54
+ }).then((G) => G.json());
55
+ } catch (N) {
56
+ throw r.error("Can't verify signature", N), new Error("Signature verification failed.");
57
57
  }
58
58
  },
59
- [o]
59
+ [a]
60
60
  );
61
- p(() => {
62
- !e || !s || n || (c(!0), P(e).then(({ message: t, nonce: a }) => {
63
- F(t), _(a), c(!1);
61
+ y(() => {
62
+ !t || !o || n || (c(!0), T(t).then(({ message: e, nonce: s }) => {
63
+ O(e), w(s), c(!1);
64
64
  }).finally(() => {
65
65
  c(!1);
66
66
  }));
67
- }, [e, s, P, n]), p(() => {
67
+ }, [t, o, T, n]), y(() => {
68
68
  if (!i || !n) return;
69
- const t = q(o || C, async () => i, {
70
- "x-evm-address": e,
69
+ const e = Y(a || S, async () => i, {
70
+ "x-evm-address": t,
71
71
  "x-glyph-nonce": n
72
72
  });
73
- h(() => t);
74
- }, [i, e, o, n]);
75
- const K = u(async () => {
76
- await x();
77
- }, [x]), v = u(async () => {
78
- var t, a, f, y, w;
79
- if (r.log("authenticate"), !e) {
73
+ d(() => e);
74
+ }, [i, t, a, n]);
75
+ const $ = l(async () => {
76
+ await v();
77
+ }, [v]), p = l(async () => {
78
+ if (r.log("authenticate"), !t) {
80
79
  r.error("no wallet connected.");
81
80
  return;
82
81
  }
83
82
  try {
84
- if (!e || !s || !d || !n) {
85
- h(null), c(!1);
83
+ if (!t || !o || !u || !n) {
84
+ d(null), c(!1);
86
85
  return;
87
86
  }
88
87
  c(!0);
89
- const l = await m({ account: e, message: d });
90
- console.log(n, d, l);
91
- const B = (t = await j(e, l, n)) == null ? void 0 : t.token;
92
- I(B);
93
- } catch (l) {
94
- r.error("Authentication failed", l), (w = (f = (a = l == null ? void 0 : l.message) == null ? void 0 : a.toLowerCase) == null ? void 0 : (y = f.call(a)).includes) != null && w.call(y, "user rejected") || await alert(
88
+ const e = await f({ account: t, message: u });
89
+ console.log(n, u, e);
90
+ const s = (await k(t, e, n))?.token;
91
+ m(s);
92
+ } catch (e) {
93
+ r.error("Authentication failed", e), e?.message?.toLowerCase?.().includes?.("user rejected") || await alert(
95
94
  "Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in."
96
- ), h(null), I(null), _(null);
95
+ ), d(null), m(null), w(null);
97
96
  } finally {
98
- c(!1), E == null || E();
97
+ c(!1), j?.();
99
98
  }
100
- }, [e, s, d, n, m, j]), G = u(async () => {
101
- _(null), I(null), c(!1), h(null), S == null || S();
102
- }, []), R = u(
103
- async ({ message: t }) => {
104
- if (!e || !s)
99
+ }, [t, o, u, n, f, k]), D = l(async () => {
100
+ w(null), m(null), c(!1), d(null), M?.();
101
+ }, []), F = l(
102
+ async ({ message: e }) => {
103
+ if (!t || !o)
105
104
  throw new Error("Wallet not connected");
106
- return m({ account: e, message: t });
105
+ return f({ account: t, message: e });
107
106
  },
108
- [e, s, m]
109
- ), Y = u(
110
- async ({ transaction: t }) => {
111
- if (!e || !s) throw new Error("Wallet not connected");
112
- return N({ ...t, chainId: b || z.id });
107
+ [t, o, f]
108
+ ), K = l(
109
+ async ({ transaction: e }) => {
110
+ if (!t || !o) throw new Error("Wallet not connected");
111
+ return C({ ...e, chainId: _ || B.id });
113
112
  },
114
- [e, s, N, b]
115
- ), [M, W] = g(!1);
116
- return U({
113
+ [t, o, C, _]
114
+ ), [b, x] = g(!1);
115
+ return X({
117
116
  onConnect: () => {
118
- A && W(!0);
117
+ h && x(!0);
119
118
  },
120
119
  onDisconnect: () => {
121
- G();
120
+ D();
122
121
  }
123
- }), p(() => {
124
- A && s && e && M && n && d && (v(), W(!1));
125
- }, [s, e, v, M, n, d, A]), /* @__PURE__ */ H.jsx(
126
- Q.Provider,
122
+ }), y(() => {
123
+ h && o && t && b && n && u && (p(), x(!1));
124
+ }, [o, t, p, b, n, u, h]), /* @__PURE__ */ J.jsx(
125
+ q.Provider,
127
126
  {
128
127
  value: {
129
- ready: !$ && !!n,
130
- authenticated: s && !!e && i !== null,
128
+ ready: !W && !!n,
129
+ authenticated: o && !!t && i !== null,
131
130
  symbol: "APE",
132
- glyphUrl: o,
131
+ glyphUrl: a,
133
132
  // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
134
- hideWidget: !s || !e,
135
- login: v,
136
- logout: K,
133
+ hideWidget: !o || !t,
134
+ login: p,
135
+ logout: $,
137
136
  // on disconnect, logoutSideEffect is called and clears states
138
- signMessage: R,
139
- sendTransaction: Y,
140
- apiFetch: D
137
+ signMessage: F,
138
+ sendTransaction: K,
139
+ apiFetch: L
141
140
  },
142
- children: O
141
+ children: P
143
142
  }
144
143
  );
145
144
  };
146
- ee.displayName = "EIP1193Strategy";
145
+ Z.displayName = "EIP1193Strategy";
147
146
  export {
148
- ee as default
147
+ Z as default
149
148
  };
@@ -1,115 +1,108 @@
1
- import { c as K, i as O, S as R, G as F, j as Q, a as X, b as Z, W as L } from "./index.js";
2
- import { usePrivy as ss, useCrossAppAccounts as es, useWallets as ts } from "@privy-io/react-auth";
3
- import { memo as as, useState as y, useEffect as rs, useCallback as g } from "react";
4
- import { useChainId as ns } from "wagmi";
5
- const t = K("PrivyStrategy"), N = ({ children: V, glyphUrl: f, onLogin: i, onLogout: l, useStagingTenant: h }) => {
6
- const [Y, A] = y(!0), [j, m] = y(null), [a, U] = y(null), [n, H] = y(!1), w = ns(), {
7
- ready: c,
8
- authenticated: p,
9
- user: o,
10
- getAccessToken: b,
11
- login: E,
12
- logout: v,
13
- signMessage: G,
14
- sendTransaction: S
15
- } = ss(), { signMessage: I, sendTransaction: T } = es();
16
- t.debug(c, p, !!o);
17
- const { wallets: B } = ts();
18
- rs(() => {
19
- var M, u, D;
20
- if (!c) {
21
- m(null), A(!0);
1
+ import { c as B, i as $, S as x, G as C, j as q, a as z, b as J, W as K } from "./index.js";
2
+ import { usePrivy as O, useCrossAppAccounts as Q, useWallets as X } from "@privy-io/react-auth";
3
+ import { memo as Z, useState as d, useEffect as ss, useCallback as l } from "react";
4
+ import { useChainId as es } from "wagmi";
5
+ const t = B("PrivyStrategy"), M = ({ children: D, glyphUrl: p, onLogin: m, onLogout: v, useStagingTenant: u }) => {
6
+ const [L, y] = d(!0), [R, g] = d(null), [a, F] = d(null), [n, N] = d(!1), P = es(), {
7
+ ready: o,
8
+ authenticated: i,
9
+ user: c,
10
+ getAccessToken: _,
11
+ login: w,
12
+ logout: f,
13
+ signMessage: b,
14
+ sendTransaction: E
15
+ } = O(), { signMessage: G, sendTransaction: S } = Q();
16
+ t.debug(o, i, !!c);
17
+ const { wallets: V } = X();
18
+ ss(() => {
19
+ if (!o) {
20
+ g(null), y(!0);
22
21
  return;
23
22
  }
24
- if (!p || !o) {
25
- m(null), A(!1);
23
+ if (!i || !c) {
24
+ g(null), y(!1);
26
25
  return;
27
26
  }
28
27
  let e;
29
- const r = (M = o.linkedAccounts) == null ? void 0 : M.find(
28
+ const r = c.linkedAccounts?.find(
30
29
  (s) => s.type === "wallet" && s.chainType === "ethereum" && s.walletClientType === "privy"
31
- ), W = r && O(r.address);
32
- W && t.debug("Privy (main) EVM embedded wallet", r.address), t.debug("finding cross-app accounts...");
33
- const k = ((D = (u = o.linkedAccounts) == null ? void 0 : u.filter) == null ? void 0 : D.call(u, (s) => s.type === "cross_app")) || [], x = k.filter(
34
- (s) => {
35
- var d;
36
- return ((d = s.providerApp) == null ? void 0 : d.id) !== (h ? R : F);
37
- }
30
+ ), I = r && $(r.address);
31
+ I && t.debug("Privy (main) EVM embedded wallet", r.address), t.debug("finding cross-app accounts...");
32
+ const T = c.linkedAccounts?.filter?.((s) => s.type === "cross_app") || [], W = T.filter(
33
+ (s) => s.providerApp?.id !== (u ? x : C)
38
34
  );
39
- t.debug("linked accounts - non-Glyph", { accounts: x });
40
- const P = x.map((s) => s.embeddedWallets[0].address);
41
- P.length > 0 && (e = P[0], t.log("using cross_app (non-Glyph) account"), P.length > 1 && t.warn("too many cross_app accounts"));
42
- const C = k.filter(
43
- (s) => {
44
- var d;
45
- return ((d = s.providerApp) == null ? void 0 : d.id) === (h ? R : F);
46
- }
35
+ t.debug("linked accounts - non-Glyph", { accounts: W });
36
+ const h = W.map((s) => s.embeddedWallets[0].address);
37
+ h.length > 0 && (e = h[0], t.log("using cross_app (non-Glyph) account"), h.length > 1 && t.warn("too many cross_app accounts"));
38
+ const k = T.filter(
39
+ (s) => s.providerApp?.id === (u ? x : C)
47
40
  );
48
- t.debug("linked accounts - Glyph", { accounts: C });
49
- const _ = C.map((s) => s.embeddedWallets[0].address);
50
- _.length > 0 && (e = _[0], t.log("using cross_app (Glyph) account"), _.length > 1 && t.warn("too many cross_app accounts")), e ? (H(!0), t.log("using cross_app account", e)) : W && (e = r.address, t.log("using Privy (main) EVM embedded wallet", e)), U(e ?? null), (async () => {
41
+ t.debug("linked accounts - Glyph", { accounts: k });
42
+ const A = k.map((s) => s.embeddedWallets[0].address);
43
+ A.length > 0 && (e = A[0], t.log("using cross_app (Glyph) account"), A.length > 1 && t.warn("too many cross_app accounts")), e ? (N(!0), t.log("using cross_app account", e)) : I && (e = r.address, t.log("using Privy (main) EVM embedded wallet", e)), F(e ?? null), (async () => {
51
44
  if (!e) {
52
45
  t.error("user has no wallet");
53
46
  return;
54
47
  }
55
- const s = Z(
56
- f || L,
57
- async () => await b(),
48
+ const s = J(
49
+ p || K,
50
+ async () => await _(),
58
51
  { "x-evm-address": e }
59
52
  );
60
- m(() => s), A(!1);
53
+ g(() => s), y(!1);
61
54
  })();
62
55
  }, [
63
- f,
64
56
  p,
65
- c,
57
+ i,
66
58
  o,
67
- h,
59
+ c,
60
+ u,
68
61
  n,
69
- B,
62
+ V,
70
63
  a,
71
- b,
72
- v
64
+ _,
65
+ f
73
66
  ]);
74
- const $ = g(async () => {
75
- await E(), i == null || i();
76
- }, [i, E]), q = g(async () => {
77
- v(), l == null || l();
78
- }, [l, v]), z = g(
67
+ const Y = l(async () => {
68
+ await w(), m?.();
69
+ }, [m, w]), j = l(async () => {
70
+ f(), v?.();
71
+ }, [v, f]), U = l(
79
72
  async ({ message: e }) => {
80
73
  if (!a) throw new Error("No wallet address found");
81
- return n ? I(e, { address: a }) : G({ message: e });
74
+ return n ? G(e, { address: a }) : b({ message: e });
82
75
  },
83
- [a, n, I, G]
84
- ), J = g(
76
+ [a, n, G, b]
77
+ ), H = l(
85
78
  async ({ transaction: e }) => {
86
79
  if (!a) throw new Error("No wallet address found");
87
- const r = { ...e, chainId: w };
88
- return n ? T(r, { address: a }) : S(r, { address: a });
80
+ const r = { ...e, chainId: P };
81
+ return n ? S(r, { address: a }) : E(r, { address: a });
89
82
  },
90
- [w, n, a, T, S]
83
+ [P, n, a, S, E]
91
84
  );
92
- return /* @__PURE__ */ Q.jsx(
93
- X.Provider,
85
+ return /* @__PURE__ */ q.jsx(
86
+ z.Provider,
94
87
  {
95
88
  value: {
96
- ready: c && !Y,
97
- authenticated: c && p,
89
+ ready: o && !L,
90
+ authenticated: o && i,
98
91
  symbol: "APE",
99
- glyphUrl: f,
92
+ glyphUrl: p,
100
93
  // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
101
- login: $,
102
- logout: q,
103
- signMessage: z,
104
- sendTransaction: J,
105
- apiFetch: j
94
+ login: Y,
95
+ logout: j,
96
+ signMessage: U,
97
+ sendTransaction: H,
98
+ apiFetch: R
106
99
  },
107
- children: V
100
+ children: D
108
101
  }
109
102
  );
110
103
  };
111
- N.displayName = "PrivyStrategy";
112
- const ps = as(N);
104
+ M.displayName = "PrivyStrategy";
105
+ const cs = Z(M);
113
106
  export {
114
- ps as default
107
+ cs as default
115
108
  };