@b3dotfun/sdk 0.1.69-alpha.0 → 0.1.69-alpha.2
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/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
- package/dist/cjs/global-account/react/components/B3Provider/AuthenticationProvider.js +2 -1
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
- package/dist/cjs/global-account/react/hooks/useAutoSelectWallet.js +31 -3
- package/dist/cjs/global-account/react/hooks/useTWAuth.js +0 -1
- package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
- package/dist/esm/global-account/react/components/B3Provider/AuthenticationProvider.js +2 -1
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +2 -2
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
- package/dist/esm/global-account/react/hooks/useAutoSelectWallet.js +33 -5
- package/dist/esm/global-account/react/hooks/useTWAuth.js +0 -1
- package/dist/types/global-account/react/components/B3Provider/AuthenticationProvider.d.ts +3 -1
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +4 -2
- package/dist/types/global-account/react/hooks/useAutoSelectWallet.d.ts +6 -3
- package/package.json +1 -1
- package/src/global-account/react/components/B3Provider/AuthenticationProvider.tsx +4 -0
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +9 -2
- package/src/global-account/react/hooks/useAutoSelectWallet.ts +40 -6
- package/src/global-account/react/hooks/useTWAuth.tsx +0 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
2
|
+
declare const AuthenticationProvider: ({ partnerId, automaticallySetFirstEoa, defaultEoaProvider, }: {
|
|
2
3
|
partnerId: string;
|
|
3
4
|
automaticallySetFirstEoa: boolean;
|
|
5
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
4
6
|
}) => null;
|
|
5
7
|
export default AuthenticationProvider;
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const hooks_1 = require("../../hooks");
|
|
4
4
|
const useAutoSelectWallet_1 = require("../../hooks/useAutoSelectWallet");
|
|
5
|
-
const AuthenticationProvider = ({ partnerId, automaticallySetFirstEoa, }) => {
|
|
5
|
+
const AuthenticationProvider = ({ partnerId, automaticallySetFirstEoa, defaultEoaProvider, }) => {
|
|
6
6
|
(0, hooks_1.useAuthentication)(partnerId);
|
|
7
7
|
(0, useAutoSelectWallet_1.useAutoSelectWallet)({
|
|
8
8
|
enabled: automaticallySetFirstEoa,
|
|
9
|
+
defaultEoaProvider,
|
|
9
10
|
});
|
|
10
11
|
return null;
|
|
11
12
|
};
|
|
@@ -2,18 +2,20 @@ import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAny
|
|
|
2
2
|
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
3
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
4
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
5
|
-
import { Account, Wallet } from "thirdweb/wallets";
|
|
5
|
+
import { Account, EIP1193, Wallet } from "thirdweb/wallets";
|
|
6
6
|
import { CreateConnectorFn } from "wagmi";
|
|
7
7
|
import { ClientType } from "../../../client-manager";
|
|
8
8
|
/**
|
|
9
9
|
* Main B3Provider component
|
|
10
10
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
11
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
12
12
|
theme: "light" | "dark";
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
accountOverride?: Account;
|
|
15
15
|
environment?: "development" | "production";
|
|
16
16
|
automaticallySetFirstEoa?: boolean;
|
|
17
|
+
/** EIP-1193 provider to auto-connect as the default EOA wallet (e.g., Farcaster frame wallet) */
|
|
18
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
17
19
|
simDuneApiKey?: string;
|
|
18
20
|
toaster?: {
|
|
19
21
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
@@ -24,7 +24,7 @@ const queryClient = new react_query_1.QueryClient();
|
|
|
24
24
|
/**
|
|
25
25
|
* Main B3Provider component
|
|
26
26
|
*/
|
|
27
|
-
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
27
|
+
function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey,
|
|
28
28
|
// deprecated since v0.0.87
|
|
29
29
|
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, defaultPermissions, }) {
|
|
30
30
|
// Initialize Google Analytics on mount
|
|
@@ -36,7 +36,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
36
36
|
(0, client_manager_1.setClientType)(clientType);
|
|
37
37
|
}, [clientType]);
|
|
38
38
|
const wagmiConfig = (0, react_2.useMemo)(() => (0, createWagmiConfig_1.createWagmiConfig)({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
39
|
-
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: (0, jsx_runtime_1.jsxs)(B3ConfigProvider_1.B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, defaultPermissions: defaultPermissions, children: [(0, jsx_runtime_1.jsx)(ToastContextConnector, {}), (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" })] }), (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(react_3.ThirdwebProvider, { children: (0, jsx_runtime_1.jsx)(wagmi_1.WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(react_1.TooltipProvider, { children: (0, jsx_runtime_1.jsx)(index_1.ToastProvider, { children: (0, jsx_runtime_1.jsx)(LocalSDKProvider_1.LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: (0, jsx_runtime_1.jsxs)(B3ConfigProvider_1.B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, defaultPermissions: defaultPermissions, children: [(0, jsx_runtime_1.jsx)(ToastContextConnector, {}), (0, jsx_runtime_1.jsxs)(react_1.RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, (0, jsx_runtime_1.jsx)(StyleRoot_1.StyleRoot, { id: "b3-root" })] }), (0, jsx_runtime_1.jsx)(AuthenticationProvider_1.default, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa, defaultEoaProvider: defaultEoaProvider })] }) }) }) }) }) }) }));
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Component to connect the toast context to the global toast API
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
1
2
|
/**
|
|
2
|
-
* Hook to automatically
|
|
3
|
-
*
|
|
3
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
4
|
+
* select the first EOA wallet when user is authenticated.
|
|
5
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider.
|
|
4
6
|
*/
|
|
5
|
-
export declare function useAutoSelectWallet({ enabled }: {
|
|
7
|
+
export declare function useAutoSelectWallet({ enabled, defaultEoaProvider, }: {
|
|
6
8
|
enabled: boolean;
|
|
9
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
7
10
|
}): void;
|
|
@@ -1,19 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAutoSelectWallet = useAutoSelectWallet;
|
|
4
|
+
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
4
5
|
const debug_1 = require("../../../shared/utils/debug");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
const react_2 = require("thirdweb/react");
|
|
8
|
+
const wallets_1 = require("thirdweb/wallets");
|
|
7
9
|
const stores_1 = require("../stores");
|
|
8
10
|
const debug = (0, debug_1.debugB3React)("useAutoSelectWallet");
|
|
9
11
|
/**
|
|
10
|
-
* Hook to automatically
|
|
11
|
-
*
|
|
12
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
13
|
+
* select the first EOA wallet when user is authenticated.
|
|
14
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider.
|
|
12
15
|
*/
|
|
13
|
-
function useAutoSelectWallet({ enabled }) {
|
|
16
|
+
function useAutoSelectWallet({ enabled, defaultEoaProvider, }) {
|
|
14
17
|
const isAuthenticated = (0, stores_1.useAuthStore)(state => state.isAuthenticated);
|
|
15
18
|
const wallets = (0, react_2.useConnectedWallets)();
|
|
16
19
|
const setActiveWallet = (0, react_2.useSetActiveWallet)();
|
|
20
|
+
const addConnectedWallet = (0, react_2.useAddConnectedWallet)();
|
|
21
|
+
const hasConnectedProvider = (0, react_1.useRef)(false);
|
|
22
|
+
// Auto-connect the default EOA provider (e.g. Farcaster frame wallet) on mount.
|
|
23
|
+
// Uses useAddConnectedWallet instead of useConnect so the wallet is added to
|
|
24
|
+
// connectedWallets WITHOUT becoming the active wallet. This prevents
|
|
25
|
+
// useAuthentication's logout/onTimeout from disconnecting it (logout only
|
|
26
|
+
// disconnects ecosystem wallets and the active wallet).
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (!defaultEoaProvider || hasConnectedProvider.current)
|
|
29
|
+
return;
|
|
30
|
+
hasConnectedProvider.current = true;
|
|
31
|
+
const connectDefaultProvider = async () => {
|
|
32
|
+
try {
|
|
33
|
+
const wallet = wallets_1.EIP1193.fromProvider({ provider: defaultEoaProvider });
|
|
34
|
+
await wallet.connect({ client: thirdweb_1.client });
|
|
35
|
+
addConnectedWallet(wallet);
|
|
36
|
+
debug("Auto-connected default EOA provider", wallet.id);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
debug("Failed to auto-connect default EOA provider", error);
|
|
40
|
+
hasConnectedProvider.current = false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
connectDefaultProvider();
|
|
44
|
+
}, [defaultEoaProvider, addConnectedWallet]);
|
|
17
45
|
const setWallet = (0, react_1.useCallback)((wallet) => {
|
|
18
46
|
debug("@@setWallet", wallet.id, wallet.getAccount()?.address);
|
|
19
47
|
setActiveWallet(wallet);
|
|
@@ -16,7 +16,6 @@ const useSearchParamsSSR_1 = require("./useSearchParamsSSR");
|
|
|
16
16
|
* @deprecated Use useAuth() instead
|
|
17
17
|
*/
|
|
18
18
|
function useTWAuth() {
|
|
19
|
-
console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
|
|
20
19
|
const referralCode = (0, useSearchParamsSSR_1.useSearchParam)("referralCode");
|
|
21
20
|
const authenticate = (0, react_1.useCallback)(async (wallet, partnerId) => {
|
|
22
21
|
if (!wallet || !wallet?.getAuthToken?.())
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
2
|
+
declare const AuthenticationProvider: ({ partnerId, automaticallySetFirstEoa, defaultEoaProvider, }: {
|
|
2
3
|
partnerId: string;
|
|
3
4
|
automaticallySetFirstEoa: boolean;
|
|
5
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
4
6
|
}) => null;
|
|
5
7
|
export default AuthenticationProvider;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useAuthentication } from "../../hooks/index.js";
|
|
2
2
|
import { useAutoSelectWallet } from "../../hooks/useAutoSelectWallet.js";
|
|
3
|
-
const AuthenticationProvider = ({ partnerId, automaticallySetFirstEoa, }) => {
|
|
3
|
+
const AuthenticationProvider = ({ partnerId, automaticallySetFirstEoa, defaultEoaProvider, }) => {
|
|
4
4
|
useAuthentication(partnerId);
|
|
5
5
|
useAutoSelectWallet({
|
|
6
6
|
enabled: automaticallySetFirstEoa,
|
|
7
|
+
defaultEoaProvider,
|
|
7
8
|
});
|
|
8
9
|
return null;
|
|
9
10
|
};
|
|
@@ -2,18 +2,20 @@ import { CreateOnrampOrderParams } from "../../../../anyspend/react/hooks/useAny
|
|
|
2
2
|
import { CreateOrderParams } from "../../../../anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
3
|
import { PermissionsConfig } from "../../../../global-account/types/permissions";
|
|
4
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
5
|
-
import { Account, Wallet } from "thirdweb/wallets";
|
|
5
|
+
import { Account, EIP1193, Wallet } from "thirdweb/wallets";
|
|
6
6
|
import { CreateConnectorFn } from "wagmi";
|
|
7
7
|
import { ClientType } from "../../../client-manager";
|
|
8
8
|
/**
|
|
9
9
|
* Main B3Provider component
|
|
10
10
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
11
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
12
12
|
theme: "light" | "dark";
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
accountOverride?: Account;
|
|
15
15
|
environment?: "development" | "production";
|
|
16
16
|
automaticallySetFirstEoa?: boolean;
|
|
17
|
+
/** EIP-1193 provider to auto-connect as the default EOA wallet (e.g., Farcaster frame wallet) */
|
|
18
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
17
19
|
simDuneApiKey?: string;
|
|
18
20
|
toaster?: {
|
|
19
21
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
@@ -18,7 +18,7 @@ const queryClient = new QueryClient();
|
|
|
18
18
|
/**
|
|
19
19
|
* Main B3Provider component
|
|
20
20
|
*/
|
|
21
|
-
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey,
|
|
21
|
+
export function B3Provider({ theme = "light", children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey,
|
|
22
22
|
// deprecated since v0.0.87
|
|
23
23
|
toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors = false, createClientReferenceId, defaultPermissions, }) {
|
|
24
24
|
// Initialize Google Analytics on mount
|
|
@@ -30,7 +30,7 @@ toaster: _toaster, clientType = "rest", rpcUrls, partnerId, stripePublishableKey
|
|
|
30
30
|
setClientType(clientType);
|
|
31
31
|
}, [clientType]);
|
|
32
32
|
const wagmiConfig = useMemo(() => createWagmiConfig({ partnerId, rpcUrls, connectors, overrideDefaultConnectors }), [partnerId, rpcUrls, connectors, overrideDefaultConnectors]);
|
|
33
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa })] }) }) }) }) }) }) }));
|
|
33
|
+
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, reconnectOnMount: false, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(ToastProvider, { children: _jsx(LocalSDKProvider, { onConnectCallback: onConnect, onLogoutCallback: onLogout, children: _jsxs(B3ConfigProvider, { accountOverride: accountOverride, environment: environment, automaticallySetFirstEoa: !!automaticallySetFirstEoa, theme: theme, clientType: clientType, partnerId: partnerId, stripePublishableKey: stripePublishableKey, createClientReferenceId: createClientReferenceId, defaultPermissions: defaultPermissions, children: [_jsx(ToastContextConnector, {}), _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" })] }), _jsx(AuthenticationProvider, { partnerId: partnerId, automaticallySetFirstEoa: !!automaticallySetFirstEoa, defaultEoaProvider: defaultEoaProvider })] }) }) }) }) }) }) }));
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Component to connect the toast context to the global toast API
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
1
2
|
/**
|
|
2
|
-
* Hook to automatically
|
|
3
|
-
*
|
|
3
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
4
|
+
* select the first EOA wallet when user is authenticated.
|
|
5
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider.
|
|
4
6
|
*/
|
|
5
|
-
export declare function useAutoSelectWallet({ enabled }: {
|
|
7
|
+
export declare function useAutoSelectWallet({ enabled, defaultEoaProvider, }: {
|
|
6
8
|
enabled: boolean;
|
|
9
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
7
10
|
}): void;
|
|
@@ -1,16 +1,44 @@
|
|
|
1
|
+
import { client } from "../../../shared/utils/thirdweb.js";
|
|
1
2
|
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
2
|
-
import { useCallback, useEffect } from "react";
|
|
3
|
-
import { getLastAuthProvider, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { getLastAuthProvider, useAddConnectedWallet, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
|
|
5
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
4
6
|
import { useAuthStore } from "../stores/index.js";
|
|
5
7
|
const debug = debugB3React("useAutoSelectWallet");
|
|
6
8
|
/**
|
|
7
|
-
* Hook to automatically
|
|
8
|
-
*
|
|
9
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
10
|
+
* 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.
|
|
9
12
|
*/
|
|
10
|
-
export function useAutoSelectWallet({ enabled }) {
|
|
13
|
+
export function useAutoSelectWallet({ enabled, defaultEoaProvider, }) {
|
|
11
14
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
12
15
|
const wallets = useConnectedWallets();
|
|
13
16
|
const setActiveWallet = useSetActiveWallet();
|
|
17
|
+
const addConnectedWallet = useAddConnectedWallet();
|
|
18
|
+
const hasConnectedProvider = useRef(false);
|
|
19
|
+
// Auto-connect the default EOA provider (e.g. Farcaster frame wallet) on mount.
|
|
20
|
+
// Uses useAddConnectedWallet instead of useConnect so the wallet is added to
|
|
21
|
+
// connectedWallets WITHOUT becoming the active wallet. This prevents
|
|
22
|
+
// useAuthentication's logout/onTimeout from disconnecting it (logout only
|
|
23
|
+
// disconnects ecosystem wallets and the active wallet).
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!defaultEoaProvider || hasConnectedProvider.current)
|
|
26
|
+
return;
|
|
27
|
+
hasConnectedProvider.current = true;
|
|
28
|
+
const connectDefaultProvider = async () => {
|
|
29
|
+
try {
|
|
30
|
+
const wallet = EIP1193.fromProvider({ provider: defaultEoaProvider });
|
|
31
|
+
await wallet.connect({ client });
|
|
32
|
+
addConnectedWallet(wallet);
|
|
33
|
+
debug("Auto-connected default EOA provider", wallet.id);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
debug("Failed to auto-connect default EOA provider", error);
|
|
37
|
+
hasConnectedProvider.current = false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
connectDefaultProvider();
|
|
41
|
+
}, [defaultEoaProvider, addConnectedWallet]);
|
|
14
42
|
const setWallet = useCallback((wallet) => {
|
|
15
43
|
debug("@@setWallet", wallet.id, wallet.getAccount()?.address);
|
|
16
44
|
setActiveWallet(wallet);
|
|
@@ -10,7 +10,6 @@ import { useSearchParam } from "./useSearchParamsSSR.js";
|
|
|
10
10
|
* @deprecated Use useAuth() instead
|
|
11
11
|
*/
|
|
12
12
|
export function useTWAuth() {
|
|
13
|
-
console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
|
|
14
13
|
const referralCode = useSearchParam("referralCode");
|
|
15
14
|
const authenticate = useCallback(async (wallet, partnerId) => {
|
|
16
15
|
if (!wallet || !wallet?.getAuthToken?.())
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
2
|
+
declare const AuthenticationProvider: ({ partnerId, automaticallySetFirstEoa, defaultEoaProvider, }: {
|
|
2
3
|
partnerId: string;
|
|
3
4
|
automaticallySetFirstEoa: boolean;
|
|
5
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
4
6
|
}) => null;
|
|
5
7
|
export default AuthenticationProvider;
|
|
@@ -2,18 +2,20 @@ import { CreateOnrampOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useA
|
|
|
2
2
|
import { CreateOrderParams } from "@b3dotfun/sdk/anyspend/react/hooks/useAnyspendCreateOrder";
|
|
3
3
|
import { PermissionsConfig } from "@b3dotfun/sdk/global-account/types/permissions";
|
|
4
4
|
import "@relayprotocol/relay-kit-ui/styles.css";
|
|
5
|
-
import { Account, Wallet } from "thirdweb/wallets";
|
|
5
|
+
import { Account, EIP1193, Wallet } from "thirdweb/wallets";
|
|
6
6
|
import { CreateConnectorFn } from "wagmi";
|
|
7
7
|
import { ClientType } from "../../../client-manager";
|
|
8
8
|
/**
|
|
9
9
|
* Main B3Provider component
|
|
10
10
|
*/
|
|
11
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
11
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, automaticallySetFirstEoa, defaultEoaProvider, simDuneApiKey, toaster: _toaster, clientType, rpcUrls, partnerId, stripePublishableKey, onConnect, onLogout, connectors, overrideDefaultConnectors, createClientReferenceId, defaultPermissions, }: {
|
|
12
12
|
theme: "light" | "dark";
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
accountOverride?: Account;
|
|
15
15
|
environment?: "development" | "production";
|
|
16
16
|
automaticallySetFirstEoa?: boolean;
|
|
17
|
+
/** EIP-1193 provider to auto-connect as the default EOA wallet (e.g., Farcaster frame wallet) */
|
|
18
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
17
19
|
simDuneApiKey?: string;
|
|
18
20
|
toaster?: {
|
|
19
21
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
1
2
|
/**
|
|
2
|
-
* Hook to automatically
|
|
3
|
-
*
|
|
3
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
4
|
+
* select the first EOA wallet when user is authenticated.
|
|
5
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider.
|
|
4
6
|
*/
|
|
5
|
-
export declare function useAutoSelectWallet({ enabled }: {
|
|
7
|
+
export declare function useAutoSelectWallet({ enabled, defaultEoaProvider, }: {
|
|
6
8
|
enabled: boolean;
|
|
9
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
7
10
|
}): void;
|
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
import { EIP1193 } from "thirdweb/wallets";
|
|
1
2
|
import { useAuthentication } from "../../hooks";
|
|
2
3
|
import { useAutoSelectWallet } from "../../hooks/useAutoSelectWallet";
|
|
3
4
|
|
|
4
5
|
const AuthenticationProvider = ({
|
|
5
6
|
partnerId,
|
|
6
7
|
automaticallySetFirstEoa,
|
|
8
|
+
defaultEoaProvider,
|
|
7
9
|
}: {
|
|
8
10
|
partnerId: string;
|
|
9
11
|
automaticallySetFirstEoa: boolean;
|
|
12
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
10
13
|
}) => {
|
|
11
14
|
useAuthentication(partnerId);
|
|
12
15
|
useAutoSelectWallet({
|
|
13
16
|
enabled: automaticallySetFirstEoa,
|
|
17
|
+
defaultEoaProvider,
|
|
14
18
|
});
|
|
15
19
|
|
|
16
20
|
return null;
|
|
@@ -8,7 +8,7 @@ import "@relayprotocol/relay-kit-ui/styles.css";
|
|
|
8
8
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
9
9
|
import { useEffect, useMemo } from "react";
|
|
10
10
|
import { ThirdwebProvider } from "thirdweb/react";
|
|
11
|
-
import { Account, Wallet } from "thirdweb/wallets";
|
|
11
|
+
import { Account, EIP1193, Wallet } from "thirdweb/wallets";
|
|
12
12
|
import { CreateConnectorFn, WagmiProvider } from "wagmi";
|
|
13
13
|
import { ClientType, setClientType } from "../../../client-manager";
|
|
14
14
|
import { StyleRoot } from "../StyleRoot";
|
|
@@ -29,6 +29,7 @@ export function B3Provider({
|
|
|
29
29
|
accountOverride,
|
|
30
30
|
environment,
|
|
31
31
|
automaticallySetFirstEoa,
|
|
32
|
+
defaultEoaProvider,
|
|
32
33
|
simDuneApiKey,
|
|
33
34
|
// deprecated since v0.0.87
|
|
34
35
|
toaster: _toaster,
|
|
@@ -48,6 +49,8 @@ export function B3Provider({
|
|
|
48
49
|
accountOverride?: Account;
|
|
49
50
|
environment?: "development" | "production";
|
|
50
51
|
automaticallySetFirstEoa?: boolean;
|
|
52
|
+
/** EIP-1193 provider to auto-connect as the default EOA wallet (e.g., Farcaster frame wallet) */
|
|
53
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
51
54
|
simDuneApiKey?: string;
|
|
52
55
|
toaster?: {
|
|
53
56
|
position?: "top-center" | "top-right" | "bottom-center" | "bottom-right";
|
|
@@ -104,7 +107,11 @@ export function B3Provider({
|
|
|
104
107
|
{/* For the modal https://github.com/b3-fun/b3/blob/main/packages/sdk/src/global-account/react/components/ui/dialog.tsx#L46 */}
|
|
105
108
|
<StyleRoot id="b3-root" />
|
|
106
109
|
</RelayKitProviderWrapper>
|
|
107
|
-
<AuthenticationProvider
|
|
110
|
+
<AuthenticationProvider
|
|
111
|
+
partnerId={partnerId}
|
|
112
|
+
automaticallySetFirstEoa={!!automaticallySetFirstEoa}
|
|
113
|
+
defaultEoaProvider={defaultEoaProvider}
|
|
114
|
+
/>
|
|
108
115
|
</B3ConfigProvider>
|
|
109
116
|
</LocalSDKProvider>
|
|
110
117
|
</ToastProvider>
|
|
@@ -1,19 +1,53 @@
|
|
|
1
|
+
import { client } from "@b3dotfun/sdk/shared/utils/thirdweb";
|
|
1
2
|
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";
|
|
3
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
4
|
+
import { getLastAuthProvider, useAddConnectedWallet, useConnectedWallets, useSetActiveWallet } from "thirdweb/react";
|
|
5
|
+
import { EIP1193, Wallet } from "thirdweb/wallets";
|
|
5
6
|
import { useAuthStore } from "../stores";
|
|
6
7
|
|
|
7
8
|
const debug = debugB3React("useAutoSelectWallet");
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Hook to automatically
|
|
11
|
-
*
|
|
11
|
+
* Hook to automatically connect a default EOA provider (if given) and
|
|
12
|
+
* select the first EOA wallet when user is authenticated.
|
|
13
|
+
* Only auto-selects if the last auth was via wallet or no previous auth provider.
|
|
12
14
|
*/
|
|
13
|
-
export function useAutoSelectWallet({
|
|
15
|
+
export function useAutoSelectWallet({
|
|
16
|
+
enabled,
|
|
17
|
+
defaultEoaProvider,
|
|
18
|
+
}: {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
defaultEoaProvider?: EIP1193.EIP1193Provider;
|
|
21
|
+
}) {
|
|
14
22
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
15
23
|
const wallets = useConnectedWallets();
|
|
16
24
|
const setActiveWallet = useSetActiveWallet();
|
|
25
|
+
const addConnectedWallet = useAddConnectedWallet();
|
|
26
|
+
const hasConnectedProvider = useRef(false);
|
|
27
|
+
|
|
28
|
+
// Auto-connect the default EOA provider (e.g. Farcaster frame wallet) on mount.
|
|
29
|
+
// Uses useAddConnectedWallet instead of useConnect so the wallet is added to
|
|
30
|
+
// connectedWallets WITHOUT becoming the active wallet. This prevents
|
|
31
|
+
// useAuthentication's logout/onTimeout from disconnecting it (logout only
|
|
32
|
+
// disconnects ecosystem wallets and the active wallet).
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!defaultEoaProvider || hasConnectedProvider.current) return;
|
|
35
|
+
hasConnectedProvider.current = true;
|
|
36
|
+
|
|
37
|
+
const connectDefaultProvider = async () => {
|
|
38
|
+
try {
|
|
39
|
+
const wallet = EIP1193.fromProvider({ provider: defaultEoaProvider });
|
|
40
|
+
await wallet.connect({ client });
|
|
41
|
+
addConnectedWallet(wallet);
|
|
42
|
+
debug("Auto-connected default EOA provider", wallet.id);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
debug("Failed to auto-connect default EOA provider", error);
|
|
45
|
+
hasConnectedProvider.current = false;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
connectDefaultProvider();
|
|
50
|
+
}, [defaultEoaProvider, addConnectedWallet]);
|
|
17
51
|
|
|
18
52
|
const setWallet = useCallback(
|
|
19
53
|
(wallet: Wallet) => {
|
|
@@ -12,7 +12,6 @@ import { useSearchParam } from "./useSearchParamsSSR";
|
|
|
12
12
|
* @deprecated Use useAuth() instead
|
|
13
13
|
*/
|
|
14
14
|
export function useTWAuth() {
|
|
15
|
-
console.warn("useTWAuth is deprecated. Please migrate to useAuth() for authentication.");
|
|
16
15
|
const referralCode = useSearchParam("referralCode");
|
|
17
16
|
|
|
18
17
|
const authenticate = useCallback(
|