@use-glyph/sdk-react 1.0.28 → 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.
- package/dist/EIP1193Strategy.js +92 -93
- package/dist/PrivyStrategy.js +70 -77
- package/dist/assets/sdk-react.css +1 -1
- package/dist/glyph-widget.umd.js +55 -73
- package/dist/index.js +8846 -10030
- package/dist/types/assets/svg/ActivityIcon.d.ts +1 -1
- package/dist/types/assets/svg/ApecoinIcon.d.ts +1 -1
- package/dist/types/assets/svg/BackIcon.d.ts +1 -1
- package/dist/types/assets/svg/CaretDownIcon.d.ts +1 -1
- package/dist/types/assets/svg/CopyIcon.d.ts +1 -1
- package/dist/types/assets/svg/EditIcon.d.ts +1 -1
- package/dist/types/assets/svg/Ellipse.d.ts +7 -0
- package/dist/types/assets/svg/FailureIcon.d.ts +1 -1
- package/dist/types/assets/svg/GlyphIcon.d.ts +1 -1
- package/dist/types/assets/svg/HelpIcon.d.ts +1 -1
- package/dist/types/assets/svg/HomeIcon.d.ts +1 -1
- package/dist/types/assets/svg/InfoIcon.d.ts +1 -1
- package/dist/types/assets/svg/LinkIcon.d.ts +1 -1
- package/dist/types/assets/svg/LinkedNFTChip.d.ts +1 -1
- package/dist/types/assets/svg/LoadingCircleIcon..d.ts +1 -1
- package/dist/types/assets/svg/NFTsIcon.d.ts +1 -1
- package/dist/types/assets/svg/PlusSign.d.ts +1 -1
- package/dist/types/assets/svg/ProfileViewPattern.d.ts +1 -1
- package/dist/types/assets/svg/QRIcon.d.ts +1 -1
- package/dist/types/assets/svg/SuccessIcon.d.ts +1 -1
- package/dist/types/assets/svg/SuccessViewPattern.d.ts +1 -1
- package/dist/types/assets/svg/TokensIcon.d.ts +1 -1
- package/dist/types/assets/svg/TxSendIcon.d.ts +1 -1
- package/dist/types/assets/svg/WalletsTabFilledIcon.d.ts +1 -1
- package/dist/types/assets/svg/WalletsTabOutlinedIcon.d.ts +1 -1
- package/dist/types/lib/constants.d.ts +1 -2
- package/package.json +39 -40
- package/dist/types/components/ui/select.d.ts +0 -13
- package/dist/types/components/widget/UnsupportedChainOverlay.d.ts +0 -5
- package/dist/types/lib/providers.d.ts +0 -13777
package/dist/EIP1193Strategy.js
CHANGED
|
@@ -1,149 +1,148 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { useState as g, useEffect as
|
|
3
|
-
import { useAccount as
|
|
4
|
-
const
|
|
5
|
-
children:
|
|
6
|
-
glyphUrl:
|
|
7
|
-
onLogin:
|
|
8
|
-
onLogout:
|
|
9
|
-
askForSignature:
|
|
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 [
|
|
12
|
-
r.log({ address:
|
|
13
|
-
const [i,
|
|
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(
|
|
18
|
-
} catch (
|
|
19
|
-
return r.warn("Error reading session token",
|
|
17
|
+
return localStorage.getItem(A);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return r.warn("Error reading session token", e), null;
|
|
20
20
|
}
|
|
21
|
-
}), [
|
|
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(
|
|
26
|
-
} catch (
|
|
27
|
-
return r.warn("Error reading session nonce",
|
|
25
|
+
return localStorage.getItem(I);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return r.warn("Error reading session nonce", e), null;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
|
|
30
|
+
y(() => {
|
|
31
31
|
try {
|
|
32
|
-
!i || !n ? (localStorage.removeItem(
|
|
33
|
-
} catch (
|
|
34
|
-
r.error("Error saving session token",
|
|
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
|
|
38
|
-
async (
|
|
37
|
+
const T = l(
|
|
38
|
+
async (e) => {
|
|
39
39
|
try {
|
|
40
40
|
return await fetch(
|
|
41
|
-
`${
|
|
42
|
-
).then((
|
|
43
|
-
} catch (
|
|
44
|
-
throw r.error("Can't fetch 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
|
-
[
|
|
48
|
-
),
|
|
49
|
-
async (
|
|
47
|
+
[a]
|
|
48
|
+
), k = l(
|
|
49
|
+
async (e, s, E) => {
|
|
50
50
|
try {
|
|
51
|
-
return await fetch(`${
|
|
51
|
+
return await fetch(`${a || S}/api/widget/auth/verify/${e}`, {
|
|
52
52
|
method: "POST",
|
|
53
|
-
body: JSON.stringify({ signature:
|
|
54
|
-
}).then((
|
|
55
|
-
} catch (
|
|
56
|
-
throw r.error("Can't verify signature",
|
|
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
|
-
[
|
|
59
|
+
[a]
|
|
60
60
|
);
|
|
61
|
-
|
|
62
|
-
!
|
|
63
|
-
|
|
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
|
-
}, [
|
|
67
|
+
}, [t, o, T, n]), y(() => {
|
|
68
68
|
if (!i || !n) return;
|
|
69
|
-
const
|
|
70
|
-
"x-evm-address":
|
|
69
|
+
const e = Y(a || S, async () => i, {
|
|
70
|
+
"x-evm-address": t,
|
|
71
71
|
"x-glyph-nonce": n
|
|
72
72
|
});
|
|
73
|
-
|
|
74
|
-
}, [i,
|
|
75
|
-
const
|
|
76
|
-
await
|
|
77
|
-
}, [
|
|
78
|
-
|
|
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 (!
|
|
85
|
-
|
|
83
|
+
if (!t || !o || !u || !n) {
|
|
84
|
+
d(null), c(!1);
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
87
|
c(!0);
|
|
89
|
-
const
|
|
90
|
-
console.log(n,
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
} catch (
|
|
94
|
-
r.error("Authentication failed",
|
|
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
|
-
),
|
|
95
|
+
), d(null), m(null), w(null);
|
|
97
96
|
} finally {
|
|
98
|
-
c(!1),
|
|
97
|
+
c(!1), j?.();
|
|
99
98
|
}
|
|
100
|
-
}, [
|
|
101
|
-
|
|
102
|
-
}, []),
|
|
103
|
-
async ({ message:
|
|
104
|
-
if (!
|
|
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
|
|
105
|
+
return f({ account: t, message: e });
|
|
107
106
|
},
|
|
108
|
-
[
|
|
109
|
-
),
|
|
110
|
-
async ({ transaction:
|
|
111
|
-
if (!
|
|
112
|
-
return
|
|
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
|
-
[
|
|
115
|
-
), [
|
|
116
|
-
return
|
|
113
|
+
[t, o, C, _]
|
|
114
|
+
), [b, x] = g(!1);
|
|
115
|
+
return X({
|
|
117
116
|
onConnect: () => {
|
|
118
|
-
|
|
117
|
+
h && x(!0);
|
|
119
118
|
},
|
|
120
119
|
onDisconnect: () => {
|
|
121
|
-
|
|
120
|
+
D();
|
|
122
121
|
}
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
}, [
|
|
126
|
-
|
|
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:
|
|
130
|
-
authenticated:
|
|
128
|
+
ready: !W && !!n,
|
|
129
|
+
authenticated: o && !!t && i !== null,
|
|
131
130
|
symbol: "APE",
|
|
132
|
-
glyphUrl:
|
|
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: !
|
|
135
|
-
login:
|
|
136
|
-
logout:
|
|
133
|
+
hideWidget: !o || !t,
|
|
134
|
+
login: p,
|
|
135
|
+
logout: $,
|
|
137
136
|
// on disconnect, logoutSideEffect is called and clears states
|
|
138
|
-
signMessage:
|
|
139
|
-
sendTransaction:
|
|
140
|
-
apiFetch:
|
|
137
|
+
signMessage: F,
|
|
138
|
+
sendTransaction: K,
|
|
139
|
+
apiFetch: L
|
|
141
140
|
},
|
|
142
|
-
children:
|
|
141
|
+
children: P
|
|
143
142
|
}
|
|
144
143
|
);
|
|
145
144
|
};
|
|
146
|
-
|
|
145
|
+
Z.displayName = "EIP1193Strategy";
|
|
147
146
|
export {
|
|
148
|
-
|
|
147
|
+
Z as default
|
|
149
148
|
};
|
package/dist/PrivyStrategy.js
CHANGED
|
@@ -1,115 +1,108 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { usePrivy as
|
|
3
|
-
import { memo as
|
|
4
|
-
import { useChainId as
|
|
5
|
-
const t =
|
|
6
|
-
const [
|
|
7
|
-
ready:
|
|
8
|
-
authenticated:
|
|
9
|
-
user:
|
|
10
|
-
getAccessToken:
|
|
11
|
-
login:
|
|
12
|
-
logout:
|
|
13
|
-
signMessage:
|
|
14
|
-
sendTransaction:
|
|
15
|
-
} =
|
|
16
|
-
t.debug(
|
|
17
|
-
const { wallets:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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 (!
|
|
25
|
-
|
|
23
|
+
if (!i || !c) {
|
|
24
|
+
g(null), y(!1);
|
|
26
25
|
return;
|
|
27
26
|
}
|
|
28
27
|
let e;
|
|
29
|
-
const r =
|
|
28
|
+
const r = c.linkedAccounts?.find(
|
|
30
29
|
(s) => s.type === "wallet" && s.chainType === "ethereum" && s.walletClientType === "privy"
|
|
31
|
-
),
|
|
32
|
-
|
|
33
|
-
const
|
|
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:
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const
|
|
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:
|
|
49
|
-
const
|
|
50
|
-
|
|
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 =
|
|
56
|
-
|
|
57
|
-
async () => await
|
|
48
|
+
const s = J(
|
|
49
|
+
p || K,
|
|
50
|
+
async () => await _(),
|
|
58
51
|
{ "x-evm-address": e }
|
|
59
52
|
);
|
|
60
|
-
|
|
53
|
+
g(() => s), y(!1);
|
|
61
54
|
})();
|
|
62
55
|
}, [
|
|
63
|
-
f,
|
|
64
56
|
p,
|
|
65
|
-
|
|
57
|
+
i,
|
|
66
58
|
o,
|
|
67
|
-
|
|
59
|
+
c,
|
|
60
|
+
u,
|
|
68
61
|
n,
|
|
69
|
-
|
|
62
|
+
V,
|
|
70
63
|
a,
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
_,
|
|
65
|
+
f
|
|
73
66
|
]);
|
|
74
|
-
const
|
|
75
|
-
await
|
|
76
|
-
}, [
|
|
77
|
-
|
|
78
|
-
}, [
|
|
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 ?
|
|
74
|
+
return n ? G(e, { address: a }) : b({ message: e });
|
|
82
75
|
},
|
|
83
|
-
[a, n,
|
|
84
|
-
),
|
|
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:
|
|
88
|
-
return n ?
|
|
80
|
+
const r = { ...e, chainId: P };
|
|
81
|
+
return n ? S(r, { address: a }) : E(r, { address: a });
|
|
89
82
|
},
|
|
90
|
-
[
|
|
83
|
+
[P, n, a, S, E]
|
|
91
84
|
);
|
|
92
|
-
return /* @__PURE__ */
|
|
93
|
-
|
|
85
|
+
return /* @__PURE__ */ q.jsx(
|
|
86
|
+
z.Provider,
|
|
94
87
|
{
|
|
95
88
|
value: {
|
|
96
|
-
ready:
|
|
97
|
-
authenticated:
|
|
89
|
+
ready: o && !L,
|
|
90
|
+
authenticated: o && i,
|
|
98
91
|
symbol: "APE",
|
|
99
|
-
glyphUrl:
|
|
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:
|
|
103
|
-
signMessage:
|
|
104
|
-
sendTransaction:
|
|
105
|
-
apiFetch:
|
|
94
|
+
login: Y,
|
|
95
|
+
logout: j,
|
|
96
|
+
signMessage: U,
|
|
97
|
+
sendTransaction: H,
|
|
98
|
+
apiFetch: R
|
|
106
99
|
},
|
|
107
|
-
children:
|
|
100
|
+
children: D
|
|
108
101
|
}
|
|
109
102
|
);
|
|
110
103
|
};
|
|
111
|
-
|
|
112
|
-
const
|
|
104
|
+
M.displayName = "PrivyStrategy";
|
|
105
|
+
const cs = Z(M);
|
|
113
106
|
export {
|
|
114
|
-
|
|
107
|
+
cs as default
|
|
115
108
|
};
|