[bugfix] add try catch for health calls (#382)
This commit is contained in:
parent
e76a5dfc96
commit
9b6ea6b1cc
@ -134,15 +134,24 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!healthComputer) return
|
if (!healthComputer) return
|
||||||
|
try {
|
||||||
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
|
setHealthFactor(Number(compute_health_js(healthComputer).max_ltv_health_factor) || 10)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
}, [healthComputer])
|
}, [healthComputer])
|
||||||
|
|
||||||
const computeMaxBorrowAmount = useCallback(
|
const computeMaxBorrowAmount = useCallback(
|
||||||
(denom: string, target: BorrowTarget) => {
|
(denom: string, target: BorrowTarget) => {
|
||||||
if (!healthComputer) return BN_ZERO
|
if (!healthComputer) return BN_ZERO
|
||||||
|
try {
|
||||||
return BN(max_borrow_estimate_js(healthComputer, denom, target))
|
return BN(max_borrow_estimate_js(healthComputer, denom, target))
|
||||||
.times(1 - HEALTH_BUFFER)
|
.times(1 - HEALTH_BUFFER)
|
||||||
.integerValue()
|
.integerValue()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
return BN_ZERO
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[healthComputer],
|
[healthComputer],
|
||||||
)
|
)
|
||||||
@ -150,9 +159,14 @@ export default function useHealthComputer(account?: Account) {
|
|||||||
const computeMaxWithdrawAmount = useCallback(
|
const computeMaxWithdrawAmount = useCallback(
|
||||||
(denom: string) => {
|
(denom: string) => {
|
||||||
if (!healthComputer) return BN_ZERO
|
if (!healthComputer) return BN_ZERO
|
||||||
|
try {
|
||||||
return BN(max_withdraw_estimate_js(healthComputer, denom))
|
return BN(max_withdraw_estimate_js(healthComputer, denom))
|
||||||
.times(1 - HEALTH_BUFFER)
|
.times(1 - HEALTH_BUFFER)
|
||||||
.integerValue()
|
.integerValue()
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
return BN_ZERO
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[healthComputer],
|
[healthComputer],
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user