@b3dotfun/sdk 0.0.47-alpha.2 → 0.0.47-test.5
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 +6 -225
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +3 -5
- 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/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +245 -0
- package/dist/cjs/shared/utils/index.d.ts +0 -1
- package/dist/cjs/shared/utils/index.js +0 -1
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +3 -5
- 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/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +243 -0
- package/dist/esm/shared/utils/index.d.ts +0 -1
- package/dist/esm/shared/utils/index.js +0 -1
- 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/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +1 -0
- package/dist/types/shared/utils/index.d.ts +0 -1
- package/package.json +3 -23
- package/src/anyspend/react/components/AnySpendCustom.tsx +3 -5
- 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
- package/src/shared/utils/index.ts +0 -1
- package/dist/cjs/notifications/index.d.ts +0 -3
- package/dist/cjs/notifications/index.js +0 -25
- package/dist/cjs/notifications/react/hooks/index.d.ts +0 -1
- package/dist/cjs/notifications/react/hooks/index.js +0 -17
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/cjs/notifications/react/hooks/useNotifications.js +0 -148
- package/dist/cjs/notifications/react/index.d.ts +0 -1
- package/dist/cjs/notifications/react/index.js +0 -17
- package/dist/cjs/notifications/services/api.d.ts +0 -67
- package/dist/cjs/notifications/services/api.js +0 -184
- package/dist/cjs/notifications/services/index.d.ts +0 -1
- package/dist/cjs/notifications/services/index.js +0 -17
- package/dist/cjs/notifications/types/index.d.ts +0 -51
- package/dist/cjs/notifications/types/index.js +0 -2
- package/dist/cjs/shared/utils/auth-token.d.ts +0 -7
- package/dist/cjs/shared/utils/auth-token.js +0 -17
- package/dist/esm/notifications/index.d.ts +0 -3
- package/dist/esm/notifications/index.js +0 -7
- package/dist/esm/notifications/react/hooks/index.d.ts +0 -1
- package/dist/esm/notifications/react/hooks/index.js +0 -1
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/esm/notifications/react/hooks/useNotifications.js +0 -145
- package/dist/esm/notifications/react/index.d.ts +0 -1
- package/dist/esm/notifications/react/index.js +0 -1
- package/dist/esm/notifications/services/api.d.ts +0 -67
- package/dist/esm/notifications/services/api.js +0 -179
- package/dist/esm/notifications/services/index.d.ts +0 -1
- package/dist/esm/notifications/services/index.js +0 -1
- package/dist/esm/notifications/types/index.d.ts +0 -51
- package/dist/esm/shared/utils/auth-token.d.ts +0 -7
- package/dist/esm/shared/utils/auth-token.js +0 -11
- package/dist/types/notifications/index.d.ts +0 -3
- package/dist/types/notifications/react/hooks/index.d.ts +0 -1
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +0 -42
- package/dist/types/notifications/react/index.d.ts +0 -1
- package/dist/types/notifications/services/api.d.ts +0 -67
- package/dist/types/notifications/services/index.d.ts +0 -1
- package/dist/types/notifications/types/index.d.ts +0 -51
- package/dist/types/shared/utils/auth-token.d.ts +0 -7
- package/src/notifications/index.ts +0 -9
- package/src/notifications/react/hooks/index.ts +0 -1
- package/src/notifications/react/hooks/useNotifications.ts +0 -153
- package/src/notifications/react/index.ts +0 -1
- package/src/notifications/services/api.ts +0 -217
- package/src/notifications/services/index.ts +0 -1
- package/src/notifications/types/index.ts +0 -58
- package/src/shared/utils/auth-token.ts +0 -13
- /package/dist/{esm/notifications/types/index.js → cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
|
|
4
|
+
*
|
|
5
|
+
* Custom hook to manage user state with react-query
|
|
6
|
+
* This allows for invalidation and refetching of user data
|
|
7
|
+
*/
|
|
8
|
+
export declare function useUserQuery(): {
|
|
9
|
+
user: {
|
|
10
|
+
email?: string | undefined;
|
|
11
|
+
username?: string | undefined;
|
|
12
|
+
telNumber?: string | undefined;
|
|
13
|
+
ens?: string | undefined;
|
|
14
|
+
avatar?: string | undefined;
|
|
15
|
+
preferences?: {} | undefined;
|
|
16
|
+
referredBy?: string | {} | undefined;
|
|
17
|
+
sourceApp?: string | undefined;
|
|
18
|
+
referralCode?: string | undefined;
|
|
19
|
+
userGroups?: number[] | undefined;
|
|
20
|
+
isMigratedFromBSMNT?: boolean | undefined;
|
|
21
|
+
privyLinkedAccounts?: {
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
address?: string | undefined;
|
|
24
|
+
email?: string | undefined;
|
|
25
|
+
chain_type?: string | undefined;
|
|
26
|
+
lv?: number | undefined;
|
|
27
|
+
wallet_client_type?: string | undefined;
|
|
28
|
+
smart_wallet_type?: string | undefined;
|
|
29
|
+
subject?: string | undefined;
|
|
30
|
+
type: string;
|
|
31
|
+
}[] | undefined;
|
|
32
|
+
twProfiles?: {
|
|
33
|
+
type: string;
|
|
34
|
+
details: {
|
|
35
|
+
id?: string | undefined;
|
|
36
|
+
name?: string | undefined;
|
|
37
|
+
address?: string | undefined;
|
|
38
|
+
email?: string | undefined;
|
|
39
|
+
phone?: string | undefined;
|
|
40
|
+
username?: string | undefined;
|
|
41
|
+
fid?: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
}[] | undefined;
|
|
44
|
+
_id: string | {};
|
|
45
|
+
userId: string;
|
|
46
|
+
smartAccountAddress: string;
|
|
47
|
+
createdAt: number;
|
|
48
|
+
updatedAt: number;
|
|
49
|
+
partnerIds: {
|
|
50
|
+
privyId?: string | undefined;
|
|
51
|
+
thirdwebId?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
} | undefined;
|
|
54
|
+
setUser: (newUser?: Users) => void;
|
|
55
|
+
refetchUser: () => Promise<void>;
|
|
56
|
+
clearUser: () => void;
|
|
57
|
+
queryKey: string[];
|
|
58
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUserQuery = useUserQuery;
|
|
4
|
+
const debug_1 = require("../../../shared/utils/debug");
|
|
5
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
6
|
+
const debug = (0, debug_1.debugB3React)("useUserQuery");
|
|
7
|
+
const USER_QUERY_KEY = ["b3-user"];
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the user from localStorage
|
|
10
|
+
*/
|
|
11
|
+
function getUserFromStorage() {
|
|
12
|
+
if (typeof window === "undefined") {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
17
|
+
return storedUser ? JSON.parse(storedUser) : null;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Saves user to localStorage
|
|
26
|
+
*/
|
|
27
|
+
function saveUserToStorage(user) {
|
|
28
|
+
if (typeof window === "undefined") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (user) {
|
|
32
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
localStorage.removeItem("b3-user");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
|
|
40
|
+
*
|
|
41
|
+
* Custom hook to manage user state with react-query
|
|
42
|
+
* This allows for invalidation and refetching of user data
|
|
43
|
+
*/
|
|
44
|
+
function useUserQuery() {
|
|
45
|
+
const queryClient = (0, react_query_1.useQueryClient)();
|
|
46
|
+
// Query to get user data (primarily from cache/localStorage)
|
|
47
|
+
const { data: user } = (0, react_query_1.useQuery)({
|
|
48
|
+
queryKey: USER_QUERY_KEY,
|
|
49
|
+
queryFn: getUserFromStorage,
|
|
50
|
+
staleTime: Infinity, // User data doesn't go stale automatically
|
|
51
|
+
gcTime: Infinity, // Keep in cache indefinitely
|
|
52
|
+
initialData: getUserFromStorage,
|
|
53
|
+
});
|
|
54
|
+
// Mutation to update user
|
|
55
|
+
const setUserMutation = (0, react_query_1.useMutation)({
|
|
56
|
+
mutationFn: async (newUser) => {
|
|
57
|
+
const userToSave = newUser ?? null;
|
|
58
|
+
saveUserToStorage(userToSave);
|
|
59
|
+
return userToSave;
|
|
60
|
+
},
|
|
61
|
+
onSuccess: data => {
|
|
62
|
+
queryClient.setQueryData(USER_QUERY_KEY, data);
|
|
63
|
+
debug("User updated", data);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
// Helper function to set user (maintains backward compatibility)
|
|
67
|
+
const setUser = (newUser) => {
|
|
68
|
+
setUserMutation.mutate(newUser);
|
|
69
|
+
};
|
|
70
|
+
// Helper function to invalidate and refetch user
|
|
71
|
+
const refetchUser = async () => {
|
|
72
|
+
await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
73
|
+
return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
|
|
74
|
+
};
|
|
75
|
+
// Helper function to clear user
|
|
76
|
+
const clearUser = () => {
|
|
77
|
+
setUser(undefined);
|
|
78
|
+
};
|
|
79
|
+
return {
|
|
80
|
+
user: user ?? undefined,
|
|
81
|
+
setUser,
|
|
82
|
+
refetchUser,
|
|
83
|
+
clearUser,
|
|
84
|
+
queryKey: USER_QUERY_KEY,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
|
|
2
|
+
[k: string]: import("viem").HttpTransport<undefined, false>;
|
|
3
|
+
}, readonly [import("wagmi").CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
|
|
4
|
+
connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
|
|
5
|
+
accounts: withCapabilities extends true ? readonly {
|
|
6
|
+
address: `0x${string}`;
|
|
7
|
+
capabilities: Record<string, unknown>;
|
|
8
|
+
}[] : readonly `0x${string}`[];
|
|
9
|
+
chainId: number;
|
|
10
|
+
}>;
|
|
11
|
+
}, {
|
|
12
|
+
"thirdweb:lastChainId": number;
|
|
13
|
+
}>]>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWagmiConfig = useWagmiConfig;
|
|
4
|
+
const constants_1 = require("../../../shared/constants");
|
|
5
|
+
const supported_1 = require("../../../shared/constants/chains/supported");
|
|
6
|
+
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
7
|
+
const wagmi_adapter_1 = require("@thirdweb-dev/wagmi-adapter");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const viem_1 = require("viem");
|
|
10
|
+
const wagmi_1 = require("wagmi");
|
|
11
|
+
function useWagmiConfig(partnerId, rpcUrls) {
|
|
12
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
13
|
+
// when parent component passes new object references with same content
|
|
14
|
+
const rpcUrlsString = (0, react_1.useMemo)(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
15
|
+
const ecocystemConfig = (0, react_1.useMemo)(() => {
|
|
16
|
+
return {
|
|
17
|
+
ecosystemId: constants_1.ecosystemWalletId,
|
|
18
|
+
partnerId: partnerId,
|
|
19
|
+
client: thirdweb_1.client,
|
|
20
|
+
};
|
|
21
|
+
}, [partnerId]);
|
|
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 = (0, react_1.useMemo)(() => {
|
|
27
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
28
|
+
return (0, wagmi_1.createConfig)({
|
|
29
|
+
chains: [supported_1.supportedChains[0], ...supported_1.supportedChains.slice(1)],
|
|
30
|
+
transports: Object.fromEntries(supported_1.supportedChains.map(chain => [chain.id, (0, viem_1.http)(parsedRpcUrls?.[chain.id])])),
|
|
31
|
+
connectors: [
|
|
32
|
+
(0, wagmi_adapter_1.inAppWalletConnector)({
|
|
33
|
+
...ecocystemConfig,
|
|
34
|
+
client: thirdweb_1.client,
|
|
35
|
+
}),
|
|
36
|
+
// injected(),
|
|
37
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
38
|
+
],
|
|
39
|
+
});
|
|
40
|
+
}, [rpcUrlsString, ecocystemConfig]);
|
|
41
|
+
return wagmiConfig;
|
|
42
|
+
}
|
|
@@ -32,8 +32,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
32
32
|
sessionKeyAddress?: Address;
|
|
33
33
|
/** Unique identifier for the partner application */
|
|
34
34
|
partnerId: string;
|
|
35
|
-
/** Whether to authenticate with Sign In With Ethereum */
|
|
36
|
-
loginWithSiwe?: boolean;
|
|
37
35
|
/** Whether to close the modal after successful login */
|
|
38
36
|
closeAfterLogin?: boolean;
|
|
39
37
|
/** Source of the sign-in request */
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const react_1 = require("@testing-library/react");
|
|
5
|
+
const useCurrencyConversion_1 = require("../useCurrencyConversion");
|
|
6
|
+
// Mock the external dependencies
|
|
7
|
+
// Store mock rates for different quote currencies
|
|
8
|
+
const mockRates = {};
|
|
9
|
+
// Mock store state
|
|
10
|
+
const mockStoreState = {
|
|
11
|
+
selectedCurrency: "B3",
|
|
12
|
+
baseCurrency: "B3",
|
|
13
|
+
setSelectedCurrency: vitest_1.vi.fn(),
|
|
14
|
+
setBaseCurrency: vitest_1.vi.fn(),
|
|
15
|
+
};
|
|
16
|
+
vitest_1.vi.mock("@b3dotfun/sdk/global-account/react", () => ({
|
|
17
|
+
useExchangeRate: vitest_1.vi.fn((params) => {
|
|
18
|
+
const rate = mockRates[params?.quoteCurrency];
|
|
19
|
+
return { rate };
|
|
20
|
+
}),
|
|
21
|
+
}));
|
|
22
|
+
vitest_1.vi.mock("@b3dotfun/sdk/shared/utils/number", () => ({
|
|
23
|
+
formatDisplayNumber: vitest_1.vi.fn((value) => {
|
|
24
|
+
const num = Number(value);
|
|
25
|
+
if (isNaN(num))
|
|
26
|
+
return "0";
|
|
27
|
+
return num.toLocaleString("en-US", { maximumFractionDigits: 6 });
|
|
28
|
+
}),
|
|
29
|
+
}));
|
|
30
|
+
vitest_1.vi.mock("../../stores/currencyStore", () => ({
|
|
31
|
+
useCurrencyStore: vitest_1.vi.fn((selector) => {
|
|
32
|
+
if (selector) {
|
|
33
|
+
return selector(mockStoreState);
|
|
34
|
+
}
|
|
35
|
+
return mockStoreState;
|
|
36
|
+
}),
|
|
37
|
+
CURRENCY_SYMBOLS: {
|
|
38
|
+
B3: "B3",
|
|
39
|
+
USD: "$",
|
|
40
|
+
EUR: "€",
|
|
41
|
+
GBP: "£",
|
|
42
|
+
JPY: "¥",
|
|
43
|
+
CAD: "C$",
|
|
44
|
+
AUD: "A$",
|
|
45
|
+
ETH: "ETH",
|
|
46
|
+
SOL: "SOL",
|
|
47
|
+
KRW: "₩",
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
(0, vitest_1.describe)("useCurrencyConversion", () => {
|
|
51
|
+
(0, vitest_1.beforeEach)(() => {
|
|
52
|
+
vitest_1.vi.clearAllMocks();
|
|
53
|
+
// Reset mock rates to default
|
|
54
|
+
Object.keys(mockRates).forEach(key => delete mockRates[key]);
|
|
55
|
+
mockRates.USD = 1.0;
|
|
56
|
+
// Reset store state
|
|
57
|
+
mockStoreState.selectedCurrency = "B3";
|
|
58
|
+
mockStoreState.baseCurrency = "B3";
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.describe)("formatCurrencyValue", () => {
|
|
61
|
+
(0, vitest_1.it)("should format base currency (B3) without conversion", () => {
|
|
62
|
+
mockStoreState.selectedCurrency = "B3";
|
|
63
|
+
mockStoreState.baseCurrency = "B3";
|
|
64
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
65
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
66
|
+
(0, vitest_1.expect)(formatted).toContain("B3");
|
|
67
|
+
(0, vitest_1.expect)(formatted).toContain("100");
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.it)("should show base currency when exchange rate is unavailable", () => {
|
|
70
|
+
mockRates.USD = undefined;
|
|
71
|
+
mockStoreState.selectedCurrency = "USD";
|
|
72
|
+
mockStoreState.baseCurrency = "B3";
|
|
73
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
74
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
75
|
+
(0, vitest_1.expect)(formatted).toContain("B3");
|
|
76
|
+
(0, vitest_1.expect)(formatted).not.toContain("$");
|
|
77
|
+
});
|
|
78
|
+
(0, vitest_1.it)("should format USD with prefix symbol", () => {
|
|
79
|
+
mockRates.USD = 2.0;
|
|
80
|
+
mockStoreState.selectedCurrency = "USD";
|
|
81
|
+
mockStoreState.baseCurrency = "B3";
|
|
82
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
83
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
84
|
+
(0, vitest_1.expect)(formatted).toMatch(/^\$/);
|
|
85
|
+
(0, vitest_1.expect)(formatted).toContain("200");
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)("should format EUR with prefix symbol", () => {
|
|
88
|
+
mockRates.EUR = 1.8;
|
|
89
|
+
mockRates.USD = 2.0;
|
|
90
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
91
|
+
mockStoreState.baseCurrency = "B3";
|
|
92
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
93
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
94
|
+
(0, vitest_1.expect)(formatted).toMatch(/^€/);
|
|
95
|
+
});
|
|
96
|
+
(0, vitest_1.it)("should format JPY without decimals", () => {
|
|
97
|
+
mockRates.JPY = 150;
|
|
98
|
+
mockRates.USD = 2.0;
|
|
99
|
+
mockStoreState.selectedCurrency = "JPY";
|
|
100
|
+
mockStoreState.baseCurrency = "B3";
|
|
101
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
102
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
103
|
+
(0, vitest_1.expect)(formatted).toContain("¥");
|
|
104
|
+
(0, vitest_1.expect)(formatted).not.toContain(".");
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.it)("should format KRW without decimals", () => {
|
|
107
|
+
mockRates.KRW = 1300;
|
|
108
|
+
mockRates.USD = 2.0;
|
|
109
|
+
mockStoreState.selectedCurrency = "KRW";
|
|
110
|
+
mockStoreState.baseCurrency = "B3";
|
|
111
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
112
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
113
|
+
(0, vitest_1.expect)(formatted).toContain("₩");
|
|
114
|
+
(0, vitest_1.expect)(formatted).not.toContain(".");
|
|
115
|
+
});
|
|
116
|
+
(0, vitest_1.it)("should format ETH with suffix symbol", () => {
|
|
117
|
+
mockRates.ETH = 0.0005;
|
|
118
|
+
mockRates.USD = 2.0;
|
|
119
|
+
mockStoreState.selectedCurrency = "ETH";
|
|
120
|
+
mockStoreState.baseCurrency = "B3";
|
|
121
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
122
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
123
|
+
(0, vitest_1.expect)(formatted).toContain("ETH");
|
|
124
|
+
(0, vitest_1.expect)(formatted).not.toMatch(/^ETH/);
|
|
125
|
+
});
|
|
126
|
+
(0, vitest_1.it)("should format SOL with suffix symbol", () => {
|
|
127
|
+
mockRates.SOL = 0.05;
|
|
128
|
+
mockRates.USD = 2.0;
|
|
129
|
+
mockStoreState.selectedCurrency = "SOL";
|
|
130
|
+
mockStoreState.baseCurrency = "B3";
|
|
131
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
132
|
+
const formatted = result.current.formatCurrencyValue(100);
|
|
133
|
+
(0, vitest_1.expect)(formatted).toContain("SOL");
|
|
134
|
+
(0, vitest_1.expect)(formatted).not.toMatch(/^SOL/);
|
|
135
|
+
});
|
|
136
|
+
(0, vitest_1.it)("should handle small USD amounts with proper conversion", () => {
|
|
137
|
+
mockRates.USD = 1.5;
|
|
138
|
+
mockStoreState.selectedCurrency = "USD";
|
|
139
|
+
mockStoreState.baseCurrency = "B3";
|
|
140
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
141
|
+
const formatted = result.current.formatCurrencyValue(10);
|
|
142
|
+
// 10 * 1.5 = 15
|
|
143
|
+
(0, vitest_1.expect)(formatted).toMatch(/^\$/);
|
|
144
|
+
(0, vitest_1.expect)(formatted).toContain("15");
|
|
145
|
+
});
|
|
146
|
+
(0, vitest_1.it)("should apply correct exchange rate conversion", () => {
|
|
147
|
+
const testRate = 3.5;
|
|
148
|
+
mockRates.USD = testRate;
|
|
149
|
+
mockStoreState.selectedCurrency = "USD";
|
|
150
|
+
mockStoreState.baseCurrency = "B3";
|
|
151
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
152
|
+
const inputValue = 100;
|
|
153
|
+
const formatted = result.current.formatCurrencyValue(inputValue);
|
|
154
|
+
(0, vitest_1.expect)(formatted).toContain("350");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
(0, vitest_1.describe)("return values", () => {
|
|
158
|
+
(0, vitest_1.it)("should return selected currency", () => {
|
|
159
|
+
mockStoreState.selectedCurrency = "USD";
|
|
160
|
+
mockStoreState.baseCurrency = "B3";
|
|
161
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
162
|
+
(0, vitest_1.expect)(result.current.selectedCurrency).toBe("USD");
|
|
163
|
+
});
|
|
164
|
+
(0, vitest_1.it)("should return base currency", () => {
|
|
165
|
+
mockStoreState.selectedCurrency = "USD";
|
|
166
|
+
mockStoreState.baseCurrency = "B3";
|
|
167
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
168
|
+
(0, vitest_1.expect)(result.current.baseCurrency).toBe("B3");
|
|
169
|
+
});
|
|
170
|
+
(0, vitest_1.it)("should return exchange rate", () => {
|
|
171
|
+
const testRate = 2.5;
|
|
172
|
+
mockRates.USD = testRate;
|
|
173
|
+
mockStoreState.selectedCurrency = "USD";
|
|
174
|
+
mockStoreState.baseCurrency = "B3";
|
|
175
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
176
|
+
(0, vitest_1.expect)(result.current.exchangeRate).toBe(testRate);
|
|
177
|
+
});
|
|
178
|
+
(0, vitest_1.it)("should return correct currency symbols", () => {
|
|
179
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
180
|
+
mockStoreState.baseCurrency = "B3";
|
|
181
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
182
|
+
(0, vitest_1.expect)(result.current.selectedCurrencySymbol).toBe("€");
|
|
183
|
+
(0, vitest_1.expect)(result.current.baseCurrencySymbol).toBe("B3");
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
(0, vitest_1.describe)("formatTooltipValue", () => {
|
|
187
|
+
(0, vitest_1.it)("should show USD equivalent when displaying base currency", () => {
|
|
188
|
+
mockRates.USD = 1.5;
|
|
189
|
+
mockStoreState.selectedCurrency = "B3";
|
|
190
|
+
mockStoreState.baseCurrency = "B3";
|
|
191
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
192
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
193
|
+
(0, vitest_1.expect)(tooltip).toContain("USD");
|
|
194
|
+
(0, vitest_1.expect)(tooltip).toContain("150");
|
|
195
|
+
});
|
|
196
|
+
(0, vitest_1.it)("should show base currency when displaying other currency", () => {
|
|
197
|
+
mockRates.EUR = 0.9;
|
|
198
|
+
mockRates.USD = 1.2;
|
|
199
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
200
|
+
mockStoreState.baseCurrency = "B3";
|
|
201
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
202
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
203
|
+
(0, vitest_1.expect)(tooltip).toContain("B3");
|
|
204
|
+
(0, vitest_1.expect)(tooltip).toContain("100");
|
|
205
|
+
});
|
|
206
|
+
(0, vitest_1.it)("should handle custom currency for base currency", () => {
|
|
207
|
+
mockRates.USD = 2.0;
|
|
208
|
+
mockRates.EUR = 1.8;
|
|
209
|
+
mockStoreState.selectedCurrency = "EUR";
|
|
210
|
+
mockStoreState.baseCurrency = "B3";
|
|
211
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
212
|
+
const tooltip = result.current.formatTooltipValue(100, "B3");
|
|
213
|
+
(0, vitest_1.expect)(tooltip).toContain("USD");
|
|
214
|
+
(0, vitest_1.expect)(tooltip).toContain("200");
|
|
215
|
+
});
|
|
216
|
+
(0, vitest_1.it)("should handle custom currency for non-base currency", () => {
|
|
217
|
+
mockRates.USD = 2.0;
|
|
218
|
+
mockStoreState.selectedCurrency = "USD";
|
|
219
|
+
mockStoreState.baseCurrency = "B3";
|
|
220
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
221
|
+
const tooltip = result.current.formatTooltipValue(50, "ETH");
|
|
222
|
+
(0, vitest_1.expect)(tooltip).toContain("ETH");
|
|
223
|
+
(0, vitest_1.expect)(tooltip).toContain("50");
|
|
224
|
+
});
|
|
225
|
+
(0, vitest_1.it)("should handle absolute values for negative amounts", () => {
|
|
226
|
+
mockRates.USD = 1.5;
|
|
227
|
+
mockStoreState.selectedCurrency = "B3";
|
|
228
|
+
mockStoreState.baseCurrency = "B3";
|
|
229
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
230
|
+
const tooltip = result.current.formatTooltipValue(-100);
|
|
231
|
+
(0, vitest_1.expect)(tooltip).toContain("USD");
|
|
232
|
+
(0, vitest_1.expect)(tooltip).toContain("150");
|
|
233
|
+
(0, vitest_1.expect)(tooltip).not.toContain("-");
|
|
234
|
+
});
|
|
235
|
+
(0, vitest_1.it)("should handle exchange rate unavailable", () => {
|
|
236
|
+
mockRates.USD = undefined;
|
|
237
|
+
mockStoreState.selectedCurrency = "B3";
|
|
238
|
+
mockStoreState.baseCurrency = "B3";
|
|
239
|
+
const { result } = (0, react_1.renderHook)(() => (0, useCurrencyConversion_1.useCurrencyConversion)());
|
|
240
|
+
const tooltip = result.current.formatTooltipValue(100);
|
|
241
|
+
(0, vitest_1.expect)(tooltip).toContain("USD");
|
|
242
|
+
(0, vitest_1.expect)(tooltip).toContain("100");
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Export utility functions
|
|
18
|
-
__exportStar(require("./auth-token"), exports);
|
|
19
18
|
__exportStar(require("./cn"), exports);
|
|
20
19
|
__exportStar(require("./formatNumber"), exports);
|
|
21
20
|
__exportStar(require("./formatUsername"), exports);
|
|
@@ -234,13 +234,11 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
234
234
|
useEffect(() => {
|
|
235
235
|
if (oat?.data?.order.status === "executed" && !onSuccessCalled.current) {
|
|
236
236
|
console.log("Calling onSuccess");
|
|
237
|
-
const
|
|
238
|
-
const lastRelayTxHash = relayTxs?.[relayTxs.length - 1]?.txHash;
|
|
239
|
-
const txHash = oat?.data?.executeTx?.txHash || lastRelayTxHash;
|
|
237
|
+
const txHash = oat?.data?.executeTx?.txHash;
|
|
240
238
|
onSuccess?.(txHash);
|
|
241
239
|
onSuccessCalled.current = true;
|
|
242
240
|
}
|
|
243
|
-
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash,
|
|
241
|
+
}, [oat?.data?.order.status, oat?.data?.executeTx?.txHash, onSuccess]);
|
|
244
242
|
// Reset flag when orderId changes
|
|
245
243
|
useEffect(() => {
|
|
246
244
|
onSuccessCalled.current = false;
|
|
@@ -430,7 +428,7 @@ function AnySpendCustomInner({ loadOrder, mode = "modal", activeTab: activeTabPr
|
|
|
430
428
|
const historyView = (_jsx("div", { className: cn("mx-auto flex w-full max-w-2xl flex-col items-center p-5", mode === "modal" && "bg-b3-react-background"), children: _jsx(OrderHistory, { mode: mode, onBack: () => {
|
|
431
429
|
setActivePanel(PanelView.HISTORY);
|
|
432
430
|
}, onSelectOrder: onSelectOrder }) }));
|
|
433
|
-
const orderDetailsView = (_jsxs("div", { className: cn("mx-auto flex w-full flex-col items-center gap-4
|
|
431
|
+
const orderDetailsView = (_jsxs("div", { className: cn("mx-auto flex w-full flex-col items-center gap-4", mode === "modal" && "bg-b3-react-background rounded-xl"), children: [oat && (_jsx(OrderDetails, { mode: mode, order: oat.data.order, depositTxs: oat.data.depositTxs, relayTxs: oat.data.relayTxs, executeTx: oat.data.executeTx, refundTxs: oat.data.refundTxs, cryptoPaymentMethod: activeTab === "fiat" ? CryptoPaymentMethodType.NONE : selectedCryptoPaymentMethod, selectedCryptoPaymentMethod: selectedCryptoPaymentMethod, onPaymentMethodChange: setSelectedCryptoPaymentMethod, onBack: () => {
|
|
434
432
|
setOrderId(undefined);
|
|
435
433
|
setActivePanel(PanelView.CONFIRM_ORDER);
|
|
436
434
|
// Remove orderId from URL when canceling
|
|
@@ -19,12 +19,12 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
19
19
|
};
|
|
20
20
|
clientType?: ClientType;
|
|
21
21
|
rpcUrls?: Record<number, string>;
|
|
22
|
-
partnerId
|
|
22
|
+
partnerId: string;
|
|
23
23
|
}): import("react/jsx-runtime").JSX.Element;
|
|
24
24
|
/**
|
|
25
25
|
* Inner provider component that provides the actual B3Context
|
|
26
26
|
*/
|
|
27
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
|
|
27
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, }: {
|
|
28
28
|
children: React.ReactNode;
|
|
29
29
|
accountOverride?: Account;
|
|
30
30
|
environment: B3ContextType["environment"];
|
|
@@ -32,4 +32,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
32
32
|
automaticallySetFirstEoa: boolean;
|
|
33
33
|
theme: "light" | "dark";
|
|
34
34
|
clientType?: ClientType;
|
|
35
|
+
partnerId: string;
|
|
35
36
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "../../../../global-account/react/index.js";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { RelayKitProviderWrapper, TooltipProvider, useAuthentication, useAuthStore, } from "../../../../global-account/react/index.js";
|
|
3
|
+
import { useWagmiConfig } from "../../../../global-account/react/hooks/useWagmiConfig.js";
|
|
3
4
|
import { loadGA4Script } from "../../../../global-account/utils/analytics.js";
|
|
4
|
-
import { ecosystemWalletId } from "../../../../shared/constants/index.js";
|
|
5
|
-
import { supportedChains } from "../../../../shared/constants/chains/supported.js";
|
|
6
5
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
7
|
-
import { client } from "../../../../shared/utils/thirdweb.js";
|
|
8
6
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
9
7
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
10
|
-
import {
|
|
11
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
8
|
+
import { useCallback, useEffect, useState } from "react";
|
|
12
9
|
import { Toaster } from "sonner";
|
|
13
10
|
import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
|
|
14
|
-
import {
|
|
11
|
+
import { WagmiProvider } from "wagmi";
|
|
15
12
|
import { setClientType } from "../../../client-manager.js";
|
|
16
13
|
import { StyleRoot } from "../StyleRoot.js";
|
|
17
14
|
import { B3Context } from "./types.js";
|
|
@@ -39,76 +36,25 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
|
|
|
39
36
|
useEffect(() => {
|
|
40
37
|
setClientType(clientType);
|
|
41
38
|
}, [clientType]);
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
return undefined;
|
|
45
|
-
return {
|
|
46
|
-
ecosystemId: ecosystemWalletId,
|
|
47
|
-
partnerId: partnerId,
|
|
48
|
-
client,
|
|
49
|
-
};
|
|
50
|
-
}, [partnerId]);
|
|
51
|
-
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
52
|
-
// when parent component passes new object references with same content
|
|
53
|
-
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
54
|
-
/**
|
|
55
|
-
* Creates wagmi config with optional custom RPC URLs
|
|
56
|
-
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
57
|
-
*/
|
|
58
|
-
const wagmiConfig = useMemo(() => {
|
|
59
|
-
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
60
|
-
return createConfig({
|
|
61
|
-
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
62
|
-
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
63
|
-
connectors: [
|
|
64
|
-
inAppWalletConnector({
|
|
65
|
-
...(ecocystemConfig || {}),
|
|
66
|
-
client,
|
|
67
|
-
}),
|
|
68
|
-
// injected(),
|
|
69
|
-
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
}, [ecocystemConfig, rpcUrlsString]);
|
|
73
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
|
|
39
|
+
const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
|
|
40
|
+
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, partnerId: partnerId, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
|
|
74
41
|
}
|
|
75
42
|
/**
|
|
76
43
|
* Inner provider component that provides the actual B3Context
|
|
77
44
|
*/
|
|
78
|
-
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", }) {
|
|
45
|
+
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", partnerId, }) {
|
|
79
46
|
const activeAccount = useActiveAccount();
|
|
80
47
|
const [manuallySelectedWallet, setManuallySelectedWallet] = useState(undefined);
|
|
81
48
|
const wallets = useConnectedWallets();
|
|
82
|
-
const setActiveWallet = useSetActiveWallet();
|
|
83
49
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
50
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
51
|
+
const setActiveWallet = useSetActiveWallet();
|
|
52
|
+
const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
53
|
+
debug("@@B3Provider:isConnected", isConnected);
|
|
84
54
|
debug("@@wallets", wallets);
|
|
85
|
-
|
|
86
|
-
// Try to restore user from localStorage on initialization
|
|
87
|
-
if (typeof window !== "undefined") {
|
|
88
|
-
try {
|
|
89
|
-
const storedUser = localStorage.getItem("b3-user");
|
|
90
|
-
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.warn("Failed to restore user from localStorage:", error);
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
});
|
|
55
|
+
debug("@@B3Provider:user", user);
|
|
99
56
|
// Use given accountOverride or activeAccount from thirdweb
|
|
100
57
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
101
|
-
// Persist user to localStorage when it changes
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
if (typeof window !== "undefined") {
|
|
104
|
-
if (user) {
|
|
105
|
-
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
localStorage.removeItem("b3-user");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}, [user]);
|
|
112
58
|
const setWallet = useCallback((wallet) => {
|
|
113
59
|
setManuallySelectedWallet(wallet);
|
|
114
60
|
const account = wallet.getAccount();
|
|
@@ -141,6 +87,7 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
141
87
|
wallet: manuallySelectedWallet,
|
|
142
88
|
user,
|
|
143
89
|
setUser,
|
|
90
|
+
refetchUser,
|
|
144
91
|
initialized: true,
|
|
145
92
|
ready: !!effectiveAccount,
|
|
146
93
|
automaticallySetFirstEoa,
|
|
@@ -148,5 +95,9 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
148
95
|
defaultPermissions,
|
|
149
96
|
theme,
|
|
150
97
|
clientType,
|
|
151
|
-
|
|
98
|
+
partnerId: partnerId,
|
|
99
|
+
}, children: _jsx(InnerProvider2, { children: children }) }));
|
|
152
100
|
}
|
|
101
|
+
const InnerProvider2 = ({ children }) => {
|
|
102
|
+
return _jsx(_Fragment, { children: children });
|
|
103
|
+
};
|