fix perp funding rate

This commit is contained in:
tjs 2022-12-09 16:37:44 -05:00
parent 46b32d01ce
commit 6ad10826ca
2 changed files with 7 additions and 10 deletions

View File

@ -27,7 +27,7 @@ const PerpMarketsTable = () => {
const showTableView = width ? width > breakpoints.md : false const showTableView = width ? width > breakpoints.md : false
// const bids = mangoStore((s) => s.selectedMarket.bidsAccount) // const bids = mangoStore((s) => s.selectedMarket.bidsAccount)
// const asks = mangoStore((s) => s.selectedMarket.asksAccount) // const asks = mangoStore((s) => s.selectedMarket.asksAccount)
const rate = usePerpFundingRate() const rates = usePerpFundingRate()
return ( return (
<ContentBox hideBorder hidePadding> <ContentBox hideBorder hidePadding>
@ -63,12 +63,8 @@ const PerpMarketsTable = () => {
const chartData = coingeckoData ? coingeckoData.prices : undefined const chartData = coingeckoData ? coingeckoData.prices : undefined
let fundingRate let fundingRate
if ( if (rates.isSuccess && rates.data) {
rate.isSuccess const marketRate = rates.data.find(
// && bids instanceof BookSide &&
// asks instanceof BookSide
) {
const marketRate = rate.data.find(
(r) => r.market_index === market.perpMarketIndex (r) => r.market_index === market.perpMarketIndex
) )
fundingRate = `${marketRate?.funding_apr.toFixed(2)}%` fundingRate = `${marketRate?.funding_apr.toFixed(2)}%`

View File

@ -27,23 +27,24 @@ export const usePerpFundingRate = () => {
} }
) )
return res return Array.isArray(res?.data) ? res : { isSuccess: false, data: null }
} }
const PerpFundingRate = () => { const PerpFundingRate = () => {
const { selectedMarket } = useSelectedMarket() const { selectedMarket } = useSelectedMarket()
const rate = usePerpFundingRate() const rate = usePerpFundingRate()
// const bids = mangoStore((s) => s.selectedMarket.bidsAccount) // const bids = mangoStore((s) => s.selectedMarket.bidsAccount)
// const asks = mangoStore((s) => s.selectedMarket.asksAccount) // const asks = mangoStore((s) => s.selectedMarket.asksAccount)
const fundingRate = useMemo(() => { const fundingRate = useMemo(() => {
if (rate.isSuccess && selectedMarket instanceof PerpMarket) { if (rate.isSuccess && selectedMarket instanceof PerpMarket) {
const marketRate = rate?.data.find( const marketRate = rate?.data?.find(
(r) => r.market_index === selectedMarket.perpMarketIndex (r) => r.market_index === selectedMarket.perpMarketIndex
) )
return marketRate?.funding_rate_hourly return marketRate?.funding_rate_hourly
} }
}, [rate]) }, [rate, selectedMarket])
return ( return (
<> <>