use loaded perp market to display open interest

This commit is contained in:
Tyler Shipe 2021-08-23 13:58:37 -04:00
parent a7b5c8a96a
commit fbd6eeda3b
1 changed files with 6 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import useOraclePrice from '../hooks/useOraclePrice'
import DayHighLow from './DayHighLow' import DayHighLow from './DayHighLow'
import { useEffect } from 'react' import { useEffect } from 'react'
import { formatUsdValue } from '../utils' import { formatUsdValue } from '../utils'
import { PerpMarket } from '@blockworks-foundation/mango-client'
function calculateFundingRate(perpStats, perpMarket, oraclePrice) { function calculateFundingRate(perpStats, perpMarket, oraclePrice) {
const oldestStat = perpStats[perpStats.length - 1] const oldestStat = perpStats[perpStats.length - 1]
@ -34,10 +35,10 @@ function calculateFundingRate(perpStats, perpMarket, oraclePrice) {
return (fundingInQuoteDecimals / basePriceInBaseLots) * 100 return (fundingInQuoteDecimals / basePriceInBaseLots) * 100
} }
function parseOpenInterest(perpStats, perpMarket) { function parseOpenInterest(perpMarket: PerpMarket) {
if (!perpStats?.length || !perpMarket) return 0 if (!perpMarket) return 0
return perpMarket.baseLotsToNumber(perpStats[0].openInterest / 2) return perpMarket.baseLotsToNumber(perpMarket.openInterest) / 2
} }
const MarketHeader = () => { const MarketHeader = () => {
@ -232,11 +233,8 @@ const MarketHeader = () => {
Open Interest Open Interest
</div> </div>
<div className="font-semibold text-th-fgd-1 text-xs"> <div className="font-semibold text-th-fgd-1 text-xs">
{parseOpenInterest(perpStats, selectedMarket) ? ( {selectedMarket ? (
`${parseOpenInterest( `${parseOpenInterest(selectedMarket)} ${baseSymbol}`
perpStats,
selectedMarket
)} ${baseSymbol}`
) : ( ) : (
<MarketDataLoader /> <MarketDataLoader />
)} )}