mango-ui-v3/components/DayHighLow.tsx

47 lines
1.2 KiB
TypeScript
Raw Normal View History

import useOraclePrice from '../hooks/useOraclePrice'
2021-08-15 06:31:59 -07:00
import { formatUsdValue } from '../utils'
import { MarketDataLoader } from './MarketDetails'
2021-08-13 14:30:39 -07:00
2022-02-17 01:44:28 -08:00
interface DayHighLowProps {
high: number
low: number
isTableView?: boolean
}
const DayHighLow = ({ high, low, isTableView }: DayHighLowProps) => {
const price = useOraclePrice()
2021-08-13 14:30:39 -07:00
let rangePercent = 0
let latestPrice = 0
if (price) {
latestPrice = price?.toNumber()
}
2021-08-14 03:26:54 -07:00
if (high) {
rangePercent = ((latestPrice - low) * 100) / (high - low)
2021-08-13 14:30:39 -07:00
}
return (
2022-02-19 01:11:29 -08:00
<div className="flex items-center justify-between md:block">
<div className="flex items-center">
2022-02-17 01:44:28 -08:00
<div className={`pr-2 text-th-fgd-2 ${!isTableView && 'md:text-xs'}`}>
{low ? formatUsdValue(low) : <MarketDataLoader />}
2021-08-13 14:30:39 -07:00
</div>
2022-03-21 04:56:37 -07:00
<div className="flex h-1.5 w-12 rounded bg-th-bkg-3 sm:w-16">
<div
style={{
2021-08-13 14:30:39 -07:00
width: `${rangePercent}%`,
}}
className="flex rounded bg-th-primary"
></div>
</div>
2022-02-17 01:44:28 -08:00
<div className={`pl-2 text-th-fgd-2 ${!isTableView && 'md:text-xs'}`}>
{high ? formatUsdValue(high) : <MarketDataLoader />}
2021-08-13 14:30:39 -07:00
</div>
</div>
</div>
)
}
export default DayHighLow