Skip to content

Commit

Permalink
fix: logic so that no quotes are generated when value is outside min …
Browse files Browse the repository at this point in the history
…or max

Co-authored-by: Jean Ribeiro <[email protected]>
  • Loading branch information
nicole-obrien and jeeanribeiro committed Aug 8, 2024
1 parent 95e6694 commit 82069cb
Showing 1 changed file with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -115,23 +121,25 @@
}
}
$: 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 }[] = []
let selectedQuoteId: number | undefined = undefined
let latestQuoteRequestId = 0
let loading = false
async function updateQuote(): Promise<void> {
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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 82069cb

Please sign in to comment.