diff --git a/packages/frontend/app/components/LiquidityDialog.tsx b/packages/frontend/app/components/LiquidityDialog.tsx index dc8e43c1a5..00757aea2f 100644 --- a/packages/frontend/app/components/LiquidityDialog.tsx +++ b/packages/frontend/app/components/LiquidityDialog.tsx @@ -1,19 +1,47 @@ import { Dialog } from '@headlessui/react' import { Form } from '@remix-run/react' +import type { ChangeEvent } from 'react' +import { useState } from 'react' import { XIcon } from '~/components/icons' import { Button, Input } from '~/components/ui' +type BasicAsset = { + code: string + scale: number +} + type LiquidityDialogProps = { title: string onClose: () => void type: 'Deposit' | 'Withdraw' + asset: BasicAsset } export const LiquidityDialog = ({ title, onClose, - type + type, + asset }: LiquidityDialogProps) => { + const [actualAmount, setActualAmount] = useState(0) + const [errorMessage, setErrorMessage] = useState('') + + const handleChange = (e: ChangeEvent) => { + const userInput = e.target.value + const scaledInput = parseFloat(userInput) * Math.pow(10, asset.scale) + const integerScaledInput = Math.floor(scaledInput) + if (scaledInput < 0) { + const error = 'The amount should be a positive value' + setErrorMessage(error) + } else if (scaledInput !== integerScaledInput) { + const error = 'The asset scale cannot accomodate this value' + setErrorMessage(error) + } else { + setErrorMessage('') + } + setActualAmount(integerScaledInput) + } + return (
@@ -38,13 +66,23 @@ export const LiquidityDialog = ({ {title}
+