@b3dotfun/sdk 0.0.47-test.4 → 0.0.47
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 +2 -3
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.js +64 -15
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/cjs/global-account/react/components/B3Provider/B3Provider.native.js +21 -26
- package/dist/cjs/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/cjs/global-account/react/components/B3Provider/types.js +0 -2
- package/dist/cjs/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- 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 +22 -6
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +2 -3
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +45 -10
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -2
- package/dist/cjs/global-account/react/components/custom/ManageAccountButton.js +1 -2
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +84 -134
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/cjs/global-account/react/hooks/useHandleConnectWithPrivy.js +1 -2
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.js +68 -19
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/esm/global-account/react/components/B3Provider/B3Provider.native.js +19 -24
- package/dist/esm/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/esm/global-account/react/components/B3Provider/types.js +0 -2
- package/dist/esm/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- 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 +23 -7
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +3 -4
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +46 -11
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +2 -3
- package/dist/esm/global-account/react/components/custom/ManageAccountButton.js +2 -3
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/esm/global-account/react/hooks/useAuthentication.js +87 -137
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/esm/global-account/react/hooks/useHandleConnectWithPrivy.js +2 -3
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +2 -0
- package/dist/types/global-account/react/components/B3Provider/B3Provider.d.ts +2 -3
- package/dist/types/global-account/react/components/B3Provider/B3Provider.native.d.ts +2 -6
- package/dist/types/global-account/react/components/B3Provider/types.d.ts +0 -2
- package/dist/types/global-account/react/components/ManageAccount/BalanceContent.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Flow.d.ts +1 -1
- package/dist/types/global-account/react/components/SignInWithB3/SignInWithB3Privy.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +2 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStepCustom.d.ts +2 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +2 -51
- package/dist/types/global-account/react/hooks/useHandleConnectWithPrivy.d.ts +1 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +2 -0
- package/package.json +3 -3
- package/src/global-account/react/components/B3Provider/B3Provider.native.tsx +35 -51
- package/src/global-account/react/components/B3Provider/B3Provider.tsx +72 -28
- package/src/global-account/react/components/B3Provider/types.ts +0 -4
- package/src/global-account/react/components/ManageAccount/BalanceContent.tsx +3 -2
- 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 +23 -4
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +3 -4
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +46 -8
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +2 -2
- package/src/global-account/react/components/custom/ManageAccountButton.tsx +2 -3
- package/src/global-account/react/hooks/useAuthentication.ts +90 -159
- package/src/global-account/react/hooks/useHandleConnectWithPrivy.tsx +2 -3
- package/src/global-account/react/stores/useModalStore.ts +2 -0
- package/dist/cjs/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/cjs/global-account/react/hooks/useUserQuery.js +0 -86
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/dist/cjs/global-account/react/hooks/useWagmiConfig.js +0 -42
- package/dist/esm/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/esm/global-account/react/hooks/useUserQuery.js +0 -83
- package/dist/esm/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/dist/esm/global-account/react/hooks/useWagmiConfig.js +0 -39
- package/dist/types/global-account/react/hooks/useUserQuery.d.ts +0 -58
- package/dist/types/global-account/react/hooks/useWagmiConfig.d.ts +0 -13
- package/src/global-account/react/hooks/useUserQuery.ts +0 -95
- package/src/global-account/react/hooks/useWagmiConfig.tsx +0 -44
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Wallet } from "thirdweb/wallets";
|
|
2
1
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
3
|
-
export declare function useAuthentication(partnerId: string): {
|
|
2
|
+
export declare function useAuthentication(partnerId: string, loginWithSiwe?: boolean): {
|
|
4
3
|
logout: (callback?: () => void) => Promise<void>;
|
|
5
4
|
isAuthenticated: boolean;
|
|
6
5
|
isReady: boolean;
|
|
@@ -8,54 +7,6 @@ export declare function useAuthentication(partnerId: string): {
|
|
|
8
7
|
isConnected: boolean;
|
|
9
8
|
wallet: import("thirdweb/dist/types/wallets/in-app/core/wallet/types").EcosystemWallet;
|
|
10
9
|
preAuthenticate: typeof preAuthenticate;
|
|
11
|
-
connect: (
|
|
10
|
+
connect: (strategyOptions?: import("thirdweb/wallets").SingleStepAuthArgsType) => Promise<import("thirdweb/wallets").Wallet | null>;
|
|
12
11
|
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;
|
|
61
12
|
};
|
|
@@ -8,148 +8,116 @@ const app_1 = __importDefault(require("../../../global-account/app"));
|
|
|
8
8
|
const bsmnt_1 = require("../../../global-account/bsmnt");
|
|
9
9
|
const react_1 = require("../../../global-account/react");
|
|
10
10
|
const constants_1 = require("../../../shared/constants");
|
|
11
|
+
const supported_1 = require("../../../shared/constants/chains/supported");
|
|
11
12
|
const debug_1 = require("../../../shared/utils/debug");
|
|
12
13
|
const thirdweb_1 = require("../../../shared/utils/thirdweb");
|
|
13
|
-
const core_1 = require("@wagmi/core");
|
|
14
14
|
const react_2 = require("react");
|
|
15
15
|
const react_3 = require("thirdweb/react");
|
|
16
16
|
const wallets_1 = require("thirdweb/wallets");
|
|
17
17
|
const in_app_1 = require("thirdweb/wallets/in-app");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const useWagmiConfig_1 = require("./useWagmiConfig");
|
|
18
|
+
const useConnect_1 = require("./useConnect");
|
|
19
|
+
const useSiwe_1 = require("./useSiwe");
|
|
21
20
|
const debug = (0, debug_1.debugB3React)("useAuthentication");
|
|
22
|
-
function useAuthentication(partnerId) {
|
|
21
|
+
function useAuthentication(partnerId, loginWithSiwe) {
|
|
23
22
|
const { disconnect } = (0, react_3.useDisconnect)();
|
|
24
23
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
25
24
|
const activeWallet = (0, react_3.useActiveWallet)();
|
|
25
|
+
const { authenticate } = (0, useSiwe_1.useSiwe)();
|
|
26
|
+
const { setUser } = (0, react_1.useB3)();
|
|
26
27
|
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
27
28
|
const setIsAuthenticated = (0, react_1.useAuthStore)(state => state.setIsAuthenticated);
|
|
29
|
+
const setIsConnecting = (0, react_1.useAuthStore)(state => state.setIsConnecting);
|
|
28
30
|
const setIsConnected = (0, react_1.useAuthStore)(state => state.setIsConnected);
|
|
29
31
|
const isConnecting = (0, react_1.useAuthStore)(state => state.isConnecting);
|
|
30
32
|
const isConnected = (0, react_1.useAuthStore)(state => state.isConnected);
|
|
31
|
-
const
|
|
33
|
+
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
32
34
|
const setIsAuthenticating = (0, react_1.useAuthStore)(state => state.setIsAuthenticating);
|
|
33
|
-
const
|
|
34
|
-
const setActiveWallet = (0, react_3.useSetActiveWallet)();
|
|
35
|
+
const isAuthenticating = (0, react_1.useAuthStore)(state => state.isAuthenticating);
|
|
35
36
|
const hasStartedConnecting = (0, react_1.useAuthStore)(state => state.hasStartedConnecting);
|
|
36
|
-
const
|
|
37
|
-
const {
|
|
38
|
-
const useAutoConnectLoadingPrevious = (0, react_2.useRef)(false);
|
|
39
|
-
const wagmiConfig = (0, useWagmiConfig_1.useWagmiConfig)(partnerId);
|
|
40
|
-
const { connect } = (0, wagmi_1.useConnect)();
|
|
41
|
-
const activeWagmiAccount = (0, wagmi_1.useAccount)();
|
|
42
|
-
debug("@@activeWagmiAccount", activeWagmiAccount);
|
|
37
|
+
const setHasStartedConnecting = (0, react_1.useAuthStore)(state => state.setHasStartedConnecting);
|
|
38
|
+
const { connect } = (0, useConnect_1.useConnect)(partnerId, supported_1.b3MainnetThirdWeb);
|
|
43
39
|
const wallet = (0, wallets_1.ecosystemWallet)(constants_1.ecosystemWalletId, {
|
|
44
40
|
partnerId: partnerId,
|
|
45
41
|
});
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// If it's not an in-app wallet or it is the ecosystem wallet, connect
|
|
59
|
-
(connector.id !== "in-app-wallet" || (connector.id === "in-app-wallet" && twWallet.id === constants_1.ecosystemWalletId))) {
|
|
60
|
-
try {
|
|
61
|
-
const options = {
|
|
62
|
-
wallet: twWallet, // the connected wallet
|
|
63
|
-
};
|
|
64
|
-
debug("@@syncWagmi:connecting", { twWallet, connector });
|
|
65
|
-
connect({
|
|
66
|
-
connector,
|
|
67
|
-
...options,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.error("@@syncWagmi:error", error);
|
|
72
|
-
}
|
|
42
|
+
const { isLoading: useAutoConnectLoading } = (0, react_3.useAutoConnect)({
|
|
43
|
+
client: thirdweb_1.client,
|
|
44
|
+
wallets: [wallet],
|
|
45
|
+
onConnect: async (wallet) => {
|
|
46
|
+
setHasStartedConnecting(true);
|
|
47
|
+
try {
|
|
48
|
+
setIsConnected(true);
|
|
49
|
+
if (!loginWithSiwe) {
|
|
50
|
+
debug("Skipping SIWE login", { loginWithSiwe });
|
|
51
|
+
setIsAuthenticated(true);
|
|
52
|
+
setIsAuthenticating(false);
|
|
53
|
+
return;
|
|
73
54
|
}
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
debug("setIsAuthenticating:true:4");
|
|
56
|
+
const account = await wallet.getAccount();
|
|
57
|
+
if (!account) {
|
|
58
|
+
throw new Error("No account found during auto-connect");
|
|
76
59
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
60
|
+
// Try to re-authenticate first
|
|
61
|
+
try {
|
|
62
|
+
const userAuth = await app_1.default.reAuthenticate();
|
|
63
|
+
setUser(userAuth.user);
|
|
64
|
+
setIsAuthenticated(true);
|
|
65
|
+
setIsAuthenticating(false);
|
|
66
|
+
debug("Re-authenticated successfully", { userAuth });
|
|
67
|
+
// Authenticate on BSMNT with B3 JWT
|
|
68
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
69
|
+
console.log("@@b3Jwt", b3Jwt);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// If re-authentication fails, try fresh authentication
|
|
73
|
+
debug("Re-authentication failed, attempting fresh authentication");
|
|
74
|
+
const userAuth = await authenticate(account, partnerId);
|
|
75
|
+
setUser(userAuth.user);
|
|
76
|
+
setIsAuthenticated(true);
|
|
77
|
+
setIsAuthenticating(false);
|
|
78
|
+
debug("Fresh authentication successful", { userAuth });
|
|
79
|
+
// Authenticate on BSMNT with B3 JWT
|
|
80
|
+
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
81
|
+
console.log("@@b3Jwt", b3Jwt);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
debug("Auto-connect authentication failed", { error });
|
|
86
|
+
setIsAuthenticated(false);
|
|
87
|
+
debug("setIsAuthenticating:false:4");
|
|
88
|
+
setUser();
|
|
89
|
+
}
|
|
100
90
|
setIsAuthenticating(false);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
debug("Re-authentication failed, attempting fresh authentication");
|
|
109
|
-
const userAuth = await authenticate(account, partnerId);
|
|
110
|
-
setUser(userAuth.user);
|
|
111
|
-
setIsAuthenticated(true);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* useAutoConnectLoading starts as false
|
|
95
|
+
*/
|
|
96
|
+
(0, react_2.useEffect)(() => {
|
|
97
|
+
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
112
98
|
setIsAuthenticating(false);
|
|
113
|
-
debug("Fresh authentication successful", { userAuth });
|
|
114
|
-
// Authenticate on BSMNT with B3 JWT
|
|
115
|
-
const b3Jwt = await (0, bsmnt_1.authenticateWithB3JWT)(userAuth.accessToken);
|
|
116
|
-
debug("@@b3Jwt", b3Jwt);
|
|
117
99
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
setIsAuthenticating(true);
|
|
125
|
-
await setActiveWallet(wallet);
|
|
126
|
-
await authenticateUser(wallet);
|
|
100
|
+
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
101
|
+
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
102
|
+
// Ensure isAuthenticating stays true until we're fully ready
|
|
103
|
+
(0, react_2.useEffect)(() => {
|
|
104
|
+
if (useAutoConnectLoading) {
|
|
105
|
+
setIsConnecting(true);
|
|
127
106
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
else if (!isAuthenticated) {
|
|
108
|
+
// Only set isAuthenticating to false if we're not authenticated
|
|
109
|
+
// This prevents the flicker state where both isAuthenticating and isAuthenticated are false
|
|
110
|
+
const timeout = setTimeout(() => {
|
|
111
|
+
debug("setIsAuthenticating:false:5a");
|
|
112
|
+
setIsConnecting(false);
|
|
113
|
+
}, 100); // Add a small delay to prevent quick flickers
|
|
114
|
+
return () => clearTimeout(timeout);
|
|
132
115
|
}
|
|
133
|
-
|
|
134
|
-
setIsAuthenticating
|
|
116
|
+
else {
|
|
117
|
+
debug("setIsAuthenticating:false:5b");
|
|
118
|
+
setIsConnecting(false);
|
|
135
119
|
}
|
|
136
|
-
|
|
137
|
-
isAuthenticated,
|
|
138
|
-
isAuthenticating,
|
|
139
|
-
isConnected,
|
|
140
|
-
});
|
|
141
|
-
}, [
|
|
142
|
-
authenticateUser,
|
|
143
|
-
isAuthenticated,
|
|
144
|
-
isAuthenticating,
|
|
145
|
-
isConnected,
|
|
146
|
-
setActiveWallet,
|
|
147
|
-
setHasStartedConnecting,
|
|
148
|
-
setIsAuthenticated,
|
|
149
|
-
setIsAuthenticating,
|
|
150
|
-
setIsConnected,
|
|
151
|
-
setUser,
|
|
152
|
-
]);
|
|
120
|
+
}, [useAutoConnectLoading, isAuthenticated, setIsConnecting, setIsConnected]);
|
|
153
121
|
const logout = async (callback) => {
|
|
154
122
|
if (activeWallet) {
|
|
155
123
|
debug("@@logout:activeWallet", activeWallet);
|
|
@@ -175,21 +143,7 @@ function useAuthentication(partnerId) {
|
|
|
175
143
|
setUser();
|
|
176
144
|
callback?.();
|
|
177
145
|
};
|
|
178
|
-
const
|
|
179
|
-
client: thirdweb_1.client,
|
|
180
|
-
wallets: [wallet],
|
|
181
|
-
onConnect: onConnect,
|
|
182
|
-
});
|
|
183
|
-
/**
|
|
184
|
-
* useAutoConnectLoading starts as false
|
|
185
|
-
*/
|
|
186
|
-
(0, react_2.useEffect)(() => {
|
|
187
|
-
if (!useAutoConnectLoading && useAutoConnectLoadingPrevious.current && !hasStartedConnecting) {
|
|
188
|
-
setIsAuthenticating(false);
|
|
189
|
-
}
|
|
190
|
-
useAutoConnectLoadingPrevious.current = useAutoConnectLoading;
|
|
191
|
-
}, [useAutoConnectLoading, hasStartedConnecting, setIsAuthenticating]);
|
|
192
|
-
const isReady = isAuthenticated && !isAuthenticating;
|
|
146
|
+
const isReady = isAuthenticated && !useAutoConnectLoading && !isAuthenticating;
|
|
193
147
|
return {
|
|
194
148
|
logout,
|
|
195
149
|
isAuthenticated,
|
|
@@ -198,11 +152,7 @@ function useAuthentication(partnerId) {
|
|
|
198
152
|
isConnected,
|
|
199
153
|
wallet,
|
|
200
154
|
preAuthenticate: in_app_1.preAuthenticate,
|
|
201
|
-
connect
|
|
155
|
+
connect,
|
|
202
156
|
isAuthenticating,
|
|
203
|
-
onConnect,
|
|
204
|
-
user,
|
|
205
|
-
refetchUser: authenticateUser,
|
|
206
|
-
setUser,
|
|
207
157
|
};
|
|
208
158
|
}
|
|
@@ -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(chain?: Chain, onSuccess?: (account: Account) => void): {
|
|
7
|
+
export declare function useHandleConnectWithPrivy(partnerId: string, 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;
|
|
@@ -10,8 +10,7 @@ const debug = (0, debug_1.debugB3React)("@@b3:useHandleConnectWithPrivy");
|
|
|
10
10
|
* This essentially wraps our useConnect hook to handle the Privy auth flow.
|
|
11
11
|
* Currently, this is for the basement-privy strategy
|
|
12
12
|
*/
|
|
13
|
-
function useHandleConnectWithPrivy(chain, onSuccess) {
|
|
14
|
-
const { partnerId } = (0, react_1.useB3)();
|
|
13
|
+
function useHandleConnectWithPrivy(partnerId, chain, onSuccess) {
|
|
15
14
|
if (!chain) {
|
|
16
15
|
throw new Error("Chain is required");
|
|
17
16
|
}
|
|
@@ -32,6 +32,8 @@ 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;
|
|
35
37
|
/** Whether to close the modal after successful login */
|
|
36
38
|
closeAfterLogin?: boolean;
|
|
37
39
|
/** 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, }: {
|
|
28
28
|
children: React.ReactNode;
|
|
29
29
|
accountOverride?: Account;
|
|
30
30
|
environment: B3ContextType["environment"];
|
|
@@ -32,5 +32,4 @@ export declare function InnerProvider({ children, accountOverride, environment,
|
|
|
32
32
|
automaticallySetFirstEoa: boolean;
|
|
33
33
|
theme: "light" | "dark";
|
|
34
34
|
clientType?: ClientType;
|
|
35
|
-
partnerId: string;
|
|
36
35
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
2
|
-
import { RelayKitProviderWrapper, TooltipProvider,
|
|
3
|
-
import { useWagmiConfig } from "../../../../global-account/react/hooks/useWagmiConfig.js";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RelayKitProviderWrapper, TooltipProvider, useAuthStore } from "../../../../global-account/react/index.js";
|
|
4
3
|
import { loadGA4Script } from "../../../../global-account/utils/analytics.js";
|
|
4
|
+
import { ecosystemWalletId } from "../../../../shared/constants/index.js";
|
|
5
|
+
import { supportedChains } from "../../../../shared/constants/chains/supported.js";
|
|
5
6
|
import { debugB3React } from "../../../../shared/utils/debug.js";
|
|
7
|
+
import { client } from "../../../../shared/utils/thirdweb.js";
|
|
6
8
|
import "@reservoir0x/relay-kit-ui/styles.css";
|
|
7
9
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
8
|
-
import {
|
|
10
|
+
import { inAppWalletConnector } from "@thirdweb-dev/wagmi-adapter";
|
|
11
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
9
12
|
import { Toaster } from "sonner";
|
|
10
13
|
import { getLastAuthProvider, ThirdwebProvider, useActiveAccount, useConnectedWallets, useSetActiveWallet, } from "thirdweb/react";
|
|
11
|
-
import { WagmiProvider } from "wagmi";
|
|
14
|
+
import { createConfig, http, WagmiProvider } from "wagmi";
|
|
12
15
|
import { setClientType } from "../../../client-manager.js";
|
|
13
16
|
import { StyleRoot } from "../StyleRoot.js";
|
|
14
17
|
import { B3Context } from "./types.js";
|
|
@@ -36,25 +39,76 @@ export function B3Provider({ theme = "light", children, accountOverride, environ
|
|
|
36
39
|
useEffect(() => {
|
|
37
40
|
setClientType(clientType);
|
|
38
41
|
}, [clientType]);
|
|
39
|
-
const
|
|
40
|
-
|
|
42
|
+
const ecocystemConfig = useMemo(() => {
|
|
43
|
+
if (!partnerId)
|
|
44
|
+
return undefined;
|
|
45
|
+
return {
|
|
46
|
+
ecosystemId: ecosystemWalletId,
|
|
47
|
+
partnerId: partnerId,
|
|
48
|
+
client,
|
|
49
|
+
};
|
|
50
|
+
}, [partnerId]);
|
|
51
|
+
// Stringify rpcUrls for stable comparison to prevent wagmiConfig recreation
|
|
52
|
+
// when parent component passes new object references with same content
|
|
53
|
+
const rpcUrlsString = useMemo(() => (rpcUrls ? JSON.stringify(rpcUrls) : undefined), [rpcUrls]);
|
|
54
|
+
/**
|
|
55
|
+
* Creates wagmi config with optional custom RPC URLs
|
|
56
|
+
* @param rpcUrls - Optional mapping of chain IDs to RPC URLs
|
|
57
|
+
*/
|
|
58
|
+
const wagmiConfig = useMemo(() => {
|
|
59
|
+
const parsedRpcUrls = rpcUrlsString ? JSON.parse(rpcUrlsString) : undefined;
|
|
60
|
+
return createConfig({
|
|
61
|
+
chains: [supportedChains[0], ...supportedChains.slice(1)],
|
|
62
|
+
transports: Object.fromEntries(supportedChains.map(chain => [chain.id, http(parsedRpcUrls?.[chain.id])])),
|
|
63
|
+
connectors: [
|
|
64
|
+
inAppWalletConnector({
|
|
65
|
+
...(ecocystemConfig || {}),
|
|
66
|
+
client,
|
|
67
|
+
}),
|
|
68
|
+
// injected(),
|
|
69
|
+
// coinbaseWallet({ appName: "HypeDuel" }),
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
}, [ecocystemConfig, rpcUrlsString]);
|
|
73
|
+
return (_jsx(ThirdwebProvider, { children: _jsx(WagmiProvider, { config: wagmiConfig, children: _jsx(QueryClientProvider, { client: queryClient, children: _jsx(TooltipProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, automaticallySetFirstEoa: !!automaticallySetFirstEoa, clientType: clientType, children: _jsxs(RelayKitProviderWrapper, { simDuneApiKey: simDuneApiKey, children: [children, _jsx(StyleRoot, { id: "b3-root" }), _jsx(Toaster, { theme: theme, position: toaster?.position, style: toaster?.style })] }) }) }) }) }) }));
|
|
41
74
|
}
|
|
42
75
|
/**
|
|
43
76
|
* Inner provider component that provides the actual B3Context
|
|
44
77
|
*/
|
|
45
|
-
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket",
|
|
78
|
+
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, automaticallySetFirstEoa, theme = "light", clientType = "socket", }) {
|
|
46
79
|
const activeAccount = useActiveAccount();
|
|
47
80
|
const [manuallySelectedWallet, setManuallySelectedWallet] = useState(undefined);
|
|
48
81
|
const wallets = useConnectedWallets();
|
|
49
|
-
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
50
|
-
const isConnected = useAuthStore(state => state.isConnected);
|
|
51
82
|
const setActiveWallet = useSetActiveWallet();
|
|
52
|
-
const
|
|
53
|
-
debug("@@B3Provider:isConnected", isConnected);
|
|
83
|
+
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
54
84
|
debug("@@wallets", wallets);
|
|
55
|
-
|
|
85
|
+
const [user, setUser] = useState(() => {
|
|
86
|
+
// Try to restore user from localStorage on initialization
|
|
87
|
+
if (typeof window !== "undefined") {
|
|
88
|
+
try {
|
|
89
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
90
|
+
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
});
|
|
56
99
|
// Use given accountOverride or activeAccount from thirdweb
|
|
57
100
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
101
|
+
// Persist user to localStorage when it changes
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (typeof window !== "undefined") {
|
|
104
|
+
if (user) {
|
|
105
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
localStorage.removeItem("b3-user");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, [user]);
|
|
58
112
|
const setWallet = useCallback((wallet) => {
|
|
59
113
|
setManuallySelectedWallet(wallet);
|
|
60
114
|
const account = wallet.getAccount();
|
|
@@ -87,7 +141,6 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
87
141
|
wallet: manuallySelectedWallet,
|
|
88
142
|
user,
|
|
89
143
|
setUser,
|
|
90
|
-
refetchUser,
|
|
91
144
|
initialized: true,
|
|
92
145
|
ready: !!effectiveAccount,
|
|
93
146
|
automaticallySetFirstEoa,
|
|
@@ -95,9 +148,5 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
95
148
|
defaultPermissions,
|
|
96
149
|
theme,
|
|
97
150
|
clientType,
|
|
98
|
-
|
|
99
|
-
}, children: _jsx(InnerProvider2, { children: children }) }));
|
|
151
|
+
}, children: children }));
|
|
100
152
|
}
|
|
101
|
-
const InnerProvider2 = ({ children }) => {
|
|
102
|
-
return _jsx(_Fragment, { children: children });
|
|
103
|
-
};
|
|
@@ -5,25 +5,21 @@ 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, }: {
|
|
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>;
|
|
16
14
|
}): import("react/jsx-runtime").JSX.Element;
|
|
17
15
|
/**
|
|
18
16
|
* Inner provider component that provides the actual B3Context
|
|
19
17
|
*/
|
|
20
|
-
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType,
|
|
18
|
+
export declare function InnerProvider({ children, accountOverride, environment, defaultPermissions, theme, clientType, }: {
|
|
21
19
|
children: React.ReactNode;
|
|
22
20
|
accountOverride?: Account;
|
|
23
21
|
environment: B3ContextType["environment"];
|
|
24
22
|
defaultPermissions?: PermissionsConfig;
|
|
25
23
|
theme: "light" | "dark";
|
|
26
24
|
clientType?: ClientType;
|
|
27
|
-
partnerId: string;
|
|
28
|
-
rpcUrls?: Record<number, string>;
|
|
29
25
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { useState } from "react";
|
|
3
4
|
import { ThirdwebProvider, useActiveAccount } from "thirdweb/react";
|
|
4
|
-
import { WagmiProvider } from "wagmi";
|
|
5
|
-
import { useAuthentication } from "../../hooks/useAuthentication.js";
|
|
6
|
-
import { useWagmiConfig } from "../../hooks/useWagmiConfig.js";
|
|
7
5
|
import { B3Context } from "./types.js";
|
|
8
6
|
/**
|
|
9
7
|
* Default permissions configuration for B3 provider
|
|
@@ -19,32 +17,29 @@ const queryClient = new QueryClient();
|
|
|
19
17
|
/**
|
|
20
18
|
* Main B3Provider component
|
|
21
19
|
*/
|
|
22
|
-
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket",
|
|
23
|
-
return (_jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType,
|
|
20
|
+
export function B3Provider({ theme = "light", children, accountOverride, environment, clientType = "socket", }) {
|
|
21
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThirdwebProvider, { children: _jsx(InnerProvider, { accountOverride: accountOverride, environment: environment, theme: theme, clientType: clientType, children: children }) }) }));
|
|
24
22
|
}
|
|
25
23
|
/**
|
|
26
24
|
* Inner provider component that provides the actual B3Context
|
|
27
25
|
*/
|
|
28
|
-
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket",
|
|
26
|
+
export function InnerProvider({ children, accountOverride, environment, defaultPermissions = DEFAULT_PERMISSIONS, theme = "light", clientType = "socket", }) {
|
|
29
27
|
const activeAccount = useActiveAccount();
|
|
30
|
-
const
|
|
31
|
-
const wagmiConfig = useWagmiConfig(partnerId, rpcUrls);
|
|
28
|
+
const [user, setUser] = useState(undefined);
|
|
32
29
|
// Use given accountOverride or activeAccount from thirdweb
|
|
33
30
|
const effectiveAccount = accountOverride || activeAccount;
|
|
34
|
-
return (_jsx(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
refetchUser,
|
|
49
|
-
}, children: children }) }) }));
|
|
31
|
+
return (_jsx(B3Context.Provider, { value: {
|
|
32
|
+
account: effectiveAccount,
|
|
33
|
+
automaticallySetFirstEoa: false,
|
|
34
|
+
setWallet: () => { },
|
|
35
|
+
wallet: undefined,
|
|
36
|
+
user,
|
|
37
|
+
setUser,
|
|
38
|
+
initialized: true,
|
|
39
|
+
ready: !!effectiveAccount,
|
|
40
|
+
environment,
|
|
41
|
+
defaultPermissions,
|
|
42
|
+
theme,
|
|
43
|
+
clientType,
|
|
44
|
+
}, children: children }));
|
|
50
45
|
}
|
|
@@ -12,14 +12,12 @@ export interface B3ContextType {
|
|
|
12
12
|
setWallet: (wallet: Wallet) => void;
|
|
13
13
|
wallet?: Wallet;
|
|
14
14
|
setUser: (user?: Users) => void;
|
|
15
|
-
refetchUser: () => Promise<any>;
|
|
16
15
|
initialized: boolean;
|
|
17
16
|
ready: boolean;
|
|
18
17
|
environment?: "development" | "production";
|
|
19
18
|
defaultPermissions?: PermissionsConfig;
|
|
20
19
|
theme: "light" | "dark";
|
|
21
20
|
clientType: ClientType;
|
|
22
|
-
partnerId: string;
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Context for B3 provider
|
|
@@ -9,11 +9,9 @@ export const B3Context = createContext({
|
|
|
9
9
|
setWallet: () => { },
|
|
10
10
|
wallet: undefined,
|
|
11
11
|
setUser: () => { },
|
|
12
|
-
refetchUser: async () => { },
|
|
13
12
|
initialized: false,
|
|
14
13
|
ready: false,
|
|
15
14
|
environment: "development",
|
|
16
15
|
theme: "light",
|
|
17
16
|
clientType: "rest",
|
|
18
|
-
partnerId: "",
|
|
19
17
|
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
interface BalanceContentProps {
|
|
2
2
|
onLogout?: () => void;
|
|
3
|
+
partnerId: string;
|
|
3
4
|
showDeposit?: boolean;
|
|
4
5
|
showSwap?: boolean;
|
|
5
6
|
}
|
|
6
|
-
export declare function BalanceContent({ onLogout, showDeposit, showSwap }: BalanceContentProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function BalanceContent({ onLogout, partnerId, showDeposit, showSwap }: BalanceContentProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|