mango-ui-v3/components/trade_form/EstPriceImpact.tsx

81 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-09-30 07:21:45 -07:00
import { InformationCircleIcon } from '@heroicons/react/outline'
import Tippy from '@tippyjs/react'
import 'tippy.js/animations/scale.css'
2021-10-01 09:21:09 -07:00
import { percentFormat } from '../../utils'
import { useTranslation } from 'next-i18next'
2021-09-30 07:21:45 -07:00
2021-10-01 08:32:15 -07:00
const EstPriceImpact = ({
priceImpact,
}: {
2021-10-05 12:12:26 -07:00
priceImpact?: { slippage: number[]; takerFee: number[] }
2021-10-01 08:32:15 -07:00
}) => {
const { t } = useTranslation('common')
const priceImpactAbs = priceImpact.slippage[0]
const priceImpactRel = priceImpact.slippage[1]
2021-09-30 07:21:45 -07:00
return (
<div
className={`border-t border-th-bkg-4 flex items-center justify-center mt-2 pt-2 text-th-fgd-4 text-xs`}
2021-09-30 07:21:45 -07:00
>
{t('price-impact')}:
2021-09-30 07:21:45 -07:00
<span
className={`font-bold opacity-80 ml-2 ${
2021-10-01 09:21:09 -07:00
priceImpactRel <= 0.005
2021-09-30 07:21:45 -07:00
? 'text-th-green'
2021-10-01 09:21:09 -07:00
: priceImpactRel > 0.005 && priceImpactRel <= 0.01
2021-09-30 07:21:45 -07:00
? 'text-th-orange'
: 'text-th-red'
}`}
>
2021-10-01 08:32:15 -07:00
${priceImpactAbs.toFixed(2)}
<span className="mx-1 text-th-fgd-4">|</span>
2021-10-01 09:21:09 -07:00
{percentFormat.format(priceImpactRel)}
2021-09-30 07:21:45 -07:00
</span>
<Tippy
animation="scale"
placement="top"
appendTo={() => document.body}
maxWidth="20rem"
interactive
delay={0}
content={
<div
className={`rounded p-4 text-xs bg-th-bkg-3 leading-4 shadow-md text-th-fgd-3 outline-none space-y-1.5 w-56 focus:outline-none`}
>
<div className="flex justify-between">
{t('slippage')}:
2021-09-30 07:21:45 -07:00
<span className="text-th-fgd-1">
2021-10-01 08:32:15 -07:00
${priceImpact.slippage[0].toFixed(2)}
2021-09-30 07:21:45 -07:00
<span className="px-1 text-th-fgd-4">|</span>
2021-10-01 09:21:09 -07:00
{percentFormat.format(priceImpact.slippage[1])}
2021-09-30 07:21:45 -07:00
</span>
</div>
2021-10-01 08:32:15 -07:00
{/* <div className="flex justify-between">
2021-09-30 07:21:45 -07:00
Maker Fee:
<span className="text-th-fgd-1">
${priceImpact.makerFee[0]}
<span className="px-1 text-th-fgd-4">|</span>
2021-10-01 08:32:15 -07:00
{priceImpact.makerFee[1].toFixed(2)}%
2021-09-30 07:21:45 -07:00
</span>
2021-10-01 08:32:15 -07:00
</div> */}
2021-09-30 07:21:45 -07:00
<div className="flex justify-between">
{t('taker-fee')}:
2021-09-30 07:21:45 -07:00
<span className="text-th-fgd-1">
2021-10-01 08:32:15 -07:00
${priceImpact.takerFee[0].toFixed(2)}
2021-09-30 07:21:45 -07:00
<span className="px-1 text-th-fgd-4">|</span>
2021-10-01 09:21:09 -07:00
{percentFormat.format(priceImpact.takerFee[1])}
2021-09-30 07:21:45 -07:00
</span>
</div>
</div>
}
>
<div className="outline-none focus:outline-none">
<InformationCircleIcon className="h-5 w-5 ml-2 text-th-primary opacity-70" />
2021-09-30 07:21:45 -07:00
</div>
</Tippy>
</div>
)
}
export default EstPriceImpact