@use-glyph/sdk-react 1.2.12 → 2.0.0-rc.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/EIP1193Strategy.js +96 -87
- package/dist/EIP1193Strategy.js.map +1 -1
- package/dist/PrivyStrategy.js +85 -67
- package/dist/PrivyStrategy.js.map +1 -1
- package/dist/assets/sdk-react.css +1 -1
- package/dist/glyph-widget.es.js +18 -17
- package/dist/glyph-widget.umd.js +89 -37
- package/dist/glyph-widget.umd.js.map +1 -1
- package/dist/index.js +33720 -13816
- package/dist/index.js.map +1 -1
- package/dist/types/assets/svg/TxSwapIcon.d.ts +1 -0
- package/dist/types/components/shared/ActivityRow.d.ts +1 -0
- package/dist/types/components/shared/{ChainIcon.d.ts → NativeTokenIcon.d.ts} +1 -1
- package/dist/types/components/shared/WalletViewTemplate.d.ts +2 -0
- package/dist/types/components/ui/button.d.ts +1 -1
- package/dist/types/components/ui/dialog.d.ts +21 -0
- package/dist/types/components/ui/drawer.d.ts +18 -0
- package/dist/types/components/widget/WalletHomeTab.d.ts +3 -4
- package/dist/types/components/widget/WalletMainView.d.ts +3 -6
- package/dist/types/components/widget/WalletSendFundView.d.ts +2 -2
- package/dist/types/components/widget/WalletTradeView.d.ts +8 -0
- package/dist/types/components/widget/internal/SendFundChainAndTokenSelector.d.ts +6 -0
- package/dist/types/components/widget/internal/SwapChainAndTokenSelector.d.ts +7 -0
- package/dist/types/components/widget/internal/TokenAndChainIcon.d.ts +13 -0
- package/dist/types/components/widget/{WalletSendFundEnterAddressView.d.ts → internal/WalletSendFundEnterAddressView.d.ts} +1 -1
- package/dist/types/components/widget/{WalletSendFundPendingView.d.ts → internal/WalletSendFundPendingView.d.ts} +2 -2
- package/dist/types/components/widget/{WalletSendFundSuccessView.d.ts → internal/WalletSendFundSuccessView.d.ts} +1 -1
- package/dist/types/components/widget/internal/WalletSwapTopUpGas.d.ts +13 -0
- package/dist/types/components/widget/internal/WalletTokenVsNftSwitcher.d.ts +5 -0
- package/dist/types/components/widget/internal/WalletTradeFailedView.d.ts +12 -0
- package/dist/types/components/widget/internal/WalletTradePendingView.d.ts +13 -0
- package/dist/types/components/widget/internal/WalletTradeSuccessView.d.ts +13 -0
- package/dist/types/components/widget/{WidgetGradient.d.ts → internal/WidgetGradient.d.ts} +1 -1
- package/dist/types/context/GlyphSwapContext.d.ts +18 -0
- package/dist/types/context/GlyphSwapProvider.d.ts +3 -0
- package/dist/types/context/GlyphUserDataContext.d.ts +3 -0
- package/dist/types/context/GlyphUserDataProvider.d.ts +2 -5
- package/dist/types/context/GlyphViewProvider.d.ts +2 -4
- package/dist/types/context/strategies/EIP1193Strategy.d.ts +2 -2
- package/dist/types/context/strategies/LoadingStrategy.d.ts +2 -3
- package/dist/types/context/strategies/PrivyStrategy.d.ts +2 -1
- package/dist/types/hooks/useActivity.d.ts +1 -0
- package/dist/types/hooks/useBalances.d.ts +3 -0
- package/dist/types/hooks/useGlyph.d.ts +10 -7
- package/dist/types/hooks/useGlyphConfigureDynamicChains.d.ts +12 -0
- package/dist/types/hooks/useGlyphFunding.d.ts +1 -1
- package/dist/types/hooks/useGlyphRelayEvmAdapter.d.ts +2 -0
- package/dist/types/hooks/useRelayExecute.d.ts +9 -0
- package/dist/types/hooks/useRelayIntentStatus.d.ts +18 -0
- package/dist/types/hooks/useRelayQuote.d.ts +175 -0
- package/dist/types/hooks/useRelayTokenList.d.ts +25 -0
- package/dist/types/hooks/useTokenBalance.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lib/constants.d.ts +10 -6
- package/dist/types/lib/eip1193/GlyphWalletProvider.d.ts +2 -8
- package/dist/types/lib/intl.d.ts +1 -1
- package/dist/types/lib/privy/GlyphPrivyProvider.d.ts +8 -9
- package/dist/types/lib/relay.d.ts +2 -0
- package/dist/types/lib/utils.d.ts +15 -2
- package/dist/types/types/GlyphWidgetTypes.d.ts +13 -2
- package/package.json +3 -1
- package/dist/types/assets/svg/APEIcon.d.ts +0 -2
- package/dist/types/assets/svg/APE_ETH.d.ts +0 -1
- package/dist/types/assets/svg/APE_USD.d.ts +0 -1
- package/dist/types/assets/svg/APE_WAPE.d.ts +0 -1
- package/dist/types/assets/svg/ApechainIcon.d.ts +0 -1
- package/dist/types/assets/svg/ApecoinIcon.d.ts +0 -2
- package/dist/types/assets/svg/BaseIcon.d.ts +0 -1
- package/dist/types/assets/svg/ETH.d.ts +0 -1
- package/dist/types/assets/svg/POL.d.ts +0 -1
- package/dist/types/assets/svg/USDCIcon.d.ts +0 -1
- /package/dist/types/components/widget/{WalletFundFailedView.d.ts → internal/WalletFundFailedView.d.ts} +0 -0
- /package/dist/types/components/widget/{WalletFundPendingView.d.ts → internal/WalletFundPendingView.d.ts} +0 -0
- /package/dist/types/components/widget/{WalletFundSuccessView.d.ts → internal/WalletFundSuccessView.d.ts} +0 -0
- /package/dist/types/components/widget/{WalletSendFundFailedView.d.ts → internal/WalletSendFundFailedView.d.ts} +0 -0
package/dist/EIP1193Strategy.js
CHANGED
|
@@ -1,148 +1,157 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as g, useEffect as
|
|
3
|
-
import { useAccount as
|
|
4
|
-
import { c as
|
|
5
|
-
const
|
|
6
|
-
children:
|
|
7
|
-
glyphUrl:
|
|
8
|
-
onLogin:
|
|
9
|
-
onLogout:
|
|
10
|
-
askForSignature:
|
|
1
|
+
import { jsx as J } from "react/jsx-runtime";
|
|
2
|
+
import { useState as g, useEffect as m, useCallback as a } from "react";
|
|
3
|
+
import { useAccount as R, useDisconnect as q, useSignMessage as z, useSignTypedData as H, useSendTransaction as Q, useAccountEffect as V } from "wagmi";
|
|
4
|
+
import { c as X, W as A, b as Z, a as U } from "./index.js";
|
|
5
|
+
const T = "__glyph-widget-token__", I = "__glyph-widget-nonce__", s = X("EIP1193Strategy"), re = ({
|
|
6
|
+
children: x,
|
|
7
|
+
glyphUrl: c,
|
|
8
|
+
onLogin: M,
|
|
9
|
+
onLogout: P,
|
|
10
|
+
askForSignature: p = !0
|
|
11
11
|
}) => {
|
|
12
|
-
const [j,
|
|
13
|
-
|
|
14
|
-
const [
|
|
12
|
+
const [j, i] = g(!1), [L, f] = g(null), { address: t, isConnected: n, chainId: _ } = R(), { disconnectAsync: v } = q(), { signMessageAsync: y } = z(), { signTypedDataAsync: k } = H(), { sendTransactionAsync: C } = Q();
|
|
13
|
+
s.log({ address: t, isConnected: n });
|
|
14
|
+
const [l, w] = g(() => {
|
|
15
15
|
if (typeof window > "u")
|
|
16
16
|
return null;
|
|
17
17
|
try {
|
|
18
|
-
return localStorage.getItem(
|
|
18
|
+
return localStorage.getItem(T);
|
|
19
19
|
} catch (e) {
|
|
20
|
-
return
|
|
20
|
+
return s.warn("Error reading session token", e), null;
|
|
21
21
|
}
|
|
22
|
-
}), [u, O] = g(null), [
|
|
22
|
+
}), [u, O] = g(null), [o, E] = g(() => {
|
|
23
23
|
if (typeof window > "u")
|
|
24
24
|
return null;
|
|
25
25
|
try {
|
|
26
|
-
return localStorage.getItem(
|
|
26
|
+
return localStorage.getItem(I);
|
|
27
27
|
} catch (e) {
|
|
28
|
-
return
|
|
28
|
+
return s.warn("Error reading session nonce", e), null;
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
|
|
31
|
+
m(() => {
|
|
32
32
|
try {
|
|
33
|
-
!
|
|
33
|
+
!l || !o ? (localStorage.removeItem(T), localStorage.removeItem(I)) : (localStorage.setItem(T, l), localStorage.setItem(I, o));
|
|
34
34
|
} catch (e) {
|
|
35
|
-
|
|
35
|
+
s.error("Error saving session token", e);
|
|
36
36
|
}
|
|
37
|
-
}, [
|
|
38
|
-
const
|
|
37
|
+
}, [o, l]);
|
|
38
|
+
const b = a(
|
|
39
39
|
async (e) => {
|
|
40
40
|
try {
|
|
41
41
|
return await fetch(
|
|
42
|
-
`${
|
|
43
|
-
).then((
|
|
44
|
-
} catch (
|
|
45
|
-
throw
|
|
42
|
+
`${c || A}/api/widget/auth/message/${e}`
|
|
43
|
+
).then((d) => d.json());
|
|
44
|
+
} catch (r) {
|
|
45
|
+
throw s.error("Can't fetch message to sign", r), new Error("Failed to fetch the message to sign.");
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
[
|
|
49
|
-
),
|
|
50
|
-
async (e,
|
|
48
|
+
[c]
|
|
49
|
+
), D = a(
|
|
50
|
+
async (e, r, d) => {
|
|
51
51
|
try {
|
|
52
|
-
return await fetch(`${
|
|
52
|
+
return await fetch(`${c || A}/api/widget/auth/verify/${e}`, {
|
|
53
53
|
method: "POST",
|
|
54
|
-
body: JSON.stringify({ signature:
|
|
55
|
-
}).then((
|
|
56
|
-
} catch (
|
|
57
|
-
throw
|
|
54
|
+
body: JSON.stringify({ signature: r, nonce: d })
|
|
55
|
+
}).then((B) => B.json());
|
|
56
|
+
} catch (h) {
|
|
57
|
+
throw s.error("Can't verify signature", h), new Error("Signature verification failed.");
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
|
-
[
|
|
60
|
+
[c]
|
|
61
61
|
);
|
|
62
|
-
|
|
63
|
-
!t || !
|
|
64
|
-
O(e),
|
|
62
|
+
m(() => {
|
|
63
|
+
!t || !n || o || (i(!0), b(t).then(({ message: e, nonce: r }) => {
|
|
64
|
+
O(e), E(r), i(!1);
|
|
65
65
|
}).finally(() => {
|
|
66
|
-
|
|
66
|
+
i(!1);
|
|
67
67
|
}));
|
|
68
|
-
}, [t,
|
|
69
|
-
if (!
|
|
70
|
-
const e =
|
|
68
|
+
}, [t, n, b, o]), m(() => {
|
|
69
|
+
if (!l || !o) return;
|
|
70
|
+
const e = Z(c || A, async () => l, {
|
|
71
71
|
"x-evm-address": t,
|
|
72
|
-
"x-glyph-nonce":
|
|
72
|
+
"x-glyph-nonce": o
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
}, [
|
|
76
|
-
const $ =
|
|
74
|
+
f(() => e);
|
|
75
|
+
}, [l, t, c, o]);
|
|
76
|
+
const $ = a(async () => {
|
|
77
77
|
await v();
|
|
78
|
-
}, [v]),
|
|
79
|
-
if (
|
|
80
|
-
|
|
78
|
+
}, [v]), S = a(async () => {
|
|
79
|
+
if (s.log("authenticate"), !t) {
|
|
80
|
+
s.error("no wallet connected.");
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
try {
|
|
84
|
-
if (!t || !
|
|
85
|
-
|
|
84
|
+
if (!t || !n || !u || !o) {
|
|
85
|
+
f(null), i(!1);
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
const e = await
|
|
90
|
-
console.log(
|
|
91
|
-
const
|
|
92
|
-
w(
|
|
88
|
+
i(!0);
|
|
89
|
+
const e = await y({ account: t, message: u });
|
|
90
|
+
console.log(o, u, e);
|
|
91
|
+
const r = (await D(t, e, o))?.token;
|
|
92
|
+
w(r);
|
|
93
93
|
} catch (e) {
|
|
94
|
-
|
|
94
|
+
s.error("Authentication failed", e), e?.message?.toLowerCase?.().includes?.("user rejected") || await alert(
|
|
95
95
|
"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in."
|
|
96
|
-
),
|
|
96
|
+
), f(null), w(null), E(null);
|
|
97
97
|
} finally {
|
|
98
|
-
|
|
98
|
+
i(!1), M?.();
|
|
99
99
|
}
|
|
100
|
-
}, [t,
|
|
101
|
-
|
|
102
|
-
}, []),
|
|
100
|
+
}, [t, n, u, o, y, D]), F = a(async () => {
|
|
101
|
+
E(null), w(null), i(!1), f(null), P?.();
|
|
102
|
+
}, []), K = a(
|
|
103
103
|
async ({ message: e }) => {
|
|
104
|
-
if (!t || !
|
|
104
|
+
if (!t || !n)
|
|
105
105
|
throw new Error("Wallet not connected");
|
|
106
|
-
return
|
|
106
|
+
return y({ account: t, message: e });
|
|
107
107
|
},
|
|
108
|
-
[t,
|
|
109
|
-
),
|
|
108
|
+
[t, n, y]
|
|
109
|
+
), G = a(
|
|
110
|
+
async ({ data: e }) => {
|
|
111
|
+
if (!t || !n)
|
|
112
|
+
throw new Error("Wallet not connected");
|
|
113
|
+
const r = e.types, d = e.primaryType, h = e.message;
|
|
114
|
+
return k({ types: r, primaryType: d, message: h });
|
|
115
|
+
},
|
|
116
|
+
[t, n, k]
|
|
117
|
+
), Y = a(
|
|
110
118
|
async ({ transaction: e }) => {
|
|
111
|
-
if (!t || !
|
|
112
|
-
return C({ ...e, chainId:
|
|
119
|
+
if (!t || !n) throw new Error("Wallet not connected");
|
|
120
|
+
return C({ ...e, chainId: e.chainId || _ });
|
|
113
121
|
},
|
|
114
|
-
[t,
|
|
115
|
-
), [
|
|
116
|
-
return
|
|
122
|
+
[t, n, C, _]
|
|
123
|
+
), [N, W] = g(!1);
|
|
124
|
+
return V({
|
|
117
125
|
onConnect: () => {
|
|
118
|
-
|
|
126
|
+
p && W(!0);
|
|
119
127
|
},
|
|
120
128
|
onDisconnect: () => {
|
|
121
|
-
|
|
129
|
+
F();
|
|
122
130
|
}
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
}, [
|
|
126
|
-
|
|
131
|
+
}), m(() => {
|
|
132
|
+
p && n && t && N && o && u && (S(), W(!1));
|
|
133
|
+
}, [n, t, S, N, o, u, p]), /* @__PURE__ */ J(
|
|
134
|
+
U.Provider,
|
|
127
135
|
{
|
|
128
136
|
value: {
|
|
129
|
-
ready: !j && !!
|
|
130
|
-
authenticated:
|
|
131
|
-
glyphUrl:
|
|
137
|
+
ready: !j && !!o,
|
|
138
|
+
authenticated: n && !!t && l !== null,
|
|
139
|
+
glyphUrl: c,
|
|
132
140
|
// Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
|
|
133
|
-
hideWidget: !
|
|
134
|
-
login:
|
|
141
|
+
hideWidget: !n || !t,
|
|
142
|
+
login: S,
|
|
135
143
|
logout: $,
|
|
136
144
|
// on disconnect, logoutSideEffect is called and clears states
|
|
137
|
-
signMessage:
|
|
138
|
-
|
|
145
|
+
signMessage: K,
|
|
146
|
+
signTypedData: G,
|
|
147
|
+
sendTransaction: Y,
|
|
139
148
|
apiFetch: L
|
|
140
149
|
},
|
|
141
|
-
children:
|
|
150
|
+
children: x
|
|
142
151
|
}
|
|
143
152
|
);
|
|
144
153
|
};
|
|
145
154
|
export {
|
|
146
|
-
|
|
155
|
+
re as default
|
|
147
156
|
};
|
|
148
157
|
//# sourceMappingURL=EIP1193Strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EIP1193Strategy.js","sources":["../src/context/strategies/EIP1193Strategy.tsx"],"sourcesContent":["import { UnsignedTransactionRequest } from \"@privy-io/react-auth\";\nimport { FC, useCallback, useEffect, useState } from \"react\";\nimport { apeChain } from \"viem/chains\";\nimport { useAccount, useAccountEffect, useDisconnect, useSendTransaction, useSignMessage } from \"wagmi\";\nimport { WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptionsWithSignature } from \"../../types\";\nimport { GlyphApiFetch, GlyphContext, createApiFetch } from \"../GlyphContext\";\n\ntype GlyphSigningMsgResponse = { message: string; nonce: string };\ntype GlyphSignatureVerifyResponse = { token: string };\n\nconst TOKEN_KEY = \"__glyph-widget-token__\";\nconst NONCE_KEY = \"__glyph-widget-nonce__\";\nconst logger = createLogger(\"EIP1193Strategy\");\n\nconst EIP1193Strategy: FC<BaseGlyphProviderOptionsWithSignature> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n askForSignature = true\n}) => {\n const [loading, setLoading] = useState(false);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const { address, isConnected, chainId } = useAccount(); // detect wallet connection\n const { disconnectAsync } = useDisconnect(); // disconnect the wallet\n const { signMessageAsync } = useSignMessage(); // signing messages with the wallet\n const { sendTransactionAsync } = useSendTransaction(); // sending transactions with the wallet\n\n logger.log({ address, isConnected });\n\n // Fetch authentication token from session storage\n const [token, setToken] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(TOKEN_KEY);\n } catch (error) {\n logger.warn(\"Error reading session token\", error);\n return null;\n }\n });\n\n const [message, setMessage] = useState<string | null>(null);\n\n // fetch nonce from session storage\n const [sessNonce, setSessNonce] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(NONCE_KEY);\n } catch (error) {\n logger.warn(\"Error reading session nonce\", error);\n return null;\n }\n });\n\n // Keep token and nonce updated in session storage\n useEffect(() => {\n try {\n if (!token || !sessNonce) {\n localStorage.removeItem(TOKEN_KEY);\n localStorage.removeItem(NONCE_KEY);\n } else {\n localStorage.setItem(TOKEN_KEY, token!);\n localStorage.setItem(NONCE_KEY, sessNonce!);\n }\n } catch (error) {\n logger.error(\"Error saving session token\", error);\n }\n }, [sessNonce, token]);\n\n const fetchMessageToSign = useCallback(\n async (address: string): Promise<GlyphSigningMsgResponse> => {\n try {\n const payload = (await fetch(\n `${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/message/${address}`\n ).then((resp) => resp.json())) as GlyphSigningMsgResponse;\n\n return payload;\n } catch (error) {\n logger.error(\"Can't fetch message to sign\", error);\n throw new Error(\"Failed to fetch the message to sign.\");\n }\n },\n [glyphUrl]\n );\n\n const verifySignature = useCallback(\n async (address: string, signature: string, nonce: string): Promise<GlyphSignatureVerifyResponse> => {\n try {\n const payload = await fetch(`${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/verify/${address}`, {\n method: \"POST\",\n body: JSON.stringify({ signature, nonce })\n }).then((resp) => resp.json());\n return payload as unknown as GlyphSignatureVerifyResponse;\n } catch (error) {\n logger.error(\"Can't verify signature\", error);\n throw new Error(\"Signature verification failed.\");\n }\n },\n [glyphUrl]\n );\n\n useEffect(() => {\n if (!address || !isConnected) return;\n if (sessNonce) return;\n\n setLoading(true);\n fetchMessageToSign(address)\n .then(({ message, nonce }) => {\n setMessage(message);\n setSessNonce(nonce);\n setLoading(false);\n })\n .finally(() => {\n setLoading(false);\n });\n }, [address, isConnected, fetchMessageToSign, sessNonce]);\n\n useEffect(() => {\n if (!token || !sessNonce) return;\n\n const glyphApiFetch = createApiFetch(glyphUrl || WIDGET_API_BASE_URL, async () => token, {\n \"x-evm-address\": address!,\n \"x-glyph-nonce\": sessNonce!\n });\n setApiFetch(() => glyphApiFetch);\n }, [token, address, glyphUrl, sessNonce]);\n\n const disconnect = useCallback(async () => {\n await disconnectAsync();\n }, [disconnectAsync]);\n\n const authenticate = useCallback(async () => {\n logger.log(\"authenticate\");\n if (!address) {\n logger.error(\"no wallet connected.\");\n return;\n }\n\n try {\n if (!address || !isConnected || !message || !sessNonce) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n // Sign a message with the wallet to authenticate\n setLoading(true);\n\n const userSignature = await signMessageAsync({ account: address, message: message });\n console.log(sessNonce, message, userSignature);\n\n const token = (await verifySignature(address, userSignature, sessNonce))?.token;\n\n setToken(token);\n } catch (error) {\n logger.error(\"Authentication failed\", error);\n if (!(error as Error)?.message?.toLowerCase?.().includes?.(\"user rejected\")) {\n await alert(\n \"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in.\"\n );\n }\n setApiFetch(null);\n setToken(null);\n setSessNonce(null);\n } finally {\n setLoading(false);\n onLogin?.();\n }\n }, [address, isConnected, message, sessNonce, signMessageAsync, verifySignature]);\n\n const logoutSideEffect = useCallback(async () => {\n setSessNonce(null);\n setToken(null);\n setLoading(false);\n setApiFetch(null);\n onLogout?.();\n }, []);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n return signMessageAsync({ account: address, message });\n },\n [address, isConnected, signMessageAsync]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: Omit<UnsignedTransactionRequest, \"chainId\"> }) => {\n if (!address || !isConnected) throw new Error(\"Wallet not connected\");\n\n return sendTransactionAsync({ ...transaction, chainId: chainId || apeChain.id } as any);\n },\n [address, isConnected, sendTransactionAsync, chainId]\n );\n\n const [tryAuthenticate, setTryAuthenticate] = useState<boolean>(false);\n // Perform graceful logout when the wallet is disconnected from anywhere within the app\n useAccountEffect({\n onConnect: () => {\n if (askForSignature) {\n // Perform initial authentication when the wallet is connected\n setTryAuthenticate(true);\n }\n },\n onDisconnect: () => {\n logoutSideEffect();\n }\n });\n useEffect(() => {\n if (askForSignature && isConnected && address && tryAuthenticate && sessNonce && message) {\n // Initial authentication\n authenticate();\n setTryAuthenticate(false);\n }\n }, [isConnected, address, authenticate, tryAuthenticate, sessNonce, message, askForSignature]);\n\n return (\n <GlyphContext.Provider\n value={{\n ready: !loading && !!sessNonce,\n authenticated: isConnected && !!address && token !== null,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n hideWidget: !isConnected || !address,\n login: authenticate,\n logout: disconnect, // on disconnect, logoutSideEffect is called and clears states\n signMessage,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n children={children}\n />\n );\n};\n\nexport default EIP1193Strategy;\n"],"names":["TOKEN_KEY","NONCE_KEY","logger","createLogger","EIP1193Strategy","children","glyphUrl","onLogin","onLogout","askForSignature","loading","setLoading","useState","apiFetch","setApiFetch","address","isConnected","chainId","useAccount","disconnectAsync","useDisconnect","signMessageAsync","useSignMessage","sendTransactionAsync","useSendTransaction","token","setToken","error","message","setMessage","sessNonce","setSessNonce","useEffect","fetchMessageToSign","useCallback","WIDGET_API_BASE_URL","resp","verifySignature","signature","nonce","glyphApiFetch","createApiFetch","disconnect","authenticate","userSignature","logoutSideEffect","signMessage","sendTransaction","transaction","apeChain","tryAuthenticate","setTryAuthenticate","useAccountEffect","jsx","GlyphContext"],"mappings":";;;;AAYA,MAAMA,IAAY,0BACZC,IAAY,0BACZC,IAASC,EAAa,iBAAiB,GAEvCC,KAA6D,CAAC;AAAA,EAChE,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,iBAAAC,IAAkB;AACtB,MAA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AA,IAAA;AAAA,EAAA;AAGZ;"}
|
|
1
|
+
{"version":3,"file":"EIP1193Strategy.js","sources":["../src/context/strategies/EIP1193Strategy.tsx"],"sourcesContent":["import { SignTypedDataParams, UnsignedTransactionRequest } from \"@privy-io/react-auth\";\nimport react, { useCallback, useEffect, useState } from \"react\";\nimport {\n useAccount,\n useAccountEffect,\n useDisconnect,\n useSendTransaction,\n useSignMessage,\n useSignTypedData\n} from \"wagmi\";\nimport { WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptionsWithSignature } from \"../../types\";\nimport { GlyphApiFetch, GlyphContext, createApiFetch } from \"../GlyphContext\";\n\ntype GlyphSigningMsgResponse = { message: string; nonce: string };\ntype GlyphSignatureVerifyResponse = { token: string };\n\nconst TOKEN_KEY = \"__glyph-widget-token__\";\nconst NONCE_KEY = \"__glyph-widget-nonce__\";\nconst logger = createLogger(\"EIP1193Strategy\");\n\nconst EIP1193Strategy: react.FC<BaseGlyphProviderOptionsWithSignature> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n askForSignature = true\n}) => {\n const [loading, setLoading] = useState(false);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const { address, isConnected, chainId } = useAccount(); // detect wallet connection\n const { disconnectAsync } = useDisconnect(); // disconnect the wallet\n const { signMessageAsync } = useSignMessage(); // signing messages with the wallet\n const { signTypedDataAsync } = useSignTypedData(); // signing typed data with the wallet\n const { sendTransactionAsync } = useSendTransaction(); // sending transactions with the wallet\n\n logger.log({ address, isConnected });\n\n // Fetch authentication token from session storage\n const [token, setToken] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(TOKEN_KEY);\n } catch (error) {\n logger.warn(\"Error reading session token\", error);\n return null;\n }\n });\n\n const [message, setMessage] = useState<string | null>(null);\n\n // fetch nonce from session storage\n const [sessNonce, setSessNonce] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(NONCE_KEY);\n } catch (error) {\n logger.warn(\"Error reading session nonce\", error);\n return null;\n }\n });\n\n // Keep token and nonce updated in session storage\n useEffect(() => {\n try {\n if (!token || !sessNonce) {\n localStorage.removeItem(TOKEN_KEY);\n localStorage.removeItem(NONCE_KEY);\n } else {\n localStorage.setItem(TOKEN_KEY, token!);\n localStorage.setItem(NONCE_KEY, sessNonce!);\n }\n } catch (error) {\n logger.error(\"Error saving session token\", error);\n }\n }, [sessNonce, token]);\n\n const fetchMessageToSign = useCallback(\n async (address: string): Promise<GlyphSigningMsgResponse> => {\n try {\n const payload = (await fetch(\n `${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/message/${address}`\n ).then((resp) => resp.json())) as GlyphSigningMsgResponse;\n\n return payload;\n } catch (error) {\n logger.error(\"Can't fetch message to sign\", error);\n throw new Error(\"Failed to fetch the message to sign.\");\n }\n },\n [glyphUrl]\n );\n\n const verifySignature = useCallback(\n async (address: string, signature: string, nonce: string): Promise<GlyphSignatureVerifyResponse> => {\n try {\n const payload = await fetch(`${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/verify/${address}`, {\n method: \"POST\",\n body: JSON.stringify({ signature, nonce })\n }).then((resp) => resp.json());\n return payload as unknown as GlyphSignatureVerifyResponse;\n } catch (error) {\n logger.error(\"Can't verify signature\", error);\n throw new Error(\"Signature verification failed.\");\n }\n },\n [glyphUrl]\n );\n\n useEffect(() => {\n if (!address || !isConnected) return;\n if (sessNonce) return;\n\n setLoading(true);\n fetchMessageToSign(address)\n .then(({ message, nonce }) => {\n setMessage(message);\n setSessNonce(nonce);\n setLoading(false);\n })\n .finally(() => {\n setLoading(false);\n });\n }, [address, isConnected, fetchMessageToSign, sessNonce]);\n\n useEffect(() => {\n if (!token || !sessNonce) return;\n\n const glyphApiFetch = createApiFetch(glyphUrl || WIDGET_API_BASE_URL, async () => token, {\n \"x-evm-address\": address!,\n \"x-glyph-nonce\": sessNonce!\n });\n setApiFetch(() => glyphApiFetch);\n }, [token, address, glyphUrl, sessNonce]);\n\n const disconnect = useCallback(async () => {\n await disconnectAsync();\n }, [disconnectAsync]);\n\n const authenticate = useCallback(async () => {\n logger.log(\"authenticate\");\n if (!address) {\n logger.error(\"no wallet connected.\");\n return;\n }\n\n try {\n if (!address || !isConnected || !message || !sessNonce) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n // Sign a message with the wallet to authenticate\n setLoading(true);\n\n const userSignature = await signMessageAsync({ account: address, message: message });\n console.log(sessNonce, message, userSignature);\n\n const token = (await verifySignature(address, userSignature, sessNonce))?.token;\n\n setToken(token);\n } catch (error) {\n logger.error(\"Authentication failed\", error);\n if (!(error as Error)?.message?.toLowerCase?.().includes?.(\"user rejected\")) {\n await alert(\n \"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in.\"\n );\n }\n setApiFetch(null);\n setToken(null);\n setSessNonce(null);\n } finally {\n setLoading(false);\n onLogin?.();\n }\n }, [address, isConnected, message, sessNonce, signMessageAsync, verifySignature]);\n\n const logoutSideEffect = useCallback(async () => {\n setSessNonce(null);\n setToken(null);\n setLoading(false);\n setApiFetch(null);\n onLogout?.();\n }, []);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n return signMessageAsync({ account: address, message });\n },\n [address, isConnected, signMessageAsync]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n const types = data.types;\n const primaryType = data.primaryType as string;\n const message = data.message;\n return signTypedDataAsync({ types, primaryType, message });\n },\n [address, isConnected, signTypedDataAsync]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!address || !isConnected) throw new Error(\"Wallet not connected\");\n\n return sendTransactionAsync({ ...transaction, chainId: transaction.chainId || chainId } as any);\n },\n [address, isConnected, sendTransactionAsync, chainId]\n );\n\n const [tryAuthenticate, setTryAuthenticate] = useState<boolean>(false);\n // Perform graceful logout when the wallet is disconnected from anywhere within the app\n useAccountEffect({\n onConnect: () => {\n if (askForSignature) {\n // Perform initial authentication when the wallet is connected\n setTryAuthenticate(true);\n }\n },\n onDisconnect: () => {\n logoutSideEffect();\n }\n });\n useEffect(() => {\n if (askForSignature && isConnected && address && tryAuthenticate && sessNonce && message) {\n // Initial authentication\n authenticate();\n setTryAuthenticate(false);\n }\n }, [isConnected, address, authenticate, tryAuthenticate, sessNonce, message, askForSignature]);\n\n return (\n <GlyphContext.Provider\n value={{\n ready: !loading && !!sessNonce,\n authenticated: isConnected && !!address && token !== null,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n hideWidget: !isConnected || !address,\n login: authenticate,\n logout: disconnect, // on disconnect, logoutSideEffect is called and clears states\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n children={children}\n />\n );\n};\n\nexport default EIP1193Strategy;\n"],"names":["TOKEN_KEY","NONCE_KEY","logger","createLogger","EIP1193Strategy","children","glyphUrl","onLogin","onLogout","askForSignature","loading","setLoading","useState","apiFetch","setApiFetch","address","isConnected","chainId","useAccount","disconnectAsync","useDisconnect","signMessageAsync","useSignMessage","signTypedDataAsync","useSignTypedData","sendTransactionAsync","useSendTransaction","token","setToken","error","message","setMessage","sessNonce","setSessNonce","useEffect","fetchMessageToSign","useCallback","WIDGET_API_BASE_URL","resp","verifySignature","signature","nonce","glyphApiFetch","createApiFetch","disconnect","authenticate","userSignature","logoutSideEffect","signMessage","signTypedData","data","types","primaryType","sendTransaction","transaction","tryAuthenticate","setTryAuthenticate","useAccountEffect","jsx","GlyphContext"],"mappings":";;;;AAkBA,MAAMA,IAAY,0BACZC,IAAY,0BACZC,IAASC,EAAa,iBAAiB,GAEvCC,KAAmE,CAAC;AAAA,EACtE,UAAAC;AAAA,EACA,UAAA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AmB,EAAK;AAAA,EAEhC,GAAG,CAACxC,GAAaD,GAAS8B,GAAcU,GAAiBvB,GAAWF,GAASrB,CAAe,CAAC,GAGzF,gBAAAiD;AAAA,IAACC,EAAa;AAAA,IAAb;AAAA,MACG,OAAO;AAAA,QACH,OAAO,CAACjD,KAAW,CAAC,CAACsB;AAAA,QACrB,eAAehB,KAAe,CAAC,CAACD,KAAWY,MAAU;AAAA,QACrD,UAAArB;AAAA;AAAA,QACA,YAAY,CAACU,KAAe,CAACD;AAAA,QAC7B,OAAO8B;AAAA,QACP,QAAQD;AAAA;AAAA,QACR,aAAAI;AAAA,QACA,eAAAC;AAAA,QACA,iBAAAI;AAAA,QACA,UAAAxC;AAAA,MAAA;AAAA,MAEJ,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
|
package/dist/PrivyStrategy.js
CHANGED
|
@@ -1,107 +1,125 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { usePrivy as
|
|
3
|
-
import { memo as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
const t =
|
|
7
|
-
|
|
1
|
+
import { jsx as q } from "react/jsx-runtime";
|
|
2
|
+
import { usePrivy as z, useCrossAppAccounts as J, useWallets as K } from "@privy-io/react-auth";
|
|
3
|
+
import { memo as O, useState as l, useEffect as Q, useCallback as i } from "react";
|
|
4
|
+
import { useChainId as X } from "wagmi";
|
|
5
|
+
import { c as Z, i as ss, S as M, G as x, a as es, b as ts, W as as } from "./index.js";
|
|
6
|
+
const t = Z("PrivyStrategy"), ns = ({
|
|
7
|
+
children: L,
|
|
8
|
+
glyphUrl: p,
|
|
9
|
+
onLogin: m,
|
|
10
|
+
onLogout: v,
|
|
11
|
+
useStagingTenant: u
|
|
12
|
+
}) => {
|
|
13
|
+
const [F, y] = l(!0), [N, g] = l(null), [a, R] = l(null), [n, V] = l(!1), w = X(), {
|
|
8
14
|
ready: o,
|
|
9
|
-
authenticated:
|
|
15
|
+
authenticated: d,
|
|
10
16
|
user: c,
|
|
11
|
-
getAccessToken:
|
|
12
|
-
login:
|
|
13
|
-
logout:
|
|
14
|
-
signMessage:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
getAccessToken: P,
|
|
18
|
+
login: _,
|
|
19
|
+
logout: h,
|
|
20
|
+
signMessage: T,
|
|
21
|
+
signTypedData: b,
|
|
22
|
+
sendTransaction: E
|
|
23
|
+
} = z(), {
|
|
24
|
+
signMessage: G,
|
|
25
|
+
signTypedData: I,
|
|
26
|
+
sendTransaction: S
|
|
27
|
+
} = J();
|
|
28
|
+
t.debug(o, d, !!c);
|
|
29
|
+
const { wallets: Y } = K();
|
|
30
|
+
Q(() => {
|
|
20
31
|
if (!o) {
|
|
21
32
|
g(null), y(!0);
|
|
22
33
|
return;
|
|
23
34
|
}
|
|
24
|
-
if (!
|
|
35
|
+
if (!d || !c) {
|
|
25
36
|
g(null), y(!1);
|
|
26
37
|
return;
|
|
27
38
|
}
|
|
28
|
-
let
|
|
39
|
+
let s;
|
|
29
40
|
const r = c.linkedAccounts?.find(
|
|
30
|
-
(
|
|
31
|
-
),
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
(
|
|
41
|
+
(e) => e.type === "wallet" && e.chainType === "ethereum" && e.walletClientType === "privy"
|
|
42
|
+
), D = r && ss(r.address);
|
|
43
|
+
D && t.debug("Privy (main) EVM embedded wallet", r.address), t.debug("finding cross-app accounts...");
|
|
44
|
+
const W = c.linkedAccounts?.filter?.((e) => e.type === "cross_app") || [], k = W.filter(
|
|
45
|
+
(e) => e.providerApp?.id !== (u ? M : x)
|
|
35
46
|
);
|
|
36
|
-
t.debug("linked accounts - non-Glyph", { accounts:
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
(
|
|
47
|
+
t.debug("linked accounts - non-Glyph", { accounts: k });
|
|
48
|
+
const f = k.map((e) => e.embeddedWallets[0].address);
|
|
49
|
+
f.length > 0 && (s = f[0], t.log("using cross_app (non-Glyph) account"), f.length > 1 && t.warn("too many cross_app accounts"));
|
|
50
|
+
const C = W.filter(
|
|
51
|
+
(e) => e.providerApp?.id === (u ? M : x)
|
|
41
52
|
);
|
|
42
|
-
t.debug("linked accounts - Glyph", { accounts:
|
|
43
|
-
const A =
|
|
44
|
-
A.length > 0 && (
|
|
45
|
-
if (!
|
|
53
|
+
t.debug("linked accounts - Glyph", { accounts: C });
|
|
54
|
+
const A = C.map((e) => e.embeddedWallets[0].address);
|
|
55
|
+
A.length > 0 && (s = A[0], t.log("using cross_app (Glyph) account"), A.length > 1 && t.warn("too many cross_app accounts")), s ? (V(!0), t.log("using cross_app account", s)) : D && (s = r.address, t.log("using Privy (main) EVM embedded wallet", s)), R(s ?? null), (async () => {
|
|
56
|
+
if (!s) {
|
|
46
57
|
t.error("user has no wallet");
|
|
47
58
|
return;
|
|
48
59
|
}
|
|
49
|
-
const
|
|
50
|
-
p ||
|
|
51
|
-
async () => await
|
|
52
|
-
{ "x-evm-address":
|
|
60
|
+
const e = ts(
|
|
61
|
+
p || as,
|
|
62
|
+
async () => await P(),
|
|
63
|
+
{ "x-evm-address": s }
|
|
53
64
|
);
|
|
54
|
-
g(() =>
|
|
65
|
+
g(() => e), y(!1);
|
|
55
66
|
})();
|
|
56
67
|
}, [
|
|
57
68
|
p,
|
|
58
|
-
|
|
69
|
+
d,
|
|
59
70
|
o,
|
|
60
71
|
c,
|
|
61
72
|
u,
|
|
62
73
|
n,
|
|
63
|
-
|
|
74
|
+
Y,
|
|
64
75
|
a,
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
P,
|
|
77
|
+
h
|
|
67
78
|
]);
|
|
68
|
-
const
|
|
69
|
-
await
|
|
70
|
-
}, [m,
|
|
71
|
-
|
|
72
|
-
}, [v,
|
|
73
|
-
async ({ message:
|
|
79
|
+
const U = i(async () => {
|
|
80
|
+
await _(), m?.();
|
|
81
|
+
}, [m, _]), H = i(async () => {
|
|
82
|
+
h(), v?.();
|
|
83
|
+
}, [v, h]), j = i(
|
|
84
|
+
async ({ message: s }) => {
|
|
74
85
|
if (!a) throw new Error("No wallet address found");
|
|
75
|
-
return n ?
|
|
86
|
+
return n ? G(s, { address: a }) : (await T({ message: s })).signature;
|
|
76
87
|
},
|
|
77
|
-
[a, n,
|
|
78
|
-
),
|
|
79
|
-
async ({
|
|
88
|
+
[a, n, G, T]
|
|
89
|
+
), B = i(
|
|
90
|
+
async ({ data: s }) => {
|
|
80
91
|
if (!a) throw new Error("No wallet address found");
|
|
81
|
-
|
|
82
|
-
return n ? I(r, { address: a }) : G(r, { address: a });
|
|
92
|
+
return n ? I(s, { address: a }) : (await b(s)).signature;
|
|
83
93
|
},
|
|
84
|
-
[
|
|
94
|
+
[a, n, I, b]
|
|
95
|
+
), $ = i(
|
|
96
|
+
async ({ transaction: s }) => {
|
|
97
|
+
if (!a) throw new Error("No wallet address found");
|
|
98
|
+
const r = { ...s, chainId: s.chainId || w };
|
|
99
|
+
return n ? S(r, { address: a }) : (await E(r, { address: a })).hash;
|
|
100
|
+
},
|
|
101
|
+
[w, n, a, S, E]
|
|
85
102
|
);
|
|
86
|
-
return /* @__PURE__ */
|
|
87
|
-
|
|
103
|
+
return /* @__PURE__ */ q(
|
|
104
|
+
es.Provider,
|
|
88
105
|
{
|
|
89
106
|
value: {
|
|
90
|
-
ready: o && !
|
|
91
|
-
authenticated: o &&
|
|
107
|
+
ready: o && !F,
|
|
108
|
+
authenticated: o && d,
|
|
92
109
|
glyphUrl: p,
|
|
93
110
|
// Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
|
|
94
|
-
login:
|
|
95
|
-
logout:
|
|
96
|
-
signMessage:
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
login: U,
|
|
112
|
+
logout: H,
|
|
113
|
+
signMessage: j,
|
|
114
|
+
signTypedData: B,
|
|
115
|
+
sendTransaction: $,
|
|
116
|
+
apiFetch: N
|
|
99
117
|
},
|
|
100
|
-
children:
|
|
118
|
+
children: L
|
|
101
119
|
}
|
|
102
120
|
);
|
|
103
|
-
},
|
|
121
|
+
}, ps = O(ns);
|
|
104
122
|
export {
|
|
105
|
-
|
|
123
|
+
ps as default
|
|
106
124
|
};
|
|
107
125
|
//# sourceMappingURL=PrivyStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivyStrategy.js","sources":["../src/context/strategies/PrivyStrategy.tsx"],"sourcesContent":["import {\n UnsignedTransactionRequest,\n useCrossAppAccounts,\n usePrivy,\n useWallets,\n WalletWithMetadata\n} from \"@privy-io/react-auth\";\nimport { FC, memo, useCallback, useEffect, useState } from \"react\";\nimport { GLYPH_PRIVY_APP_ID, STAGING_GLYPH_PRIVY_APP_ID, WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger, isEthereumAddress } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptions } from \"../../types\";\nimport { createApiFetch, GlyphApiFetch, GlyphContext } from \"../GlyphContext\";\nimport { useChainId } from \"wagmi\";\n\nconst logger = createLogger(\"PrivyStrategy\");\n\nconst PrivyStrategy: FC<BaseGlyphProviderOptions> = ({ children, glyphUrl, onLogin, onLogout, useStagingTenant }) => {\n const [loading, setLoading] = useState<boolean>(true);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const [walletAddress, setWalletAddress] = useState<string | null>(null);\n const [usesCrossapp, setUsesCrossapp] = useState<boolean>(false);\n const chainId = useChainId();\n\n const {\n ready: privyReady,\n authenticated: privyAuthenticated,\n user: privyUser,\n getAccessToken: getPrivyAccessToken,\n login: privyLogin,\n logout: privyLogout,\n signMessage: privySignMessage,\n sendTransaction: privySendTransaction\n } = usePrivy();\n const { signMessage: crossAppSignMessage, sendTransaction: crossAppSendTransaction } = useCrossAppAccounts();\n\n logger.debug(privyReady, privyAuthenticated, !!privyUser);\n const { wallets } = useWallets();\n\n useEffect(() => {\n // If Privy is not ready, reset widget state (loading: true)\n if (!privyReady) {\n setApiFetch(null);\n setLoading(true);\n return;\n }\n\n // If user is not authenticated, reset widget state (loading: false)\n if (!privyAuthenticated || !privyUser) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n let address: string | undefined;\n\n const privyEvmWallet = privyUser!.linkedAccounts?.find(\n (w) => w.type === \"wallet\" && w.chainType === \"ethereum\" && w.walletClientType === \"privy\"\n ) as WalletWithMetadata | undefined;\n\n const hasPrivyEvmWallet = privyEvmWallet && isEthereumAddress(privyEvmWallet.address);\n if (hasPrivyEvmWallet) logger.debug(\"Privy (main) EVM embedded wallet\", privyEvmWallet.address);\n\n logger.debug(\"finding cross-app accounts...\");\n // Cross-app accounts are always EVM addresses\n const crossAppAccounts = privyUser!.linkedAccounts?.filter?.((account) => account.type === \"cross_app\") || [];\n\n const otherAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id !== (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - non-Glyph\", { accounts: otherAccounts });\n const otherAddresses = otherAccounts.map((account) => account.embeddedWallets[0].address);\n if (otherAddresses.length > 0) {\n address = otherAddresses[0];\n logger.log(\"using cross_app (non-Glyph) account\");\n if (otherAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n const glyphAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id === (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - Glyph\", { accounts: glyphAccounts });\n const glyphAddresses = glyphAccounts.map((account) => account.embeddedWallets[0].address);\n if (glyphAddresses.length > 0) {\n address = glyphAddresses[0];\n logger.log(\"using cross_app (Glyph) account\");\n if (glyphAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n if (address) {\n setUsesCrossapp(true);\n logger.log(\"using cross_app account\", address);\n } else if (hasPrivyEvmWallet) {\n address = privyEvmWallet.address;\n logger.log(\"using Privy (main) EVM embedded wallet\", address);\n }\n\n setWalletAddress(address ?? null);\n\n // Fetch user data from Glyph API\n const fetchUserData = async () => {\n // If no address is found, stop here\n if (!address) {\n logger.error(\"user has no wallet\");\n return;\n }\n\n const glyphApiFetch = createApiFetch(\n glyphUrl || WIDGET_API_BASE_URL,\n async () => (await getPrivyAccessToken())!,\n { \"x-evm-address\": address }\n );\n setApiFetch(() => glyphApiFetch);\n setLoading(false);\n };\n\n fetchUserData();\n }, [\n glyphUrl,\n privyAuthenticated,\n privyReady,\n privyUser,\n useStagingTenant,\n usesCrossapp,\n wallets,\n walletAddress,\n getPrivyAccessToken,\n privyLogout\n ]);\n\n const authenticate = useCallback(async () => {\n await privyLogin();\n onLogin?.();\n }, [onLogin, privyLogin]);\n\n const logout = useCallback(async () => {\n privyLogout();\n onLogout?.();\n }, [onLogout, privyLogout]);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n\n return usesCrossapp\n ? crossAppSignMessage(message, { address: walletAddress })\n : privySignMessage({ message });\n },\n [walletAddress, usesCrossapp, crossAppSignMessage, privySignMessage]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: Omit<UnsignedTransactionRequest, \"chainId\"> }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n const tx = { ...transaction, chainId };\n\n return usesCrossapp\n ? crossAppSendTransaction(tx, { address: walletAddress })\n : privySendTransaction(tx, { address: walletAddress });\n },\n [chainId, usesCrossapp, walletAddress, crossAppSendTransaction, privySendTransaction]\n );\n\n return (\n <GlyphContext.Provider\n value={{\n ready: privyReady && !loading,\n authenticated: privyReady && privyAuthenticated,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n login: authenticate,\n logout,\n signMessage,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n >\n {children}\n </GlyphContext.Provider>\n );\n};\n\nexport default memo(PrivyStrategy);\n"],"names":["logger","createLogger","PrivyStrategy","children","glyphUrl","onLogin","onLogout","useStagingTenant","loading","setLoading","useState","apiFetch","setApiFetch","walletAddress","setWalletAddress","usesCrossapp","setUsesCrossapp","chainId","useChainId","privyReady","privyAuthenticated","privyUser","getPrivyAccessToken","privyLogin","privyLogout","privySignMessage","privySendTransaction","usePrivy","crossAppSignMessage","crossAppSendTransaction","useCrossAppAccounts","wallets","useWallets","useEffect","address","privyEvmWallet","w","hasPrivyEvmWallet","isEthereumAddress","crossAppAccounts","account","otherAccounts","STAGING_GLYPH_PRIVY_APP_ID","GLYPH_PRIVY_APP_ID","otherAddresses","glyphAccounts","glyphAddresses","glyphApiFetch","createApiFetch","WIDGET_API_BASE_URL","authenticate","useCallback","logout","signMessage","message","sendTransaction","transaction","tx","jsx","GlyphContext","PrivyStrategy$1","memo"],"mappings":";;;;;AAcA,MAAMA,IAASC,EAAa,eAAe,GAErCC,KAA8C,CAAC,EAAE,UAAAC,GAAU,UAAAC,GAAU,SAAAC,GAAS,UAAAC,GAAU,kBAAAC,QAAuB;AACjH,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAkB,EAAI,GAC9C,CAACC,GAAUC,CAAW,IAAIF,EAA+B,IAAI,GAC7D,CAACG,GAAeC,CAAgB,IAAIJ,EAAwB,IAAI,GAChE,CAACK,GAAcC,CAAe,IAAIN,EAAkB,EAAK,GACzDO,IAAUC,GAAA,GAEV;AAAA,IACF,OAAOC;AAAA,IACP,eAAeC;AAAA,IACf,MAAMC;AAAA,IACN,gBAAgBC;AAAA,IAChB,OAAOC;AAAA,IACP,QAAQC;AAAA,IACR,aAAaC;AAAA,IACb,iBAAiBC;AAAA,EAAA,IACjBC,EAAA,GACE,EAAE,aAAaC,GAAqB,iBAAiBC,EAAA,IAA4BC,EAAA;AAEvF,EAAA9B,EAAO,MAAMmB,GAAYC,GAAoB,CAAC,CAACC,CAAS;AACxD,QAAM,EAAE,SAAAU,EAAA,IAAYC,EAAA;AAEpB,EAAAC,EAAU,MAAM;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;AACrF,UAAI,CAAC3C,EAAe,OAAM,IAAI,MAAM,yBAAyB;AAC7D,YAAM4C,IAAK,EAAE,GAAGD,GAAa,SAAAvC,EAAA;AAE7B,aAAOF,IACDc,EAAwB4B,GAAI,EAAE,SAAS5C,GAAe,IACtDa,EAAqB+B,GAAI,EAAE,SAAS5C,GAAe;AAAA,IAC7D;AAAA,IACA,CAACI,GAASF,GAAcF,GAAegB,GAAyBH,CAAoB;AAAA,EAAA;AAGxF,SACI,gBAAAgC;AAAA,IAACC,EAAa;AAAA,IAAb;AAAA,MACG,OAAO;AAAA,QACH,OAAOxC,KAAc,CAACX;AAAA,QACtB,eAAeW,KAAcC;AAAA,QAC7B,UAAAhB;AAAA;AAAA,QACA,OAAO8C;AAAA,QACP,QAAAE;AAAA,QACA,aAAAC;AAAA,QACA,iBAAAE;AAAA,QACA,UAAA5C;AAAA,MAAA;AAAA,MAGH,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGb,GAEAyD,KAAeC,EAAK3D,EAAa;"}
|
|
1
|
+
{"version":3,"file":"PrivyStrategy.js","sources":["../src/context/strategies/PrivyStrategy.tsx"],"sourcesContent":["import {\n SignTypedDataParams,\n UnsignedTransactionRequest,\n useCrossAppAccounts,\n usePrivy,\n useWallets,\n WalletWithMetadata\n} from \"@privy-io/react-auth\";\nimport react, { memo, useCallback, useEffect, useState } from \"react\";\nimport { useChainId } from \"wagmi\";\nimport { GLYPH_PRIVY_APP_ID, STAGING_GLYPH_PRIVY_APP_ID, WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger, isEthereumAddress } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptions } from \"../../types\";\nimport { createApiFetch, GlyphApiFetch, GlyphContext } from \"../GlyphContext\";\n\nconst logger = createLogger(\"PrivyStrategy\");\n\nconst PrivyStrategy: react.FC<BaseGlyphProviderOptions> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n useStagingTenant\n}) => {\n const [loading, setLoading] = useState<boolean>(true);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const [walletAddress, setWalletAddress] = useState<string | null>(null);\n const [usesCrossapp, setUsesCrossapp] = useState<boolean>(false);\n const chainId = useChainId();\n\n const {\n ready: privyReady,\n authenticated: privyAuthenticated,\n user: privyUser,\n getAccessToken: getPrivyAccessToken,\n login: privyLogin,\n logout: privyLogout,\n signMessage: privySignMessage,\n signTypedData: privySignTypedData,\n sendTransaction: privySendTransaction\n } = usePrivy();\n\n const {\n signMessage: crossAppSignMessage,\n signTypedData: crossAppSignTypedData,\n sendTransaction: crossAppSendTransaction\n } = useCrossAppAccounts();\n\n logger.debug(privyReady, privyAuthenticated, !!privyUser);\n const { wallets } = useWallets();\n\n useEffect(() => {\n // If Privy is not ready, reset widget state (loading: true)\n if (!privyReady) {\n setApiFetch(null);\n setLoading(true);\n return;\n }\n\n // If user is not authenticated, reset widget state (loading: false)\n if (!privyAuthenticated || !privyUser) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n let address: string | undefined;\n\n const privyEvmWallet = privyUser!.linkedAccounts?.find(\n (w) => w.type === \"wallet\" && w.chainType === \"ethereum\" && w.walletClientType === \"privy\"\n ) as WalletWithMetadata | undefined;\n\n const hasPrivyEvmWallet = privyEvmWallet && isEthereumAddress(privyEvmWallet.address);\n if (hasPrivyEvmWallet) logger.debug(\"Privy (main) EVM embedded wallet\", privyEvmWallet.address);\n\n logger.debug(\"finding cross-app accounts...\");\n // Cross-app accounts are always EVM addresses\n const crossAppAccounts = privyUser!.linkedAccounts?.filter?.((account) => account.type === \"cross_app\") || [];\n\n const otherAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id !== (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - non-Glyph\", { accounts: otherAccounts });\n const otherAddresses = otherAccounts.map((account) => account.embeddedWallets[0].address);\n if (otherAddresses.length > 0) {\n address = otherAddresses[0];\n logger.log(\"using cross_app (non-Glyph) account\");\n if (otherAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n const glyphAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id === (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - Glyph\", { accounts: glyphAccounts });\n const glyphAddresses = glyphAccounts.map((account) => account.embeddedWallets[0].address);\n if (glyphAddresses.length > 0) {\n address = glyphAddresses[0];\n logger.log(\"using cross_app (Glyph) account\");\n if (glyphAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n if (address) {\n setUsesCrossapp(true);\n logger.log(\"using cross_app account\", address);\n } else if (hasPrivyEvmWallet) {\n address = privyEvmWallet.address;\n logger.log(\"using Privy (main) EVM embedded wallet\", address);\n }\n\n setWalletAddress(address ?? null);\n\n // Fetch user data from Glyph API\n const fetchUserData = async () => {\n // If no address is found, stop here\n if (!address) {\n logger.error(\"user has no wallet\");\n return;\n }\n\n const glyphApiFetch = createApiFetch(\n glyphUrl || WIDGET_API_BASE_URL,\n async () => (await getPrivyAccessToken())!,\n { \"x-evm-address\": address }\n );\n setApiFetch(() => glyphApiFetch);\n setLoading(false);\n };\n\n fetchUserData();\n }, [\n glyphUrl,\n privyAuthenticated,\n privyReady,\n privyUser,\n useStagingTenant,\n usesCrossapp,\n wallets,\n walletAddress,\n getPrivyAccessToken,\n privyLogout\n ]);\n\n const authenticate = useCallback(async () => {\n await privyLogin();\n onLogin?.();\n }, [onLogin, privyLogin]);\n\n const logout = useCallback(async () => {\n privyLogout();\n onLogout?.();\n }, [onLogout, privyLogout]);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n\n return usesCrossapp\n ? crossAppSignMessage(message, { address: walletAddress })\n : (await privySignMessage({ message })).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignMessage, privySignMessage]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n return usesCrossapp\n ? crossAppSignTypedData(data, { address: walletAddress })\n : (await privySignTypedData(data)).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignTypedData, privySignTypedData]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n const tx = { ...transaction, chainId: transaction.chainId || chainId };\n\n return usesCrossapp\n ? crossAppSendTransaction(tx, { address: walletAddress })\n : (await privySendTransaction(tx, { address: walletAddress })).hash;\n },\n [chainId, usesCrossapp, walletAddress, crossAppSendTransaction, privySendTransaction]\n );\n\n return (\n <GlyphContext.Provider\n value={{\n ready: privyReady && !loading,\n authenticated: privyReady && privyAuthenticated,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n login: authenticate,\n logout,\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n >\n {children}\n </GlyphContext.Provider>\n );\n};\n\nexport default memo(PrivyStrategy);\n"],"names":["logger","createLogger","PrivyStrategy","children","glyphUrl","onLogin","onLogout","useStagingTenant","loading","setLoading","useState","apiFetch","setApiFetch","walletAddress","setWalletAddress","usesCrossapp","setUsesCrossapp","chainId","useChainId","privyReady","privyAuthenticated","privyUser","getPrivyAccessToken","privyLogin","privyLogout","privySignMessage","privySignTypedData","privySendTransaction","usePrivy","crossAppSignMessage","crossAppSignTypedData","crossAppSendTransaction","useCrossAppAccounts","wallets","useWallets","useEffect","address","privyEvmWallet","w","hasPrivyEvmWallet","isEthereumAddress","crossAppAccounts","account","otherAccounts","STAGING_GLYPH_PRIVY_APP_ID","GLYPH_PRIVY_APP_ID","otherAddresses","glyphAccounts","glyphAddresses","glyphApiFetch","createApiFetch","WIDGET_API_BASE_URL","authenticate","useCallback","logout","signMessage","message","signTypedData","data","sendTransaction","trans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