mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-15 01:41:21 +00:00
31 lines
900 B
TypeScript
31 lines
900 B
TypeScript
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
import { useAuthStore } from "../state/auth";
|
|
import { useAppStore } from "../state/app";
|
|
import { EnumCollisionStrength, hashWord } from "../utils/encryption";
|
|
|
|
|
|
export const useAppInfo = (appName?: string, publicSalt?: string) => {
|
|
const setAppState = useAppStore((state)=> state.setAppState)
|
|
const appNameHashed = useAppStore((state)=> state.appNameHashed)
|
|
|
|
|
|
const handleAppInfoSetup = useCallback(async (name: string, salt: string)=> {
|
|
const appNameHashed = await hashWord(name, EnumCollisionStrength.HIGH, salt)
|
|
setAppState({
|
|
appName: name,
|
|
publicSalt: salt,
|
|
appNameHashed
|
|
})
|
|
}, [])
|
|
|
|
useEffect(()=> {
|
|
if(appName && publicSalt){
|
|
handleAppInfoSetup(appName, publicSalt)
|
|
}
|
|
}, [appName, publicSalt, handleAppInfoSetup])
|
|
return {
|
|
appName,
|
|
appNameHashed
|
|
};
|
|
};
|