From 82069cbf074120296d1918ffdd75f230c426b0ab Mon Sep 17 00:00:00 2001 From: Nicole O'Brien Date: Thu, 8 Aug 2024 17:21:36 +0100 Subject: [PATCH] fix: logic so that no quotes are generated when value is outside min or max Co-authored-by: Jean Ribeiro --- .../components/TransakExchangePanel.svelte | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte index d4d7c2200e..559e707bd8 100644 --- a/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte +++ b/packages/desktop/views/dashboard/buy-sell/components/TransakExchangePanel.svelte @@ -73,6 +73,8 @@ // Payment Options Selector let paymentOptions: IOption[] let selectedPaymentOption: IOption | undefined + let minValue: number | undefined + let maxValue: number | undefined function updatePaymentOptions( supportedCurrencies: TransakFiatCurrencies | undefined, selectedCurrency: string @@ -86,14 +88,18 @@ if (!paymentOptions.some((paymentOption) => paymentOption.value === selectedPaymentOption?.value)) { selectedPaymentOption = paymentOptions?.[0] } + + const selectedTransakFiatCurrencyPaymentOption = $transakFiatCurrencies?.[ + selectedCurrency + ]?.paymentOptions?.find((paymentOption) => paymentOption.id === selectedPaymentOption?.value) + minValue = selectedTransakFiatCurrencyPaymentOption?.minAmount + maxValue = selectedTransakFiatCurrencyPaymentOption?.maxAmount } $: updatePaymentOptions($transakFiatCurrencies, selectedCurrency) // Recipient Input let recipientInput let selectedRecipient: Subject | undefined - let minValue: number | undefined - let maxValue: number | undefined function updateSelectedRecipient( account: IAccountState | undefined, cryptoCurrency: TransakCryptoCurrency | undefined @@ -115,13 +121,6 @@ } } $: updateSelectedRecipient($selectedAccount, selectedCryptoCurrency) - $: { - const selectedTransakFiatCurrencyPaymentOption = $transakFiatCurrencies?.[ - selectedCurrency - ]?.paymentOptions?.find((paymentOption) => paymentOption.id === selectedPaymentOption?.value) - minValue = selectedTransakFiatCurrencyPaymentOption?.minAmount - maxValue = selectedTransakFiatCurrencyPaymentOption?.maxAmount - } // Quotations let quotes: { fiatAmount: number; cryptoAmount: number; provider: string }[] = [] @@ -129,9 +128,18 @@ let latestQuoteRequestId = 0 let loading = false async function updateQuote(): Promise { + const requestId = ++latestQuoteRequestId // Increment the request ID loading = true - stopQuoteTimer() selectedQuoteId = undefined + stopQuoteTimer() + if ( + (minValue !== undefined && Number(fiatValue) < minValue) || + (maxValue !== undefined && Number(fiatValue) > maxValue) + ) { + quotes = [] + loading = false + return + } if (!selectedPaymentOption) { loading = false @@ -149,7 +157,6 @@ quotes = [] - const requestId = ++latestQuoteRequestId // Increment the request ID const response = await getTransakPrice(params) // Only update the quote if this is the latest request @@ -171,7 +178,13 @@ loading = false } - $: selectedCurrency, selectedCryptoCurrency, selectedPaymentOption, fiatValue, void updateQuote() + $: selectedCurrency, + selectedCryptoCurrency, + selectedPaymentOption, + fiatValue, + minValue, + maxValue, + void updateQuote() // Quotations timer let displayedQuotationTime: string | null = null