From 38d91239064b6aed4836dc35965ae5a198770e6e Mon Sep 17 00:00:00 2001 From: PhilReact Date: Sun, 22 Jun 2025 01:20:25 +0300 Subject: [PATCH] fix sell amount input --- src/components/Grids/TradeOffers.tsx | 4 +-- src/components/sell/CreateSell.tsx | 38 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/components/Grids/TradeOffers.tsx b/src/components/Grids/TradeOffers.tsx index 1d55ee4..69933a5 100644 --- a/src/components/Grids/TradeOffers.tsx +++ b/src/components/Grids/TradeOffers.tsx @@ -55,9 +55,9 @@ import { MainContainer, } from "./Table-styles"; -export const baseLocalHost = window.location.host; +// export const baseLocalHost = window.location.host; // export const baseLocalHost = "devnet-nodes.qortal.link:11111"; -// export const baseLocalHost = "127.0.0.1:22391"; +export const baseLocalHost = "127.0.0.1:22391"; import CloseIcon from "@mui/icons-material/Close"; import ContentCopyIcon from "@mui/icons-material/ContentCopy"; diff --git a/src/components/sell/CreateSell.tsx b/src/components/sell/CreateSell.tsx index 543ba69..edd0687 100644 --- a/src/components/sell/CreateSell.tsx +++ b/src/components/sell/CreateSell.tsx @@ -103,8 +103,8 @@ export const CustomInput = styled(TextField)({ export const CreateSell = ({ qortAddress, show }) => { const [open, setOpen] = React.useState(false); const [openStuckOrders, setOpenStuckOrders] = React.useState(false); - const [qortAmount, setQortAmount] = React.useState(0); - const [foreignAmount, setForeignAmount] = React.useState(0); + const [qortAmount, setQortAmount] = React.useState(''); + const [foreignAmount, setForeignAmount] = React.useState(''); const { updateTemporaryFailedTradeBots, sellOrders, @@ -120,8 +120,8 @@ export const CreateSell = ({ qortAddress, show }) => { }; const handleClose = () => { setOpen(false); - setForeignAmount(0); - setQortAmount(0); + setForeignAmount(''); + setQortAmount(''); }; const createSellOrder = async () => { @@ -133,9 +133,9 @@ export const CreateSell = ({ qortAddress, show }) => { const res = await qortalRequestWithTimeout( { action: "CREATE_TRADE_SELL_ORDER", - qortAmount, + qortAmount: +qortAmount, foreignBlockchain: selectedCoin, - foreignAmount: qortAmount * foreignAmount, + foreignAmount: +qortAmount * +foreignAmount, }, 900000 ); @@ -155,8 +155,8 @@ export const CreateSell = ({ qortAddress, show }) => { } if (!res?.error) { setOpenAlert(true); - setForeignAmount(0); - setQortAmount(0); + setForeignAmount(''); + setQortAmount(''); setOpen(false); setInfo({ @@ -281,7 +281,13 @@ export const CreateSell = ({ qortAddress, show }) => { id="standard-adornment-name" type="number" value={qortAmount} - onChange={(e) => setQortAmount(+e.target.value)} + onChange={(e) => { + const value = e.target.value; + const regex = /^\d*\.?\d{0,8}$/; // allows up to 8 decimal places + if (value === '' || regex.test(value)) { + setQortAmount(value); + } + }} autoComplete="off" /> @@ -293,13 +299,19 @@ export const CreateSell = ({ qortAddress, show }) => { id="standard-adornment-amount" type="number" value={foreignAmount} - onChange={(e) => setForeignAmount(+e.target.value)} + onChange={(e) => { + const value = e.target.value; + const regex = /^\d*\.?\d{0,8}$/; // allows up to 8 decimal places + if (value === '' || regex.test(value)) { + setForeignAmount(value); + } + }} autoComplete="off" /> - {`${qortAmount * foreignAmount} ${getCoinLabel()}`} for{" "} - {qortAmount} QORT + {`${Number(+qortAmount * +foreignAmount)?.toFixed(8)} ${getCoinLabel()}`} for{" "} + {qortAmount || 0} QORT { disabled={ !qortAmount || !( - qortAmount * foreignAmount > + +qortAmount * +foreignAmount > minimumAmountSellTrades[selectedCoin]?.value ) }