@b3dotfun/sdk 0.0.87-alpha.1 → 0.0.87-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +18 -24
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/cjs/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/cjs/global-account/react/components/AvatarEditor/AvatarEditor.js +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +17 -47
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/cjs/global-account/react/components/B3Provider/types.js +4 -4
- package/dist/cjs/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3.js +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Account.js +10 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/cjs/global-account/react/components/B3Provider/useB3Config.js +23 -0
- package/dist/cjs/global-account/react/components/LinkAccount/LinkAccount.js +1 -1
- package/dist/cjs/global-account/react/components/LinkAccount/LinkNewAccount.js +1 -2
- package/dist/cjs/global-account/react/components/ManageAccount/ProfileSection.js +2 -1
- package/dist/cjs/global-account/react/components/ManageAccount/SettingsProfileCard.js +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3.js +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +2 -1
- package/dist/cjs/global-account/react/components/index.d.ts +2 -0
- package/dist/cjs/global-account/react/components/index.js +7 -3
- package/dist/cjs/global-account/react/hooks/useAccountWallet.js +3 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.js +42 -0
- package/dist/cjs/global-account/react/hooks/useTurnkeyAuth.js +6 -4
- package/dist/cjs/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +18 -24
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +0 -1
- package/dist/esm/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/esm/global-account/react/components/AvatarEditor/AvatarEditor.js +3 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +21 -51
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +6 -7
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/esm/global-account/react/components/B3Provider/types.js +4 -4
- package/dist/esm/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3.js +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Account.js +6 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/esm/global-account/react/components/B3Provider/useB3Config.js +19 -0
- package/dist/esm/global-account/react/components/LinkAccount/LinkAccount.js +2 -2
- package/dist/esm/global-account/react/components/LinkAccount/LinkNewAccount.js +2 -3
- package/dist/esm/global-account/react/components/ManageAccount/ProfileSection.js +3 -2
- package/dist/esm/global-account/react/components/ManageAccount/SettingsProfileCard.js +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3.js +3 -2
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +3 -2
- package/dist/esm/global-account/react/components/index.d.ts +2 -0
- package/dist/esm/global-account/react/components/index.js +2 -0
- package/dist/esm/global-account/react/hooks/useAccountWallet.js +4 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.js +39 -0
- package/dist/esm/global-account/react/hooks/useTurnkeyAuth.js +6 -4
- package/dist/esm/global-account/react/hooks/useUnifiedChainSwitchAndExecute.js +2 -2
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/react/hooks/useSigMint.d.ts +1 -1
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -5
- package/dist/types/global-account/react/components/B3Provider/useB3.d.ts +1 -0
- package/dist/types/global-account/react/components/B3Provider/useB3Account.d.ts +1 -0
- package/dist/types/global-account/react/components/B3Provider/useB3Config.d.ts +9 -0
- package/dist/types/global-account/react/components/index.d.ts +2 -0
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useAutoSelectWallet.d.ts +7 -0
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +1 -1
- package/package.json +1 -1
- package/src/anyspend/react/components/AnySpend.tsx +37 -40
- package/src/anyspend/react/components/AnySpendCustom.tsx +0 -2
- package/src/global-account/react/components/AvatarEditor/AvatarEditor.tsx +10 -2
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +6 -7
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +20 -71
- package/src/global-account/react/components/B3Provider/types.ts +8 -9
- package/src/global-account/react/components/B3Provider/useB3.ts +1 -0
- package/src/global-account/react/components/B3Provider/useB3Account.ts +7 -0
- package/src/global-account/react/components/B3Provider/useB3Config.ts +34 -0
- package/src/global-account/react/components/LinkAccount/LinkAccount.tsx +2 -2
- package/src/global-account/react/components/LinkAccount/LinkNewAccount.tsx +2 -3
- package/src/global-account/react/components/ManageAccount/ProfileSection.tsx +10 -2
- package/src/global-account/react/components/ManageAccount/SettingsProfileCard.tsx +3 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3.tsx +2 -2
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +5 -2
- package/src/global-account/react/components/index.ts +2 -0
- package/src/global-account/react/hooks/useAccountWallet.tsx +4 -3
- package/src/global-account/react/hooks/useAutoSelectWallet.ts +51 -0
- package/src/global-account/react/hooks/useTurnkeyAuth.ts +7 -5
- package/src/global-account/react/hooks/useUnifiedChainSwitchAndExecute.ts +2 -2
|
@@ -1162,47 +1162,44 @@ function AnySpendInner({
|
|
|
1162
1162
|
)}
|
|
1163
1163
|
|
|
1164
1164
|
{/* Reverse swap direction section */}
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
>
|
|
1202
|
-
<div className="relative flex items-center justify-center transition-opacity">
|
|
1203
|
-
<ArrowDown className="text-as-primary/50 h-5 w-5" />
|
|
1165
|
+
{activeTab === "crypto" && (
|
|
1166
|
+
<div className="z-10 -my-6 flex justify-center">
|
|
1167
|
+
<Button
|
|
1168
|
+
variant="ghost"
|
|
1169
|
+
className={cn(
|
|
1170
|
+
"border-as-stroke bg-as-surface-primary h-10 w-10 rounded-xl border-2 sm:h-8 sm:w-8 sm:rounded-xl",
|
|
1171
|
+
isBuyMode && "cursor-default",
|
|
1172
|
+
selectedDstChainId === HYPERLIQUID_CHAIN_ID && "cursor-not-allowed opacity-50",
|
|
1173
|
+
)}
|
|
1174
|
+
onClick={() => {
|
|
1175
|
+
if (isBuyMode) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// Prevent swapping if destination is Hyperliquid (only supported as destination, not source)
|
|
1180
|
+
if (selectedDstChainId === HYPERLIQUID_CHAIN_ID) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
// Swap chain selections
|
|
1185
|
+
setSelectedSrcChainId(selectedDstChainId);
|
|
1186
|
+
setSelectedDstChainId(selectedSrcChainId);
|
|
1187
|
+
|
|
1188
|
+
// Swap token selections
|
|
1189
|
+
setSelectedSrcToken(selectedDstToken);
|
|
1190
|
+
setSelectedDstToken(selectedSrcToken);
|
|
1191
|
+
|
|
1192
|
+
// Swap amounts
|
|
1193
|
+
setSrcAmount(dstAmount);
|
|
1194
|
+
setDstAmount(srcAmount);
|
|
1195
|
+
}}
|
|
1196
|
+
>
|
|
1197
|
+
<div className="relative flex items-center justify-center transition-opacity">
|
|
1198
|
+
<ArrowDown className="text-as-primary/50 h-5 w-5" />
|
|
1199
|
+
</div>
|
|
1200
|
+
</Button>
|
|
1204
1201
|
</div>
|
|
1205
|
-
|
|
1202
|
+
)}
|
|
1206
1203
|
|
|
1207
1204
|
{/* Receive section - Hidden when fiat tab is active */}
|
|
1208
1205
|
{/* Receive section - Hidden when fiat tab is active */}
|
|
@@ -336,8 +336,6 @@ function AnySpendCustomInner({
|
|
|
336
336
|
}
|
|
337
337
|
}, [srcChainId, tokenList, getTokenWithBalance, nativeTokens, fungibleTokens, dirtySelectSrcToken, dstToken.address]);
|
|
338
338
|
|
|
339
|
-
// const { account: isAuthenticated } = useB3();
|
|
340
|
-
|
|
341
339
|
const getRelayQuoteRequest = useMemo(() => {
|
|
342
340
|
return generateGetRelayQuoteRequest({
|
|
343
341
|
orderType: orderType,
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
IPFSMediaRenderer,
|
|
7
|
+
toast,
|
|
8
|
+
useAuthentication,
|
|
9
|
+
useB3Config,
|
|
10
|
+
useProfile,
|
|
11
|
+
} from "@b3dotfun/sdk/global-account/react";
|
|
5
12
|
import { validateImageUrl } from "@b3dotfun/sdk/global-account/react/utils/profileDisplay";
|
|
6
13
|
import { cn } from "@b3dotfun/sdk/shared/utils/cn";
|
|
7
14
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
@@ -50,7 +57,8 @@ export function AvatarEditor({ onSetAvatar, className }: AvatarEditorProps) {
|
|
|
50
57
|
const [zoom, setZoom] = useState(1);
|
|
51
58
|
const [croppedAreaPixels, setCroppedAreaPixels] = useState<Area | null>(null);
|
|
52
59
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
53
|
-
const {
|
|
60
|
+
const { partnerId } = useB3Config();
|
|
61
|
+
const { user, setUser } = useAuthentication(partnerId);
|
|
54
62
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
55
63
|
const contentType = useModalStore(state => state.contentType);
|
|
56
64
|
|
|
@@ -6,7 +6,6 @@ import { Account, Wallet } from "thirdweb/wallets";
|
|
|
6
6
|
import { ClientType } from "../../../client-manager";
|
|
7
7
|
|
|
8
8
|
import { WagmiProvider } from "wagmi";
|
|
9
|
-
import { useAuthentication } from "../../hooks/useAuthentication";
|
|
10
9
|
import { createWagmiConfig } from "../../utils/createWagmiConfig";
|
|
11
10
|
import { LocalSDKProvider } from "./LocalSDKProvider";
|
|
12
11
|
import { B3Context, B3ContextType } from "./types";
|
|
@@ -89,7 +88,7 @@ export function InnerProvider({
|
|
|
89
88
|
rpcUrls?: Record<number, string>;
|
|
90
89
|
}) {
|
|
91
90
|
const activeAccount = useActiveAccount();
|
|
92
|
-
const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
91
|
+
//const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
93
92
|
const wagmiConfig = createWagmiConfig({ partnerId, rpcUrls });
|
|
94
93
|
|
|
95
94
|
// Use given accountOverride or activeAccount from thirdweb
|
|
@@ -100,12 +99,12 @@ export function InnerProvider({
|
|
|
100
99
|
<QueryClientProvider client={queryClient}>
|
|
101
100
|
<B3Context.Provider
|
|
102
101
|
value={{
|
|
103
|
-
account: effectiveAccount,
|
|
102
|
+
//account: effectiveAccount,
|
|
104
103
|
automaticallySetFirstEoa: false,
|
|
105
|
-
setWallet: () => {},
|
|
104
|
+
//setWallet: () => {},
|
|
106
105
|
wallet: undefined,
|
|
107
|
-
user,
|
|
108
|
-
setUser,
|
|
106
|
+
//user,
|
|
107
|
+
//setUser,
|
|
109
108
|
initialized: true,
|
|
110
109
|
ready: !!effectiveAccount,
|
|
111
110
|
environment,
|
|
@@ -113,7 +112,7 @@ export function InnerProvider({
|
|
|
113
112
|
theme,
|
|
114
113
|
clientType,
|
|
115
114
|
partnerId,
|
|
116
|
-
refetchUser,
|
|
115
|
+
//refetchUser,
|
|
117
116
|
}}
|
|
118
117
|
>
|
|
119
118
|
{children}
|
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
2
2
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
TooltipProvider,
|
|
6
|
-
useAuthentication,
|
|
7
|
-
useAuthStore,
|
|
8
|
-
} from "@b3dotfun/sdk/global-account/react";
|
|
3
|
+
import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "@b3dotfun/sdk/global-account/react";
|
|
4
|
+
import { useAutoSelectWallet } from "@b3dotfun/sdk/global-account/react/hooks/useAutoSelectWallet";
|
|
9
5
|
import { createWagmiConfig } from "@b3dotfun/sdk/global-account/react/utils/createWagmiConfig";
|
|
10
6
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
11
7
|
import { loadGA4Script } from "@b3dotfun/sdk/global-account/utils/analytics";
|
|
12
|
-
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
13
8
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
14
9
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
getLastAuthProvider,
|
|
18
|
-
ThirdwebProvider,
|
|
19
|
-
useActiveAccount,
|
|
20
|
-
useConnectedWallets,
|
|
21
|
-
useSetActiveWallet,
|
|
22
|
-
} from "thirdweb/react";
|
|
10
|
+
import { useEffect, useMemo } from "react";
|
|
11
|
+
import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
|
|
23
12
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
24
13
|
import { CreateConnectorFn, WagmiProvider } from "wagmi";
|
|
25
14
|
import { ClientType, setClientType } from "../../../client-manager";
|
|
@@ -28,8 +17,6 @@ import { setToastContext, ToastProvider, useToastContext } from "../Toast/index"
|
|
|
28
17
|
import { LocalSDKProvider } from "./LocalSDKProvider";
|
|
29
18
|
import { B3Context, B3ContextType } from "./types";
|
|
30
19
|
|
|
31
|
-
const debug = debugB3React("B3Provider");
|
|
32
|
-
|
|
33
20
|
/**
|
|
34
21
|
* Default permissions configuration for B3 provider
|
|
35
22
|
*/
|
|
@@ -164,66 +151,32 @@ export function InnerProvider({
|
|
|
164
151
|
enableTurnkey?: boolean;
|
|
165
152
|
}) {
|
|
166
153
|
const activeAccount = useActiveAccount();
|
|
167
|
-
const [manuallySelectedWallet, setManuallySelectedWallet] = useState<Wallet | undefined>(undefined);
|
|
168
|
-
const wallets = useConnectedWallets();
|
|
169
154
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
170
|
-
const isConnected = useAuthStore(state => state.isConnected);
|
|
171
|
-
const justCompletedLogin = useAuthStore(state => state.justCompletedLogin);
|
|
172
|
-
const setActiveWallet = useSetActiveWallet();
|
|
173
|
-
const { user, setUser, refetchUser } = useAuthentication(partnerId);
|
|
174
|
-
|
|
175
|
-
debug("@@B3Provider:isConnected", isConnected);
|
|
176
|
-
debug("@@wallets", wallets);
|
|
177
|
-
debug("@@B3Provider:user", user);
|
|
178
|
-
debug("@@B3Provider:justCompletedLogin", justCompletedLogin);
|
|
155
|
+
//const isConnected = useAuthStore(state => state.isConnected);
|
|
156
|
+
//const justCompletedLogin = useAuthStore(state => state.justCompletedLogin);
|
|
179
157
|
|
|
180
158
|
// Use given accountOverride or activeAccount from thirdweb
|
|
159
|
+
// WOJ: why if isAuthenticated is false, we don't use activeAccount, which should be undefined?
|
|
160
|
+
// skip isAuthenticated check ?
|
|
181
161
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
182
162
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
setManuallySelectedWallet(wallet);
|
|
186
|
-
const account = wallet.getAccount();
|
|
187
|
-
debug("@@setWallet", wallet.id, account?.address);
|
|
188
|
-
setActiveWallet(wallet);
|
|
189
|
-
},
|
|
190
|
-
[setManuallySelectedWallet, setActiveWallet],
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
useEffect(() => {
|
|
194
|
-
const autoSelectFirstEOAWallet = async () => {
|
|
195
|
-
// Only proceed if auto-selection is enabled and user is authenticated
|
|
196
|
-
if (!automaticallySetFirstEoa || !isAuthenticated) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Find the first EOA wallet (excluding ecosystem wallets)
|
|
201
|
-
const isEOAWallet = (wallet: Wallet) => !wallet.id.startsWith("ecosystem.");
|
|
202
|
-
const firstEOAWallet = wallets.find(isEOAWallet);
|
|
203
|
-
|
|
204
|
-
if (firstEOAWallet) {
|
|
205
|
-
// Only auto-select if the last auth was via wallet or no previous auth provider
|
|
206
|
-
const lastAuthProvider = await getLastAuthProvider();
|
|
207
|
-
const shouldAutoSelect = lastAuthProvider === null || lastAuthProvider === "wallet";
|
|
208
|
-
|
|
209
|
-
if (shouldAutoSelect) {
|
|
210
|
-
setWallet(firstEOAWallet);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
};
|
|
163
|
+
// Wrapper to set active wallet via thirdweb
|
|
164
|
+
// Note: `wallet` in context is deprecated - use useActiveWallet() from thirdweb/react instead
|
|
214
165
|
|
|
215
|
-
|
|
216
|
-
|
|
166
|
+
// Auto-select first EOA wallet when enabled
|
|
167
|
+
useAutoSelectWallet({
|
|
168
|
+
enabled: automaticallySetFirstEoa,
|
|
169
|
+
});
|
|
217
170
|
|
|
218
171
|
return (
|
|
219
172
|
<B3Context.Provider
|
|
220
173
|
value={{
|
|
221
174
|
account: effectiveAccount,
|
|
222
|
-
setWallet,
|
|
223
|
-
wallet:
|
|
224
|
-
user,
|
|
225
|
-
setUser,
|
|
226
|
-
refetchUser,
|
|
175
|
+
// setWallet,
|
|
176
|
+
//wallet: undefined, // Deprecated: use useActiveWallet() from thirdweb/react instead
|
|
177
|
+
//user,
|
|
178
|
+
//setUser,
|
|
179
|
+
//refetchUser,
|
|
227
180
|
initialized: true,
|
|
228
181
|
ready: !!effectiveAccount,
|
|
229
182
|
automaticallySetFirstEoa,
|
|
@@ -237,15 +190,11 @@ export function InnerProvider({
|
|
|
237
190
|
enableTurnkey,
|
|
238
191
|
}}
|
|
239
192
|
>
|
|
240
|
-
|
|
193
|
+
{children}
|
|
241
194
|
</B3Context.Provider>
|
|
242
195
|
);
|
|
243
196
|
}
|
|
244
197
|
|
|
245
|
-
const InnerProvider2 = ({ children }: { children: React.ReactNode }) => {
|
|
246
|
-
return <>{children}</>;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
198
|
/**
|
|
250
199
|
* Component to connect the toast context to the global toast API
|
|
251
200
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Users } from "@b3dotfun/b3-api";
|
|
2
1
|
import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOnrampOrder";
|
|
3
2
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
4
3
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
@@ -12,11 +11,11 @@ import { ClientType } from "../../../client-manager";
|
|
|
12
11
|
export interface B3ContextType {
|
|
13
12
|
account?: Account;
|
|
14
13
|
automaticallySetFirstEoa: boolean;
|
|
15
|
-
user?: Users;
|
|
16
|
-
setWallet: (wallet: Wallet) => void;
|
|
14
|
+
//user?: Users;
|
|
15
|
+
//setWallet: (wallet: Wallet) => void;
|
|
17
16
|
wallet?: Wallet;
|
|
18
|
-
setUser: (user?: Users) => void;
|
|
19
|
-
refetchUser: () => Promise<any>;
|
|
17
|
+
//setUser: (user?: Users) => void;
|
|
18
|
+
//refetchUser: () => Promise<any>;
|
|
20
19
|
initialized: boolean;
|
|
21
20
|
ready: boolean;
|
|
22
21
|
environment?: "development" | "production";
|
|
@@ -35,11 +34,11 @@ export interface B3ContextType {
|
|
|
35
34
|
export const B3Context = createContext<B3ContextType>({
|
|
36
35
|
account: undefined,
|
|
37
36
|
automaticallySetFirstEoa: false,
|
|
38
|
-
user: undefined,
|
|
39
|
-
setWallet: () => {},
|
|
37
|
+
//user: undefined,
|
|
38
|
+
//setWallet: () => {},
|
|
40
39
|
wallet: undefined,
|
|
41
|
-
setUser: () => {},
|
|
42
|
-
refetchUser: async () => {},
|
|
40
|
+
//setUser: () => {},
|
|
41
|
+
//refetchUser: async () => {},
|
|
43
42
|
initialized: false,
|
|
44
43
|
ready: false,
|
|
45
44
|
environment: "development",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useContext, useMemo } from "react";
|
|
2
|
+
import { B3Context } from "./types";
|
|
3
|
+
|
|
4
|
+
export const useB3Config = () => {
|
|
5
|
+
const context = useContext(B3Context);
|
|
6
|
+
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error("useB3 must be used within a B3Provider");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
automaticallySetFirstEoa,
|
|
13
|
+
environment,
|
|
14
|
+
theme,
|
|
15
|
+
clientType,
|
|
16
|
+
partnerId,
|
|
17
|
+
createClientReferenceId,
|
|
18
|
+
enableTurnkey,
|
|
19
|
+
} = context;
|
|
20
|
+
|
|
21
|
+
// Return a stable reference
|
|
22
|
+
return useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
automaticallySetFirstEoa,
|
|
25
|
+
environment,
|
|
26
|
+
theme,
|
|
27
|
+
clientType,
|
|
28
|
+
partnerId,
|
|
29
|
+
createClientReferenceId,
|
|
30
|
+
enableTurnkey,
|
|
31
|
+
}),
|
|
32
|
+
[automaticallySetFirstEoa, environment, theme, clientType, partnerId, createClientReferenceId, enableTurnkey],
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Button,
|
|
4
4
|
ManageAccountModalProps,
|
|
5
5
|
toast,
|
|
6
|
-
|
|
6
|
+
useAuthentication,
|
|
7
7
|
useModalStore,
|
|
8
8
|
useQueryB3,
|
|
9
9
|
} from "@b3dotfun/sdk/global-account/react";
|
|
@@ -37,7 +37,7 @@ export const LinkAccount = ({
|
|
|
37
37
|
const isLinking = useModalStore(state => state.isLinking);
|
|
38
38
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
39
39
|
const contentType = useModalStore(state => state.contentType);
|
|
40
|
-
const { user, setUser } =
|
|
40
|
+
const { user, setUser } = useAuthentication(partnerId);
|
|
41
41
|
const [isUpdatingCode, setIsUpdatingCode] = useState(false);
|
|
42
42
|
const [newReferralCode, setNewReferralCode] = useState("");
|
|
43
43
|
const [isEditingCode, setIsEditingCode] = useState(false);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
2
|
-
import { toast } from "@b3dotfun/sdk/global-account/react";
|
|
2
|
+
import { toast, useB3Account } from "@b3dotfun/sdk/global-account/react";
|
|
3
3
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
4
4
|
import { thirdwebB3Mainnet } from "@b3dotfun/sdk/shared/constants/chains/b3Chain";
|
|
5
5
|
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
@@ -11,7 +11,6 @@ import { createWallet, preAuthenticate, WalletId } from "thirdweb/wallets";
|
|
|
11
11
|
import { WalletRow } from "../..";
|
|
12
12
|
import { LinkNewAccountModalProps, useModalStore } from "../../stores/useModalStore";
|
|
13
13
|
import { getProfileDisplayInfo } from "../../utils/profileDisplay";
|
|
14
|
-
import { useB3 } from "../B3Provider/useB3";
|
|
15
14
|
import { AppleIcon } from "../icons/AppleIcon";
|
|
16
15
|
import { DiscordIcon } from "../icons/DiscordIcon";
|
|
17
16
|
import { FarcasterIcon } from "../icons/FarcasterIcon";
|
|
@@ -117,7 +116,7 @@ export function LinkNewAccount({
|
|
|
117
116
|
originalProfile: profile,
|
|
118
117
|
}));
|
|
119
118
|
|
|
120
|
-
const
|
|
119
|
+
const account = useB3Account();
|
|
121
120
|
const { mutate: linkProfile } = useLinkProfile();
|
|
122
121
|
|
|
123
122
|
const onSuccess = useCallback(async () => {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useAccountWallet,
|
|
3
|
+
useAuthentication,
|
|
4
|
+
useB3Config,
|
|
5
|
+
useModalStore,
|
|
6
|
+
useProfile,
|
|
7
|
+
useSimBalance,
|
|
8
|
+
} from "@b3dotfun/sdk/global-account/react";
|
|
2
9
|
import { formatUsername } from "@b3dotfun/sdk/shared/utils";
|
|
3
10
|
import { formatDisplayNumber } from "@b3dotfun/sdk/shared/utils/number";
|
|
4
11
|
import { Pencil } from "lucide-react";
|
|
@@ -15,7 +22,8 @@ const ProfileSection = () => {
|
|
|
15
22
|
address: eoaAddress || account?.address,
|
|
16
23
|
fresh: true,
|
|
17
24
|
});
|
|
18
|
-
const {
|
|
25
|
+
const { partnerId } = useB3Config();
|
|
26
|
+
const { user } = useAuthentication(partnerId);
|
|
19
27
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
20
28
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
21
29
|
const navigateBack = useModalStore(state => state.navigateBack);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ens_normalize } from "@adraffy/ens-normalize";
|
|
2
2
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
3
|
-
import { toast,
|
|
3
|
+
import { toast, useAuthentication, useB3Config, useModalStore, useProfile } from "@b3dotfun/sdk/global-account/react";
|
|
4
4
|
import { formatUsername } from "@b3dotfun/sdk/shared/utils";
|
|
5
5
|
import { Check, Loader2, Pencil, X } from "lucide-react";
|
|
6
6
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -17,7 +17,8 @@ const SettingsProfileCard = () => {
|
|
|
17
17
|
address: eoaAddress || account?.address,
|
|
18
18
|
fresh: true,
|
|
19
19
|
});
|
|
20
|
-
const {
|
|
20
|
+
const { partnerId } = useB3Config();
|
|
21
|
+
const { user, setUser } = useAuthentication(partnerId);
|
|
21
22
|
const setB3ModalOpen = useModalStore(state => state.setB3ModalOpen);
|
|
22
23
|
const setB3ModalContentType = useModalStore(state => state.setB3ModalContentType);
|
|
23
24
|
const navigateBack = useModalStore(state => state.navigateBack);
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
SignInWithB3ModalProps,
|
|
4
4
|
StyleRoot,
|
|
5
5
|
useAuthStore,
|
|
6
|
-
useB3,
|
|
7
6
|
useIsMobile,
|
|
8
7
|
useModalStore,
|
|
9
8
|
} from "@b3dotfun/sdk/global-account/react";
|
|
10
9
|
import { ReactNode, useEffect } from "react";
|
|
10
|
+
import { useB3Account } from "../B3Provider/useB3Account";
|
|
11
11
|
import { ManageAccountButton } from "../custom/ManageAccountButton";
|
|
12
12
|
import { Loading } from "../ui/Loading";
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ export type SignInWithB3Props = Omit<SignInWithB3ModalProps, "type" | "showBackB
|
|
|
20
20
|
|
|
21
21
|
export function SignInWithB3(props: SignInWithB3Props) {
|
|
22
22
|
const { setB3ModalOpen, setB3ModalContentType, setEcoSystemAccountAddress } = useModalStore();
|
|
23
|
-
const
|
|
23
|
+
const account = useB3Account();
|
|
24
24
|
const { isAuthenticating, isAuthenticated } = useAuthStore();
|
|
25
25
|
const isMobile = useIsMobile();
|
|
26
26
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Loading,
|
|
3
3
|
SignInWithB3ModalProps,
|
|
4
|
+
useAuthentication,
|
|
4
5
|
useAuthStore,
|
|
5
|
-
|
|
6
|
+
useB3Config,
|
|
6
7
|
useGetAllTWSigners,
|
|
7
8
|
useModalStore,
|
|
8
9
|
} from "@b3dotfun/sdk/global-account/react";
|
|
@@ -33,7 +34,9 @@ export function SignInWithB3Flow({
|
|
|
33
34
|
source = "signInWithB3Button",
|
|
34
35
|
signersEnabled = false,
|
|
35
36
|
}: SignInWithB3ModalProps) {
|
|
36
|
-
const { automaticallySetFirstEoa,
|
|
37
|
+
const { automaticallySetFirstEoa, enableTurnkey } = useB3Config();
|
|
38
|
+
const { user, refetchUser } = useAuthentication(partnerId);
|
|
39
|
+
|
|
37
40
|
const [step, setStep] = useState<"login" | "permissions" | null>(source === "requestPermissions" ? null : "login");
|
|
38
41
|
const [sessionKeyAdded, setSessionKeyAdded] = useState(source === "requestPermissions" ? true : false);
|
|
39
42
|
const { setB3ModalContentType, setB3ModalOpen, isOpen, contentType } = useModalStore();
|
|
@@ -5,6 +5,8 @@ export { B3Provider, InnerProvider } from "./B3Provider/B3Provider";
|
|
|
5
5
|
export { RelayKitProviderWrapper } from "./B3Provider/RelayKitProviderWrapper";
|
|
6
6
|
export { B3Context, type B3ContextType } from "./B3Provider/types";
|
|
7
7
|
export { useB3 } from "./B3Provider/useB3";
|
|
8
|
+
export { useB3Account } from "./B3Provider/useB3Account";
|
|
9
|
+
export { useB3Config } from "./B3Provider/useB3Config";
|
|
8
10
|
export { StyleRoot } from "./StyleRoot";
|
|
9
11
|
|
|
10
12
|
// SignInWithB3 Components
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useProfile } from "@b3dotfun/sdk/global-account/react";
|
|
2
2
|
import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants";
|
|
3
3
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
4
4
|
import { useEffect, useMemo, useState } from "react";
|
|
5
5
|
import { getLastAuthProvider, useActiveWallet, useConnectedWallets, useWalletImage } from "thirdweb/react";
|
|
6
6
|
import { Account, Wallet } from "thirdweb/wallets";
|
|
7
7
|
import { socialIcons } from "thirdweb/wallets/in-app";
|
|
8
|
+
import { useB3Account } from "../components/B3Provider/useB3Account";
|
|
8
9
|
|
|
9
10
|
const debug = debugB3React("useAccountWallet");
|
|
10
11
|
|
|
@@ -49,7 +50,7 @@ export function useAccountWallet(): {
|
|
|
49
50
|
// const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
50
51
|
// can we possibly just use useActiveAccount here?
|
|
51
52
|
// --------------------
|
|
52
|
-
const
|
|
53
|
+
const account = useB3Account();
|
|
53
54
|
|
|
54
55
|
const activeWallet = useActiveWallet();
|
|
55
56
|
const connectedWallets = useConnectedWallets();
|
|
@@ -114,7 +115,7 @@ export function useAccountWallet(): {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
export function useAccountWalletImage(): string {
|
|
117
|
-
const
|
|
118
|
+
const account = useB3Account();
|
|
118
119
|
|
|
119
120
|
const activeWallet = useActiveWallet();
|
|
120
121
|
const connectedWallets = useConnectedWallets();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
2
|
+
import { useCallback, useEffect } from "react";
|
|
3
|
+
import { getLastAuthProvider, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
|
|
4
|
+
import { Wallet } from "thirdweb/wallets";
|
|
5
|
+
import { useAuthStore } from "../stores";
|
|
6
|
+
|
|
7
|
+
const debug = debugB3React("useAutoSelectWallet");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Hook to automatically select the first EOA wallet when user is authenticated
|
|
11
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider
|
|
12
|
+
*/
|
|
13
|
+
export function useAutoSelectWallet({ enabled }: { enabled: boolean }) {
|
|
14
|
+
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
15
|
+
const wallets = useConnectedWallets();
|
|
16
|
+
const setActiveWallet = useSetActiveWallet();
|
|
17
|
+
|
|
18
|
+
const setWallet = useCallback(
|
|
19
|
+
(wallet: Wallet) => {
|
|
20
|
+
debug("@@setWallet", wallet.id, wallet.getAccount()?.address);
|
|
21
|
+
setActiveWallet(wallet);
|
|
22
|
+
},
|
|
23
|
+
[setActiveWallet],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const autoSelectFirstEOAWallet = async () => {
|
|
28
|
+
// Only proceed if auto-selection is enabled and user is authenticated
|
|
29
|
+
if (!enabled || !isAuthenticated) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Find the first EOA wallet (excluding ecosystem wallets)
|
|
34
|
+
const isEOAWallet = (wallet: Wallet) => !wallet.id.startsWith("ecosystem.");
|
|
35
|
+
const firstEOAWallet = wallets.find(isEOAWallet);
|
|
36
|
+
|
|
37
|
+
if (firstEOAWallet) {
|
|
38
|
+
// Only auto-select if the last auth was via wallet or no previous auth provider
|
|
39
|
+
const lastAuthProvider = await getLastAuthProvider();
|
|
40
|
+
const shouldAutoSelect = lastAuthProvider === null || lastAuthProvider === "wallet";
|
|
41
|
+
|
|
42
|
+
if (shouldAutoSelect) {
|
|
43
|
+
debug("Auto-selecting first EOA wallet", firstEOAWallet.id);
|
|
44
|
+
setWallet(firstEOAWallet);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
autoSelectFirstEOAWallet();
|
|
50
|
+
}, [enabled, isAuthenticated, setWallet, wallets]);
|
|
51
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import app from "../../app";
|
|
2
|
-
import { useAuthStore } from "../stores";
|
|
3
|
-
import { useCallback, useState } from "react";
|
|
4
|
-
import { useB3 } from "../components/B3Provider/useB3";
|
|
5
1
|
import { TurnkeyAuthInitResponse } from "@b3dotfun/b3-api";
|
|
6
2
|
import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug";
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
4
|
+
import app from "../../app";
|
|
5
|
+
import { useB3Config } from "../components";
|
|
6
|
+
import { useAuthStore } from "../stores";
|
|
7
|
+
import { useAuthentication } from "./useAuthentication";
|
|
7
8
|
|
|
8
9
|
const debug = debugB3React("useTurnkeyAuth");
|
|
9
10
|
|
|
@@ -32,7 +33,8 @@ export function useTurnkeyAuth(): UseTurnkeyAuthReturn {
|
|
|
32
33
|
const [error, setError] = useState<string | null>(null);
|
|
33
34
|
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
34
35
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
35
|
-
const {
|
|
36
|
+
const { partnerId } = useB3Config();
|
|
37
|
+
const { user } = useAuthentication(partnerId);
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Step 1: Initiate login with email
|