Skip to content

Commit

Permalink
Merge pull request #608 from DeXter-on-Radix/fix-pair-selector-issue
Browse files Browse the repository at this point in the history
BUG REPORT + FIX: Selecting pairs other than DEXTR/XRD silently crashed app
  • Loading branch information
Radstakes authored Nov 12, 2024
2 parents 6ba1c42 + d89b77f commit 8de4277
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app/components/OrderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
pairAddressIsSet,
priceIsValid,
tokenIsSpecified,
amountIsPositive,
submitOrder,
} from "state/orderInputSlice";
import { Calculator } from "services/Calculator";
Expand Down Expand Up @@ -118,7 +119,8 @@ export function OrderInput() {
if (
pairAddressIsSet(pairAddress) &&
priceIsValid(price, type) &&
tokenIsSpecified(specifiedToken)
tokenIsSpecified(specifiedToken) &&
amountIsPositive(specifiedToken, token1, token2)
) {
dispatch(fetchQuote());
}
Expand Down
13 changes: 13 additions & 0 deletions src/app/state/orderInputSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8de4277

Please sign in to comment.