From 0125739f306750589253ece77507053b7f058f22 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sun, 13 Apr 2025 18:17:04 +0300 Subject: [PATCH] added getBalance --- src/hooks/useAuth.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index 5c93714..9bad9b9 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -74,15 +74,18 @@ const setBalance = useAuthStore((s) => s.setBalance); } }, [setErrorLoadingUser, setIsLoadingUser, setUser]); - const getBalance = useCallback(async (address: string) => { + const getBalance = useCallback(async (address: string): Promise => { try { const response = await qortalRequest({ action: "GET_BALANCE", address, }); - setBalance(Number(response) || 0); + const userBalance = Number(response) || 0 + setBalance(userBalance); + return userBalance } catch (error) { setBalance(0); + return 0 } }, [setBalance]); @@ -122,6 +125,12 @@ const setBalance = useAuthStore((s) => s.setBalance); } }, [balanceSetting?.onlyOnMount, balanceSetting?.interval, address, getBalance, balanceSetInterval]); + const manualGetBalance = useCallback(async () : Promise => { + if(!address) throw new Error('Not authenticated') + const res = await getBalance(address) + return res + }, [address]) + return { address, publicKey, @@ -130,7 +139,8 @@ const setBalance = useAuthStore((s) => s.setBalance); balance, isLoadingUser, isLoadingInitialBalance, - errorLoadingUser, + errorMessageLoadingUser: errorLoadingUser, authenticateUser, + getBalance: manualGetBalance }; };