diff --git a/src/store/shop/shop.models.ts b/src/store/shop/shop.models.ts index 2804bbba9b..fcb71eda56 100644 --- a/src/store/shop/shop.models.ts +++ b/src/store/shop/shop.models.ts @@ -178,6 +178,7 @@ export interface Invoice { threshold: number; }; }; + usdAmount: number; } export interface PhoneCountryInfo { diff --git a/src/store/wallet/effects/send/send.ts b/src/store/wallet/effects/send/send.ts index 05e3ea8076..ebbb95a56e 100644 --- a/src/store/wallet/effects/send/send.ts +++ b/src/store/wallet/effects/send/send.ts @@ -354,15 +354,31 @@ export const getNonce = ( }; export const getInvoiceEffectiveRate = - (invoice: Invoice, coin: string, chain: string): Effect => + ( + invoice: Invoice, + defaultAltCurrencyIsoCode: string, + coin: string, + chain: string, + ): Effect => dispatch => { const precision = dispatch(GetPrecision(coin, chain)); + if (!precision) { + return undefined; + } + const invoiceCurrency = getCurrencyCodeFromCoinAndChain(coin, chain); - return ( - precision && - invoice.price / - (invoice.paymentSubtotals[invoiceCurrency] / precision.unitToSatoshi) - ); + const toUnit = + invoice.paymentSubtotals[invoiceCurrency] / precision.unitToSatoshi; + + if (defaultAltCurrencyIsoCode === 'USD') { + return invoice.usdAmount / toUnit; + } + + if (defaultAltCurrencyIsoCode === invoice.currency) { + return invoice.price / toUnit; + } + + return undefined; }; /* @@ -445,11 +461,17 @@ export const buildTxDetails = } amount = Number(amount); // Support BN (use number instead string only for view) - const effectiveRate = - (invoice && - invoiceCurrency && - dispatch(getInvoiceEffectiveRate(invoice, invoiceCurrency, chain))) || - undefined; + let effectiveRate; + if (invoice && invoiceCurrency) { + effectiveRate = dispatch( + getInvoiceEffectiveRate( + invoice, + defaultAltCurrencyIsoCode, + invoiceCurrency, + chain, + ), + ); + } const opts = { effectiveRate, defaultAltCurrencyIsoCode,