@b3dotfun/sdk 0.0.36-alpha.0 → 0.0.36-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,9 +49,33 @@ function InnerProvider({ children, accountOverride, environment, defaultPermissi
|
|
|
49
49
|
const wallets = (0, react_3.useConnectedWallets)();
|
|
50
50
|
const setActiveWallet = (0, react_3.useSetActiveWallet)();
|
|
51
51
|
const isAuthenticated = (0, react_1.useAuthStore)(state => state.isAuthenticated);
|
|
52
|
-
const [user, setUser] = (0, react_2.useState)(
|
|
52
|
+
const [user, setUser] = (0, react_2.useState)(() => {
|
|
53
|
+
// Try to restore user from localStorage on initialization
|
|
54
|
+
if (typeof window !== "undefined") {
|
|
55
|
+
try {
|
|
56
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
57
|
+
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
});
|
|
53
66
|
// Use given accountOverride or activeAccount from thirdweb
|
|
54
67
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
68
|
+
// Persist user to localStorage when it changes
|
|
69
|
+
(0, react_2.useEffect)(() => {
|
|
70
|
+
if (typeof window !== "undefined") {
|
|
71
|
+
if (user) {
|
|
72
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
localStorage.removeItem("b3-user");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, [user]);
|
|
55
79
|
const setWallet = (0, react_2.useCallback)((wallet) => {
|
|
56
80
|
setManuallySelectedWallet(wallet);
|
|
57
81
|
const account = wallet.getAccount();
|
|
@@ -44,9 +44,33 @@ export function InnerProvider({ children, accountOverride, environment, defaultP
|
|
|
44
44
|
const wallets = useConnectedWallets();
|
|
45
45
|
const setActiveWallet = useSetActiveWallet();
|
|
46
46
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
47
|
-
const [user, setUser] = useState(
|
|
47
|
+
const [user, setUser] = useState(() => {
|
|
48
|
+
// Try to restore user from localStorage on initialization
|
|
49
|
+
if (typeof window !== "undefined") {
|
|
50
|
+
try {
|
|
51
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
52
|
+
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
});
|
|
48
61
|
// Use given accountOverride or activeAccount from thirdweb
|
|
49
62
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
63
|
+
// Persist user to localStorage when it changes
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (typeof window !== "undefined") {
|
|
66
|
+
if (user) {
|
|
67
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
localStorage.removeItem("b3-user");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, [user]);
|
|
50
74
|
const setWallet = useCallback((wallet) => {
|
|
51
75
|
setManuallySelectedWallet(wallet);
|
|
52
76
|
const account = wallet.getAccount();
|
package/package.json
CHANGED
|
@@ -115,11 +115,34 @@ export function InnerProvider({
|
|
|
115
115
|
const setActiveWallet = useSetActiveWallet();
|
|
116
116
|
const isAuthenticated = useAuthStore(state => state.isAuthenticated);
|
|
117
117
|
|
|
118
|
-
const [user, setUser] = useState<Users | undefined>(
|
|
118
|
+
const [user, setUser] = useState<Users | undefined>(() => {
|
|
119
|
+
// Try to restore user from localStorage on initialization
|
|
120
|
+
if (typeof window !== "undefined") {
|
|
121
|
+
try {
|
|
122
|
+
const storedUser = localStorage.getItem("b3-user");
|
|
123
|
+
return storedUser ? JSON.parse(storedUser) : undefined;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.warn("Failed to restore user from localStorage:", error);
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return undefined;
|
|
130
|
+
});
|
|
119
131
|
|
|
120
132
|
// Use given accountOverride or activeAccount from thirdweb
|
|
121
133
|
const effectiveAccount = isAuthenticated ? accountOverride || activeAccount : undefined;
|
|
122
134
|
|
|
135
|
+
// Persist user to localStorage when it changes
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (typeof window !== "undefined") {
|
|
138
|
+
if (user) {
|
|
139
|
+
localStorage.setItem("b3-user", JSON.stringify(user));
|
|
140
|
+
} else {
|
|
141
|
+
localStorage.removeItem("b3-user");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}, [user]);
|
|
145
|
+
|
|
123
146
|
const setWallet = useCallback(
|
|
124
147
|
(wallet: Wallet) => {
|
|
125
148
|
setManuallySelectedWallet(wallet);
|