Skip to content

Commit

Permalink
disable swap if min amt is not met
Browse files Browse the repository at this point in the history
  • Loading branch information
munanadi committed Sep 27, 2021
1 parent 3f213aa commit fa88bc9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const useStyles = makeStyles((theme) => ({
fontSize: 16,
fontWeight: 700,
padding: theme.spacing(1.5),
"&:disabled": {
cursor: "not-allowed",
pointerEvents: 'all !important'
}
},
swapToFromButton: {
display: "block",
Expand Down Expand Up @@ -348,6 +352,16 @@ export function SwapButton() {
const quoteMintInfo = useMint(quoteMint);
const quoteWallet = useOwnedTokenAccount(quoteMint);

let minimumAmt = fromMarket?.minOrderSize ?? 0;
let baseMint = fromMarket?.decoded.baseMint ?? null;

let minAmtCondt = false;
if (baseMint?.toString() === fromMint.toString()) {
minAmtCondt = fromAmount >= minimumAmt;
} else {
minAmtCondt = fromAmount >= minimumAmt * (fair ?? 0);
}

// Click handler.
const sendSwapTransaction = async () => {
if (!fromMintInfo || !toMintInfo) {
Expand Down Expand Up @@ -446,7 +460,7 @@ export function SwapButton() {
variant="contained"
className={styles.swapButton}
onClick={sendSwapTransaction}
disabled={!canSwap}
disabled={!canSwap && !minAmtCondt}
>
Swap
</Button>
Expand Down

0 comments on commit fa88bc9

Please sign in to comment.