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