refactor: move state detection to context so we can set it at the app level
This commit is contained in:
parent
2ffc9a69f0
commit
aa6ede68f0
|
@ -35,6 +35,7 @@ type LumeContextType = {
|
||||||
setIsLoggedIn: (value: boolean) => void;
|
setIsLoggedIn: (value: boolean) => void;
|
||||||
lume: LumeObject;
|
lume: LumeObject;
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
setReady: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const networkRegistry = createNetworkRegistryClient();
|
const networkRegistry = createNetworkRegistryClient();
|
||||||
|
@ -122,8 +123,6 @@ const LumeProvider = ({ children }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAndUpdateNetworks();
|
fetchAndUpdateNetworks();
|
||||||
loginComplete().then(() => isMounted.current && setIsLoggedIn(true));
|
|
||||||
init().then(() => isMounted.current && setReady(true));
|
|
||||||
|
|
||||||
const subDone = networkRegistry.subscribeToUpdates(() =>
|
const subDone = networkRegistry.subscribeToUpdates(() =>
|
||||||
fetchAndUpdateNetworks(),
|
fetchAndUpdateNetworks(),
|
||||||
|
@ -137,7 +136,8 @@ const LumeProvider = ({ children }) => {
|
||||||
}, [fetchAndUpdateNetworks]);
|
}, [fetchAndUpdateNetworks]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LumeContext.Provider value={{ lume, ready, isLoggedIn, setIsLoggedIn }}>
|
<LumeContext.Provider
|
||||||
|
value={{ lume, ready, setReady, isLoggedIn, setIsLoggedIn }}>
|
||||||
{children}
|
{children}
|
||||||
</LumeContext.Provider>
|
</LumeContext.Provider>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue