From 9b6ea6b1ccb7368fb132f5d0d9337feef758b7d1 Mon Sep 17 00:00:00 2001 From: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com> Date: Mon, 21 Aug 2023 08:02:44 -0300 Subject: [PATCH] [bugfix] add try catch for health calls (#382) --- src/hooks/useHealthComputer.tsx | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/hooks/useHealthComputer.tsx b/src/hooks/useHealthComputer.tsx index efcdf6f1..86114a22 100644 --- a/src/hooks/useHealthComputer.tsx +++ b/src/hooks/useHealthComputer.tsx @@ -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], )