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