mango-v4-ui/components/shared/TradePriceDifference.tsx

36 lines
924 B
TypeScript
Raw Normal View History

2023-11-04 05:24:17 -07:00
import { useMemo } from 'react'
2024-03-13 18:31:49 -07:00
import Tooltip from './Tooltip'
import { useTranslation } from 'react-i18next'
2023-11-04 05:24:17 -07:00
const TradePriceDifference = ({
currentPrice,
newPrice,
}: {
currentPrice: number | undefined
newPrice: number | undefined
}) => {
2024-03-13 18:31:49 -07:00
const { t } = useTranslation('trade')
2023-11-04 05:24:17 -07:00
const priceDifference = useMemo(() => {
if (!currentPrice || !newPrice) return 0
const difference = ((newPrice - currentPrice) / currentPrice) * 100
return difference
}, [currentPrice, newPrice])
return (
2024-03-13 18:31:49 -07:00
<Tooltip content={t('tooltip-limit-price-difference')}>
<p
className={`tooltip-underline font-mono text-xs ${
priceDifference >= 0 ? 'text-th-up' : 'text-th-down'
}`}
>
{priceDifference
? (priceDifference > 0 ? '+' : '') + priceDifference.toFixed(2)
: '0.00'}
%
</p>
</Tooltip>
2023-11-04 05:24:17 -07:00
)
}
export default TradePriceDifference