mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-14 17:41:20 +00:00
update version
This commit is contained in:
parent
25b6cc43e3
commit
c49993729e
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "qapp-core",
|
"name": "qapp-core",
|
||||||
"version": "1.0.16",
|
"version": "1.0.17",
|
||||||
"description": "Qortal's core React library with global state, UI components, and utilities",
|
"description": "Qortal's core React library with global state, UI components, and utilities",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/index.mjs",
|
||||||
|
@ -19,14 +19,18 @@ export type BalanceSetting =
|
|||||||
interval?: number;
|
interval?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface userAccountInfo {
|
||||||
|
address: string;
|
||||||
|
publicKey: string
|
||||||
|
}
|
||||||
export interface UseAuthProps {
|
export interface UseAuthProps {
|
||||||
balanceSetting?: BalanceSetting;
|
balanceSetting?: BalanceSetting;
|
||||||
/** User will be prompted for authentication on start-up */
|
/** User will be prompted for authentication on start-up */
|
||||||
authenticateOnMount?: boolean;
|
authenticateOnMount?: boolean;
|
||||||
|
userAccountInfo?: userAccountInfo | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAuth = ({ balanceSetting, authenticateOnMount = true }: UseAuthProps) => {
|
export const useAuth = ({ balanceSetting, authenticateOnMount = true, userAccountInfo = null }: UseAuthProps) => {
|
||||||
const address = useAuthStore((s) => s.address);
|
const address = useAuthStore((s) => s.address);
|
||||||
const publicKey = useAuthStore((s) => s.publicKey);
|
const publicKey = useAuthStore((s) => s.publicKey);
|
||||||
const name = useAuthStore((s) => s.name);
|
const name = useAuthStore((s) => s.name);
|
||||||
@ -45,12 +49,12 @@ const setBalance = useAuthStore((s) => s.setBalance);
|
|||||||
|
|
||||||
const balanceSetIntervalRef = useRef<null | ReturnType<typeof setInterval>>(null);
|
const balanceSetIntervalRef = useRef<null | ReturnType<typeof setInterval>>(null);
|
||||||
|
|
||||||
const authenticateUser = useCallback(async () => {
|
const authenticateUser = useCallback(async (userAccountInfo?: userAccountInfo) => {
|
||||||
try {
|
try {
|
||||||
setErrorLoadingUser(null);
|
setErrorLoadingUser(null);
|
||||||
setIsLoadingUser(true);
|
setIsLoadingUser(true);
|
||||||
|
|
||||||
const account = await qortalRequest({
|
const account = userAccountInfo || await qortalRequest({
|
||||||
action: "GET_USER_ACCOUNT",
|
action: "GET_USER_ACCOUNT",
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,7 +108,10 @@ const setBalance = useAuthStore((s) => s.setBalance);
|
|||||||
if (authenticateOnMount) {
|
if (authenticateOnMount) {
|
||||||
authenticateUser();
|
authenticateUser();
|
||||||
}
|
}
|
||||||
}, [authenticateOnMount, authenticateUser]);
|
if(userAccountInfo?.address && userAccountInfo?.publicKey){
|
||||||
|
authenticateUser(userAccountInfo);
|
||||||
|
}
|
||||||
|
}, [authenticateOnMount, authenticateUser, userAccountInfo?.address, userAccountInfo?.publicKey]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (address && (balanceSetting?.onlyOnMount || (balanceSetting?.interval && !isNaN(balanceSetting?.interval)))) {
|
if (address && (balanceSetting?.onlyOnMount || (balanceSetting?.interval && !isNaN(balanceSetting?.interval)))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user