@b3dotfun/sdk 0.0.47-alpha.0 → 0.0.47-test.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  3. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +15 -64
  4. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  5. package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +26 -21
  6. package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +2 -0
  7. package/dist/cjs/global-account/react/components/B3Provider/types.js +2 -0
  8. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  9. package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  10. package/dist/cjs/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  11. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  12. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +1 -1
  13. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  14. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +6 -22
  15. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  16. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -2
  17. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  18. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +10 -45
  19. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  20. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -1
  21. package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +2 -1
  22. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +51 -2
  23. package/dist/cjs/global-account/react/hooks/useAuthentication.js +134 -84
  24. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  25. package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -1
  26. package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +58 -0
  27. package/dist/cjs/global-account/react/hooks/useUserQuery.js +86 -0
  28. package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  29. package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +42 -0
  30. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +0 -2
  31. package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  32. package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +19 -68
  33. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  34. package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +24 -19
  35. package/dist/esm/global-account/react/components/B3Provider/types.d.ts +2 -0
  36. package/dist/esm/global-account/react/components/B3Provider/types.js +2 -0
  37. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  38. package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.js +2 -2
  39. package/dist/esm/global-account/react/components/ManageAccount/ManageAccount.js +1 -1
  40. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +2 -2
  41. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -2
  42. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  43. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +7 -23
  44. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  45. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +4 -3
  46. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  47. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +11 -46
  48. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  49. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +3 -2
  50. package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +3 -2
  51. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +51 -2
  52. package/dist/esm/global-account/react/hooks/useAuthentication.js +137 -87
  53. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  54. package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +3 -2
  55. package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +58 -0
  56. package/dist/esm/global-account/react/hooks/useUserQuery.js +83 -0
  57. package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  58. package/dist/esm/global-account/react/hooks/useWagmiConfig.js +39 -0
  59. package/dist/esm/global-account/react/stores/useModalStore.d.ts +0 -2
  60. package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +3 -2
  61. package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +6 -2
  62. package/dist/types/global-account/react/components/B3Provider/types.d.ts +2 -0
  63. package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +1 -2
  64. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
  65. package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +1 -2
  66. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -2
  67. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +1 -2
  68. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +51 -2
  69. package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
  70. package/dist/types/global-account/react/hooks/useUserQuery.d.ts +58 -0
  71. package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +13 -0
  72. package/dist/types/global-account/react/stores/useModalStore.d.ts +0 -2
  73. package/package.json +3 -3
  74. package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +51 -35
  75. package/src/global-account/react/components/B3Provider/B3Provider.tsx +28 -72
  76. package/src/global-account/react/components/B3Provider/types.ts +4 -0
  77. package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +2 -3
  78. package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +1 -1
  79. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +2 -2
  80. package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
  81. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +4 -23
  82. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +4 -3
  83. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +8 -46
  84. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
  85. package/src/global-account/react/components/custom/ManageAccountButton.tsx +3 -2
  86. package/src/global-account/react/hooks/useAuthentication.ts +159 -90
  87. package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +3 -2
  88. package/src/global-account/react/hooks/useUserQuery.ts +95 -0
  89. package/src/global-account/react/hooks/useWagmiConfig.tsx +44 -0
  90. package/src/global-account/react/stores/useModalStore.ts +0 -2
@@ -4,8 +4,7 @@ interface SignInWithB3PrivyProps {
4
4
  onError?: (error: Error) => Promise<void>;
5
5
  onSuccess: (account: Account) => Promise<void>;
6
6
  accessToken?: string;
7
- partnerId: string;
8
7
  chain: Chain;
9
8
  }
10
- export declare function SignInWithB3Privy({ onSuccess, onError, partnerId, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps): import("react/jsx-runtime").JSX.Element;
11
10
  export {};
@@ -9,7 +9,6 @@ interface LoginStepProps {
9
9
  /** Optional callback function called when an error occurs */
10
10
  onError?: (error: Error) => Promise<void>;
11
11
  /** Partner ID used for authentication */
12
- partnerId: string;
13
12
  /** Blockchain chain information */
14
13
  chain: Chain;
15
14
  /** Optional authentication strategy options */
@@ -20,5 +19,5 @@ interface LoginStepContainerProps {
20
19
  partnerId?: string;
21
20
  }
22
21
  export declare function LoginStepContainer({ children, partnerId }: LoginStepContainerProps): import("react/jsx-runtime").JSX.Element;
23
- export declare function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
22
+ export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
24
23
  export {};
@@ -5,10 +5,9 @@ interface LoginStepCustomProps {
5
5
  automaticallySetFirstEoa: boolean;
6
6
  onSuccess: (account: Account) => Promise<void>;
7
7
  onError?: (error: Error) => Promise<void>;
8
- partnerId: string;
9
8
  chain: Chain;
10
9
  strategies: AllowedStrategy[];
11
10
  maxInitialWallets?: number;
12
11
  }
13
- export declare function LoginStepCustom({ onSuccess, onError, partnerId, chain, strategies, maxInitialWallets, automaticallySetFirstEoa, }: LoginStepCustomProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function LoginStepCustom({ onSuccess, onError, chain, strategies, maxInitialWallets, automaticallySetFirstEoa, }: LoginStepCustomProps): import("react/jsx-runtime").JSX.Element;
14
13
  export {};
@@ -1,5 +1,6 @@
1
+ import { Wallet } from "thirdweb/wallets";
1
2
  import { preAuthenticate } from "thirdweb/wallets/in-app";
2
- export declare function useAuthentication(partnerId: string, loginWithSiwe?: boolean): {
3
+ export declare function useAuthentication(partnerId: string): {
3
4
  logout: (callback?: () => void) => Promise<void>;
4
5
  isAuthenticated: boolean;
5
6
  isReady: boolean;
@@ -7,6 +8,54 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
7
8
  isConnected: boolean;
8
9
  wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
9
10
  preAuthenticate: typeof preAuthenticate;
10
- connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
11
+ connect: (wallet: Wallet) => Promise<void>;
11
12
  isAuthenticating: boolean;
13
+ onConnect: (wallet: Wallet) => Promise<void>;
14
+ user: {
15
+ email?: string | undefined;
16
+ username?: string | undefined;
17
+ telNumber?: string | undefined;
18
+ ens?: string | undefined;
19
+ avatar?: string | undefined;
20
+ preferences?: {} | undefined;
21
+ referredBy?: string | {} | undefined;
22
+ sourceApp?: string | undefined;
23
+ referralCode?: string | undefined;
24
+ userGroups?: number[] | undefined;
25
+ isMigratedFromBSMNT?: boolean | undefined;
26
+ privyLinkedAccounts?: {
27
+ name?: string | undefined;
28
+ address?: string | undefined;
29
+ email?: string | undefined;
30
+ chain_type?: string | undefined;
31
+ lv?: number | undefined;
32
+ wallet_client_type?: string | undefined;
33
+ smart_wallet_type?: string | undefined;
34
+ subject?: string | undefined;
35
+ type: string;
36
+ }[] | undefined;
37
+ twProfiles?: {
38
+ type: string;
39
+ details: {
40
+ id?: string | undefined;
41
+ name?: string | undefined;
42
+ address?: string | undefined;
43
+ email?: string | undefined;
44
+ phone?: string | undefined;
45
+ username?: string | undefined;
46
+ fid?: string | undefined;
47
+ };
48
+ }[] | undefined;
49
+ _id: string | {};
50
+ userId: string;
51
+ smartAccountAddress: string;
52
+ createdAt: number;
53
+ updatedAt: number;
54
+ partnerIds: {
55
+ privyId?: string | undefined;
56
+ thirdwebId?: string | undefined;
57
+ };
58
+ } | undefined;
59
+ refetchUser: (wallet?: Wallet) => Promise<void>;
60
+ setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
12
61
  };
@@ -4,7 +4,7 @@ import { Account } from "thirdweb/wallets";
4
4
  * This essentially wraps our useConnect hook to handle the Privy auth flow.
5
5
  * Currently, this is for the basement-privy strategy
6
6
  */
7
- export declare function useHandleConnectWithPrivy(partnerId: string, chain?: Chain, onSuccess?: (account: Account) => void): {
7
+ export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
8
8
  connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
9
9
  isLoading: boolean;
10
10
  fullToken: string | null;
@@ -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,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
+ }>]>;
@@ -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 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@b3dotfun/sdk",
3
- "version": "0.0.47-alpha.0",
3
+ "version": "0.0.47-test.4",
4
4
  "source": "src/index.ts",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "react-native": "./dist/cjs/index.native.js",
@@ -281,7 +281,7 @@
281
281
  "@solana/web3.js": "^1.98.2",
282
282
  "@stripe/react-stripe-js": "^3.7.0",
283
283
  "@stripe/stripe-js": "^7.3.1",
284
- "@thirdweb-dev/wagmi-adapter": "^0.2.141",
284
+ "@thirdweb-dev/wagmi-adapter": "0.2.159",
285
285
  "@web3icons/react": "3.16.0",
286
286
  "big.js": "^7.0.1",
287
287
  "class-variance-authority": "0.7.0",
@@ -354,7 +354,7 @@
354
354
  "react": "^18.0.0 || ^19.0.0",
355
355
  "react-dom": "^18.0.0 || ^19.0.0",
356
356
  "react-native-mmkv": "^3.2.0",
357
- "thirdweb": "5.106.0",
357
+ "thirdweb": "5.108.9",
358
358
  "three": "^0.175.0",
359
359
  "viem": "^2.28.1",
360
360
  "wagmi": "^2.14.15"
@@ -1,12 +1,13 @@
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";
4
3
  import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
5
4
  import { Account } from "thirdweb/wallets";
6
5
 
7
- import { Users } from "@b3dotfun/b3-api";
8
6
  import { ClientType } from "../../../client-manager";
9
7
 
8
+ import { WagmiProvider } from "wagmi";
9
+ import { useAuthentication } from "../../hooks/useAuthentication";
10
+ import { useWagmiConfig } from "../../hooks/useWagmiConfig";
10
11
  import { B3Context, B3ContextType } from "./types";
11
12
 
12
13
  /**
@@ -31,28 +32,32 @@ export function B3Provider({
31
32
  accountOverride,
32
33
  environment,
33
34
  clientType = "socket",
35
+ partnerId,
36
+ rpcUrls,
34
37
  }: {
35
38
  theme: "light" | "dark";
36
39
  children: React.ReactNode;
37
40
  accountOverride?: Account;
38
41
  environment: B3ContextType["environment"];
39
42
  clientType?: ClientType;
43
+ partnerId: string;
44
+ rpcUrls?: Record<number, string>;
40
45
  }) {
41
46
  return (
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>
47
+ <ThirdwebProvider>
48
+ <InnerProvider
49
+ accountOverride={accountOverride}
50
+ environment={environment}
51
+ theme={theme}
52
+ clientType={clientType}
53
+ partnerId={partnerId}
54
+ rpcUrls={rpcUrls}
55
+ >
56
+ {/* <RelayKitProviderWrapper> */}
57
+ {children}
58
+ {/* </RelayKitProviderWrapper> */}
59
+ </InnerProvider>
60
+ </ThirdwebProvider>
56
61
  );
57
62
  }
58
63
 
@@ -66,6 +71,8 @@ export function InnerProvider({
66
71
  defaultPermissions = DEFAULT_PERMISSIONS,
67
72
  theme = "light",
68
73
  clientType = "socket",
74
+ partnerId,
75
+ rpcUrls,
69
76
  }: {
70
77
  children: React.ReactNode;
71
78
  accountOverride?: Account;
@@ -73,31 +80,40 @@ export function InnerProvider({
73
80
  defaultPermissions?: PermissionsConfig;
74
81
  theme: "light" | "dark";
75
82
  clientType?: ClientType;
83
+ partnerId: string;
84
+ rpcUrls?: Record<number, string>;
76
85
  }) {
77
86
  const activeAccount = useActiveAccount();
78
- const [user, setUser] = useState<Users | undefined>(undefined);
87
+ const { user, setUser, refetchUser } = useAuthentication(partnerId);
88
+ const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
79
89
 
80
90
  // Use given accountOverride or activeAccount from thirdweb
81
91
  const effectiveAccount = accountOverride || activeAccount;
82
92
 
83
93
  return (
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>
94
+ <WagmiProvider config={wagmiConfig}>
95
+ <QueryClientProvider client={queryClient}>
96
+ <B3Context.Provider
97
+ value={{
98
+ account: effectiveAccount,
99
+ automaticallySetFirstEoa: false,
100
+ setWallet: () => {},
101
+ wallet: undefined,
102
+ user,
103
+ setUser,
104
+ initialized: true,
105
+ ready: !!effectiveAccount,
106
+ environment,
107
+ defaultPermissions,
108
+ theme,
109
+ clientType,
110
+ partnerId,
111
+ refetchUser,
112
+ }}
113
+ >
114
+ {children}
115
+ </B3Context.Provider>
116
+ </QueryClientProvider>
117
+ </WagmiProvider>
102
118
  );
103
119
  }
@@ -1,15 +1,16 @@
1
- import { Users } from "@b3dotfun/b3-api";
2
- import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "@b3dotfun/sdk/global-account/react";
1
+ import {
2
+ RelayKitProviderWrapper,
3
+ TooltipProvider,
4
+ useAuthentication,
5
+ useAuthStore,
6
+ } from "@b3dotfun/sdk/global-account/react";
7
+ import { useWagmiConfig } from "@b3dotfun/sdk/global-account/react/hooks/useWagmiConfig";
3
8
  import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
4
9
  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";
7
10
  import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
8
- import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
9
11
  import "@reservoir0x/relay-kit-ui/styles.css";
10
12
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
11
- import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
12
- import { useCallback, useEffect, useMemo, useState } from "react";
13
+ import { useCallback, useEffect, useState } from "react";
13
14
  import { Toaster } from "sonner";
14
15
  import {
15
16
  getLastAuthProvider,
@@ -19,7 +20,7 @@ import {
19
20
  useSetActiveWallet,
20
21
  } from "thirdweb/react";
21
22
  import { Account, Wallet } from "thirdweb/wallets";
22
- import { createConfig, http, WagmiProvider } from "wagmi";
23
+ import { WagmiProvider } from "wagmi";
23
24
  import { ClientType, setClientType } from "../../../client-manager";
24
25
  import { StyleRoot } from "../StyleRoot";
25
26
  import { B3Context, B3ContextType } from "./types";
@@ -66,7 +67,7 @@ export function B3Provider({
66
67
  };
67
68
  clientType?: ClientType;
68
69
  rpcUrls?: Record<number, string>;
69
- partnerId?: string;
70
+ partnerId: string;
70
71
  }) {
71
72
  // Initialize Google Analytics on mount
72
73
  useEffect(() => {
@@ -77,45 +78,11 @@ export function B3Provider({
77
78
  useEffect(() => {
78
79
  setClientType(clientType);
79
80
  }, [clientType]);
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]);
81
+ const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
115
82
 
116
83
  return (
117
84
  <ThirdwebProvider>
118
- <WagmiProvider config={wagmiConfig}>
85
+ <WagmiProvider config={wagmiConfig} reconnectOnMount={false}>
119
86
  <QueryClientProvider client={queryClient}>
120
87
  <TooltipProvider>
121
88
  <InnerProvider
@@ -124,6 +91,7 @@ export function B3Provider({
124
91
  theme={theme}
125
92
  automaticallySetFirstEoa={!!automaticallySetFirstEoa}
126
93
  clientType={clientType}
94
+ partnerId={partnerId}
127
95
  >
128
96
  <RelayKitProviderWrapper simDuneApiKey={simDuneApiKey}>
129
97
  {children}
@@ -150,6 +118,7 @@ export function InnerProvider({
150
118
  automaticallySetFirstEoa,
151
119
  theme = "light",
152
120
  clientType = "socket",
121
+ partnerId,
153
122
  }: {
154
123
  children: React.ReactNode;
155
124
  accountOverride?: Account;
@@ -158,42 +127,23 @@ export function InnerProvider({
158
127
  automaticallySetFirstEoa: boolean;
159
128
  theme: "light" | "dark";
160
129
  clientType?: ClientType;
130
+ partnerId: string;
161
131
  }) {
162
132
  const activeAccount = useActiveAccount();
163
133
  const [manuallySelectedWallet, setManuallySelectedWallet] = useState<Wallet | undefined>(undefined);
164
134
  const wallets = useConnectedWallets();
165
- const setActiveWallet = useSetActiveWallet();
166
135
  const isAuthenticated = useAuthStore(state => state.isAuthenticated);
167
- debug("@@wallets", wallets);
136
+ const isConnected = useAuthStore(state => state.isConnected);
137
+ const setActiveWallet = useSetActiveWallet();
138
+ const { user, setUser, refetchUser } = useAuthentication(partnerId);
168
139
 
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
- });
140
+ debug("@@B3Provider:isConnected", isConnected);
141
+ debug("@@wallets", wallets);
142
+ debug("@@B3Provider:user", user);
182
143
 
183
144
  // Use given accountOverride or activeAccount from thirdweb
184
145
  const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
185
146
 
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
-
197
147
  const setWallet = useCallback(
198
148
  (wallet: Wallet) => {
199
149
  setManuallySelectedWallet(wallet);
@@ -237,6 +187,7 @@ export function InnerProvider({
237
187
  wallet: manuallySelectedWallet,
238
188
  user,
239
189
  setUser,
190
+ refetchUser,
240
191
  initialized: true,
241
192
  ready: !!effectiveAccount,
242
193
  automaticallySetFirstEoa,
@@ -244,9 +195,14 @@ export function InnerProvider({
244
195
  defaultPermissions,
245
196
  theme,
246
197
  clientType,
198
+ partnerId: partnerId,
247
199
  }}
248
200
  >
249
- {children}
201
+ <InnerProvider2>{children}</InnerProvider2>
250
202
  </B3Context.Provider>
251
203
  );
252
204
  }
205
+
206
+ const InnerProvider2 = ({ children }: { children: React.ReactNode }) => {
207
+ return <>{children}</>;
208
+ };
@@ -14,12 +14,14 @@ export interface B3ContextType {
14
14
  setWallet: (wallet: Wallet) => void;
15
15
  wallet?: Wallet;
16
16
  setUser: (user?: Users) => void;
17
+ refetchUser: () => Promise<any>;
17
18
  initialized: boolean;
18
19
  ready: boolean;
19
20
  environment?: "development" | "production";
20
21
  defaultPermissions?: PermissionsConfig;
21
22
  theme: "light" | "dark";
22
23
  clientType: ClientType;
24
+ partnerId: string;
23
25
  }
24
26
 
25
27
  /**
@@ -32,9 +34,11 @@ export const B3Context = createContext<B3ContextType>({
32
34
  setWallet: () => {},
33
35
  wallet: undefined,
34
36
  setUser: () => {},
37
+ refetchUser: async () => {},
35
38
  initialized: false,
36
39
  ready: false,
37
40
  environment: "development",
38
41
  theme: "light",
39
42
  clientType: "rest",
43
+ partnerId: "",
40
44
  });
@@ -23,7 +23,6 @@ import { TokenBalanceRow } from "./TokenBalanceRow";
23
23
 
24
24
  interface BalanceContentProps {
25
25
  onLogout?: () => void;
26
- partnerId: string;
27
26
  showDeposit?: boolean;
28
27
  showSwap?: boolean;
29
28
  }
@@ -33,14 +32,14 @@ function centerTruncate(str: string, length = 4) {
33
32
  return `${str.slice(0, length)}...${str.slice(-length)}`;
34
33
  }
35
34
 
36
- export function BalanceContent({ onLogout, partnerId, showDeposit = true, showSwap = true }: BalanceContentProps) {
35
+ export function BalanceContent({ onLogout, showDeposit = true, showSwap = true }: BalanceContentProps) {
37
36
  const account = useActiveAccount();
38
37
  const { address: eoaAddress, info: eoaInfo } = useFirstEOA();
39
38
  const { data: profile } = useProfile({
40
39
  address: eoaAddress || account?.address,
41
40
  fresh: true,
42
41
  });
43
- const { user } = useB3();
42
+ const { user, partnerId } = useB3();
44
43
  const { setB3ModalOpen, setB3ModalContentType, navigateBack } = useModalStore();
45
44
  const { logout } = useAuthentication(partnerId);
46
45
  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} partnerId={partnerId} showDeposit={showDeposit} showSwap={showSwap} />
607
+ <BalanceContent onLogout={onLogout} 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 } = useB3();
32
+ const { automaticallySetFirstEoa, partnerId } = 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(String(process.env.NEXT_PUBLIC_THIRDWEB_PARTNER_ID));
46
+ const { logout } = useAuthentication(partnerId);
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
- useAuthentication,
5
+ useAuthStore,
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 } = useAuthentication(props.partnerId, props.loginWithSiwe);
24
+ const { isAuthenticating, isAuthenticated } = useAuthStore();
25
25
  const isMobile = useIsMobile();
26
26
 
27
27
  useEffect(() => {