@use-glyph/sdk-react 0.0.1 → 1.0.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/LICENSE +1 -1
- package/README.md +4 -149
- package/dist/EIP1193Strategy.js +114 -83
- package/dist/PrivyStrategy.js +93 -71
- package/dist/assets/sdk-react.css +1 -1
- package/dist/glyph-widget.es.js +30 -0
- package/dist/glyph-widget.umd.js +150 -0
- package/dist/index.js +8351 -7217
- package/dist/types/components/NativeGlyphConnectButton.d.ts +2 -0
- package/dist/types/context/GlyphProvider.d.ts +7 -2
- package/dist/types/context/strategies/EIP1193Strategy.d.ts +2 -2
- package/dist/types/context/strategies/PrivyStrategy.d.ts +2 -2
- package/dist/types/hooks/useGlyph.d.ts +2 -2
- package/dist/types/hooks/useGlyphFunding.d.ts +6 -0
- package/dist/types/hooks/useNativeGlyphConnection.d.ts +4 -5
- package/dist/types/index.d.ts +5 -4
- package/dist/types/lib/constants.d.ts +2 -0
- package/dist/types/lib/eip1193/GlyphWalletProvider.d.ts +7 -7
- package/dist/types/lib/eip1193/glyphWalletConnector.d.ts +1 -1
- package/dist/types/lib/eip1193/glyphWalletRK.d.ts +1 -1
- package/dist/types/lib/popup.d.ts +1 -1
- package/dist/types/lib/providers.d.ts +162 -162
- package/dist/types/lib/utils.d.ts +4 -3
- package/dist/types/types/GlyphWidgetTypes.d.ts +20 -2
- package/package.json +22 -22
- package/dist/sdk-react.es.js +0 -28
- package/dist/sdk-react.umd.js +0 -151
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
GLYPH SOFTWARE LICENSE v1.0
|
|
2
2
|
|
|
3
|
-
This Glyph Software License (this “License”) is granted by Yuga Labs, Inc. (“Yuga Labs” “we,” or “us”) to the person, entity or organization (“Licensee” or “you” or “your”) downloading or otherwise obtaining a copy of the Glyph software code published and maintained by Yuga Labs at https://github.com/yuga-labs/glyph-sdk (such software code, “Glyph Code”).
|
|
3
|
+
This Glyph Software License (this “License”) is granted by Yuga Labs, Inc. (“Yuga Labs” “we,” or “us”) to the person, entity or organization (“Licensee” or “you” or “your”) downloading or otherwise obtaining a copy of the Glyph software code published and maintained by Yuga Labs at https://github.com/yuga-labs/glyph-sdk-react (such software code, “Glyph Code”).
|
|
4
4
|
|
|
5
5
|
Yuga Labs grants to Licensee a worldwide, non-exclusive, royalty-free, non-assignable, non-transferrable, non-sublicensable limited copyright license to publicly display, publicly perform, reproduce, and distribute the Glyph Code solely for the purpose of integrating the Glyph Code into your products and services (such products and services, the “Developer Products and Services”). Reproduction and distribution of the Glyph Code by you must include a copy of this License. Except for the express license rights granted above, all right, title and interest in the Glyph Code shall remain with Yuga Labs. Use of the Glyph Code is subject to the terms and conditions set forth at https://useglyph.io/terms (the “Terms and Conditions”). This License shall automatically terminate in the event you violate any provision of this License or of the Terms and Conditions.
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -1,152 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Setup
|
|
3
|
-
To use the widget, you need to set up access to Glyph users through Privy's cross-app ecosystem and configure wagmi for EIP1193 wallets.
|
|
1
|
+
# Glyph Widget (React SDK)
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
See it in action 🚀: [https://demo.useglyph.io](https://demo.useglyph.io)
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
Dashboard ⚙️: [https://useglyph.io/](https://useglyph.io/)
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
npm install @privy-io/privy-sdk
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
2. Initialize the Privy client in your application:
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import { PrivyClient } from "@privy-io/privy-sdk";
|
|
17
|
-
|
|
18
|
-
const privy = new PrivyClient({
|
|
19
|
-
apiKey: "YOUR_PRIVY_API_KEY",
|
|
20
|
-
appId: "YOUR_APP_ID"
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Use the Priv client to access Glyph users:
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
const user = await privy.getUser("USER_ID");
|
|
28
|
-
console.log(user);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
1. Setting up wagmi for EIP1193 Wallets
|
|
32
|
-
|
|
33
|
-
Install wagmi and ethers:
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
npm install wagmi ethers
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
2. Configure wagmi in your application:
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
import { createClient, configureChains, defaultChains } from "wagmi";
|
|
43
|
-
import { publicProvider } from "wagmi/providers/public";
|
|
44
|
-
|
|
45
|
-
const { chains, provider } = configureChains(defaultChains, [publicProvider()]);
|
|
46
|
-
|
|
47
|
-
const client = createClient({
|
|
48
|
-
autoConnect: true,
|
|
49
|
-
provider
|
|
50
|
-
});
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
3. Use wagmi hooks to interact with wallets:
|
|
54
|
-
|
|
55
|
-
```js
|
|
56
|
-
import { useAccount, useConnect, useDisconnect } from "wagmi";
|
|
57
|
-
|
|
58
|
-
function Wallet() {
|
|
59
|
-
const { address, isConnected } = useAccount();
|
|
60
|
-
const { connect, connectors } = useConnect();
|
|
61
|
-
const { disconnect } = useDisconnect();
|
|
62
|
-
|
|
63
|
-
if (isConnected) {
|
|
64
|
-
return (
|
|
65
|
-
<div>
|
|
66
|
-
<div>Connected to {address}</div>
|
|
67
|
-
<button onClick={() => disconnect()}>Disconnect</button>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<div>
|
|
74
|
-
{connectors.map((connector) => (
|
|
75
|
-
<button key={connector.id} onClick={() => connect(connector)}>
|
|
76
|
-
Connect with {connector.name}
|
|
77
|
-
</button>
|
|
78
|
-
))}
|
|
79
|
-
</div>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Using with Next.js
|
|
85
|
-
|
|
86
|
-
When using this widget in a Next.js application, you may encounter the following error in the console:
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
URL scheme "webpack-internal" is not supported.
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
This happens because Next.js uses webpack for bundling, while this widget is built with Vite, and they handle asset URLs differently.
|
|
93
|
-
|
|
94
|
-
### Solution
|
|
95
|
-
|
|
96
|
-
1. Make sure you're using the latest version of the widget which includes fixes for Next.js compatibility.
|
|
97
|
-
|
|
98
|
-
2. If you're still experiencing the issue, create a `next.config.js` file in your project root (or modify your existing one) to properly handle the widget's assets:
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
/** @type {import('next').NextConfig} */
|
|
102
|
-
const nextConfig = {
|
|
103
|
-
webpack: (config) => {
|
|
104
|
-
// This helps resolve the "URL scheme webpack-internal is not supported" error
|
|
105
|
-
config.module.rules.push({
|
|
106
|
-
test: /\.(woff2|jpg|jpeg|png|svg|webp)$/,
|
|
107
|
-
type: "asset/resource"
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return config;
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
module.exports = nextConfig;
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
3. Import the CSS file explicitly in your Next.js application:
|
|
118
|
-
|
|
119
|
-
```jsx
|
|
120
|
-
// In your _app.js or layout.js
|
|
121
|
-
import "@yuga-labs/glyph-sdk-react/style.css";
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
4. If you're using Next.js App Router, you may need to add the following to your `app/layout.js` file:
|
|
125
|
-
|
|
126
|
-
```jsx
|
|
127
|
-
export const metadata = {
|
|
128
|
-
// your existing metadata
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
export default function RootLayout({ children }) {
|
|
132
|
-
return (
|
|
133
|
-
<html lang="en">
|
|
134
|
-
<head>
|
|
135
|
-
{/* Add this line to ensure fonts are loaded correctly */}
|
|
136
|
-
<link
|
|
137
|
-
href="/assets/Gramatika-Regular.woff2"
|
|
138
|
-
rel="preload"
|
|
139
|
-
as="font"
|
|
140
|
-
type="font/woff2"
|
|
141
|
-
crossOrigin="anonymous"
|
|
142
|
-
/>
|
|
143
|
-
</head>
|
|
144
|
-
<body>{children}</body>
|
|
145
|
-
</html>
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
5. Copy the font files from `node_modules/@yuga-labs/glyph-sdk-react/dist/assets/` to your `public/assets/` directory to ensure they're available at runtime.
|
|
151
|
-
|
|
152
|
-
By following these steps, you can set up the widget to access Glyph users through Privy's cross-app ecosystem and configure wagmi for EIP1193 wallets.
|
|
7
|
+
Documentation 📝: [https://docs.useglyph.io/](https://docs.useglyph.io/)
|
package/dist/EIP1193Strategy.js
CHANGED
|
@@ -1,116 +1,147 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { useState as f,
|
|
3
|
-
import { useAccount as
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const [
|
|
1
|
+
import { c as B, W as C, d as J, a as q, j as z, b as H } from "./index.js";
|
|
2
|
+
import { useState as f, useEffect as p, useCallback as d } from "react";
|
|
3
|
+
import { useAccount as Q, useDisconnect as V, useSignMessage as X, useSendTransaction as Z, useAccountEffect as L } from "wagmi";
|
|
4
|
+
const T = "__glyph-widget-token__", k = "__glyph-widget-nonce__", r = B("EIP1193Strategy"), U = ({
|
|
5
|
+
children: O,
|
|
6
|
+
glyphUrl: o,
|
|
7
|
+
onLogin: E,
|
|
8
|
+
onLogout: S,
|
|
9
|
+
askForSignature: A = !0
|
|
10
|
+
}) => {
|
|
11
|
+
const [D, c] = f(!1), [F, h] = f(null), { address: t, isConnected: s, chainId: b } = Q(), { disconnectAsync: x } = V(), { signMessageAsync: m } = X(), { sendTransactionAsync: N } = Z();
|
|
12
|
+
r.log({ address: t, isConnected: s });
|
|
13
|
+
const [i, I] = f(() => {
|
|
12
14
|
if (typeof window > "u")
|
|
13
15
|
return null;
|
|
14
16
|
try {
|
|
15
|
-
return localStorage.getItem(
|
|
17
|
+
return localStorage.getItem(T);
|
|
16
18
|
} catch (e) {
|
|
17
|
-
return
|
|
19
|
+
return r.warn("Error reading session token", e), null;
|
|
18
20
|
}
|
|
19
|
-
}), [
|
|
21
|
+
}), [g, K] = f(null), [n, _] = f(() => {
|
|
20
22
|
if (typeof window > "u")
|
|
21
23
|
return null;
|
|
22
24
|
try {
|
|
23
|
-
return localStorage.getItem(
|
|
25
|
+
return localStorage.getItem(k);
|
|
24
26
|
} catch (e) {
|
|
25
|
-
return
|
|
27
|
+
return r.warn("Error reading session nonce", e), null;
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
|
-
|
|
30
|
+
p(() => {
|
|
29
31
|
try {
|
|
30
|
-
|
|
32
|
+
!i || !n ? (localStorage.removeItem(T), localStorage.removeItem(k)) : (localStorage.setItem(T, i), localStorage.setItem(k, n));
|
|
31
33
|
} catch (e) {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}, [i, o]);
|
|
35
|
-
const v = g(async (e) => {
|
|
36
|
-
try {
|
|
37
|
-
return await fetch(`${a || S}/api/widget/auth/message/${e}`).then(
|
|
38
|
-
(c) => c.json()
|
|
39
|
-
);
|
|
40
|
-
} catch (r) {
|
|
41
|
-
throw n.error("Can't fetch message to sign", r), new Error("Failed to fetch the message to sign.");
|
|
42
|
-
}
|
|
43
|
-
}, [a]), k = g(async (e, r, c) => {
|
|
44
|
-
try {
|
|
45
|
-
return await fetch(`${a || S}/api/widget/auth/verify/${e}`, {
|
|
46
|
-
method: "POST",
|
|
47
|
-
body: JSON.stringify({ signature: r, nonce: c })
|
|
48
|
-
}).then((E) => E.json());
|
|
49
|
-
} catch (d) {
|
|
50
|
-
throw n.error("Can't verify signature", d), new Error("Signature verification failed.");
|
|
34
|
+
r.error("Error saving session token", e);
|
|
51
35
|
}
|
|
52
|
-
}, [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
}, [n, i]);
|
|
37
|
+
const P = d(
|
|
38
|
+
async (e) => {
|
|
39
|
+
try {
|
|
40
|
+
return await fetch(
|
|
41
|
+
`${o || C}/api/widget/auth/message/${e}`
|
|
42
|
+
).then((l) => l.json());
|
|
43
|
+
} catch (a) {
|
|
44
|
+
throw r.error("Can't fetch message to sign", a), new Error("Failed to fetch the message to sign.");
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[o]
|
|
48
|
+
), j = d(
|
|
49
|
+
async (e, a, l) => {
|
|
50
|
+
try {
|
|
51
|
+
return await fetch(`${o || C}/api/widget/auth/verify/${e}`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
body: JSON.stringify({ signature: a, nonce: l })
|
|
54
|
+
}).then((w) => w.json());
|
|
55
|
+
} catch (y) {
|
|
56
|
+
throw r.error("Can't verify signature", y), new Error("Signature verification failed.");
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[o]
|
|
60
|
+
);
|
|
61
|
+
p(() => {
|
|
62
|
+
!t || !s || n || (c(!0), P(t).then(({ message: e, nonce: a }) => {
|
|
63
|
+
K(e), _(a), c(!1);
|
|
64
|
+
}).finally(() => {
|
|
65
|
+
c(!1);
|
|
66
|
+
}));
|
|
67
|
+
}, [t, s, P, n]), p(() => {
|
|
68
|
+
if (!i || !n) return;
|
|
69
|
+
const e = J(o || C, async () => i, {
|
|
56
70
|
"x-evm-address": t,
|
|
57
|
-
"x-glyph-nonce":
|
|
71
|
+
"x-glyph-nonce": n
|
|
58
72
|
});
|
|
59
|
-
|
|
60
|
-
}, [
|
|
61
|
-
const
|
|
62
|
-
var e;
|
|
63
|
-
if (
|
|
64
|
-
|
|
73
|
+
h(() => e);
|
|
74
|
+
}, [i, t, o, n]);
|
|
75
|
+
const v = d(async () => {
|
|
76
|
+
var e, a, l, y, w;
|
|
77
|
+
if (r.log("authenticate"), !t) {
|
|
78
|
+
r.error("no wallet connected.");
|
|
65
79
|
return;
|
|
66
80
|
}
|
|
67
81
|
try {
|
|
68
|
-
if (!t || !s) {
|
|
69
|
-
|
|
82
|
+
if (!t || !s || !g || !n) {
|
|
83
|
+
h(null), c(!1);
|
|
70
84
|
return;
|
|
71
85
|
}
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
} catch (
|
|
76
|
-
|
|
86
|
+
c(!0);
|
|
87
|
+
const u = await m({ account: t, message: g }), Y = (e = await j(t, u, n)) == null ? void 0 : e.token;
|
|
88
|
+
I(Y);
|
|
89
|
+
} catch (u) {
|
|
90
|
+
r.error("Authentication failed", u), (w = (l = (a = u == null ? void 0 : u.message) == null ? void 0 : a.toLowerCase) == null ? void 0 : (y = l.call(a)).includes) != null && w.call(y, "user rejected") || await alert(
|
|
91
|
+
"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in."
|
|
92
|
+
), h(null), I(null), _(null);
|
|
77
93
|
} finally {
|
|
78
|
-
|
|
94
|
+
c(!1), E == null || E();
|
|
95
|
+
}
|
|
96
|
+
}, [t, s, g, n, m, j]), M = d(
|
|
97
|
+
async (e = !1) => {
|
|
98
|
+
r.log(`logout: disconnect=${e}`), _(null), I(null), c(!1), h(null), e && await x(), S == null || S();
|
|
99
|
+
},
|
|
100
|
+
[x]
|
|
101
|
+
), G = d(
|
|
102
|
+
async ({ message: e }) => {
|
|
103
|
+
if (!t || !s)
|
|
104
|
+
throw new Error("Wallet not connected");
|
|
105
|
+
return m({ account: t, message: e });
|
|
106
|
+
},
|
|
107
|
+
[t, s, m]
|
|
108
|
+
), R = d(
|
|
109
|
+
async ({ transaction: e }) => {
|
|
110
|
+
if (!t || !s) throw new Error("Wallet not connected");
|
|
111
|
+
return N({ ...e, chainId: b || q.id });
|
|
112
|
+
},
|
|
113
|
+
[t, s, N, b]
|
|
114
|
+
), [W, $] = f(!1);
|
|
115
|
+
return L({
|
|
116
|
+
onConnect: () => {
|
|
117
|
+
A && $(!0);
|
|
118
|
+
},
|
|
119
|
+
onDisconnect: () => {
|
|
120
|
+
M();
|
|
79
121
|
}
|
|
80
|
-
}
|
|
81
|
-
n
|
|
82
|
-
}, [
|
|
83
|
-
|
|
84
|
-
O.Provider,
|
|
122
|
+
}), p(() => {
|
|
123
|
+
A && s && t && W && n && g && (v(), $(!1));
|
|
124
|
+
}, [s, t, v, W, n, g, A]), /* @__PURE__ */ z.jsx(
|
|
125
|
+
H.Provider,
|
|
85
126
|
{
|
|
86
127
|
value: {
|
|
87
|
-
ready: !
|
|
88
|
-
authenticated: s && !!t &&
|
|
128
|
+
ready: !D && !!n,
|
|
129
|
+
authenticated: s && !!t && i !== null,
|
|
89
130
|
symbol: "APE",
|
|
90
|
-
glyphUrl:
|
|
131
|
+
glyphUrl: o,
|
|
132
|
+
// Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
|
|
91
133
|
hideWidget: !s || !t,
|
|
92
|
-
login:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
signMessage: async ({ message: e }) => {
|
|
99
|
-
if (!t || !s)
|
|
100
|
-
throw new Error("Wallet not connected");
|
|
101
|
-
return w({ account: t, message: e });
|
|
102
|
-
},
|
|
103
|
-
sendTransaction: async ({ transaction: e }) => {
|
|
104
|
-
if (!t || !s) throw new Error("Wallet not connected");
|
|
105
|
-
return F({ ...e, chainId: j || D.id });
|
|
106
|
-
},
|
|
107
|
-
apiFetch: P
|
|
134
|
+
login: v,
|
|
135
|
+
logout: M,
|
|
136
|
+
signMessage: G,
|
|
137
|
+
sendTransaction: R,
|
|
138
|
+
apiFetch: F
|
|
108
139
|
},
|
|
109
|
-
children:
|
|
140
|
+
children: O
|
|
110
141
|
}
|
|
111
142
|
);
|
|
112
143
|
};
|
|
113
|
-
|
|
144
|
+
U.displayName = "EIP1193Strategy";
|
|
114
145
|
export {
|
|
115
|
-
|
|
146
|
+
U as default
|
|
116
147
|
};
|
package/dist/PrivyStrategy.js
CHANGED
|
@@ -1,92 +1,114 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { usePrivy as
|
|
3
|
-
import { memo as
|
|
4
|
-
const
|
|
5
|
-
const [
|
|
6
|
-
ready:
|
|
7
|
-
authenticated:
|
|
8
|
-
user:
|
|
9
|
-
getAccessToken:
|
|
10
|
-
login:
|
|
11
|
-
logout:
|
|
12
|
-
signMessage:
|
|
13
|
-
sendTransaction:
|
|
14
|
-
} =
|
|
15
|
-
|
|
16
|
-
const { wallets: H } =
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
if (!
|
|
20
|
-
|
|
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";
|
|
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), {
|
|
6
|
+
ready: c,
|
|
7
|
+
authenticated: i,
|
|
8
|
+
user: o,
|
|
9
|
+
getAccessToken: w,
|
|
10
|
+
login: b,
|
|
11
|
+
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();
|
|
17
|
+
rs(() => {
|
|
18
|
+
var C, l, M;
|
|
19
|
+
if (!c) {
|
|
20
|
+
m(null), A(!0);
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
if (!
|
|
24
|
-
|
|
23
|
+
if (!i || !o) {
|
|
24
|
+
m(null), A(!1);
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
let
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
let e;
|
|
28
|
+
const r = (C = o.linkedAccounts) == null ? void 0 : C.find(
|
|
29
|
+
(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(
|
|
33
|
+
(s) => {
|
|
34
|
+
var d;
|
|
35
|
+
return ((d = s.providerApp) == null ? void 0 : d.id) !== (f ? D : R);
|
|
34
36
|
}
|
|
35
37
|
);
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
(
|
|
41
|
-
var
|
|
42
|
-
return ((
|
|
38
|
+
t.debug("linked accounts - non-Glyph", { accounts: k });
|
|
39
|
+
const P = k.map((s) => s.embeddedWallets[0].address);
|
|
40
|
+
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
|
+
(s) => {
|
|
43
|
+
var d;
|
|
44
|
+
return ((d = s.providerApp) == null ? void 0 : d.id) === (f ? D : R);
|
|
43
45
|
}
|
|
44
46
|
);
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
if (!
|
|
49
|
-
|
|
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 () => {
|
|
50
|
+
if (!e) {
|
|
51
|
+
t.error("user has no wallet");
|
|
50
52
|
return;
|
|
51
53
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
async () => await
|
|
55
|
-
{ "x-evm-address":
|
|
54
|
+
const s = Z(
|
|
55
|
+
y || L,
|
|
56
|
+
async () => await w(),
|
|
57
|
+
{ "x-evm-address": e }
|
|
56
58
|
);
|
|
57
|
-
|
|
59
|
+
m(() => s), A(!1);
|
|
58
60
|
})();
|
|
59
|
-
}, [
|
|
60
|
-
|
|
61
|
+
}, [
|
|
62
|
+
y,
|
|
63
|
+
i,
|
|
64
|
+
c,
|
|
65
|
+
o,
|
|
66
|
+
f,
|
|
67
|
+
n,
|
|
68
|
+
H,
|
|
69
|
+
a,
|
|
70
|
+
w,
|
|
71
|
+
v
|
|
72
|
+
]);
|
|
73
|
+
const B = u(async () => {
|
|
74
|
+
await b(), g == null || g();
|
|
75
|
+
}, [b]), $ = u(async () => {
|
|
76
|
+
v(), h == null || h();
|
|
77
|
+
}, [v]), q = u(
|
|
78
|
+
async ({ message: e }) => {
|
|
79
|
+
if (!a) throw new Error("No wallet address found");
|
|
80
|
+
return n ? S(e, { address: a }) : E({ message: e });
|
|
81
|
+
},
|
|
82
|
+
[a, n, S, E]
|
|
83
|
+
), z = u(
|
|
84
|
+
async ({ transaction: e }) => {
|
|
85
|
+
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 });
|
|
88
|
+
},
|
|
89
|
+
[a, n, T, G]
|
|
90
|
+
);
|
|
91
|
+
return /* @__PURE__ */ Q.jsx(
|
|
92
|
+
X.Provider,
|
|
61
93
|
{
|
|
62
94
|
value: {
|
|
63
|
-
ready:
|
|
64
|
-
authenticated:
|
|
95
|
+
ready: c && !V,
|
|
96
|
+
authenticated: c && i,
|
|
65
97
|
symbol: "APE",
|
|
66
|
-
glyphUrl:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
signMessage: async ({ message: s }) => {
|
|
74
|
-
if (!r) throw new Error("No wallet address found");
|
|
75
|
-
return A ? j(s, { address: r }) : V({ message: s });
|
|
76
|
-
},
|
|
77
|
-
sendTransaction: async ({ transaction: s }) => {
|
|
78
|
-
if (!r) throw new Error("No wallet address found");
|
|
79
|
-
const c = { ...s, chainId: J.id };
|
|
80
|
-
return A ? U(c, { address: r }) : Y(c, { address: r });
|
|
81
|
-
},
|
|
82
|
-
apiFetch: D
|
|
98
|
+
glyphUrl: y,
|
|
99
|
+
// 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
|
|
83
105
|
},
|
|
84
|
-
children:
|
|
106
|
+
children: N
|
|
85
107
|
}
|
|
86
108
|
);
|
|
87
109
|
};
|
|
88
|
-
|
|
89
|
-
const
|
|
110
|
+
F.displayName = "PrivyStrategy";
|
|
111
|
+
const is = as(F);
|
|
90
112
|
export {
|
|
91
|
-
|
|
113
|
+
is as default
|
|
92
114
|
};
|