fix sell amount input

This commit is contained in:
PhilReact 2025-06-22 01:20:25 +03:00
parent 0a44ef134b
commit 38d9123906
2 changed files with 27 additions and 15 deletions

View File

@ -55,9 +55,9 @@ import {
MainContainer, MainContainer,
} from "./Table-styles"; } 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 = "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 CloseIcon from "@mui/icons-material/Close";
import ContentCopyIcon from "@mui/icons-material/ContentCopy"; import ContentCopyIcon from "@mui/icons-material/ContentCopy";

View File

@ -103,8 +103,8 @@ export const CustomInput = styled(TextField)({
export const CreateSell = ({ qortAddress, show }) => { export const CreateSell = ({ qortAddress, show }) => {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const [openStuckOrders, setOpenStuckOrders] = React.useState(false); const [openStuckOrders, setOpenStuckOrders] = React.useState(false);
const [qortAmount, setQortAmount] = React.useState(0); const [qortAmount, setQortAmount] = React.useState('');
const [foreignAmount, setForeignAmount] = React.useState(0); const [foreignAmount, setForeignAmount] = React.useState<string>('');
const { const {
updateTemporaryFailedTradeBots, updateTemporaryFailedTradeBots,
sellOrders, sellOrders,
@ -120,8 +120,8 @@ export const CreateSell = ({ qortAddress, show }) => {
}; };
const handleClose = () => { const handleClose = () => {
setOpen(false); setOpen(false);
setForeignAmount(0); setForeignAmount('');
setQortAmount(0); setQortAmount('');
}; };
const createSellOrder = async () => { const createSellOrder = async () => {
@ -133,9 +133,9 @@ export const CreateSell = ({ qortAddress, show }) => {
const res = await qortalRequestWithTimeout( const res = await qortalRequestWithTimeout(
{ {
action: "CREATE_TRADE_SELL_ORDER", action: "CREATE_TRADE_SELL_ORDER",
qortAmount, qortAmount: +qortAmount,
foreignBlockchain: selectedCoin, foreignBlockchain: selectedCoin,
foreignAmount: qortAmount * foreignAmount, foreignAmount: +qortAmount * +foreignAmount,
}, },
900000 900000
); );
@ -155,8 +155,8 @@ export const CreateSell = ({ qortAddress, show }) => {
} }
if (!res?.error) { if (!res?.error) {
setOpenAlert(true); setOpenAlert(true);
setForeignAmount(0); setForeignAmount('');
setQortAmount(0); setQortAmount('');
setOpen(false); setOpen(false);
setInfo({ setInfo({
@ -281,7 +281,13 @@ export const CreateSell = ({ qortAddress, show }) => {
id="standard-adornment-name" id="standard-adornment-name"
type="number" type="number"
value={qortAmount} 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" autoComplete="off"
/> />
<Spacer height="15px" /> <Spacer height="15px" />
@ -293,13 +299,19 @@ export const CreateSell = ({ qortAddress, show }) => {
id="standard-adornment-amount" id="standard-adornment-amount"
type="number" type="number"
value={foreignAmount} 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" autoComplete="off"
/> />
<Spacer height="15px" /> <Spacer height="15px" />
<Typography> <Typography>
{`${qortAmount * foreignAmount} ${getCoinLabel()}`} for{" "} {`${Number(+qortAmount * +foreignAmount)?.toFixed(8)} ${getCoinLabel()}`} for{" "}
{qortAmount} QORT {qortAmount || 0} QORT
</Typography> </Typography>
<Typography <Typography
sx={{ sx={{
@ -320,7 +332,7 @@ export const CreateSell = ({ qortAddress, show }) => {
disabled={ disabled={
!qortAmount || !qortAmount ||
!( !(
qortAmount * foreignAmount > +qortAmount * +foreignAmount >
minimumAmountSellTrades[selectedCoin]?.value minimumAmountSellTrades[selectedCoin]?.value
) )
} }