Skip to content

Commit

Permalink
Cover a few more edge cases with showing the swap warnings (#5648)
Browse files Browse the repository at this point in the history
* more edge cases covered

* fix lint
  • Loading branch information
walmat authored Apr 22, 2024
1 parent 99ba043 commit f009a9d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/__swaps__/screens/Swap/hooks/useSwapInputsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export function useSwapInputsController({
);
const outputNativeValue =
!data.buyAmountMinusFees || !assetToBuyPrice.value
? 0
? '0'
: convertRawAmountToNativeDisplay(
data.buyAmountMinusFees.toString(),
assetToBuy.value.decimals || 18,
Expand All @@ -478,7 +478,7 @@ export function useSwapInputsController({
);
const inputNativeValue =
!data.sellAmount || !assetToSellPrice.value
? 0
? '0'
: convertRawAmountToNativeDisplay(
data.sellAmount.toString(),
assetToSell.value.decimals || 18,
Expand Down
10 changes: 5 additions & 5 deletions src/__swaps__/screens/Swap/hooks/useSwapWarning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ export const useSwapWarning = ({ SwapInputController, isFetching, sliderXPositio
break;
}
}
} else if (!isFetching && !(quote as QuoteError)?.error && (!inputNativeValue || !outputNativeValue)) {
} else if (!isFetching && !!quote && !(quote as QuoteError)?.error && (!inputNativeValue || !outputNativeValue)) {
runOnUI(updateWarning)({
type: SwapWarningType.unknown,
display: i18n.t(i18n.l.exchange.price_impact.unknown_price.title),
});
} else if (!isFetching && greaterThanOrEqualTo(impact, severePriceImpactThreshold)) {
} else if (!isFetching && !!quote && greaterThanOrEqualTo(impact, severePriceImpactThreshold)) {
runOnUI(updateWarning)({
type: SwapWarningType.severe,
display,
});
} else if (!isFetching && greaterThanOrEqualTo(impact, highPriceImpactThreshold)) {
} else if (!isFetching && !!quote && greaterThanOrEqualTo(impact, highPriceImpactThreshold)) {
runOnUI(updateWarning)({
type: SwapWarningType.high,
display,
});
} else if (!(quote as QuoteError)?.error) {
} else if (!!quote && !(quote as QuoteError)?.error) {
const serviceTime = getQuoteServiceTime({
quote: quote as CrosschainQuote,
});
Expand Down Expand Up @@ -194,7 +194,7 @@ export const useSwapWarning = ({ SwapInputController, isFetching, sliderXPositio
}

if (
previous?.quote !== current.quote ||
(current.quote && previous?.quote !== current.quote) ||
previous?.inputNativeValue !== current.inputNativeValue ||
previous?.outputNativeValue !== current.outputNativeValue
) {
Expand Down

0 comments on commit f009a9d

Please sign in to comment.