From d89b77fc5d7a43547b15c02c722897a926efaf6f Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 12 Nov 2024 23:33:09 +0100 Subject: [PATCH] fix quote cannot have 0 amount --- src/app/components/OrderInput.tsx | 4 +++- src/app/state/orderInputSlice.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/components/OrderInput.tsx b/src/app/components/OrderInput.tsx index 5d0535a7..360de2f9 100644 --- a/src/app/components/OrderInput.tsx +++ b/src/app/components/OrderInput.tsx @@ -26,6 +26,7 @@ import { pairAddressIsSet, priceIsValid, tokenIsSpecified, + amountIsPositive, submitOrder, } from "state/orderInputSlice"; import { Calculator } from "services/Calculator"; @@ -118,7 +119,8 @@ export function OrderInput() { if ( pairAddressIsSet(pairAddress) && priceIsValid(price, type) && - tokenIsSpecified(specifiedToken) + tokenIsSpecified(specifiedToken) && + amountIsPositive(specifiedToken, token1, token2) ) { dispatch(fetchQuote()); } diff --git a/src/app/state/orderInputSlice.ts b/src/app/state/orderInputSlice.ts index 28f7751f..a990d124 100644 --- a/src/app/state/orderInputSlice.ts +++ b/src/app/state/orderInputSlice.ts @@ -216,6 +216,19 @@ export function tokenIsSpecified(specifiedToken: SpecifiedToken): boolean { return specifiedToken !== SpecifiedToken.UNSPECIFIED; } +export function amountIsPositive( + specifiedToken: SpecifiedToken, + token1: TokenInput, + token2: TokenInput +): boolean { + if (specifiedToken === SpecifiedToken.TOKEN_1) { + return token1.amount > 0; + } else if (specifiedToken === SpecifiedToken.TOKEN_2) { + return token2.amount > 0; + } + return false; +} + // for getting balances out of pairSelector slice // TODO(dcts): ask @chaotic whether this can live inside pairSelector now that // the orderInputState seems not to be needed anymore.