* 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
71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
import { getPublicKey } from 'nostr-tools';
|
|
import {
|
|
createContext,
|
|
useState,
|
|
useContext,
|
|
useEffect,
|
|
useMemo,
|
|
useCallback,
|
|
useRef,
|
|
} from 'react';
|
|
import { useAuthContext } from './authContext';
|
|
// Initiate context
|
|
const KeysContextManager = createContext(null);
|
|
|
|
const KeysContextProvider = ({ children }) => {
|
|
const { authResetkey } = useAuthContext();
|
|
const [contactsPrivateKey, setContactsPrivateKey] = useState('');
|
|
const publicKey = useMemo(
|
|
() => (contactsPrivateKey ? getPublicKey(contactsPrivateKey) : null),
|
|
[contactsPrivateKey],
|
|
);
|
|
const [accountMnemoinc, setAccountMnemonic] = useState('');
|
|
const isInitialRender = useRef(true);
|
|
|
|
const toggleContactsPrivateKey = useCallback(newKey => {
|
|
setContactsPrivateKey(newKey);
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (isInitialRender.current) {
|
|
isInitialRender.current = false;
|
|
return;
|
|
}
|
|
setContactsPrivateKey('');
|
|
setAccountMnemonic('');
|
|
}, [authResetkey]);
|
|
|
|
const contextValue = useMemo(
|
|
() => ({
|
|
contactsPrivateKey,
|
|
publicKey,
|
|
toggleContactsPrivateKey,
|
|
accountMnemoinc,
|
|
setAccountMnemonic,
|
|
}),
|
|
[
|
|
contactsPrivateKey,
|
|
publicKey,
|
|
toggleContactsPrivateKey,
|
|
accountMnemoinc,
|
|
setAccountMnemonic,
|
|
],
|
|
);
|
|
|
|
return (
|
|
<KeysContextManager.Provider value={contextValue}>
|
|
{children}
|
|
</KeysContextManager.Provider>
|
|
);
|
|
};
|
|
|
|
function useKeysContext() {
|
|
const context = useContext(KeysContextManager);
|
|
if (!context) {
|
|
throw new Error('useKeysContext must be used within a KeysContextProvider');
|
|
}
|
|
return context;
|
|
}
|
|
|
|
export { KeysContextManager, KeysContextProvider, useKeysContext };
|