From d3468628be70da659e13e17547c4d00fb5bd782f Mon Sep 17 00:00:00 2001 From: tjs Date: Tue, 27 Sep 2022 11:30:25 -0400 Subject: [PATCH] spot slider should return number --- components/trade/SpotSlider.tsx | 35 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/components/trade/SpotSlider.tsx b/components/trade/SpotSlider.tsx index 4072fd14..9dcc6612 100644 --- a/components/trade/SpotSlider.tsx +++ b/components/trade/SpotSlider.tsx @@ -1,7 +1,8 @@ import LeverageSlider from '@components/swap/LeverageSlider' import mangoStore from '@store/mangoStore' import Decimal from 'decimal.js' -import { useCallback, useMemo, useState } from 'react' +import { useCallback, useMemo } from 'react' +import { notify } from 'utils/notifications' const SpotSlider = () => { const side = mangoStore((s) => s.tradeForm.side) @@ -11,22 +12,26 @@ const SpotSlider = () => { const leverageMax = useMemo(() => { const group = mangoStore.getState().group - const set = mangoStore.getState().set if (!mangoAccount || !group || !selectedMarket) return 100 - if (side === 'buy') { - const maxQuote = mangoAccount.getMaxQuoteForSerum3BidUi( - group, - selectedMarket.serumMarketExternal - ) - return new Decimal(maxQuote.toString()).toNumber() - } else { - const maxBase = mangoAccount.getMaxBaseForSerum3AskUi( - group, - selectedMarket.serumMarketExternal - ) - - return new Decimal(maxBase.toString()).toNumber() + try { + if (side === 'buy') { + return mangoAccount.getMaxQuoteForSerum3BidUi( + group, + selectedMarket.serumMarketExternal + ) + } else { + return mangoAccount.getMaxBaseForSerum3AskUi( + group, + selectedMarket.serumMarketExternal + ) + } + } catch (e) { + notify({ + type: 'error', + title: 'Error calculating max leverage.', + }) + return 0 } }, [side, selectedMarket, mangoAccount])