@b3dotfun/sdk 0.0.47-alpha.2 → 0.0.47-alpha.3
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 +3 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- 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 +6 -22
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +141 -81
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- 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 +7 -23
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.js +144 -84
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
- package/package.json +3 -3
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
- package/src/global-account/react/components/B3Provider/types.ts +4 -0
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
- 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 +4 -23
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
- package/src/global-account/react/hooks/useAuthentication.ts +170 -89
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
- package/src/global-account/react/hooks/useUserQuery.ts +95 -0
- package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
- package/src/global-account/react/stores/useModalStore.ts +0 -2
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
|
|
5
|
+
const debug = debugB3React("useUserQuery");
|
|
6
|
+
|
|
7
|
+
const USER_QUERY_KEY = ["b3-user"];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the user from localStorage
|
|
11
|
+
*/
|
|
12
|
+
function getUserFromStorage(): Users | null {
|
|
13
|
+
if (typeof window === "undefined") {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
19
|
+
return storedUser ? JSON.parse(storedUser) : null;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Saves user to localStorage
|
|
28
|
+
*/
|
|
29
|
+
function saveUserToStorage(user: Users | null) {
|
|
30
|
+
if (typeof window === "undefined") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (user) {
|
|
35
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
36
|
+
} else {
|
|
37
|
+
localStorage.removeItem("b3-user");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
|
|
43
|
+
*
|
|
44
|
+
* Custom hook to manage user state with react-query
|
|
45
|
+
* This allows for invalidation and refetching of user data
|
|
46
|
+
*/
|
|
47
|
+
export function useUserQuery() {
|
|
48
|
+
const queryClient = useQueryClient();
|
|
49
|
+
|
|
50
|
+
// Query to get user data (primarily from cache/localStorage)
|
|
51
|
+
const { data: user } = useQuery<Users | null>({
|
|
52
|
+
queryKey: USER_QUERY_KEY,
|
|
53
|
+
queryFn: getUserFromStorage,
|
|
54
|
+
staleTime: Infinity, // User data doesn't go stale automatically
|
|
55
|
+
gcTime: Infinity, // Keep in cache indefinitely
|
|
56
|
+
initialData: getUserFromStorage,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Mutation to update user
|
|
60
|
+
const setUserMutation = useMutation({
|
|
61
|
+
mutationFn: async (newUser: Users | undefined) => {
|
|
62
|
+
const userToSave = newUser ?? null;
|
|
63
|
+
saveUserToStorage(userToSave);
|
|
64
|
+
return userToSave;
|
|
65
|
+
},
|
|
66
|
+
onSuccess: data => {
|
|
67
|
+
queryClient.setQueryData(USER_QUERY_KEY, data);
|
|
68
|
+
debug("User updated", data);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Helper function to set user (maintains backward compatibility)
|
|
73
|
+
const setUser = (newUser?: Users) => {
|
|
74
|
+
setUserMutation.mutate(newUser);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Helper function to invalidate and refetch user
|
|
78
|
+
const refetchUser = async () => {
|
|
79
|
+
await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
80
|
+
return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Helper function to clear user
|
|
84
|
+
const clearUser = () => {
|
|
85
|
+
setUser(undefined);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
user: user ?? undefined,
|
|
90
|
+
setUser,
|
|
91
|
+
refetchUser,
|
|
92
|
+
clearUser,
|
|
93
|
+
queryKey: USER_QUERY_KEY,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
2
|
+
import { supportedChains } from "@b3dotfun/sdk/shared/constants/chains/supported";
|
|
3
|
+
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
4
|
+
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { http } from "viem";
|
|
7
|
+
import { createConfig } from "wagmi";
|
|
8
|
+
|
|
9
|
+
export function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>) {
|
|
10
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
11
|
+
// when parent component passes new object references with same content
|
|
12
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
13
|
+
|
|
14
|
+
const ecocystemConfig = useMemo(() => {
|
|
15
|
+
return {
|
|
16
|
+
ecosystemId: ecosystemWalletId,
|
|
17
|
+
partnerId: partnerId,
|
|
18
|
+
client,
|
|
19
|
+
};
|
|
20
|
+
}, [partnerId]);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
24
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
25
|
+
*/
|
|
26
|
+
const wagmiConfig = useMemo(() => {
|
|
27
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
28
|
+
|
|
29
|
+
return createConfig({
|
|
30
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
31
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
32
|
+
connectors: [
|
|
33
|
+
inAppWalletConnector({
|
|
34
|
+
...ecocystemConfig,
|
|
35
|
+
client,
|
|
36
|
+
}),
|
|
37
|
+
// injected(),
|
|
38
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
}, [rpcUrlsString, ecocystemConfig]);
|
|
42
|
+
|
|
43
|
+
return wagmiConfig;
|
|
44
|
+
}
|
|
@@ -35,8 +35,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
35
35
|
sessionKeyAddress?: Address;
|
|
36
36
|
/** Unique identifier for the partner application */
|
|
37
37
|
partnerId: string;
|
|
38
|
-
/** Whether to authenticate with Sign In With Ethereum */
|
|
39
|
-
loginWithSiwe?: boolean;
|
|
40
38
|
/** Whether to close the modal after successful login */
|
|
41
39
|
closeAfterLogin?: boolean;
|
|
42
40
|
/** Source of the sign-in request */
|