1+ import { eq } from 'biggystring'
12import * as React from 'react'
23import { ActivityIndicator , Image , View } from 'react-native'
34import { sprintf } from 'sprintf-js'
45
56import paymentTypeLogoApplePay from '../../assets/images/paymentTypes/paymentTypeLogoApplePay.png'
7+ import { formatFiatString } from '../../hooks/useFiatText'
68import { useHandler } from '../../hooks/useHandler'
79import { useRampPlugins } from '../../hooks/useRampPlugins'
810import { useRampQuotes } from '../../hooks/useRampQuotes'
@@ -216,6 +218,9 @@ export const RampSelectOptionScene: React.FC<Props> = (props: Props) => {
216218 )
217219}
218220
221+ const quoteHasAmounts = ( quote : RampQuote ) : boolean =>
222+ ! eq ( quote . fiatAmount , '0' ) || ! eq ( quote . cryptoAmount , '0' )
223+
219224const QuoteResult : React . FC < {
220225 providerQuotes : RampQuote [ ]
221226 onPress : ( quote : RampQuote ) => Promise < void >
@@ -242,21 +247,26 @@ const QuoteResult: React.FC<{
242247
243248 // Create items array for the CardListModal
244249 const items = providerQuotes . map ( quote => {
245- // Format the quote amount display for each provider
246250 const fiatCurrencyCode = quote . fiatCurrencyCode . replace ( 'iso:' , '' )
247251 const cryptoCurrencyCode = quote . displayCurrencyCode
248- const formattedFiatAmount = formatNumber ( quote . fiatAmount , { toFixed : 2 } )
249252
250- // Show fiat → crypto for buy, crypto → fiat for sell
251- const body =
252- quote . direction === 'buy'
253- ? `${ formattedFiatAmount } ${ fiatCurrencyCode } → ${ quote . cryptoAmount } ${ cryptoCurrencyCode } `
254- : `${ quote . cryptoAmount } ${ cryptoCurrencyCode } → ${ formattedFiatAmount } ${ fiatCurrencyCode } `
253+ const body = quoteHasAmounts ( quote )
254+ ? quote . direction === 'buy'
255+ ? `${ formatFiatString ( {
256+ fiatAmount : quote . fiatAmount
257+ } ) } ${ fiatCurrencyCode } → ${
258+ quote . cryptoAmount
259+ } ${ cryptoCurrencyCode } `
260+ : `${ quote . cryptoAmount } ${ cryptoCurrencyCode } → ${ formatFiatString ( {
261+ fiatAmount : quote . fiatAmount
262+ } ) } ${ fiatCurrencyCode } `
263+ : quote . specialQuoteRateMessage ??
264+ lstrings . failed_to_calculate_quote_rate
255265
256266 return {
257267 key : quote . pluginId ,
258268 title : quote . pluginDisplayName ,
259- icon : quote . partnerIcon , // Already full path
269+ icon : quote . partnerIcon ,
260270 body
261271 }
262272 } )
@@ -285,16 +295,20 @@ const QuoteResult: React.FC<{
285295 }
286296
287297 // Check if the currently selected quote is the best rate
298+ const hasSelectedAmounts = quoteHasAmounts ( providerQuote )
299+
288300 const isBestOption =
301+ hasSelectedAmounts &&
289302 bestQuoteOverall != null &&
303+ quoteHasAmounts ( bestQuoteOverall ) &&
290304 providerQuote . pluginId === bestQuoteOverall . pluginId &&
291305 providerQuote . paymentType === bestQuoteOverall . paymentType &&
292306 providerQuote . fiatAmount === bestQuoteOverall . fiatAmount
293307
294308 const fiatCurrencyCode = providerQuote . fiatCurrencyCode . replace ( 'iso:' , '' )
295- const formattedSelectedFiatAmount = formatNumber ( providerQuote . fiatAmount , {
296- toFixed : 2
297- } )
309+ const formattedSelectedFiatAmount = hasSelectedAmounts
310+ ? formatNumber ( providerQuote . fiatAmount , { toFixed : 2 } )
311+ : ''
298312
299313 // Get the icon for the payment type
300314 const paymentTypeIcon = getPaymentTypeIcon ( providerQuote . paymentType , theme )
@@ -333,12 +347,17 @@ const QuoteResult: React.FC<{
333347 < PaymentOptionCard
334348 title = { titleComponent }
335349 icon = { icon }
336- totalAmount = { sprintf (
337- lstrings . string_total_amount_s ,
338- providerQuote . direction === 'buy'
339- ? `${ formattedSelectedFiatAmount } ${ fiatCurrencyCode } → ${ providerQuote . cryptoAmount } ${ providerQuote . displayCurrencyCode } `
340- : `${ providerQuote . cryptoAmount } ${ providerQuote . displayCurrencyCode } → ${ formattedSelectedFiatAmount } ${ fiatCurrencyCode } `
341- ) }
350+ totalAmount = {
351+ hasSelectedAmounts
352+ ? sprintf (
353+ lstrings . string_total_amount_s ,
354+ providerQuote . direction === 'buy'
355+ ? `${ formattedSelectedFiatAmount } ${ fiatCurrencyCode } → ${ providerQuote . cryptoAmount } ${ providerQuote . displayCurrencyCode } `
356+ : `${ providerQuote . cryptoAmount } ${ providerQuote . displayCurrencyCode } → ${ formattedSelectedFiatAmount } ${ fiatCurrencyCode } `
357+ )
358+ : providerQuote . specialQuoteRateMessage ??
359+ lstrings . tap_to_view_quote_amount_and_rate
360+ }
342361 settlementTime = { formatSettlementTime ( providerQuote . settlementRange ) }
343362 partner = { {
344363 displayName : providerQuote . pluginDisplayName ,
0 commit comments