@b3dotfun/sdk 0.0.47-test.4 → 0.0.47
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/README.md +3 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +64 -15
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +21 -26
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -2
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +22 -6
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +45 -10
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -2
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +1 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +84 -134
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +1 -2
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +68 -19
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +19 -24
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/esm/global-account/react/components/B3Provider/types.js +0 -2
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
- package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +23 -7
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -4
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +46 -11
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -3
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/esm/global-account/react/hooks/useAuthentication.js +87 -137
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -3
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
- package/package.json +3 -3
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +35 -51
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +72 -28
- package/src/global-account/react/components/B3Provider/types.ts +0 -4
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +3 -2
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +23 -4
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +3 -4
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +46 -8
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -3
- package/src/global-account/react/hooks/useAuthentication.ts +90 -159
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +2 -3
- package/src/global-account/react/stores/useModalStore.ts +2 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +0 -86
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +0 -42
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/esm/global-account/react/hooks/useUserQuery.js +0 -83
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +0 -39
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/src/global-account/react/hooks/useUserQuery.ts +0 -95
- package/src/global-account/react/hooks/useWagmiConfig.tsx +0 -44
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
2
2
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
|
|
4
5
|
import { Account } from "thirdweb/wallets";
|
|
5
6
|
|
|
7
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
6
8
|
import { ClientType } from "../../../client-manager";
|
|
7
9
|
|
|
8
|
-
import { WagmiProvider } from "wagmi";
|
|
9
|
-
import { useAuthentication } from "../../hooks/useAuthentication";
|
|
10
|
-
import { useWagmiConfig } from "../../hooks/useWagmiConfig";
|
|
11
10
|
import { B3Context, B3ContextType } from "./types";
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -32,32 +31,28 @@ export function B3Provider({
|
|
|
32
31
|
accountOverride,
|
|
33
32
|
environment,
|
|
34
33
|
clientType = "socket",
|
|
35
|
-
partnerId,
|
|
36
|
-
rpcUrls,
|
|
37
34
|
}: {
|
|
38
35
|
theme: "light" | "dark";
|
|
39
36
|
children: React.ReactNode;
|
|
40
37
|
accountOverride?: Account;
|
|
41
38
|
environment: B3ContextType["environment"];
|
|
42
39
|
clientType?: ClientType;
|
|
43
|
-
partnerId: string;
|
|
44
|
-
rpcUrls?: Record<number, string>;
|
|
45
40
|
}) {
|
|
46
41
|
return (
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</
|
|
60
|
-
</
|
|
42
|
+
<QueryClientProvider client={queryClient}>
|
|
43
|
+
<ThirdwebProvider>
|
|
44
|
+
<InnerProvider
|
|
45
|
+
accountOverride={accountOverride}
|
|
46
|
+
environment={environment}
|
|
47
|
+
theme={theme}
|
|
48
|
+
clientType={clientType}
|
|
49
|
+
>
|
|
50
|
+
{/* <RelayKitProviderWrapper> */}
|
|
51
|
+
{children}
|
|
52
|
+
{/* </RelayKitProviderWrapper> */}
|
|
53
|
+
</InnerProvider>
|
|
54
|
+
</ThirdwebProvider>
|
|
55
|
+
</QueryClientProvider>
|
|
61
56
|
);
|
|
62
57
|
}
|
|
63
58
|
|
|
@@ -71,8 +66,6 @@ export function InnerProvider({
|
|
|
71
66
|
defaultPermissions = DEFAULT_PERMISSIONS,
|
|
72
67
|
theme = "light",
|
|
73
68
|
clientType = "socket",
|
|
74
|
-
partnerId,
|
|
75
|
-
rpcUrls,
|
|
76
69
|
}: {
|
|
77
70
|
children: React.ReactNode;
|
|
78
71
|
accountOverride?: Account;
|
|
@@ -80,40 +73,31 @@ export function InnerProvider({
|
|
|
80
73
|
defaultPermissions?: PermissionsConfig;
|
|
81
74
|
theme: "light" | "dark";
|
|
82
75
|
clientType?: ClientType;
|
|
83
|
-
partnerId: string;
|
|
84
|
-
rpcUrls?: Record<number, string>;
|
|
85
76
|
}) {
|
|
86
77
|
const activeAccount = useActiveAccount();
|
|
87
|
-
const
|
|
88
|
-
const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
|
|
78
|
+
const [user, setUser] = useState<Users | undefined>(undefined);
|
|
89
79
|
|
|
90
80
|
// Use given accountOverride or activeAccount from thirdweb
|
|
91
81
|
const effectiveAccount = accountOverride || activeAccount;
|
|
92
82
|
|
|
93
83
|
return (
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}}
|
|
113
|
-
>
|
|
114
|
-
{children}
|
|
115
|
-
</B3Context.Provider>
|
|
116
|
-
</QueryClientProvider>
|
|
117
|
-
</WagmiProvider>
|
|
84
|
+
<B3Context.Provider
|
|
85
|
+
value={{
|
|
86
|
+
account: effectiveAccount,
|
|
87
|
+
automaticallySetFirstEoa: false,
|
|
88
|
+
setWallet: () => {},
|
|
89
|
+
wallet: undefined,
|
|
90
|
+
user,
|
|
91
|
+
setUser,
|
|
92
|
+
initialized: true,
|
|
93
|
+
ready: !!effectiveAccount,
|
|
94
|
+
environment,
|
|
95
|
+
defaultPermissions,
|
|
96
|
+
theme,
|
|
97
|
+
clientType,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</B3Context.Provider>
|
|
118
102
|
);
|
|
119
103
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
TooltipProvider,
|
|
4
|
-
useAuthentication,
|
|
5
|
-
useAuthStore,
|
|
6
|
-
} from "@b3dotfun/sdk/global-account/react";
|
|
7
|
-
import { useWagmiConfig } from "@b3dotfun/sdk/global-account/react/hooks/useWagmiConfig";
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
8
3
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
9
4
|
import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
|
|
5
|
+
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
6
|
+
import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
|
|
10
7
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
8
|
+
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
11
9
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
12
10
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
13
|
-
import {
|
|
11
|
+
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
12
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
14
13
|
import { Toaster } from "sonner";
|
|
15
14
|
import {
|
|
16
15
|
getLastAuthProvider,
|
|
@@ -20,7 +19,7 @@ import {
|
|
|
20
19
|
useSetActiveWallet,
|
|
21
20
|
} from "thirdweb/react";
|
|
22
21
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
23
|
-
import { WagmiProvider } from "wagmi";
|
|
22
|
+
import { createConfig, http, WagmiProvider } from "wagmi";
|
|
24
23
|
import { ClientType, setClientType } from "../../../client-manager";
|
|
25
24
|
import { StyleRoot } from "../StyleRoot";
|
|
26
25
|
import { B3Context, B3ContextType } from "./types";
|
|
@@ -67,7 +66,7 @@ export function B3Provider({
|
|
|
67
66
|
};
|
|
68
67
|
clientType?: ClientType;
|
|
69
68
|
rpcUrls?: Record<number, string>;
|
|
70
|
-
partnerId
|
|
69
|
+
partnerId?: string;
|
|
71
70
|
}) {
|
|
72
71
|
// Initialize Google Analytics on mount
|
|
73
72
|
useEffect(() => {
|
|
@@ -78,11 +77,45 @@ export function B3Provider({
|
|
|
78
77
|
useEffect(() => {
|
|
79
78
|
setClientType(clientType);
|
|
80
79
|
}, [clientType]);
|
|
81
|
-
|
|
80
|
+
|
|
81
|
+
const ecocystemConfig = useMemo(() => {
|
|
82
|
+
if (!partnerId) return undefined;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
ecosystemId: ecosystemWalletId,
|
|
86
|
+
partnerId: partnerId,
|
|
87
|
+
client,
|
|
88
|
+
};
|
|
89
|
+
}, [partnerId]);
|
|
90
|
+
|
|
91
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
92
|
+
// when parent component passes new object references with same content
|
|
93
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
97
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
98
|
+
*/
|
|
99
|
+
const wagmiConfig = useMemo(() => {
|
|
100
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
101
|
+
|
|
102
|
+
return createConfig({
|
|
103
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
104
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
105
|
+
connectors: [
|
|
106
|
+
inAppWalletConnector({
|
|
107
|
+
...(ecocystemConfig || {}),
|
|
108
|
+
client,
|
|
109
|
+
}),
|
|
110
|
+
// injected(),
|
|
111
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
}, [ecocystemConfig, rpcUrlsString]);
|
|
82
115
|
|
|
83
116
|
return (
|
|
84
117
|
<ThirdwebProvider>
|
|
85
|
-
<WagmiProvider config={wagmiConfig}
|
|
118
|
+
<WagmiProvider config={wagmiConfig}>
|
|
86
119
|
<QueryClientProvider client={queryClient}>
|
|
87
120
|
<TooltipProvider>
|
|
88
121
|
<InnerProvider
|
|
@@ -91,7 +124,6 @@ export function B3Provider({
|
|
|
91
124
|
theme={theme}
|
|
92
125
|
automaticallySetFirstEoa={!!automaticallySetFirstEoa}
|
|
93
126
|
clientType={clientType}
|
|
94
|
-
partnerId={partnerId}
|
|
95
127
|
>
|
|
96
128
|
<RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
|
|
97
129
|
{children}
|
|
@@ -118,7 +150,6 @@ export function InnerProvider({
|
|
|
118
150
|
automaticallySetFirstEoa,
|
|
119
151
|
theme = "light",
|
|
120
152
|
clientType = "socket",
|
|
121
|
-
partnerId,
|
|
122
153
|
}: {
|
|
123
154
|
children: React.ReactNode;
|
|
124
155
|
accountOverride?: Account;
|
|
@@ -127,23 +158,42 @@ export function InnerProvider({
|
|
|
127
158
|
automaticallySetFirstEoa: boolean;
|
|
128
159
|
theme: "light" | "dark";
|
|
129
160
|
clientType?: ClientType;
|
|
130
|
-
partnerId: string;
|
|
131
161
|
}) {
|
|
132
162
|
const activeAccount = useActiveAccount();
|
|
133
163
|
const [manuallySelectedWallet, setManuallySelectedWallet] = useState<Wallet | undefined>(undefined);
|
|
134
164
|
const wallets = useConnectedWallets();
|
|
135
|
-
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
136
|
-
const isConnected = useAuthStore(state => state.isConnected);
|
|
137
165
|
const setActiveWallet = useSetActiveWallet();
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
debug("@@B3Provider:isConnected", isConnected);
|
|
166
|
+
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
141
167
|
debug("@@wallets", wallets);
|
|
142
|
-
|
|
168
|
+
|
|
169
|
+
const [user, setUser] = useState<Users | undefined>(() => {
|
|
170
|
+
// Try to restore user from localStorage on initialization
|
|
171
|
+
if (typeof window !== "undefined") {
|
|
172
|
+
try {
|
|
173
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
174
|
+
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
});
|
|
143
182
|
|
|
144
183
|
// Use given accountOverride or activeAccount from thirdweb
|
|
145
184
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
146
185
|
|
|
186
|
+
// Persist user to localStorage when it changes
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (typeof window !== "undefined") {
|
|
189
|
+
if (user) {
|
|
190
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
191
|
+
} else {
|
|
192
|
+
localStorage.removeItem("b3-user");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}, [user]);
|
|
196
|
+
|
|
147
197
|
const setWallet = useCallback(
|
|
148
198
|
(wallet: Wallet) => {
|
|
149
199
|
setManuallySelectedWallet(wallet);
|
|
@@ -187,7 +237,6 @@ export function InnerProvider({
|
|
|
187
237
|
wallet: manuallySelectedWallet,
|
|
188
238
|
user,
|
|
189
239
|
setUser,
|
|
190
|
-
refetchUser,
|
|
191
240
|
initialized: true,
|
|
192
241
|
ready: !!effectiveAccount,
|
|
193
242
|
automaticallySetFirstEoa,
|
|
@@ -195,14 +244,9 @@ export function InnerProvider({
|
|
|
195
244
|
defaultPermissions,
|
|
196
245
|
theme,
|
|
197
246
|
clientType,
|
|
198
|
-
partnerId: partnerId,
|
|
199
247
|
}}
|
|
200
248
|
>
|
|
201
|
-
|
|
249
|
+
{children}
|
|
202
250
|
</B3Context.Provider>
|
|
203
251
|
);
|
|
204
252
|
}
|
|
205
|
-
|
|
206
|
-
const InnerProvider2 = ({ children }: { children: React.ReactNode }) => {
|
|
207
|
-
return <>{children}</>;
|
|
208
|
-
};
|
|
@@ -14,14 +14,12 @@ export interface B3ContextType {
|
|
|
14
14
|
setWallet: (wallet: Wallet) => void;
|
|
15
15
|
wallet?: Wallet;
|
|
16
16
|
setUser: (user?: Users) => void;
|
|
17
|
-
refetchUser: () => Promise<any>;
|
|
18
17
|
initialized: boolean;
|
|
19
18
|
ready: boolean;
|
|
20
19
|
environment?: "development" | "production";
|
|
21
20
|
defaultPermissions?: PermissionsConfig;
|
|
22
21
|
theme: "light" | "dark";
|
|
23
22
|
clientType: ClientType;
|
|
24
|
-
partnerId: string;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
/**
|
|
@@ -34,11 +32,9 @@ export const B3Context = createContext<B3ContextType>({
|
|
|
34
32
|
setWallet: () => {},
|
|
35
33
|
wallet: undefined,
|
|
36
34
|
setUser: () => {},
|
|
37
|
-
refetchUser: async () => {},
|
|
38
35
|
initialized: false,
|
|
39
36
|
ready: false,
|
|
40
37
|
environment: "development",
|
|
41
38
|
theme: "light",
|
|
42
39
|
clientType: "rest",
|
|
43
|
-
partnerId: "",
|
|
44
40
|
});
|
|
@@ -23,6 +23,7 @@ import { TokenBalanceRow } from "./TokenBalanceRow";
|
|
|
23
23
|
|
|
24
24
|
interface BalanceContentProps {
|
|
25
25
|
onLogout?: () => void;
|
|
26
|
+
partnerId: string;
|
|
26
27
|
showDeposit?: boolean;
|
|
27
28
|
showSwap?: boolean;
|
|
28
29
|
}
|
|
@@ -32,14 +33,14 @@ function centerTruncate(str: string, length = 4) {
|
|
|
32
33
|
return `${str.slice(0, length)}...${str.slice(-length)}`;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export function BalanceContent({ onLogout, showDeposit = true, showSwap = true }: BalanceContentProps) {
|
|
36
|
+
export function BalanceContent({ onLogout, partnerId, showDeposit = true, showSwap = true }: BalanceContentProps) {
|
|
36
37
|
const account = useActiveAccount();
|
|
37
38
|
const { address: eoaAddress, info: eoaInfo } = useFirstEOA();
|
|
38
39
|
const { data: profile } = useProfile({
|
|
39
40
|
address: eoaAddress || account?.address,
|
|
40
41
|
fresh: true,
|
|
41
42
|
});
|
|
42
|
-
const { user
|
|
43
|
+
const { user } = useB3();
|
|
43
44
|
const { setB3ModalOpen, setB3ModalContentType, navigateBack } = useModalStore();
|
|
44
45
|
const { logout } = useAuthentication(partnerId);
|
|
45
46
|
const [logoutLoading, setLogoutLoading] = useState(false);
|
|
@@ -604,7 +604,7 @@ export function ManageAccount({
|
|
|
604
604
|
</div>
|
|
605
605
|
|
|
606
606
|
<TabsContentPrimitive value="overview" className="px-4 pb-4 pt-2">
|
|
607
|
-
<BalanceContent onLogout={onLogout} showDeposit={showDeposit} showSwap={showSwap} />
|
|
607
|
+
<BalanceContent onLogout={onLogout} partnerId={partnerId} showDeposit={showDeposit} showSwap={showSwap} />
|
|
608
608
|
</TabsContentPrimitive>
|
|
609
609
|
|
|
610
610
|
<TabsContentPrimitive value="tokens" className="px-4 pb-4 pt-2">
|
|
@@ -29,7 +29,7 @@ type SignInWithB3Props = Omit<SignInWithB3ModalProps, "type" | "showBackButton">
|
|
|
29
29
|
|
|
30
30
|
export function SignIn(props: SignInWithB3Props) {
|
|
31
31
|
const { className } = props;
|
|
32
|
-
const { automaticallySetFirstEoa
|
|
32
|
+
const { automaticallySetFirstEoa } = useB3();
|
|
33
33
|
const {
|
|
34
34
|
wallet,
|
|
35
35
|
address: globalAddress,
|
|
@@ -43,7 +43,7 @@ export function SignIn(props: SignInWithB3Props) {
|
|
|
43
43
|
} = useAccountWallet();
|
|
44
44
|
|
|
45
45
|
const isMobile = useIsMobile();
|
|
46
|
-
const { logout } = useAuthentication(
|
|
46
|
+
const { logout } = useAuthentication(String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID));
|
|
47
47
|
const onDisconnect = async () => {
|
|
48
48
|
await logout();
|
|
49
49
|
};
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
Button,
|
|
3
3
|
SignInWithB3ModalProps,
|
|
4
4
|
StyleRoot,
|
|
5
|
-
|
|
5
|
+
useAuthentication,
|
|
6
6
|
useB3,
|
|
7
7
|
useIsMobile,
|
|
8
8
|
useModalStore,
|
|
@@ -21,7 +21,7 @@ export type SignInWithB3Props = Omit<SignInWithB3ModalProps, "type" | "showBackB
|
|
|
21
21
|
export function SignInWithB3(props: SignInWithB3Props) {
|
|
22
22
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
|
|
23
23
|
const { account } = useB3();
|
|
24
|
-
const { isAuthenticating, isAuthenticated } =
|
|
24
|
+
const { isAuthenticating, isAuthenticated } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
25
25
|
const isMobile = useIsMobile();
|
|
26
26
|
|
|
27
27
|
useEffect(() => {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useB3,
|
|
6
6
|
useGetAllTWSigners,
|
|
7
7
|
useModalStore,
|
|
8
|
+
useSiwe,
|
|
8
9
|
} from "@b3dotfun/sdk/global-account/react";
|
|
9
10
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
10
11
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -30,16 +31,19 @@ export function SignInWithB3Flow({
|
|
|
30
31
|
sessionKeyAddress,
|
|
31
32
|
partnerId,
|
|
32
33
|
closeAfterLogin = false,
|
|
34
|
+
loginWithSiwe = false,
|
|
33
35
|
source = "signInWithB3Button",
|
|
34
36
|
signersEnabled = false,
|
|
35
37
|
}: SignInWithB3ModalProps) {
|
|
36
|
-
const { automaticallySetFirstEoa } = useB3();
|
|
38
|
+
const { setUser, automaticallySetFirstEoa } = useB3();
|
|
37
39
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
38
40
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
39
41
|
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
40
42
|
const account = useActiveAccount();
|
|
43
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
41
44
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
42
45
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
46
|
+
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
43
47
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
44
48
|
const [refetchError, setRefetchError] = useState<string | null>(null);
|
|
45
49
|
const {
|
|
@@ -53,6 +57,7 @@ export function SignInWithB3Flow({
|
|
|
53
57
|
enabled: signersEnabled,
|
|
54
58
|
},
|
|
55
59
|
});
|
|
60
|
+
const { authenticate } = useSiwe();
|
|
56
61
|
const [refetchQueued, setRefetchQueued] = useState(false);
|
|
57
62
|
|
|
58
63
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
@@ -170,11 +175,13 @@ export function SignInWithB3Flow({
|
|
|
170
175
|
sessionKeyAddress,
|
|
171
176
|
partnerId,
|
|
172
177
|
closeAfterLogin,
|
|
178
|
+
loginWithSiwe,
|
|
173
179
|
source: "requestPermissions",
|
|
174
180
|
});
|
|
175
181
|
}, [
|
|
176
182
|
chain,
|
|
177
183
|
closeAfterLogin,
|
|
184
|
+
loginWithSiwe,
|
|
178
185
|
onError,
|
|
179
186
|
onLoginSuccess,
|
|
180
187
|
onSessionKeySuccess,
|
|
@@ -186,9 +193,20 @@ export function SignInWithB3Flow({
|
|
|
186
193
|
|
|
187
194
|
const handleLoginSuccess = useCallback(
|
|
188
195
|
async (account: Account) => {
|
|
196
|
+
debug("Authenticating with B3 via SIWE");
|
|
197
|
+
setIsConnected(true);
|
|
198
|
+
if (loginWithSiwe) {
|
|
199
|
+
debug("setIsAuthenticating:true:1");
|
|
200
|
+
setIsAuthenticating(true);
|
|
201
|
+
const userAuth = await authenticate(account, partnerId);
|
|
202
|
+
setUser(userAuth.user);
|
|
203
|
+
}
|
|
204
|
+
debug("handleLoginSuccess:account", account);
|
|
189
205
|
onLoginSuccess?.(account);
|
|
206
|
+
debug("setIsAuthenticating:false:1");
|
|
207
|
+
setIsAuthenticating(false);
|
|
190
208
|
},
|
|
191
|
-
[onLoginSuccess],
|
|
209
|
+
[loginWithSiwe, onLoginSuccess, authenticate, partnerId, setUser, setIsConnected, setIsAuthenticating],
|
|
192
210
|
);
|
|
193
211
|
|
|
194
212
|
useEffect(() => {
|
|
@@ -225,7 +243,7 @@ export function SignInWithB3Flow({
|
|
|
225
243
|
if (step === "login") {
|
|
226
244
|
// Custom strategy
|
|
227
245
|
if (strategies?.[0] === "privy") {
|
|
228
|
-
return <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
246
|
+
return <SignInWithB3Privy onSuccess={handleLoginSuccess} partnerId={partnerId} chain={chain} />;
|
|
229
247
|
}
|
|
230
248
|
|
|
231
249
|
// Strategies are explicitly provided
|
|
@@ -233,6 +251,7 @@ export function SignInWithB3Flow({
|
|
|
233
251
|
return (
|
|
234
252
|
<LoginStepCustom
|
|
235
253
|
strategies={strategies}
|
|
254
|
+
partnerId={partnerId}
|
|
236
255
|
chain={chain}
|
|
237
256
|
onSuccess={handleLoginSuccess}
|
|
238
257
|
onError={onError}
|
|
@@ -242,7 +261,7 @@ export function SignInWithB3Flow({
|
|
|
242
261
|
}
|
|
243
262
|
|
|
244
263
|
// Default to handle all strategies we support
|
|
245
|
-
return <LoginStep chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
264
|
+
return <LoginStep partnerId={partnerId} chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
246
265
|
}
|
|
247
266
|
|
|
248
267
|
return null;
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
Loading,
|
|
3
3
|
useAuthentication,
|
|
4
4
|
useAuthStore,
|
|
5
|
-
useB3,
|
|
6
5
|
useHandleConnectWithPrivy,
|
|
7
6
|
} from "@b3dotfun/sdk/global-account/react";
|
|
8
7
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
@@ -15,12 +14,12 @@ interface SignInWithB3PrivyProps {
|
|
|
15
14
|
onError?: (error: Error) => Promise<void>;
|
|
16
15
|
onSuccess: (account: Account) => Promise<void>;
|
|
17
16
|
accessToken?: string;
|
|
17
|
+
partnerId: string;
|
|
18
18
|
chain: Chain;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps) {
|
|
22
|
-
const {
|
|
23
|
-
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
21
|
+
export function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }: SignInWithB3PrivyProps) {
|
|
22
|
+
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(partnerId, chain, onSuccess);
|
|
24
23
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
25
24
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
26
25
|
const { logout } = useAuthentication(partnerId);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useAuthentication, useB3, useQueryB3 } from "@b3dotfun/sdk/global-account/react";
|
|
1
|
+
import { useAuthentication, useAuthStore, useB3, useQueryB3 } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
3
|
+
import { debug } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
4
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
4
5
|
import { Chain } from "thirdweb";
|
|
5
6
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
@@ -13,6 +14,7 @@ interface LoginStepProps {
|
|
|
13
14
|
/** Optional callback function called when an error occurs */
|
|
14
15
|
onError?: (error: Error) => Promise<void>;
|
|
15
16
|
/** Partner ID used for authentication */
|
|
17
|
+
partnerId: string;
|
|
16
18
|
/** Blockchain chain information */
|
|
17
19
|
chain: Chain;
|
|
18
20
|
/** Optional authentication strategy options */
|
|
@@ -54,12 +56,15 @@ export function LoginStepContainer({ children, partnerId }: LoginStepContainerPr
|
|
|
54
56
|
);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
export function LoginStep({ onSuccess, chain }: LoginStepProps) {
|
|
58
|
-
const { partnerId, theme } = useB3();
|
|
59
|
+
export function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepProps) {
|
|
59
60
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
60
61
|
partnerId: partnerId,
|
|
61
62
|
});
|
|
62
|
-
|
|
63
|
+
|
|
64
|
+
const { theme } = useB3();
|
|
65
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
66
|
+
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
67
|
+
const { logout } = useAuthentication(partnerId);
|
|
63
68
|
|
|
64
69
|
return (
|
|
65
70
|
<LoginStepContainer partnerId={partnerId}>
|
|
@@ -81,21 +86,54 @@ export function LoginStep({ onSuccess, chain }: LoginStepProps) {
|
|
|
81
86
|
},
|
|
82
87
|
})
|
|
83
88
|
}
|
|
89
|
+
autoConnect
|
|
84
90
|
style={{
|
|
85
91
|
width: "100%",
|
|
86
92
|
height: "100%",
|
|
87
93
|
border: 0,
|
|
88
94
|
}}
|
|
95
|
+
// TODO: Integrate with SIWE in useSIWE
|
|
96
|
+
// auth={{
|
|
97
|
+
// isLoggedIn: async (address) => {
|
|
98
|
+
// console.log("checking if logged in!", { address });
|
|
99
|
+
// return await isLoggedIn();
|
|
100
|
+
// },
|
|
101
|
+
// doLogin: async (params) => {
|
|
102
|
+
// console.log("logging in!");
|
|
103
|
+
// await login(params);
|
|
104
|
+
// },
|
|
105
|
+
// getLoginPayload: async ({ address }) =>
|
|
106
|
+
// generatePayload({ address }),
|
|
107
|
+
// doLogout: async () => {
|
|
108
|
+
// console.log("logging out!");
|
|
109
|
+
// await logout();
|
|
110
|
+
// },
|
|
111
|
+
// }}
|
|
89
112
|
header={{
|
|
90
113
|
title: "Sign in with B3",
|
|
91
114
|
titleIcon: "https://cdn.b3.fun/b3_logo.svg",
|
|
92
115
|
}}
|
|
93
116
|
className="b3-login-step"
|
|
94
117
|
onConnect={async wallet => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
try {
|
|
119
|
+
setIsAuthenticating(true);
|
|
120
|
+
debug("setIsAuthenticating:true:6");
|
|
121
|
+
|
|
122
|
+
const account = wallet.getAccount();
|
|
123
|
+
if (!account) throw new Error("No account found");
|
|
124
|
+
|
|
125
|
+
await onSuccess(account);
|
|
126
|
+
setIsAuthenticated(true);
|
|
127
|
+
|
|
128
|
+
console.log("connected!", wallet.id);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
await onError?.(error as Error);
|
|
131
|
+
await logout();
|
|
132
|
+
setIsAuthenticated(false);
|
|
133
|
+
} finally {
|
|
134
|
+
debug("setIsAuthenticating:false:6");
|
|
135
|
+
setIsAuthenticating(false);
|
|
136
|
+
}
|
|
99
137
|
}}
|
|
100
138
|
/>
|
|
101
139
|
</LoginStepContainer>
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
LoginStepContainer,
|
|
8
8
|
useAuthentication,
|
|
9
9
|
useAuthStore,
|
|
10
|
-
useB3,
|
|
11
10
|
useConnect,
|
|
12
11
|
WalletRow,
|
|
13
12
|
} from "@b3dotfun/sdk/global-account/react";
|
|
@@ -22,6 +21,7 @@ interface LoginStepCustomProps {
|
|
|
22
21
|
automaticallySetFirstEoa: boolean;
|
|
23
22
|
onSuccess: (account: Account) => Promise<void>;
|
|
24
23
|
onError?: (error: Error) => Promise<void>;
|
|
24
|
+
partnerId: string;
|
|
25
25
|
chain: Chain;
|
|
26
26
|
strategies: AllowedStrategy[];
|
|
27
27
|
maxInitialWallets?: number;
|
|
@@ -32,12 +32,12 @@ const debug = debugB3React("LoginStepCustom");
|
|
|
32
32
|
export function LoginStepCustom({
|
|
33
33
|
onSuccess,
|
|
34
34
|
onError,
|
|
35
|
+
partnerId,
|
|
35
36
|
chain,
|
|
36
37
|
strategies,
|
|
37
38
|
maxInitialWallets = 2,
|
|
38
39
|
automaticallySetFirstEoa,
|
|
39
40
|
}: LoginStepCustomProps) {
|
|
40
|
-
const { partnerId } = useB3();
|
|
41
41
|
const [isLoading, setIsLoading] = useState(false);
|
|
42
42
|
const [showAllWallets, setShowAllWallets] = useState(false);
|
|
43
43
|
const { connect } = useConnect(partnerId, chain);
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Button, StyleRoot, useAuthentication,
|
|
1
|
+
import { Button, StyleRoot, useAuthentication, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { cn } from "@b3dotfun/sdk/shared/utils";
|
|
3
3
|
import { SignInWithB3Props } from "../SignInWithB3/SignInWithB3";
|
|
4
4
|
|
|
5
5
|
export function ManageAccountButton(props: SignInWithB3Props & { className?: string }) {
|
|
6
|
-
const { partnerId } = useB3();
|
|
7
6
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
8
|
-
const { isConnected } = useAuthentication(partnerId);
|
|
7
|
+
const { isConnected } = useAuthentication(props.partnerId, props.loginWithSiwe);
|
|
9
8
|
|
|
10
9
|
const handleClickManageAccount = () => {
|
|
11
10
|
setB3ModalContentType({
|