@b3dotfun/sdk 0.0.47-alpha.0 → 0.0.47-test.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- 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 +134 -84
- 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/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 +137 -87
- 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/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/package.json +3 -3
- 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 +159 -90
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Wallet } from "thirdweb/wallets";
|
|
1
2
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
2
|
-
export declare function useAuthentication(partnerId: string
|
|
3
|
+
export declare function useAuthentication(partnerId: string): {
|
|
3
4
|
logout: (callback?: () => void) => Promise<void>;
|
|
4
5
|
isAuthenticated: boolean;
|
|
5
6
|
isReady: boolean;
|
|
@@ -7,6 +8,54 @@ export declare function useAuthentication(partnerId: string, loginWithSiwe?: boo
|
|
|
7
8
|
isConnected: boolean;
|
|
8
9
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
9
10
|
preAuthenticate: typeof preAuthenticate;
|
|
10
|
-
connect: (
|
|
11
|
+
connect: (wallet: Wallet) => Promise<void>;
|
|
11
12
|
isAuthenticating: boolean;
|
|
13
|
+
onConnect: (wallet: Wallet) => Promise<void>;
|
|
14
|
+
user: {
|
|
15
|
+
email?: string | undefined;
|
|
16
|
+
username?: string | undefined;
|
|
17
|
+
telNumber?: string | undefined;
|
|
18
|
+
ens?: string | undefined;
|
|
19
|
+
avatar?: string | undefined;
|
|
20
|
+
preferences?: {} | undefined;
|
|
21
|
+
referredBy?: string | {} | undefined;
|
|
22
|
+
sourceApp?: string | undefined;
|
|
23
|
+
referralCode?: string | undefined;
|
|
24
|
+
userGroups?: number[] | undefined;
|
|
25
|
+
isMigratedFromBSMNT?: boolean | undefined;
|
|
26
|
+
privyLinkedAccounts?: {
|
|
27
|
+
name?: string | undefined;
|
|
28
|
+
address?: string | undefined;
|
|
29
|
+
email?: string | undefined;
|
|
30
|
+
chain_type?: string | undefined;
|
|
31
|
+
lv?: number | undefined;
|
|
32
|
+
wallet_client_type?: string | undefined;
|
|
33
|
+
smart_wallet_type?: string | undefined;
|
|
34
|
+
subject?: string | undefined;
|
|
35
|
+
type: string;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
twProfiles?: {
|
|
38
|
+
type: string;
|
|
39
|
+
details: {
|
|
40
|
+
id?: string | undefined;
|
|
41
|
+
name?: string | undefined;
|
|
42
|
+
address?: string | undefined;
|
|
43
|
+
email?: string | undefined;
|
|
44
|
+
phone?: string | undefined;
|
|
45
|
+
username?: string | undefined;
|
|
46
|
+
fid?: string | undefined;
|
|
47
|
+
};
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
_id: string | {};
|
|
50
|
+
userId: string;
|
|
51
|
+
smartAccountAddress: string;
|
|
52
|
+
createdAt: number;
|
|
53
|
+
updatedAt: number;
|
|
54
|
+
partnerIds: {
|
|
55
|
+
privyId?: string | undefined;
|
|
56
|
+
thirdwebId?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
} | undefined;
|
|
59
|
+
refetchUser: (wallet?: Wallet) => Promise<void>;
|
|
60
|
+
setUser: (newUser?: import("@b3dotfun/b3-api").Users) => void;
|
|
12
61
|
};
|
|
@@ -1,117 +1,149 @@
|
|
|
1
1
|
import app from "../../../global-account/app.js";
|
|
2
2
|
import { authenticateWithB3JWT } from "../../../global-account/bsmnt.js";
|
|
3
|
-
import { useAuthStore,
|
|
3
|
+
import { useAuthStore, useSiwe } from "../../../global-account/react/index.js";
|
|
4
4
|
import { ecosystemWalletId } from "../../../shared/constants/index.js";
|
|
5
|
-
import { b3MainnetThirdWeb } from "../../../shared/constants/chains/supported.js";
|
|
6
5
|
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
7
6
|
import { client } from "../../../shared/utils/thirdweb.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { getConnectors } from "@wagmi/core";
|
|
8
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
9
|
+
import { useActiveWallet, useAutoConnect, useConnectedWallets, useDisconnect, useSetActiveWallet, } from "thirdweb/react";
|
|
10
10
|
import { ecosystemWallet } from "thirdweb/wallets";
|
|
11
11
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
12
|
-
import { useConnect } from "
|
|
13
|
-
import {
|
|
12
|
+
import { useAccount, useConnect } from "wagmi";
|
|
13
|
+
import { useUserQuery } from "./useUserQuery.js";
|
|
14
|
+
import { useWagmiConfig } from "./useWagmiConfig.js";
|
|
14
15
|
const debug = debugB3React("useAuthentication");
|
|
15
|
-
export function useAuthentication(partnerId
|
|
16
|
+
export function useAuthentication(partnerId) {
|
|
16
17
|
const { disconnect } = useDisconnect();
|
|
17
18
|
const wallets = useConnectedWallets();
|
|
18
19
|
const activeWallet = useActiveWallet();
|
|
19
|
-
const { authenticate } = useSiwe();
|
|
20
|
-
const { setUser } = useB3();
|
|
21
20
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
22
21
|
const setIsAuthenticated = useAuthStore(state => state.setIsAuthenticated);
|
|
23
|
-
const setIsConnecting = useAuthStore(state => state.setIsConnecting);
|
|
24
22
|
const setIsConnected = useAuthStore(state => state.setIsConnected);
|
|
25
23
|
const isConnecting = useAuthStore(state => state.isConnecting);
|
|
26
24
|
const isConnected = useAuthStore(state => state.isConnected);
|
|
27
|
-
const useAutoConnectLoadingPrevious = useRef(false);
|
|
28
|
-
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
29
25
|
const isAuthenticating = useAuthStore(state => state.isAuthenticating);
|
|
30
|
-
const
|
|
26
|
+
const setIsAuthenticating = useAuthStore(state => state.setIsAuthenticating);
|
|
31
27
|
const setHasStartedConnecting = useAuthStore(state => state.setHasStartedConnecting);
|
|
32
|
-
const
|
|
28
|
+
const setActiveWallet = useSetActiveWallet();
|
|
29
|
+
const hasStartedConnecting = useAuthStore(state => state.hasStartedConnecting);
|
|
30
|
+
const { authenticate } = useSiwe();
|
|
31
|
+
const { user, setUser } = useUserQuery();
|
|
32
|
+
const useAutoConnectLoadingPrevious = useRef(false);
|
|
33
|
+
const wagmiConfig = useWagmiConfig(partnerId);
|
|
34
|
+
const { connect } = useConnect();
|
|
35
|
+
const activeWagmiAccount = useAccount();
|
|
36
|
+
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
33
37
|
const wallet = ecosystemWallet(ecosystemWalletId, {
|
|
34
38
|
partnerId: partnerId,
|
|
35
39
|
});
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
const syncWagmi = useCallback(async () => {
|
|
41
|
+
function syncWagmiFunc() {
|
|
42
|
+
const connectors = getConnectors(wagmiConfig);
|
|
43
|
+
debug("@@syncWagmi", {
|
|
44
|
+
connectors,
|
|
45
|
+
wallets,
|
|
46
|
+
});
|
|
47
|
+
// For each that matchs a TW wallet on wallets, connect to the wagmi connector
|
|
48
|
+
// or, since ecosystem wallets is separate, connect those via in-app-wallet from wagmi
|
|
49
|
+
connectors.forEach(async (connector) => {
|
|
50
|
+
const twWallet = wallets.find(wallet => wallet.id === connector.id || connector.id === "in-app-wallet");
|
|
51
|
+
if (twWallet &&
|
|
52
|
+
// If it's not an in-app wallet or it is the ecosystem wallet, connect
|
|
53
|
+
(connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === ecosystemWalletId))) {
|
|
54
|
+
try {
|
|
55
|
+
const options = {
|
|
56
|
+
wallet: twWallet, // the connected wallet
|
|
57
|
+
};
|
|
58
|
+
debug("@@syncWagmi:connecting", { twWallet, connector });
|
|
59
|
+
connect({
|
|
60
|
+
connector,
|
|
61
|
+
...options,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error("@@syncWagmi:error", error);
|
|
66
|
+
}
|
|
48
67
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!account) {
|
|
52
|
-
throw new Error("No account found during auto-connect");
|
|
68
|
+
else {
|
|
69
|
+
debug("@@syncWagmi:not-connecting", connector);
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
debug("Re-authenticated successfully", { userAuth });
|
|
61
|
-
// Authenticate on BSMNT with B3 JWT
|
|
62
|
-
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
63
|
-
console.log("@@b3Jwt", b3Jwt);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
// If re-authentication fails, try fresh authentication
|
|
67
|
-
debug("Re-authentication failed, attempting fresh authentication");
|
|
68
|
-
const userAuth = await authenticate(account, partnerId);
|
|
69
|
-
setUser(userAuth.user);
|
|
70
|
-
setIsAuthenticated(true);
|
|
71
|
-
setIsAuthenticating(false);
|
|
72
|
-
debug("Fresh authentication successful", { userAuth });
|
|
73
|
-
// Authenticate on BSMNT with B3 JWT
|
|
74
|
-
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
75
|
-
console.log("@@b3Jwt", b3Jwt);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
debug("Auto-connect authentication failed", { error });
|
|
80
|
-
setIsAuthenticated(false);
|
|
81
|
-
debug("setIsAuthenticating:false:4");
|
|
82
|
-
setUser();
|
|
83
|
-
}
|
|
84
|
-
setIsAuthenticating(false);
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
/**
|
|
88
|
-
* useAutoConnectLoading starts as false
|
|
89
|
-
*/
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
syncWagmiFunc();
|
|
74
|
+
// wagmi config shouldn't change
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
}, [partnerId, wallets]);
|
|
90
77
|
useEffect(() => {
|
|
91
|
-
|
|
78
|
+
syncWagmi();
|
|
79
|
+
}, [wallets, syncWagmi]);
|
|
80
|
+
const authenticateUser = useCallback(async (wallet) => {
|
|
81
|
+
setHasStartedConnecting(true);
|
|
82
|
+
const account = wallet ? wallet.getAccount() : activeWallet?.getAccount();
|
|
83
|
+
if (!account) {
|
|
84
|
+
throw new Error("No account found during auto-connect");
|
|
85
|
+
}
|
|
86
|
+
if (!account) {
|
|
87
|
+
throw new Error("No account found during auto-connect");
|
|
88
|
+
}
|
|
89
|
+
// Try to re-authenticate first
|
|
90
|
+
try {
|
|
91
|
+
const userAuth = await app.reAuthenticate();
|
|
92
|
+
setUser(userAuth.user);
|
|
93
|
+
setIsAuthenticated(true);
|
|
92
94
|
setIsAuthenticating(false);
|
|
95
|
+
debug("Re-authenticated successfully", { userAuth });
|
|
96
|
+
// Authenticate on BSMNT with B3 JWT
|
|
97
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
98
|
+
debug("@@b3Jwt", b3Jwt);
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
catch (error) {
|
|
101
|
+
// If re-authentication fails, try fresh authentication
|
|
102
|
+
debug("Re-authentication failed, attempting fresh authentication");
|
|
103
|
+
const userAuth = await authenticate(account, partnerId);
|
|
104
|
+
setUser(userAuth.user);
|
|
105
|
+
setIsAuthenticated(true);
|
|
106
|
+
setIsAuthenticating(false);
|
|
107
|
+
debug("Fresh authentication successful", { userAuth });
|
|
108
|
+
// Authenticate on BSMNT with B3 JWT
|
|
109
|
+
const b3Jwt = await authenticateWithB3JWT(userAuth.accessToken);
|
|
110
|
+
debug("@@b3Jwt", b3Jwt);
|
|
100
111
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
}, [activeWallet, partnerId, authenticate, setIsAuthenticated, setIsAuthenticating, setUser, setHasStartedConnecting]);
|
|
113
|
+
const onConnect = useCallback(async (wallet) => {
|
|
114
|
+
debug("@@useAuthentication:onConnect", { wallet });
|
|
115
|
+
try {
|
|
116
|
+
setHasStartedConnecting(true);
|
|
117
|
+
setIsConnected(true);
|
|
118
|
+
setIsAuthenticating(true);
|
|
119
|
+
await setActiveWallet(wallet);
|
|
120
|
+
await authenticateUser(wallet);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
debug("@@useAuthentication:onConnect:failed", { error });
|
|
124
|
+
setIsAuthenticated(false);
|
|
125
|
+
setUser(undefined);
|
|
109
126
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
setIsConnecting(false);
|
|
127
|
+
finally {
|
|
128
|
+
setIsAuthenticating(false);
|
|
113
129
|
}
|
|
114
|
-
|
|
130
|
+
debug({
|
|
131
|
+
isAuthenticated,
|
|
132
|
+
isAuthenticating,
|
|
133
|
+
isConnected,
|
|
134
|
+
});
|
|
135
|
+
}, [
|
|
136
|
+
authenticateUser,
|
|
137
|
+
isAuthenticated,
|
|
138
|
+
isAuthenticating,
|
|
139
|
+
isConnected,
|
|
140
|
+
setActiveWallet,
|
|
141
|
+
setHasStartedConnecting,
|
|
142
|
+
setIsAuthenticated,
|
|
143
|
+
setIsAuthenticating,
|
|
144
|
+
setIsConnected,
|
|
145
|
+
setUser,
|
|
146
|
+
]);
|
|
115
147
|
const logout = async (callback) => {
|
|
116
148
|
if (activeWallet) {
|
|
117
149
|
debug("@@logout:activeWallet", activeWallet);
|
|
@@ -137,7 +169,21 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
137
169
|
setUser();
|
|
138
170
|
callback?.();
|
|
139
171
|
};
|
|
140
|
-
const
|
|
172
|
+
const { isLoading: useAutoConnectLoading } = useAutoConnect({
|
|
173
|
+
client,
|
|
174
|
+
wallets: [wallet],
|
|
175
|
+
onConnect: onConnect,
|
|
176
|
+
});
|
|
177
|
+
/**
|
|
178
|
+
* useAutoConnectLoading starts as false
|
|
179
|
+
*/
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
182
|
+
setIsAuthenticating(false);
|
|
183
|
+
}
|
|
184
|
+
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
185
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
186
|
+
const isReady = isAuthenticated && !isAuthenticating;
|
|
141
187
|
return {
|
|
142
188
|
logout,
|
|
143
189
|
isAuthenticated,
|
|
@@ -146,7 +192,11 @@ export function useAuthentication(partnerId, loginWithSiwe) {
|
|
|
146
192
|
isConnected,
|
|
147
193
|
wallet,
|
|
148
194
|
preAuthenticate,
|
|
149
|
-
connect,
|
|
195
|
+
connect: onConnect,
|
|
150
196
|
isAuthenticating,
|
|
197
|
+
onConnect,
|
|
198
|
+
user,
|
|
199
|
+
refetchUser: authenticateUser,
|
|
200
|
+
setUser,
|
|
151
201
|
};
|
|
152
202
|
}
|
|
@@ -4,7 +4,7 @@ import { Account } from "thirdweb/wallets";
|
|
|
4
4
|
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
5
5
|
* Currently, this is for the basement-privy strategy
|
|
6
6
|
*/
|
|
7
|
-
export declare function useHandleConnectWithPrivy(
|
|
7
|
+
export declare function useHandleConnectWithPrivy(chain?: Chain, onSuccess?: (account: Account) => void): {
|
|
8
8
|
connectTw: () => Promise<import("thirdweb/wallets").Wallet | null | undefined>;
|
|
9
9
|
isLoading: boolean;
|
|
10
10
|
fullToken: string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useConnect } from "../../../global-account/react/index.js";
|
|
1
|
+
import { useB3, useConnect } from "../../../global-account/react/index.js";
|
|
2
2
|
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
3
3
|
import { useIdentityToken, usePrivy } from "@privy-io/react-auth";
|
|
4
4
|
import { useCallback, useRef, useState } from "react";
|
|
@@ -7,7 +7,8 @@ const debug = debugB3React("@@b3:useHandleConnectWithPrivy");
|
|
|
7
7
|
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
8
8
|
* Currently, this is for the basement-privy strategy
|
|
9
9
|
*/
|
|
10
|
-
export function useHandleConnectWithPrivy(
|
|
10
|
+
export function useHandleConnectWithPrivy(chain, onSuccess) {
|
|
11
|
+
const { partnerId } = useB3();
|
|
11
12
|
if (!chain) {
|
|
12
13
|
throw new Error("Chain is required");
|
|
13
14
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Users } from "@b3dotfun/b3-api";
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
|
|
4
|
+
*
|
|
5
|
+
* Custom hook to manage user state with react-query
|
|
6
|
+
* This allows for invalidation and refetching of user data
|
|
7
|
+
*/
|
|
8
|
+
export declare function useUserQuery(): {
|
|
9
|
+
user: {
|
|
10
|
+
email?: string | undefined;
|
|
11
|
+
username?: string | undefined;
|
|
12
|
+
telNumber?: string | undefined;
|
|
13
|
+
ens?: string | undefined;
|
|
14
|
+
avatar?: string | undefined;
|
|
15
|
+
preferences?: {} | undefined;
|
|
16
|
+
referredBy?: string | {} | undefined;
|
|
17
|
+
sourceApp?: string | undefined;
|
|
18
|
+
referralCode?: string | undefined;
|
|
19
|
+
userGroups?: number[] | undefined;
|
|
20
|
+
isMigratedFromBSMNT?: boolean | undefined;
|
|
21
|
+
privyLinkedAccounts?: {
|
|
22
|
+
name?: string | undefined;
|
|
23
|
+
address?: string | undefined;
|
|
24
|
+
email?: string | undefined;
|
|
25
|
+
chain_type?: string | undefined;
|
|
26
|
+
lv?: number | undefined;
|
|
27
|
+
wallet_client_type?: string | undefined;
|
|
28
|
+
smart_wallet_type?: string | undefined;
|
|
29
|
+
subject?: string | undefined;
|
|
30
|
+
type: string;
|
|
31
|
+
}[] | undefined;
|
|
32
|
+
twProfiles?: {
|
|
33
|
+
type: string;
|
|
34
|
+
details: {
|
|
35
|
+
id?: string | undefined;
|
|
36
|
+
name?: string | undefined;
|
|
37
|
+
address?: string | undefined;
|
|
38
|
+
email?: string | undefined;
|
|
39
|
+
phone?: string | undefined;
|
|
40
|
+
username?: string | undefined;
|
|
41
|
+
fid?: string | undefined;
|
|
42
|
+
};
|
|
43
|
+
}[] | undefined;
|
|
44
|
+
_id: string | {};
|
|
45
|
+
userId: string;
|
|
46
|
+
smartAccountAddress: string;
|
|
47
|
+
createdAt: number;
|
|
48
|
+
updatedAt: number;
|
|
49
|
+
partnerIds: {
|
|
50
|
+
privyId?: string | undefined;
|
|
51
|
+
thirdwebId?: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
} | undefined;
|
|
54
|
+
setUser: (newUser?: Users) => void;
|
|
55
|
+
refetchUser: () => Promise<void>;
|
|
56
|
+
clearUser: () => void;
|
|
57
|
+
queryKey: string[];
|
|
58
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { debugB3React } from "../../../shared/utils/debug.js";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
const debug = debugB3React("useUserQuery");
|
|
4
|
+
const USER_QUERY_KEY = ["b3-user"];
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the user from localStorage
|
|
7
|
+
*/
|
|
8
|
+
function getUserFromStorage() {
|
|
9
|
+
if (typeof window === "undefined") {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
14
|
+
return storedUser ? JSON.parse(storedUser) : null;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Saves user to localStorage
|
|
23
|
+
*/
|
|
24
|
+
function saveUserToStorage(user) {
|
|
25
|
+
if (typeof window === "undefined") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (user) {
|
|
29
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
localStorage.removeItem("b3-user");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* NOTE: THIS IS ONLY MEANT FOR INTERNAL USE, from useOnConnect
|
|
37
|
+
*
|
|
38
|
+
* Custom hook to manage user state with react-query
|
|
39
|
+
* This allows for invalidation and refetching of user data
|
|
40
|
+
*/
|
|
41
|
+
export function useUserQuery() {
|
|
42
|
+
const queryClient = useQueryClient();
|
|
43
|
+
// Query to get user data (primarily from cache/localStorage)
|
|
44
|
+
const { data: user } = useQuery({
|
|
45
|
+
queryKey: USER_QUERY_KEY,
|
|
46
|
+
queryFn: getUserFromStorage,
|
|
47
|
+
staleTime: Infinity, // User data doesn't go stale automatically
|
|
48
|
+
gcTime: Infinity, // Keep in cache indefinitely
|
|
49
|
+
initialData: getUserFromStorage,
|
|
50
|
+
});
|
|
51
|
+
// Mutation to update user
|
|
52
|
+
const setUserMutation = useMutation({
|
|
53
|
+
mutationFn: async (newUser) => {
|
|
54
|
+
const userToSave = newUser ?? null;
|
|
55
|
+
saveUserToStorage(userToSave);
|
|
56
|
+
return userToSave;
|
|
57
|
+
},
|
|
58
|
+
onSuccess: data => {
|
|
59
|
+
queryClient.setQueryData(USER_QUERY_KEY, data);
|
|
60
|
+
debug("User updated", data);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
// Helper function to set user (maintains backward compatibility)
|
|
64
|
+
const setUser = (newUser) => {
|
|
65
|
+
setUserMutation.mutate(newUser);
|
|
66
|
+
};
|
|
67
|
+
// Helper function to invalidate and refetch user
|
|
68
|
+
const refetchUser = async () => {
|
|
69
|
+
await queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
70
|
+
return queryClient.refetchQueries({ queryKey: USER_QUERY_KEY });
|
|
71
|
+
};
|
|
72
|
+
// Helper function to clear user
|
|
73
|
+
const clearUser = () => {
|
|
74
|
+
setUser(undefined);
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
user: user ?? undefined,
|
|
78
|
+
setUser,
|
|
79
|
+
refetchUser,
|
|
80
|
+
clearUser,
|
|
81
|
+
queryKey: USER_QUERY_KEY,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function useWagmiConfig(partnerId: string, rpcUrls?: Record<number, string>): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
|
|
2
|
+
[k: string]: import("viem").HttpTransport<undefined, false>;
|
|
3
|
+
}, readonly [import("wagmi").CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
|
|
4
|
+
connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
|
|
5
|
+
accounts: withCapabilities extends true ? readonly {
|
|
6
|
+
address: `0x${string}`;
|
|
7
|
+
capabilities: Record<string, unknown>;
|
|
8
|
+
}[] : readonly `0x${string}`[];
|
|
9
|
+
chainId: number;
|
|
10
|
+
}>;
|
|
11
|
+
}, {
|
|
12
|
+
"thirdweb:lastChainId": number;
|
|
13
|
+
}>]>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ecosystemWalletId } from "../../../shared/constants/index.js";
|
|
2
|
+
import { supportedChains } from "../../../shared/constants/chains/supported.js";
|
|
3
|
+
import { client } from "../../../shared/utils/thirdweb.js";
|
|
4
|
+
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { http } from "viem";
|
|
7
|
+
import { createConfig } from "wagmi";
|
|
8
|
+
export function useWagmiConfig(partnerId, rpcUrls) {
|
|
9
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
10
|
+
// when parent component passes new object references with same content
|
|
11
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
12
|
+
const ecocystemConfig = useMemo(() => {
|
|
13
|
+
return {
|
|
14
|
+
ecosystemId: ecosystemWalletId,
|
|
15
|
+
partnerId: partnerId,
|
|
16
|
+
client,
|
|
17
|
+
};
|
|
18
|
+
}, [partnerId]);
|
|
19
|
+
/**
|
|
20
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
21
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
22
|
+
*/
|
|
23
|
+
const wagmiConfig = useMemo(() => {
|
|
24
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
25
|
+
return createConfig({
|
|
26
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
27
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
28
|
+
connectors: [
|
|
29
|
+
inAppWalletConnector({
|
|
30
|
+
...ecocystemConfig,
|
|
31
|
+
client,
|
|
32
|
+
}),
|
|
33
|
+
// injected(),
|
|
34
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
}, [rpcUrlsString, ecocystemConfig]);
|
|
38
|
+
return wagmiConfig;
|
|
39
|
+
}
|
|
@@ -32,8 +32,6 @@ export interface SignInWithB3ModalProps extends BaseModalProps {
|
|
|
32
32
|
sessionKeyAddress?: Address;
|
|
33
33
|
/** Unique identifier for the partner application */
|
|
34
34
|
partnerId: string;
|
|
35
|
-
/** Whether to authenticate with Sign In With Ethereum */
|
|
36
|
-
loginWithSiwe?: boolean;
|
|
37
35
|
/** Whether to close the modal after successful login */
|
|
38
36
|
closeAfterLogin?: boolean;
|
|
39
37
|
/** Source of the sign-in request */
|
|
@@ -19,12 +19,12 @@ export declare function B3Provider({ theme, children, accountOverride, environme
|
|
|
19
19
|
};
|
|
20
20
|
clientType?: ClientType;
|
|
21
21
|
rpcUrls?: Record<number, string>;
|
|
22
|
-
partnerId
|
|
22
|
+
partnerId: string;
|
|
23
23
|
}): import("react/jsx-runtime").JSX.Element;
|
|
24
24
|
/**
|
|
25
25
|
* Inner provider component that provides the actual B3Context
|
|
26
26
|
*/
|
|
27
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, }: {
|
|
27
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, automaticallySetFirstEoa, theme, clientType, partnerId, }: {
|
|
28
28
|
children: React.ReactNode;
|
|
29
29
|
accountOverride?: Account;
|
|
30
30
|
environment: B3ContextType["environment"];
|
|
@@ -32,4 +32,5 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
32
32
|
automaticallySetFirstEoa: boolean;
|
|
33
33
|
theme: "light" | "dark";
|
|
34
34
|
clientType?: ClientType;
|
|
35
|
+
partnerId: string;
|
|
35
36
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,21 +5,25 @@ import { B3ContextType } from "./types";
|
|
|
5
5
|
/**
|
|
6
6
|
* Main B3Provider component
|
|
7
7
|
*/
|
|
8
|
-
export declare function B3Provider({ theme, children, accountOverride, environment, clientType, }: {
|
|
8
|
+
export declare function B3Provider({ theme, children, accountOverride, environment, clientType, partnerId, rpcUrls, }: {
|
|
9
9
|
theme: "light" | "dark";
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
accountOverride?: Account;
|
|
12
12
|
environment: B3ContextType["environment"];
|
|
13
13
|
clientType?: ClientType;
|
|
14
|
+
partnerId: string;
|
|
15
|
+
rpcUrls?: Record<number, string>;
|
|
14
16
|
}): import("react/jsx-runtime").JSX.Element;
|
|
15
17
|
/**
|
|
16
18
|
* Inner provider component that provides the actual B3Context
|
|
17
19
|
*/
|
|
18
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, }: {
|
|
20
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, partnerId, rpcUrls, }: {
|
|
19
21
|
children: React.ReactNode;
|
|
20
22
|
accountOverride?: Account;
|
|
21
23
|
environment: B3ContextType["environment"];
|
|
22
24
|
defaultPermissions?: PermissionsConfig;
|
|
23
25
|
theme: "light" | "dark";
|
|
24
26
|
clientType?: ClientType;
|
|
27
|
+
partnerId: string;
|
|
28
|
+
rpcUrls?: Record<number, string>;
|
|
25
29
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,12 +12,14 @@ export interface B3ContextType {
|
|
|
12
12
|
setWallet: (wallet: Wallet) => void;
|
|
13
13
|
wallet?: Wallet;
|
|
14
14
|
setUser: (user?: Users) => void;
|
|
15
|
+
refetchUser: () => Promise<any>;
|
|
15
16
|
initialized: boolean;
|
|
16
17
|
ready: boolean;
|
|
17
18
|
environment?: "development" | "production";
|
|
18
19
|
defaultPermissions?: PermissionsConfig;
|
|
19
20
|
theme: "light" | "dark";
|
|
20
21
|
clientType: ClientType;
|
|
22
|
+
partnerId: string;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Context for B3 provider
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
interface BalanceContentProps {
|
|
2
2
|
onLogout?: () => void;
|
|
3
|
-
partnerId: string;
|
|
4
3
|
showDeposit?: boolean;
|
|
5
4
|
showSwap?: boolean;
|
|
6
5
|
}
|
|
7
|
-
export declare function BalanceContent({ onLogout,
|
|
6
|
+
export declare function BalanceContent({ onLogout, showDeposit, showSwap }: BalanceContentProps): import("react/jsx-runtime").JSX.Element;
|
|
8
7
|
export {};
|
|
@@ -3,4 +3,4 @@ import { SignInWithB3ModalProps } from "@b3dotfun/sdk/global-account/react";
|
|
|
3
3
|
* Component that manages the authentication flow for Sign In With B3
|
|
4
4
|
* Handles different login providers, authentication steps, and session key management
|
|
5
5
|
*/
|
|
6
|
-
export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin,
|
|
6
|
+
export declare function SignInWithB3Flow({ strategies, onLoginSuccess, onSessionKeySuccess, onError, chain, sessionKeyAddress, partnerId, closeAfterLogin, source, signersEnabled, }: SignInWithB3ModalProps): import("react/jsx-runtime").JSX.Element | null;
|