@b3dotfun/sdk 0.0.47 → 0.0.48-alpha.1
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 +225 -6
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/cjs/anyspend/types/chain.d.ts +2 -1
- package/dist/cjs/anyspend/utils/chain.js +4 -0
- 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/notifications/index.d.ts +3 -0
- package/dist/cjs/notifications/index.js +25 -0
- package/dist/cjs/notifications/react/hooks/index.d.ts +1 -0
- package/dist/cjs/notifications/react/hooks/index.js +17 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/cjs/notifications/react/hooks/useNotifications.js +148 -0
- package/dist/cjs/notifications/react/index.d.ts +1 -0
- package/dist/cjs/notifications/react/index.js +17 -0
- package/dist/cjs/notifications/services/api.d.ts +67 -0
- package/dist/cjs/notifications/services/api.js +184 -0
- package/dist/cjs/notifications/services/index.d.ts +1 -0
- package/dist/cjs/notifications/services/index.js +17 -0
- package/dist/cjs/notifications/types/index.d.ts +51 -0
- package/dist/cjs/notifications/types/index.js +2 -0
- package/dist/cjs/shared/utils/auth-token.d.ts +7 -0
- package/dist/cjs/shared/utils/auth-token.js +17 -0
- package/dist/cjs/shared/utils/index.d.ts +1 -0
- package/dist/cjs/shared/utils/index.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +5 -3
- package/dist/esm/anyspend/types/chain.d.ts +2 -1
- package/dist/esm/anyspend/utils/chain.js +4 -0
- 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/notifications/index.d.ts +3 -0
- package/dist/esm/notifications/index.js +7 -0
- package/dist/esm/notifications/react/hooks/index.d.ts +1 -0
- package/dist/esm/notifications/react/hooks/index.js +1 -0
- package/dist/esm/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/esm/notifications/react/hooks/useNotifications.js +145 -0
- package/dist/esm/notifications/react/index.d.ts +1 -0
- package/dist/esm/notifications/react/index.js +1 -0
- package/dist/esm/notifications/services/api.d.ts +67 -0
- package/dist/esm/notifications/services/api.js +179 -0
- package/dist/esm/notifications/services/index.d.ts +1 -0
- package/dist/esm/notifications/services/index.js +1 -0
- package/dist/esm/notifications/types/index.d.ts +51 -0
- package/dist/esm/shared/utils/auth-token.d.ts +7 -0
- package/dist/esm/shared/utils/auth-token.js +11 -0
- package/dist/esm/shared/utils/index.d.ts +1 -0
- package/dist/esm/shared/utils/index.js +1 -0
- package/dist/types/anyspend/types/chain.d.ts +2 -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/notifications/index.d.ts +3 -0
- package/dist/types/notifications/react/hooks/index.d.ts +1 -0
- package/dist/types/notifications/react/hooks/useNotifications.d.ts +42 -0
- package/dist/types/notifications/react/index.d.ts +1 -0
- package/dist/types/notifications/services/api.d.ts +67 -0
- package/dist/types/notifications/services/index.d.ts +1 -0
- package/dist/types/notifications/types/index.d.ts +51 -0
- package/dist/types/shared/utils/auth-token.d.ts +7 -0
- package/dist/types/shared/utils/index.d.ts +1 -0
- package/package.json +23 -3
- package/src/anyspend/react/components/AnySpendCustom.tsx +5 -3
- package/src/anyspend/types/chain.ts +2 -1
- package/src/anyspend/utils/chain.ts +4 -0
- 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/notifications/index.ts +9 -0
- package/src/notifications/react/hooks/index.ts +1 -0
- package/src/notifications/react/hooks/useNotifications.ts +153 -0
- package/src/notifications/react/index.ts +1 -0
- package/src/notifications/services/api.ts +217 -0
- package/src/notifications/services/index.ts +1 -0
- package/src/notifications/types/index.ts +58 -0
- package/src/shared/utils/auth-token.ts +13 -0
- package/src/shared/utils/index.ts +1 -0
- package/dist/cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -245
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- package/dist/esm/shared/react/hooks/__tests__/useCurrencyConversion.test.js +0 -243
- package/dist/types/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts +0 -1
- /package/dist/{cjs/shared/react/hooks/__tests__/useCurrencyConversion.test.d.ts → esm/notifications/types/index.js} +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 {
|
|
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 {
|
|
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
|
|
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
|
-
|
|
136
|
+
const isConnected = useAuthStore(state => state.isConnected);
|
|
137
|
+
const setActiveWallet = useSetActiveWallet();
|
|
138
|
+
const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
168
139
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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,
|
|
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}
|
|
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(
|
|
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
|
-
|
|
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 } =
|
|
24
|
+
const { isAuthenticating, isAuthenticated } = useAuthStore();
|
|
25
25
|
const isMobile = useIsMobile();
|
|
26
26
|
|
|
27
27
|
useEffect(() => {
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
useB3,
|
|
6
6
|
useGetAllTWSigners,
|
|
7
7
|
useModalStore,
|
|
8
|
-
useSiwe,
|
|
9
8
|
} from "@b3dotfun/sdk/global-account/react";
|
|
10
9
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
11
10
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -31,19 +30,16 @@ export function SignInWithB3Flow({
|
|
|
31
30
|
sessionKeyAddress,
|
|
32
31
|
partnerId,
|
|
33
32
|
closeAfterLogin = false,
|
|
34
|
-
loginWithSiwe = false,
|
|
35
33
|
source = "signInWithB3Button",
|
|
36
34
|
signersEnabled = false,
|
|
37
35
|
}: SignInWithB3ModalProps) {
|
|
38
|
-
const {
|
|
36
|
+
const { automaticallySetFirstEoa } = useB3();
|
|
39
37
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
40
38
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
41
39
|
const { setB3ModalContentType, setB3ModalOpen, isOpen } = useModalStore();
|
|
42
40
|
const account = useActiveAccount();
|
|
43
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
44
41
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
45
42
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
46
|
-
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
47
43
|
const [refetchCount, setRefetchCount] = useState(0);
|
|
48
44
|
const [refetchError, setRefetchError] = useState<string | null>(null);
|
|
49
45
|
const {
|
|
@@ -57,7 +53,6 @@ export function SignInWithB3Flow({
|
|
|
57
53
|
enabled: signersEnabled,
|
|
58
54
|
},
|
|
59
55
|
});
|
|
60
|
-
const { authenticate } = useSiwe();
|
|
61
56
|
const [refetchQueued, setRefetchQueued] = useState(false);
|
|
62
57
|
|
|
63
58
|
// Enhanced refetchSigners function that tracks number of attempts
|
|
@@ -175,13 +170,11 @@ export function SignInWithB3Flow({
|
|
|
175
170
|
sessionKeyAddress,
|
|
176
171
|
partnerId,
|
|
177
172
|
closeAfterLogin,
|
|
178
|
-
loginWithSiwe,
|
|
179
173
|
source: "requestPermissions",
|
|
180
174
|
});
|
|
181
175
|
}, [
|
|
182
176
|
chain,
|
|
183
177
|
closeAfterLogin,
|
|
184
|
-
loginWithSiwe,
|
|
185
178
|
onError,
|
|
186
179
|
onLoginSuccess,
|
|
187
180
|
onSessionKeySuccess,
|
|
@@ -193,20 +186,9 @@ export function SignInWithB3Flow({
|
|
|
193
186
|
|
|
194
187
|
const handleLoginSuccess = useCallback(
|
|
195
188
|
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);
|
|
205
189
|
onLoginSuccess?.(account);
|
|
206
|
-
debug("setIsAuthenticating:false:1");
|
|
207
|
-
setIsAuthenticating(false);
|
|
208
190
|
},
|
|
209
|
-
[
|
|
191
|
+
[onLoginSuccess],
|
|
210
192
|
);
|
|
211
193
|
|
|
212
194
|
useEffect(() => {
|
|
@@ -243,7 +225,7 @@ export function SignInWithB3Flow({
|
|
|
243
225
|
if (step === "login") {
|
|
244
226
|
// Custom strategy
|
|
245
227
|
if (strategies?.[0] === "privy") {
|
|
246
|
-
return <SignInWithB3Privy onSuccess={handleLoginSuccess}
|
|
228
|
+
return <SignInWithB3Privy onSuccess={handleLoginSuccess} chain={chain} />;
|
|
247
229
|
}
|
|
248
230
|
|
|
249
231
|
// Strategies are explicitly provided
|
|
@@ -251,7 +233,6 @@ export function SignInWithB3Flow({
|
|
|
251
233
|
return (
|
|
252
234
|
<LoginStepCustom
|
|
253
235
|
strategies={strategies}
|
|
254
|
-
partnerId={partnerId}
|
|
255
236
|
chain={chain}
|
|
256
237
|
onSuccess={handleLoginSuccess}
|
|
257
238
|
onError={onError}
|
|
@@ -261,7 +242,7 @@ export function SignInWithB3Flow({
|
|
|
261
242
|
}
|
|
262
243
|
|
|
263
244
|
// Default to handle all strategies we support
|
|
264
|
-
return <LoginStep
|
|
245
|
+
return <LoginStep chain={chain} onSuccess={handleLoginSuccess} onError={onError} />;
|
|
265
246
|
}
|
|
266
247
|
|
|
267
248
|
return null;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Loading,
|
|
3
3
|
useAuthentication,
|
|
4
4
|
useAuthStore,
|
|
5
|
+
useB3,
|
|
5
6
|
useHandleConnectWithPrivy,
|
|
6
7
|
} from "@b3dotfun/sdk/global-account/react";
|
|
7
8
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
@@ -14,12 +15,12 @@ interface SignInWithB3PrivyProps {
|
|
|
14
15
|
onError?: (error: Error) => Promise<void>;
|
|
15
16
|
onSuccess: (account: Account) => Promise<void>;
|
|
16
17
|
accessToken?: string;
|
|
17
|
-
partnerId: string;
|
|
18
18
|
chain: Chain;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function SignInWithB3Privy({ onSuccess, onError,
|
|
22
|
-
const {
|
|
21
|
+
export function SignInWithB3Privy({ onSuccess, onError, chain }: SignInWithB3PrivyProps) {
|
|
22
|
+
const { partnerId } = useB3();
|
|
23
|
+
const { isLoading, connectTw, fullToken } = useHandleConnectWithPrivy(chain, onSuccess);
|
|
23
24
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
24
25
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
25
26
|
const { logout } = useAuthentication(partnerId);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useAuthentication,
|
|
1
|
+
import { useAuthentication, 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";
|
|
4
3
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
5
4
|
import { Chain } from "thirdweb";
|
|
6
5
|
import { ConnectEmbed, darkTheme, lightTheme } from "thirdweb/react";
|
|
@@ -14,7 +13,6 @@ interface LoginStepProps {
|
|
|
14
13
|
/** Optional callback function called when an error occurs */
|
|
15
14
|
onError?: (error: Error) => Promise<void>;
|
|
16
15
|
/** Partner ID used for authentication */
|
|
17
|
-
partnerId: string;
|
|
18
16
|
/** Blockchain chain information */
|
|
19
17
|
chain: Chain;
|
|
20
18
|
/** Optional authentication strategy options */
|
|
@@ -56,15 +54,12 @@ export function LoginStepContainer({ children, partnerId }: LoginStepContainerPr
|
|
|
56
54
|
);
|
|
57
55
|
}
|
|
58
56
|
|
|
59
|
-
export function LoginStep({ onSuccess,
|
|
57
|
+
export function LoginStep({ onSuccess, chain }: LoginStepProps) {
|
|
58
|
+
const { partnerId, theme } = useB3();
|
|
60
59
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
61
60
|
partnerId: partnerId,
|
|
62
61
|
});
|
|
63
|
-
|
|
64
|
-
const { theme } = useB3();
|
|
65
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
66
|
-
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
67
|
-
const { logout } = useAuthentication(partnerId);
|
|
62
|
+
const { onConnect } = useAuthentication(partnerId);
|
|
68
63
|
|
|
69
64
|
return (
|
|
70
65
|
<LoginStepContainer partnerId={partnerId}>
|
|
@@ -86,54 +81,21 @@ export function LoginStep({ onSuccess, onError, partnerId, chain }: LoginStepPro
|
|
|
86
81
|
},
|
|
87
82
|
})
|
|
88
83
|
}
|
|
89
|
-
autoConnect
|
|
90
84
|
style={{
|
|
91
85
|
width: "100%",
|
|
92
86
|
height: "100%",
|
|
93
87
|
border: 0,
|
|
94
88
|
}}
|
|
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
|
-
// }}
|
|
112
89
|
header={{
|
|
113
90
|
title: "Sign in with B3",
|
|
114
91
|
titleIcon: "https://cdn.b3.fun/b3_logo.svg",
|
|
115
92
|
}}
|
|
116
93
|
className="b3-login-step"
|
|
117
94
|
onConnect={async wallet => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
}
|
|
95
|
+
await onConnect(wallet);
|
|
96
|
+
const account = wallet.getAccount();
|
|
97
|
+
if (!account) throw new Error("No account found");
|
|
98
|
+
await onSuccess(account);
|
|
137
99
|
}}
|
|
138
100
|
/>
|
|
139
101
|
</LoginStepContainer>
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
LoginStepContainer,
|
|
8
8
|
useAuthentication,
|
|
9
9
|
useAuthStore,
|
|
10
|
+
useB3,
|
|
10
11
|
useConnect,
|
|
11
12
|
WalletRow,
|
|
12
13
|
} from "@b3dotfun/sdk/global-account/react";
|
|
@@ -21,7 +22,6 @@ interface LoginStepCustomProps {
|
|
|
21
22
|
automaticallySetFirstEoa: boolean;
|
|
22
23
|
onSuccess: (account: Account) => Promise<void>;
|
|
23
24
|
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,
|
|
36
35
|
chain,
|
|
37
36
|
strategies,
|
|
38
37
|
maxInitialWallets = 2,
|
|
39
38
|
automaticallySetFirstEoa,
|
|
40
39
|
}: 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,10 +1,11 @@
|
|
|
1
|
-
import { Button, StyleRoot, useAuthentication, useModalStore } from "@b3dotfun/sdk/global-account/react";
|
|
1
|
+
import { Button, StyleRoot, useAuthentication, useB3, 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();
|
|
6
7
|
const { setB3ModalOpen, setB3ModalContentType } = useModalStore();
|
|
7
|
-
const { isConnected } = useAuthentication(
|
|
8
|
+
const { isConnected } = useAuthentication(partnerId);
|
|
8
9
|
|
|
9
10
|
const handleClickManageAccount = () => {
|
|
10
11
|
setB3ModalContentType({
|