[bugfix] add try catch for health calls (#382)

This commit is contained in:
Bob van der Helm 2023-08-21 08:02:44 -03:00 committed by GitHub
parent e76a5dfc96
commit 9b6ea6b1cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,15 +134,24 @@ export default function useHealthComputer(account?: Account) {
useEffect(() => {
if (!healthComputer) return
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
try {
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
} catch (err) {
console.error(err)
}
}, [healthComputer])
const computeMaxBorrowAmount = useCallback(
(denom: string, target: BorrowTarget) => {
if (!healthComputer) return BN_ZERO
return BN(max_borrow_estimate_js(healthComputer, denom, target))
.times(1 - HEALTH_BUFFER)
.integerValue()
try {
return BN(max_borrow_estimate_js(healthComputer, denom, target))
.times(1 - HEALTH_BUFFER)
.integerValue()
} catch (err) {
console.error(err)
return BN_ZERO
}
},
[healthComputer],
)
@ -150,9 +159,14 @@ export default function useHealthComputer(account?: Account) {
const computeMaxWithdrawAmount = useCallback(
(denom: string) => {
if (!healthComputer) return BN_ZERO
return BN(max_withdraw_estimate_js(healthComputer, denom))
.times(1 - HEALTH_BUFFER)
.integerValue()
try {
return BN(max_withdraw_estimate_js(healthComputer, denom))
.times(1 - HEALTH_BUFFER)
.integerValue()
} catch (err) {
console.error(err)
return BN_ZERO
}
},
[healthComputer],
)