Skip to content

Commit

Permalink
Handle stale data
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Lo. committed Aug 9, 2024
1 parent 8d7f4b7 commit 7e9bf23
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/theme/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ export const LoginProvider = ({ children }) => {
setIsInitialized(true);
}

const getStaleDate = async () => {
try {
setProjects(
JSON.parse(sessionStorage.getItem(AUTH_WALLET_PROJECTS) || "{}"),
);
setUserId(getUserIdFromSessionStorage());
const accounts = await sdk.connect();
setAccount(accounts);
if (accounts && accounts.length > 0) {
setAccount(accounts[0]);
const provider = sdk.getProvider();
setProvider(provider);
}
} catch (e) {}
};

useEffect(() => {
if (isInitialized && sdk.isExtensionActive()) {
const provider = sdk.getProvider();
Expand All @@ -74,10 +90,8 @@ export const LoginProvider = ({ children }) => {
}, [isInitialized]);

useEffect(() => {
setProjects(
JSON.parse(sessionStorage.getItem(AUTH_WALLET_PROJECTS) || "{}"),
);
const url = new URL(window.location.href);
getStaleDate();
if (url.pathname.includes(REF_FAUCET_PATH)) {
const token = url.searchParams.get("token");
if (token) {
Expand Down

0 comments on commit 7e9bf23

Please sign in to comment.