mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-14 17:41:20 +00:00
added utils
This commit is contained in:
parent
315737ce98
commit
5e05ecff28
@ -4,6 +4,12 @@ import { useResources } from "../hooks/useResources";
|
||||
import { useAppInfo } from "../hooks/useAppInfo";
|
||||
import { IdentifierBuilder } from "../utils/encryption";
|
||||
import { useIdentifiers } from "../hooks/useIdentifiers";
|
||||
import { objectToBase64 } from "../utils/base64";
|
||||
|
||||
|
||||
const utils = {
|
||||
objectToBase64
|
||||
}
|
||||
|
||||
|
||||
// ✅ Define Global Context Type
|
||||
@ -12,8 +18,10 @@ interface GlobalContextType {
|
||||
resources: ReturnType<typeof useResources>;
|
||||
appInfo: ReturnType<typeof useAppInfo>;
|
||||
identifierOperations: ReturnType<typeof useIdentifiers>
|
||||
utils: typeof utils
|
||||
}
|
||||
|
||||
|
||||
// ✅ Define Config Type for Hook Options
|
||||
interface GlobalProviderProps {
|
||||
children: React.ReactNode;
|
||||
@ -29,6 +37,8 @@ interface GlobalProviderProps {
|
||||
// ✅ Create Context with Proper Type
|
||||
const GlobalContext = createContext<GlobalContextType | null>(null);
|
||||
|
||||
|
||||
|
||||
// 🔹 Global Provider (Handles Multiple Hooks)
|
||||
export const GlobalProvider = ({ children, config, identifierBuilder }: GlobalProviderProps) => {
|
||||
// ✅ Call hooks and pass in options dynamically
|
||||
@ -38,7 +48,7 @@ export const GlobalProvider = ({ children, config, identifierBuilder }: GlobalPr
|
||||
const identifierOperations = useIdentifiers(identifierBuilder, config?.publicSalt)
|
||||
|
||||
// ✅ Merge all hooks into a single `contextValue`
|
||||
const contextValue = useMemo(() => ({ auth, resources, appInfo, identifierOperations }), [auth, resources, appInfo, identifierOperations]);
|
||||
const contextValue = useMemo(() => ({ auth, resources, appInfo, identifierOperations, utils }), [auth, resources, appInfo, identifierOperations]);
|
||||
return (
|
||||
<GlobalContext.Provider value={contextValue}>
|
||||
{children}
|
||||
|
@ -5,11 +5,6 @@ import { buildIdentifier, buildSearchPrefix, IdentifierBuilder } from "../utils
|
||||
|
||||
|
||||
export const useIdentifiers = (builder?: IdentifierBuilder, publicSalt?: string) => {
|
||||
const [publicSaltVal, setPublicSaltVal] = useState(publicSalt)
|
||||
|
||||
useEffect(()=> {
|
||||
setPublicSaltVal(publicSalt)
|
||||
}, [publicSalt])
|
||||
const setIdentifierBuilder = useAppStore().setIdentifierBuilder
|
||||
const identifierBuilder = useAppStore().identifierBuilder
|
||||
const appName = useAppStore().appName
|
||||
@ -39,7 +34,6 @@ export const useIdentifiers = (builder?: IdentifierBuilder, publicSalt?: string)
|
||||
}
|
||||
}, [stringifiedBuilder])
|
||||
return {
|
||||
identifierBuilder,
|
||||
buildIdentifier: buildIdentifierFunc,
|
||||
buildSearchPrefix: buildSearchPrefixFunc
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user