Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] rate calculation when creating using crypto amount instead of usd #941

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/store/shop/shop.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export interface Invoice {
threshold: number;
};
};
usdAmount: number;
}

export interface PhoneCountryInfo {
Expand Down
29 changes: 17 additions & 12 deletions src/store/wallet/effects/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,17 @@ export const buildTxDetails =
fee = proposal.fee || 0; // proposal fee is zero for coinbase
}

const invoiceCurrency =
const selectedTransactionCurrency =
invoice?.buyerProvidedInfo!.selectedTransactionCurrency ||
wallet.currencyAbbreviation.toUpperCase();

const isOffChain = !proposal;
if (invoice && invoiceCurrency) {
if (invoice && selectedTransactionCurrency) {
amount = isOffChain
? invoice.paymentSubtotals[invoiceCurrency]
: invoice.paymentTotals[invoiceCurrency];
? invoice.paymentSubtotals[selectedTransactionCurrency]
: invoice.paymentTotals[selectedTransactionCurrency];
const coinAndChain = getCoinAndChainFromCurrencyCode(
invoiceCurrency.toLowerCase(),
selectedTransactionCurrency.toLowerCase(),
);
coin = coinAndChain.coin;
chain = coinAndChain.chain;
Expand All @@ -445,11 +445,16 @@ 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 &&
selectedTransactionCurrency &&
defaultAltCurrencyIsoCode === invoice.currency
) {
effectiveRate = dispatch(
getInvoiceEffectiveRate(invoice, selectedTransactionCurrency, chain),
);
}
const opts = {
effectiveRate,
defaultAltCurrencyIsoCode,
Expand All @@ -460,8 +465,8 @@ export const buildTxDetails =
const rateStr = getRateStr(opts);
const networkCost =
!isOffChain &&
invoiceCurrency &&
invoice?.minerFees[invoiceCurrency]?.totalFee;
selectedTransactionCurrency &&
invoice?.minerFees[selectedTransactionCurrency]?.totalFee;
const isERC20 = IsERCToken(coin, chain);
const effectiveRateForFee = isERC20 ? undefined : effectiveRate; // always use chain rates for fee values

Expand Down