2021-08-13 14:30:39 -07:00
|
|
|
function formatRangePrice(price) {
|
|
|
|
if (!price) return null
|
|
|
|
const priceAsFloat = parseFloat(price)
|
|
|
|
if (priceAsFloat > 1000) {
|
|
|
|
return priceAsFloat.toFixed(0)
|
2021-08-13 15:02:07 -07:00
|
|
|
} else if (priceAsFloat > 1) {
|
2021-08-13 14:30:39 -07:00
|
|
|
return priceAsFloat.toFixed(2)
|
|
|
|
} else {
|
|
|
|
return priceAsFloat.toFixed(4)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const DayHighLow = ({ high, low, latest }) => {
|
|
|
|
let rangePercent = 0
|
|
|
|
if (high?.baseOraclePrice) {
|
|
|
|
rangePercent =
|
|
|
|
(parseFloat(latest?.baseOraclePrice) /
|
|
|
|
parseFloat(high?.baseOraclePrice)) *
|
|
|
|
100
|
|
|
|
}
|
|
|
|
|
2021-07-20 07:21:58 -07:00
|
|
|
return (
|
|
|
|
<div className="pr-6">
|
2021-07-23 07:07:05 -07:00
|
|
|
<div className="text-center text-th-fgd-3 tiny-text">24h Range</div>
|
2021-07-20 07:21:58 -07:00
|
|
|
<div className="flex items-center">
|
2021-08-13 14:30:39 -07:00
|
|
|
<div className="pr-2 text-th-fgd-1 text-xs">
|
|
|
|
${formatRangePrice(low?.baseOraclePrice)}
|
|
|
|
</div>
|
2021-07-20 07:21:58 -07:00
|
|
|
<div className="h-1.5 flex rounded bg-th-bkg-3 w-24">
|
|
|
|
<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>
|
2021-08-13 14:30:39 -07:00
|
|
|
<div className="pl-2 text-th-fgd-1 text-xs">
|
|
|
|
${formatRangePrice(high?.baseOraclePrice)}
|
|
|
|
</div>
|
2021-07-20 07:21:58 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DayHighLow
|