@use-glyph/sdk-react 1.0.6 → 1.0.9

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.
@@ -1,4 +1,4 @@
1
- import { c as J, W as C, d as q, a as z, j as H, b as Q } from "./index.js";
1
+ import { c as J, W as C, b as q, d as z, j as H, a as Q } from "./index.js";
2
2
  import { useState as g, useEffect as p, useCallback as u } from "react";
3
3
  import { useAccount as V, useDisconnect as X, useSignMessage as Z, useSendTransaction as L, useAccountEffect as U } from "wagmi";
4
4
  const T = "__glyph-widget-token__", k = "__glyph-widget-nonce__", r = J("EIP1193Strategy"), ee = ({
@@ -1,114 +1,115 @@
1
- import { c as J, i as K, S as D, G as R, a as O, j as Q, b as X, d as Z, W as L } from "./index.js";
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
2
  import { usePrivy as ss, useCrossAppAccounts as es, useWallets as ts } from "@privy-io/react-auth";
3
- import { memo as as, useState as p, useEffect as rs, useCallback as u } from "react";
4
- const t = J("PrivyStrategy"), F = ({ children: N, glyphUrl: y, onLogin: g, onLogout: h, useStagingTenant: f }) => {
5
- const [V, A] = p(!0), [Y, m] = p(null), [a, j] = p(null), [n, U] = p(!1), {
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(), {
6
7
  ready: c,
7
- authenticated: i,
8
+ authenticated: p,
8
9
  user: o,
9
- getAccessToken: w,
10
- login: b,
10
+ getAccessToken: b,
11
+ login: E,
11
12
  logout: v,
12
- signMessage: E,
13
- sendTransaction: G
14
- } = ss(), { signMessage: S, sendTransaction: T } = es();
15
- t.debug(c, i, !!o);
16
- const { wallets: H } = ts();
13
+ signMessage: G,
14
+ sendTransaction: S
15
+ } = ss(), { signMessage: I, sendTransaction: T } = es();
16
+ t.debug(c, p, !!o);
17
+ const { wallets: B } = ts();
17
18
  rs(() => {
18
- var C, l, M;
19
+ var M, u, D;
19
20
  if (!c) {
20
21
  m(null), A(!0);
21
22
  return;
22
23
  }
23
- if (!i || !o) {
24
+ if (!p || !o) {
24
25
  m(null), A(!1);
25
26
  return;
26
27
  }
27
28
  let e;
28
- const r = (C = o.linkedAccounts) == null ? void 0 : C.find(
29
+ const r = (M = o.linkedAccounts) == null ? void 0 : M.find(
29
30
  (s) => s.type === "wallet" && s.chainType === "ethereum" && s.walletClientType === "privy"
30
- ), I = r && K(r.address);
31
- I && t.debug("Privy (main) EVM embedded wallet", r.address), t.debug("finding cross-app accounts...");
32
- const W = ((M = (l = o.linkedAccounts) == null ? void 0 : l.filter) == null ? void 0 : M.call(l, (s) => s.type === "cross_app")) || [], k = W.filter(
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(
33
34
  (s) => {
34
35
  var d;
35
- return ((d = s.providerApp) == null ? void 0 : d.id) !== (f ? D : R);
36
+ return ((d = s.providerApp) == null ? void 0 : d.id) !== (h ? R : F);
36
37
  }
37
38
  );
38
- t.debug("linked accounts - non-Glyph", { accounts: k });
39
- const P = k.map((s) => s.embeddedWallets[0].address);
39
+ t.debug("linked accounts - non-Glyph", { accounts: x });
40
+ const P = x.map((s) => s.embeddedWallets[0].address);
40
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"));
41
- const x = W.filter(
42
+ const C = k.filter(
42
43
  (s) => {
43
44
  var d;
44
- return ((d = s.providerApp) == null ? void 0 : d.id) === (f ? D : R);
45
+ return ((d = s.providerApp) == null ? void 0 : d.id) === (h ? R : F);
45
46
  }
46
47
  );
47
- t.debug("linked accounts - Glyph", { accounts: x });
48
- const _ = x.map((s) => s.embeddedWallets[0].address);
49
- _.length > 0 && (e = _[0], t.log("using cross_app (Glyph) account"), _.length > 1 && t.warn("too many cross_app accounts")), e ? (U(!0), t.log("using cross_app account", e)) : I && (e = r.address, t.log("using Privy (main) EVM embedded wallet", e)), j(e ?? null), (async () => {
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 () => {
50
51
  if (!e) {
51
52
  t.error("user has no wallet");
52
53
  return;
53
54
  }
54
55
  const s = Z(
55
- y || L,
56
- async () => await w(),
56
+ f || L,
57
+ async () => await b(),
57
58
  { "x-evm-address": e }
58
59
  );
59
60
  m(() => s), A(!1);
60
61
  })();
61
62
  }, [
62
- y,
63
- i,
63
+ f,
64
+ p,
64
65
  c,
65
66
  o,
66
- f,
67
+ h,
67
68
  n,
68
- H,
69
+ B,
69
70
  a,
70
- w,
71
+ b,
71
72
  v
72
73
  ]);
73
- const B = u(async () => {
74
- await b(), g == null || g();
75
- }, [b]), $ = u(async () => {
76
- v(), h == null || h();
77
- }, [v]), q = u(
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(
78
79
  async ({ message: e }) => {
79
80
  if (!a) throw new Error("No wallet address found");
80
- return n ? S(e, { address: a }) : E({ message: e });
81
+ return n ? I(e, { address: a }) : G({ message: e });
81
82
  },
82
- [a, n, S, E]
83
- ), z = u(
83
+ [a, n, I, G]
84
+ ), J = g(
84
85
  async ({ transaction: e }) => {
85
86
  if (!a) throw new Error("No wallet address found");
86
- const r = { ...e, chainId: O.id };
87
- return n ? T(r, { address: a }) : G(r, { address: a });
87
+ const r = { ...e, chainId: w };
88
+ return n ? T(r, { address: a }) : S(r, { address: a });
88
89
  },
89
- [a, n, T, G]
90
+ [w, n, a, T, S]
90
91
  );
91
92
  return /* @__PURE__ */ Q.jsx(
92
93
  X.Provider,
93
94
  {
94
95
  value: {
95
- ready: c && !V,
96
- authenticated: c && i,
96
+ ready: c && !Y,
97
+ authenticated: c && p,
97
98
  symbol: "APE",
98
- glyphUrl: y,
99
+ glyphUrl: f,
99
100
  // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
100
- login: B,
101
- logout: $,
102
- signMessage: q,
103
- sendTransaction: z,
104
- apiFetch: Y
101
+ login: $,
102
+ logout: q,
103
+ signMessage: z,
104
+ sendTransaction: J,
105
+ apiFetch: j
105
106
  },
106
- children: N
107
+ children: V
107
108
  }
108
109
  );
109
110
  };
110
- F.displayName = "PrivyStrategy";
111
- const is = as(F);
111
+ N.displayName = "PrivyStrategy";
112
+ const ps = as(N);
112
113
  export {
113
- is as default
114
+ ps as default
114
115
  };