1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-11 20:27:12 +01:00
metamask-extension/ui/app/pages/swaps/swaps-gas-customization-modal/swaps-gas-customization-modal.container.js
MetaMask Bot 14b5c389ed
Version v9.3.0 RC (#10739)
* Replace logic for eth swap token in fetchQuotesAndSetQuoteState with getSwapsEthToken call (#10624)

* Move swaps constants to the shared constants directory (#10614)

* Fix: ETH 'token' now only appears once in the swaps to and from dropdowns. (#10650)

* Swaps support for local testnet (#10658)

* Swaps support for local testnet

* Create util method for comparison of token addresses/symbols to default swaps token

* Get chainId from txMeta in _trackSwapsMetrics of transaction controller

* Add comment to document purpose of getTransactionGroupRecipientAddressFilter

* Use isSwapsDefaultTokenSymbol in place of repeated defaultTokenSymbol comparisons in build-quote.js

* Additional swaps network support (#10721)

* Add swaps support for bnc chain

* Use single default token address in shared/constants/swaps

* Ensure swaps gas prices are fetched from the correct chain specific endpoint (#10744)

* Ensure swaps gas prices are fetched from the correct chain specific endpoint

* Just rely on fetchWithCache to cache swaps gas prices, instead of directly using storage in getSwapsPriceEstimatesLastRetrieved

* Empty commit

* update @metamask/etherscan-link to v2.0.0 (#10747)

* Use correct block explorer name and link in swaps when on custom network (#10743)

* Use correct block explorer name and link in swaps when on custom network.

* Fix up custom etherscan link code in build-quote.js

* Use blockExplorerUrl hostname instead of 'blockExplorerBaseUrl'

* Use correct etherscan-link method for token links in build-quote

* Create correct token link in build-quote for mainnet AND custom networks

* Block explorer url improvements in awaiting-swap.js and build-quote.js

* Use swapVerifyTokenExplanation message with substitutable block explorer for all applicable locales

* Ensure that block explorer links are not shown in awaiting-swap if no url is available

* Ensure that the correct default currency symbols are used for fees on the view quote screen (#10753)

* Updating y18n and netmask to resolve dependency issues (#10765)

netmask@1.0.6 -> 2.0.1, y18n@3.2.1 -> 3.2.2, y18n@4.0.0 -> 4.0.1

* Ensure that priceSlippage fiat amounts are always shown in view-quote.js (#10762)

* Ensure that the approval fee in the swaps custom gas modal is in network specific currency (#10763)

* Use network specific swaps contract address when checking swap contract token approval (#10774)

* Set the BSC_CONTRACT_ADDRESS to lowercase (#10800)

* Ensure correct primary currency image is displayed on home screen and token list (#10777)

* [skip e2e] Update changelog for v9.3.0 (#10740)

* Version v9.3.0

* [skip e2e] Update changelog for v9.3.0 (#10803)

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
Co-authored-by: ryanml <ryanlanese@gmail.com>
Co-authored-by: David Walsh <davidwalsh83@gmail.com>
Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
2021-04-02 17:00:57 -02:30

182 lines
5.3 KiB
JavaScript

import { connect } from 'react-redux';
import BigNumber from 'bignumber.js';
import { hideModal, customSwapsGasParamsUpdated } from '../../../store/actions';
import {
conversionRateSelector as getConversionRate,
getCurrentCurrency,
getCurrentEthBalance,
getDefaultActiveButtonIndex,
getRenderableGasButtonData,
getUSDConversionRate,
getNativeCurrency,
getSwapsDefaultToken,
} from '../../../selectors';
import {
getSwapsCustomizationModalPrice,
getSwapsCustomizationModalLimit,
swapGasEstimateLoadingHasFailed,
swapGasPriceEstimateIsLoading,
getSwapGasPriceEstimateData,
swapCustomGasModalPriceEdited,
swapCustomGasModalLimitEdited,
shouldShowCustomPriceTooLowWarning,
swapCustomGasModalClosed,
} from '../../../ducks/swaps/swaps';
import {
addHexes,
getValueFromWeiHex,
sumHexWEIsToRenderableFiat,
} from '../../../helpers/utils/conversions.util';
import { formatETHFee } from '../../../helpers/utils/formatters';
import { calcGasTotal, isBalanceSufficient } from '../../send/send.utils';
import SwapsGasCustomizationModalComponent from './swaps-gas-customization-modal.component';
const mapStateToProps = (state) => {
const currentCurrency = getCurrentCurrency(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 {
value,
customGasLimitMessage = '',
customTotalSupplement = '',
extraInfoRow = null,
initialGasPrice,
initialGasLimit,
minimumGasLimit,
} = modalProps;
const buttonDataLoading = swapGasPriceEstimateIsLoading(state);
const swapsCustomizationModalPrice = getSwapsCustomizationModalPrice(state);
const swapsCustomizationModalLimit = getSwapsCustomizationModalLimit(state);
const customGasPrice = swapsCustomizationModalPrice || initialGasPrice;
const customGasLimit = swapsCustomizationModalLimit || initialGasLimit;
const customGasTotal = calcGasTotal(customGasLimit, customGasPrice);
const swapsGasPriceEstimates = getSwapGasPriceEstimateData(state);
const { averageEstimateData, fastEstimateData } = getRenderableGasButtonData(
swapsGasPriceEstimates,
customGasLimit,
true,
conversionRate,
currentCurrency,
usedCurrencySymbol,
);
const gasButtonInfo = [averageEstimateData, fastEstimateData];
const newTotalFiat = sumHexWEIsToRenderableFiat(
[value, customGasTotal, customTotalSupplement],
currentCurrency,
conversionRate,
);
const balance = getCurrentEthBalance(state);
const newTotalEth = sumHexWEIsToRenderableEth(
[value, customGasTotal, customTotalSupplement],
usedCurrencySymbol,
);
const sendAmount = sumHexWEIsToRenderableEth(
[value, '0x0'],
usedCurrencySymbol,
);
const insufficientBalance = !isBalanceSufficient({
amount: value,
gasTotal: customGasTotal,
balance,
conversionRate,
});
const customGasLimitTooLow = new BigNumber(customGasLimit, 16).lt(
minimumGasLimit,
10,
);
return {
customGasPrice,
customGasLimit,
showCustomPriceTooLowWarning: shouldShowCustomPriceTooLowWarning(state),
gasPriceButtonGroupProps: {
buttonDataLoading,
defaultActiveButtonIndex: getDefaultActiveButtonIndex(
gasButtonInfo,
customGasPrice,
),
gasButtonInfo,
},
infoRowProps: {
originalTotalFiat: sumHexWEIsToRenderableFiat(
[value, customGasTotal, customTotalSupplement],
currentCurrency,
conversionRate,
),
originalTotalEth: sumHexWEIsToRenderableEth(
[value, customGasTotal, customTotalSupplement],
usedCurrencySymbol,
),
newTotalFiat,
newTotalEth,
transactionFee: sumHexWEIsToRenderableEth(
['0x0', customGasTotal],
usedCurrencySymbol,
),
sendAmount,
extraInfoRow,
},
gasEstimateLoadingHasFailed: swapGasEstimateLoadingHasFailed(state),
insufficientBalance,
customGasLimitMessage,
customTotalSupplement,
usdConversionRate: getUSDConversionRate(state),
disableSave: insufficientBalance || customGasLimitTooLow,
minimumGasLimit,
};
};
const mapDispatchToProps = (dispatch) => {
return {
cancelAndClose: () => {
dispatch(swapCustomGasModalClosed());
dispatch(hideModal());
},
onSubmit: async (gasLimit, gasPrice) => {
await dispatch(customSwapsGasParamsUpdated(gasLimit, gasPrice));
dispatch(swapCustomGasModalClosed());
dispatch(hideModal());
},
setSwapsCustomizationModalPrice: (newPrice) => {
dispatch(swapCustomGasModalPriceEdited(newPrice));
},
setSwapsCustomizationModalLimit: (newLimit) => {
dispatch(swapCustomGasModalLimitEdited(newLimit));
},
};
};
export default connect(
mapStateToProps,
mapDispatchToProps,
)(SwapsGasCustomizationModalComponent);
function sumHexWEIsToRenderableEth(hexWEIs, currencySymbol = 'ETH') {
const hexWEIsSum = hexWEIs.filter(Boolean).reduce(addHexes);
return formatETHFee(
getValueFromWeiHex({
value: hexWEIsSum,
fromCurrency: currencySymbol,
toCurrency: currencySymbol,
numberOfDecimals: 6,
}),
currencySymbol,
);
}