mirror of
https://github.com/Qortal/qapp-core.git
synced 2025-06-14 17:41:20 +00:00
added getBalance
This commit is contained in:
parent
dab9243d23
commit
0125739f30
@ -74,15 +74,18 @@ const setBalance = useAuthStore((s) => s.setBalance);
|
|||||||
}
|
}
|
||||||
}, [setErrorLoadingUser, setIsLoadingUser, setUser]);
|
}, [setErrorLoadingUser, setIsLoadingUser, setUser]);
|
||||||
|
|
||||||
const getBalance = useCallback(async (address: string) => {
|
const getBalance = useCallback(async (address: string): Promise<number> => {
|
||||||
try {
|
try {
|
||||||
const response = await qortalRequest({
|
const response = await qortalRequest({
|
||||||
action: "GET_BALANCE",
|
action: "GET_BALANCE",
|
||||||
address,
|
address,
|
||||||
});
|
});
|
||||||
setBalance(Number(response) || 0);
|
const userBalance = Number(response) || 0
|
||||||
|
setBalance(userBalance);
|
||||||
|
return userBalance
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setBalance(0);
|
setBalance(0);
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
}, [setBalance]);
|
}, [setBalance]);
|
||||||
|
|
||||||
@ -122,6 +125,12 @@ const setBalance = useAuthStore((s) => s.setBalance);
|
|||||||
}
|
}
|
||||||
}, [balanceSetting?.onlyOnMount, balanceSetting?.interval, address, getBalance, balanceSetInterval]);
|
}, [balanceSetting?.onlyOnMount, balanceSetting?.interval, address, getBalance, balanceSetInterval]);
|
||||||
|
|
||||||
|
const manualGetBalance = useCallback(async () : Promise<number | Error> => {
|
||||||
|
if(!address) throw new Error('Not authenticated')
|
||||||
|
const res = await getBalance(address)
|
||||||
|
return res
|
||||||
|
}, [address])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
address,
|
address,
|
||||||
publicKey,
|
publicKey,
|
||||||
@ -130,7 +139,8 @@ const setBalance = useAuthStore((s) => s.setBalance);
|
|||||||
balance,
|
balance,
|
||||||
isLoadingUser,
|
isLoadingUser,
|
||||||
isLoadingInitialBalance,
|
isLoadingInitialBalance,
|
||||||
errorLoadingUser,
|
errorMessageLoadingUser: errorLoadingUser,
|
||||||
authenticateUser,
|
authenticateUser,
|
||||||
|
getBalance: manualGetBalance
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user