mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Ensure that the correct default currency symbols are used for fees on the view quote screen (#10753)
This commit is contained in:
parent
8b3d96bc84
commit
76f4e93eb2
@ -1,3 +1,4 @@
|
|||||||
export function formatETHFee(ethFee) {
|
// TODO: Rename to reflect that this function is used for more cases than ETH, and update all uses.
|
||||||
return `${ethFee} ETH`;
|
export function formatETHFee(ethFee, currencySymbol = 'ETH') {
|
||||||
|
return `${ethFee} ${currencySymbol}`;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import {
|
|||||||
getDefaultActiveButtonIndex,
|
getDefaultActiveButtonIndex,
|
||||||
getRenderableGasButtonData,
|
getRenderableGasButtonData,
|
||||||
getUSDConversionRate,
|
getUSDConversionRate,
|
||||||
|
getNativeCurrency,
|
||||||
|
getSwapsDefaultToken,
|
||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -21,7 +23,6 @@ import {
|
|||||||
shouldShowCustomPriceTooLowWarning,
|
shouldShowCustomPriceTooLowWarning,
|
||||||
swapCustomGasModalClosed,
|
swapCustomGasModalClosed,
|
||||||
} from '../../../ducks/swaps/swaps';
|
} from '../../../ducks/swaps/swaps';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
addHexes,
|
addHexes,
|
||||||
getValueFromWeiHex,
|
getValueFromWeiHex,
|
||||||
@ -34,6 +35,9 @@ import SwapsGasCustomizationModalComponent from './swaps-gas-customization-modal
|
|||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const currentCurrency = getCurrentCurrency(state);
|
const currentCurrency = getCurrentCurrency(state);
|
||||||
const conversionRate = getConversionRate(state);
|
const conversionRate = getConversionRate(state);
|
||||||
|
const nativeCurrencySymbol = getNativeCurrency(state);
|
||||||
|
const { symbol: swapsDefaultCurrencySymbol } = getSwapsDefaultToken(state);
|
||||||
|
const usedCurrencySymbol = nativeCurrencySymbol || swapsDefaultCurrencySymbol;
|
||||||
|
|
||||||
const { modalState: { props: modalProps } = {} } = state.appState.modal || {};
|
const { modalState: { props: modalProps } = {} } = state.appState.modal || {};
|
||||||
const {
|
const {
|
||||||
@ -63,6 +67,7 @@ const mapStateToProps = (state) => {
|
|||||||
true,
|
true,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
|
usedCurrencySymbol,
|
||||||
);
|
);
|
||||||
const gasButtonInfo = [averageEstimateData, fastEstimateData];
|
const gasButtonInfo = [averageEstimateData, fastEstimateData];
|
||||||
|
|
||||||
@ -74,13 +79,15 @@ const mapStateToProps = (state) => {
|
|||||||
|
|
||||||
const balance = getCurrentEthBalance(state);
|
const balance = getCurrentEthBalance(state);
|
||||||
|
|
||||||
const newTotalEth = sumHexWEIsToRenderableEth([
|
const newTotalEth = sumHexWEIsToRenderableEth(
|
||||||
value,
|
[value, customGasTotal, customTotalSupplement],
|
||||||
customGasTotal,
|
usedCurrencySymbol,
|
||||||
customTotalSupplement,
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
const sendAmount = sumHexWEIsToRenderableEth([value, '0x0']);
|
const sendAmount = sumHexWEIsToRenderableEth(
|
||||||
|
[value, '0x0'],
|
||||||
|
usedCurrencySymbol,
|
||||||
|
);
|
||||||
|
|
||||||
const insufficientBalance = !isBalanceSufficient({
|
const insufficientBalance = !isBalanceSufficient({
|
||||||
amount: value,
|
amount: value,
|
||||||
@ -112,14 +119,16 @@ const mapStateToProps = (state) => {
|
|||||||
currentCurrency,
|
currentCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
),
|
),
|
||||||
originalTotalEth: sumHexWEIsToRenderableEth([
|
originalTotalEth: sumHexWEIsToRenderableEth(
|
||||||
value,
|
[value, customGasTotal, customTotalSupplement],
|
||||||
customGasTotal,
|
usedCurrencySymbol,
|
||||||
customTotalSupplement,
|
),
|
||||||
]),
|
|
||||||
newTotalFiat,
|
newTotalFiat,
|
||||||
newTotalEth,
|
newTotalEth,
|
||||||
transactionFee: sumHexWEIsToRenderableEth(['0x0', customGasTotal]),
|
transactionFee: sumHexWEIsToRenderableEth(
|
||||||
|
['0x0', customGasTotal],
|
||||||
|
usedCurrencySymbol,
|
||||||
|
),
|
||||||
sendAmount,
|
sendAmount,
|
||||||
extraInfoRow,
|
extraInfoRow,
|
||||||
},
|
},
|
||||||
@ -158,13 +167,15 @@ export default connect(
|
|||||||
mapDispatchToProps,
|
mapDispatchToProps,
|
||||||
)(SwapsGasCustomizationModalComponent);
|
)(SwapsGasCustomizationModalComponent);
|
||||||
|
|
||||||
function sumHexWEIsToRenderableEth(hexWEIs) {
|
function sumHexWEIsToRenderableEth(hexWEIs, currencySymbol = 'ETH') {
|
||||||
const hexWEIsSum = hexWEIs.filter(Boolean).reduce(addHexes);
|
const hexWEIsSum = hexWEIs.filter(Boolean).reduce(addHexes);
|
||||||
return formatETHFee(
|
return formatETHFee(
|
||||||
getValueFromWeiHex({
|
getValueFromWeiHex({
|
||||||
value: hexWEIsSum,
|
value: hexWEIsSum,
|
||||||
toCurrency: 'ETH',
|
fromCurrency: currencySymbol,
|
||||||
|
toCurrency: currencySymbol,
|
||||||
numberOfDecimals: 6,
|
numberOfDecimals: 6,
|
||||||
}),
|
}),
|
||||||
|
currencySymbol,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -427,6 +427,7 @@ export function getRenderableNetworkFeesForQuote({
|
|||||||
sourceSymbol,
|
sourceSymbol,
|
||||||
sourceAmount,
|
sourceAmount,
|
||||||
chainId,
|
chainId,
|
||||||
|
nativeCurrencySymbol,
|
||||||
}) {
|
}) {
|
||||||
const totalGasLimitForCalculation = new BigNumber(tradeGas || '0x0', 16)
|
const totalGasLimitForCalculation = new BigNumber(tradeGas || '0x0', 16)
|
||||||
.plus(approveGas || '0x0', 16)
|
.plus(approveGas || '0x0', 16)
|
||||||
@ -456,11 +457,15 @@ export function getRenderableNetworkFeesForQuote({
|
|||||||
numberOfDecimals: 2,
|
numberOfDecimals: 2,
|
||||||
});
|
});
|
||||||
const formattedNetworkFee = formatCurrency(rawNetworkFees, currentCurrency);
|
const formattedNetworkFee = formatCurrency(rawNetworkFees, currentCurrency);
|
||||||
|
|
||||||
|
const chainCurrencySymbolToUse =
|
||||||
|
nativeCurrencySymbol || SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId].symbol;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rawNetworkFees,
|
rawNetworkFees,
|
||||||
rawEthFee: ethFee,
|
rawEthFee: ethFee,
|
||||||
feeInFiat: formattedNetworkFee,
|
feeInFiat: formattedNetworkFee,
|
||||||
feeInEth: `${ethFee} ${SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId].symbol}`,
|
feeInEth: `${ethFee} ${chainCurrencySymbolToUse}`,
|
||||||
nonGasFee,
|
nonGasFee,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ import {
|
|||||||
getTokenExchangeRates,
|
getTokenExchangeRates,
|
||||||
getSwapsDefaultToken,
|
getSwapsDefaultToken,
|
||||||
getCurrentChainId,
|
getCurrentChainId,
|
||||||
|
getNativeCurrency,
|
||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util';
|
import { toPrecisionWithoutTrailingZeros } from '../../../helpers/utils/util';
|
||||||
import { getTokens } from '../../../ducks/metamask/metamask';
|
import { getTokens } from '../../../ducks/metamask/metamask';
|
||||||
@ -128,6 +129,7 @@ export default function ViewQuote() {
|
|||||||
const swapsQuoteRefreshTime = useSelector(getSwapsQuoteRefreshTime);
|
const swapsQuoteRefreshTime = useSelector(getSwapsQuoteRefreshTime);
|
||||||
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
const defaultSwapsToken = useSelector(getSwapsDefaultToken);
|
||||||
const chainId = useSelector(getCurrentChainId);
|
const chainId = useSelector(getCurrentChainId);
|
||||||
|
const nativeCurrencySymbol = useSelector(getNativeCurrency);
|
||||||
|
|
||||||
const { isBestQuote } = usedQuote;
|
const { isBestQuote } = usedQuote;
|
||||||
|
|
||||||
@ -223,6 +225,7 @@ export default function ViewQuote() {
|
|||||||
sourceSymbol: sourceTokenSymbol,
|
sourceSymbol: sourceTokenSymbol,
|
||||||
sourceAmount: usedQuote.sourceAmount,
|
sourceAmount: usedQuote.sourceAmount,
|
||||||
chainId,
|
chainId,
|
||||||
|
nativeCurrencySymbol,
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -239,6 +242,7 @@ export default function ViewQuote() {
|
|||||||
sourceSymbol: sourceTokenSymbol,
|
sourceSymbol: sourceTokenSymbol,
|
||||||
sourceAmount: usedQuote.sourceAmount,
|
sourceAmount: usedQuote.sourceAmount,
|
||||||
chainId,
|
chainId,
|
||||||
|
nativeCurrencySymbol,
|
||||||
});
|
});
|
||||||
|
|
||||||
const tokenCost = new BigNumber(usedQuote.sourceAmount);
|
const tokenCost = new BigNumber(usedQuote.sourceAmount);
|
||||||
|
@ -134,13 +134,18 @@ export function basicPriceEstimateToETHTotal(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRenderableEthFee(estimate, gasLimit, numberOfDecimals = 9) {
|
export function getRenderableEthFee(
|
||||||
|
estimate,
|
||||||
|
gasLimit,
|
||||||
|
numberOfDecimals = 9,
|
||||||
|
nativeCurrency = 'ETH',
|
||||||
|
) {
|
||||||
const value = conversionUtil(estimate, {
|
const value = conversionUtil(estimate, {
|
||||||
fromNumericBase: 'dec',
|
fromNumericBase: 'dec',
|
||||||
toNumericBase: 'hex',
|
toNumericBase: 'hex',
|
||||||
});
|
});
|
||||||
const fee = basicPriceEstimateToETHTotal(value, gasLimit, numberOfDecimals);
|
const fee = basicPriceEstimateToETHTotal(value, gasLimit, numberOfDecimals);
|
||||||
return formatETHFee(fee);
|
return formatETHFee(fee, nativeCurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRenderableConvertedCurrencyFee(
|
export function getRenderableConvertedCurrencyFee(
|
||||||
@ -186,12 +191,18 @@ export function getRenderableGasButtonData(
|
|||||||
showFiat,
|
showFiat,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
|
nativeCurrency,
|
||||||
) {
|
) {
|
||||||
const { safeLow, average, fast } = estimates;
|
const { safeLow, average, fast } = estimates;
|
||||||
|
|
||||||
const slowEstimateData = {
|
const slowEstimateData = {
|
||||||
gasEstimateType: GAS_ESTIMATE_TYPES.SLOW,
|
gasEstimateType: GAS_ESTIMATE_TYPES.SLOW,
|
||||||
feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit),
|
feeInPrimaryCurrency: getRenderableEthFee(
|
||||||
|
safeLow,
|
||||||
|
gasLimit,
|
||||||
|
9,
|
||||||
|
nativeCurrency,
|
||||||
|
),
|
||||||
feeInSecondaryCurrency: showFiat
|
feeInSecondaryCurrency: showFiat
|
||||||
? getRenderableConvertedCurrencyFee(
|
? getRenderableConvertedCurrencyFee(
|
||||||
safeLow,
|
safeLow,
|
||||||
@ -204,7 +215,12 @@ export function getRenderableGasButtonData(
|
|||||||
};
|
};
|
||||||
const averageEstimateData = {
|
const averageEstimateData = {
|
||||||
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
|
gasEstimateType: GAS_ESTIMATE_TYPES.AVERAGE,
|
||||||
feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit),
|
feeInPrimaryCurrency: getRenderableEthFee(
|
||||||
|
average,
|
||||||
|
gasLimit,
|
||||||
|
9,
|
||||||
|
nativeCurrency,
|
||||||
|
),
|
||||||
feeInSecondaryCurrency: showFiat
|
feeInSecondaryCurrency: showFiat
|
||||||
? getRenderableConvertedCurrencyFee(
|
? getRenderableConvertedCurrencyFee(
|
||||||
average,
|
average,
|
||||||
@ -217,7 +233,12 @@ export function getRenderableGasButtonData(
|
|||||||
};
|
};
|
||||||
const fastEstimateData = {
|
const fastEstimateData = {
|
||||||
gasEstimateType: GAS_ESTIMATE_TYPES.FAST,
|
gasEstimateType: GAS_ESTIMATE_TYPES.FAST,
|
||||||
feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit),
|
feeInPrimaryCurrency: getRenderableEthFee(
|
||||||
|
fast,
|
||||||
|
gasLimit,
|
||||||
|
9,
|
||||||
|
nativeCurrency,
|
||||||
|
),
|
||||||
feeInSecondaryCurrency: showFiat
|
feeInSecondaryCurrency: showFiat
|
||||||
? getRenderableConvertedCurrencyFee(
|
? getRenderableConvertedCurrencyFee(
|
||||||
fast,
|
fast,
|
||||||
@ -295,7 +316,6 @@ export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) {
|
|||||||
safeLow,
|
safeLow,
|
||||||
gasLimit,
|
gasLimit,
|
||||||
NUMBER_OF_DECIMALS_SM_BTNS,
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
||||||
true,
|
|
||||||
),
|
),
|
||||||
priceInHexWei: getGasPriceInHexWei(safeLow, true),
|
priceInHexWei: getGasPriceInHexWei(safeLow, true),
|
||||||
},
|
},
|
||||||
@ -313,7 +333,6 @@ export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) {
|
|||||||
average,
|
average,
|
||||||
gasLimit,
|
gasLimit,
|
||||||
NUMBER_OF_DECIMALS_SM_BTNS,
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
||||||
true,
|
|
||||||
),
|
),
|
||||||
priceInHexWei: getGasPriceInHexWei(average, true),
|
priceInHexWei: getGasPriceInHexWei(average, true),
|
||||||
},
|
},
|
||||||
@ -331,7 +350,6 @@ export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) {
|
|||||||
fast,
|
fast,
|
||||||
gasLimit,
|
gasLimit,
|
||||||
NUMBER_OF_DECIMALS_SM_BTNS,
|
NUMBER_OF_DECIMALS_SM_BTNS,
|
||||||
true,
|
|
||||||
),
|
),
|
||||||
priceInHexWei: getGasPriceInHexWei(fast, true),
|
priceInHexWei: getGasPriceInHexWei(fast, true),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user