Files
com.blitzwallet/context-store/authContext.js
T
Blake KaufmanandGitHub b1a58e23b2 Reload wallet if backgrounded (#290)
* creating centralized location to handle stale background state

* adding global background threashold

* creating auth context

* disconnecting from liquid node during force auth

* reset did get to homepage variable

* fix crash if globalContactsInformation.myProfile is not set

* resetting custody account settings

* clearing keys information on reset

* remove roostock swap listener on reset

* resetting webview context on stale auth

* adding auth reset to spark context

* only load user info once per session

* only open tables once per session

* making sure to recheck login status to fix issue with initial load

* adding large heap flag

* fixing sql table open bug

* making sure didLoadUserSettings runs on app open

* fixing unqiueName being null bug

* fixing race condition causing switch to naive spark version

* misc changes
2025-12-05 09:35:51 -05:00

45 lines
1.1 KiB
JavaScript

import { createContext, useState, useContext, useEffect, useMemo } from 'react';
import { navigationRef } from '../navigation/navigationService';
import { useAppStatus } from './appStatus';
// Initiate context
const AuthStatusManager = createContext(null);
const AuthStatusProvider = ({ children }) => {
const { appState, shouldResetStateRef } = useAppStatus();
const [authResetkey, setAuthResetKey] = useState(0);
useEffect(() => {
if (appState === 'active' && shouldResetStateRef.current) {
setAuthResetKey(prev => prev + 1);
navigationRef.current.reset({
index: 0,
routes: [{ name: 'Splash' }],
});
}
}, [appState]);
const contextValue = useMemo(
() => ({
authResetkey,
}),
[authResetkey],
);
return (
<AuthStatusManager.Provider value={contextValue}>
{children}
</AuthStatusManager.Provider>
);
};
function useAuthContext() {
const context = useContext(AuthStatusManager);
if (!context) {
throw new Error('useAuthContext must be used within a AuthContextProvider');
}
return context;
}
export { AuthStatusManager, AuthStatusProvider, useAuthContext };