set trade size button to 100 when clicking max

This commit is contained in:
saml33 2022-08-23 22:41:37 +10:00
parent 331300e865
commit f888f0211f
1 changed files with 12 additions and 1 deletions

View File

@ -215,7 +215,10 @@ const SwapForm = () => {
/>
</div>
{!useMargin ? (
<PercentageSelectButtons setAmountIn={setAmountInFormValue} />
<PercentageSelectButtons
amountIn={amountInFormValue}
setAmountIn={setAmountInFormValue}
/>
) : null}
</div>
<div className="flex justify-center">
@ -377,13 +380,21 @@ const MaxSwapAmount = ({
}
const PercentageSelectButtons = ({
amountIn,
setAmountIn,
}: {
amountIn: string
setAmountIn: (x: any) => any
}) => {
const [sizePercentage, setSizePercentage] = useState('')
const { amount: tokenMax, decimals } = useTokenMax()
useEffect(() => {
if (tokenMax > 0 && Number(amountIn) === tokenMax) {
setSizePercentage('100')
}
}, [amountIn, tokenMax])
const handleSizePercentage = (percentage: string) => {
setSizePercentage(percentage)
if (tokenMax > 0) {