2022-03-19 21:04:52 -07:00
|
|
|
import useOraclePrice from '../hooks/useOraclePrice'
|
2021-08-15 06:31:59 -07:00
|
|
|
import { formatUsdValue } from '../utils'
|
2021-09-19 17:36:02 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-03-19 21:04:52 -07:00
|
|
|
const DayHighLow = ({ high, low, isTableView }: DayHighLowProps) => {
|
|
|
|
const price = useOraclePrice()
|
2021-08-13 14:30:39 -07:00
|
|
|
let rangePercent = 0
|
2022-03-19 21:04:52 -07:00
|
|
|
let latestPrice = 0
|
|
|
|
|
|
|
|
if (price) {
|
|
|
|
latestPrice = price?.toNumber()
|
|
|
|
}
|
2021-08-14 03:26:54 -07:00
|
|
|
|
2021-08-25 14:39:48 -07:00
|
|
|
if (high) {
|
2022-03-19 21:04:52 -07:00
|
|
|
rangePercent = ((latestPrice - low) * 100) / (high - low)
|
2021-08-13 14:30:39 -07:00
|
|
|
}
|
|
|
|
|
2021-07-20 07:21:58 -07:00
|
|
|
return (
|
2022-02-19 01:11:29 -08:00
|
|
|
<div className="flex items-center justify-between md:block">
|
2022-01-31 19:51:54 -08:00
|
|
|
<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'}`}>
|
2021-08-25 14:39:48 -07:00
|
|
|
{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">
|
2021-07-20 07:21:58 -07:00
|
|
|
<div
|
|
|
|
style={{
|
2021-08-13 14:30:39 -07:00
|
|
|
width: `${rangePercent}%`,
|
2021-07-20 07:21:58 -07:00
|
|
|
}}
|
|
|
|
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'}`}>
|
2021-08-25 14:39:48 -07:00
|
|
|
{high ? formatUsdValue(high) : <MarketDataLoader />}
|
2021-08-13 14:30:39 -07:00
|
|
|
</div>
|
2021-07-20 07:21:58 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DayHighLow
|