1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fixes related to swaps custom gas limit (#9858)

* Fixes related to swaps custom gas limit

* Update ui/app/pages/swaps/view-quote/view-quote.js

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>

* Move selectQuotePopover onSubmit dispatches to a single action creator

* Correct type of minimumGasLimit in view-quote.js

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
This commit is contained in:
Dan J Miller 2020-11-12 15:42:04 -03:30 committed by GitHub
parent 9df5be903b
commit 9849a9cf82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 12 deletions

View File

@ -23,6 +23,8 @@ import {
updateTransaction, updateTransaction,
resetBackgroundSwapsState, resetBackgroundSwapsState,
setSwapsLiveness, setSwapsLiveness,
setSelectedQuoteAggId,
setSwapsTxGasLimit,
} from '../../store/actions' } from '../../store/actions'
import { import {
AWAITING_SWAP_ROUTE, AWAITING_SWAP_ROUTE,
@ -95,6 +97,8 @@ const slice = createSlice({
state.approveTxId = null state.approveTxId = null
state.balanceError = false state.balanceError = false
state.fetchingQuotes = false state.fetchingQuotes = false
state.customGas.limit = null
state.customGas.price = null
}, },
retriedGetQuotes: (state) => { retriedGetQuotes: (state) => {
state.approveTxId = null state.approveTxId = null
@ -122,6 +126,10 @@ const slice = createSlice({
setToToken: (state, action) => { setToToken: (state, action) => {
state.toToken = action.payload state.toToken = action.payload
}, },
swapCustomGasModalClosed: (state) => {
state.customGas.price = null
state.customGas.limit = null
},
swapCustomGasModalPriceEdited: (state, action) => { swapCustomGasModalPriceEdited: (state, action) => {
state.customGas.price = action.payload state.customGas.price = action.payload
}, },
@ -299,6 +307,7 @@ const {
swapCustomGasModalPriceEdited, swapCustomGasModalPriceEdited,
swapCustomGasModalLimitEdited, swapCustomGasModalLimitEdited,
retrievedFallbackSwapsGasPrice, retrievedFallbackSwapsGasPrice,
swapCustomGasModalClosed,
} = actions } = actions
export { export {
@ -312,6 +321,7 @@ export {
setToToken as setSwapToToken, setToToken as setSwapToToken,
swapCustomGasModalPriceEdited, swapCustomGasModalPriceEdited,
swapCustomGasModalLimitEdited, swapCustomGasModalLimitEdited,
swapCustomGasModalClosed,
} }
export const navigateBackToBuildQuote = (history) => { export const navigateBackToBuildQuote = (history) => {
@ -339,6 +349,14 @@ export const prepareToLeaveSwaps = () => {
} }
} }
export const swapsQuoteSelected = (aggId) => {
return (dispatch) => {
dispatch(swapCustomGasModalLimitEdited(null))
dispatch(setSelectedQuoteAggId(aggId))
dispatch(setSwapsTxGasLimit(''))
}
}
export const fetchAndSetSwapsGasPriceInfo = () => { export const fetchAndSetSwapsGasPriceInfo = () => {
return async (dispatch) => { return async (dispatch) => {
const basicEstimates = await dispatch(fetchMetaSwapsGasPriceEstimates()) const basicEstimates = await dispatch(fetchMetaSwapsGasPriceEstimates())

View File

@ -1,4 +1,5 @@
import { connect } from 'react-redux' import { connect } from 'react-redux'
import BigNumber from 'bignumber.js'
import { hideModal, customSwapsGasParamsUpdated } from '../../../store/actions' import { hideModal, customSwapsGasParamsUpdated } from '../../../store/actions'
import { import {
conversionRateSelector as getConversionRate, conversionRateSelector as getConversionRate,
@ -18,6 +19,7 @@ import {
swapCustomGasModalPriceEdited, swapCustomGasModalPriceEdited,
swapCustomGasModalLimitEdited, swapCustomGasModalLimitEdited,
shouldShowCustomPriceTooLowWarning, shouldShowCustomPriceTooLowWarning,
swapCustomGasModalClosed,
} from '../../../ducks/swaps/swaps' } from '../../../ducks/swaps/swaps'
import { import {
@ -87,6 +89,11 @@ const mapStateToProps = (state) => {
conversionRate, conversionRate,
}) })
const customGasLimitTooLow = new BigNumber(customGasLimit, 16).lt(
minimumGasLimit,
10,
)
return { return {
customGasPrice, customGasPrice,
customGasLimit, customGasLimit,
@ -121,7 +128,7 @@ const mapStateToProps = (state) => {
customGasLimitMessage, customGasLimitMessage,
customTotalSupplement, customTotalSupplement,
usdConversionRate: getUSDConversionRate(state), usdConversionRate: getUSDConversionRate(state),
disableSave: insufficientBalance || customGasLimit < minimumGasLimit, disableSave: insufficientBalance || customGasLimitTooLow,
minimumGasLimit, minimumGasLimit,
} }
} }
@ -129,10 +136,12 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {
cancelAndClose: () => { cancelAndClose: () => {
dispatch(swapCustomGasModalClosed())
dispatch(hideModal()) dispatch(hideModal())
}, },
onSubmit: (gasLimit, gasPrice) => { onSubmit: async (gasLimit, gasPrice) => {
dispatch(customSwapsGasParamsUpdated(gasLimit, gasPrice)) await dispatch(customSwapsGasParamsUpdated(gasLimit, gasPrice))
dispatch(swapCustomGasModalClosed())
dispatch(hideModal()) dispatch(hideModal())
}, },
setSwapsCustomizationModalPrice: (newPrice) => { setSwapsCustomizationModalPrice: (newPrice) => {

View File

@ -11,7 +11,6 @@ import { useNewMetricEvent } from '../../../hooks/useMetricEvent'
import { useSwapsEthToken } from '../../../hooks/useSwapsEthToken' import { useSwapsEthToken } from '../../../hooks/useSwapsEthToken'
import { MetaMetricsContext } from '../../../contexts/metametrics.new' import { MetaMetricsContext } from '../../../contexts/metametrics.new'
import FeeCard from '../fee-card' import FeeCard from '../fee-card'
import { setCustomGasLimit } from '../../../ducks/gas/gas.duck'
import { import {
getQuotes, getQuotes,
getSelectedQuote, getSelectedQuote,
@ -27,6 +26,7 @@ import {
navigateBackToBuildQuote, navigateBackToBuildQuote,
signAndSendTransactions, signAndSendTransactions,
getBackgroundSwapRouteState, getBackgroundSwapRouteState,
swapsQuoteSelected,
} from '../../../ducks/swaps/swaps' } from '../../../ducks/swaps/swaps'
import { import {
conversionRateSelector, conversionRateSelector,
@ -39,8 +39,6 @@ import { getTokens } from '../../../ducks/metamask/metamask'
import { import {
safeRefetchQuotes, safeRefetchQuotes,
setCustomApproveTxData, setCustomApproveTxData,
setSwapsTxGasLimit,
setSelectedQuoteAggId,
setSwapsErrorKey, setSwapsErrorKey,
showModal, showModal,
} from '../../../store/actions' } from '../../../store/actions'
@ -445,7 +443,7 @@ export default function ViewQuote() {
: null, : null,
initialGasPrice: gasPrice, initialGasPrice: gasPrice,
initialGasLimit: maxGasLimit, initialGasLimit: maxGasLimit,
minimumGasLimit: nonCustomMaxGasLimit, minimumGasLimit: new BigNumber(nonCustomMaxGasLimit, 16).toNumber(),
}), }),
) )
@ -471,11 +469,7 @@ export default function ViewQuote() {
<SelectQuotePopover <SelectQuotePopover
quoteDataRows={renderablePopoverData} quoteDataRows={renderablePopoverData}
onClose={() => setSelectQuotePopoverShown(false)} onClose={() => setSelectQuotePopoverShown(false)}
onSubmit={(aggId) => { onSubmit={(aggId) => dispatch(swapsQuoteSelected(aggId))}
dispatch(setSelectedQuoteAggId(aggId))
dispatch(setCustomGasLimit(null))
dispatch(setSwapsTxGasLimit(''))
}}
swapToSymbol={destinationTokenSymbol} swapToSymbol={destinationTokenSymbol}
initialAggId={usedQuote.aggregator} initialAggId={usedQuote.aggregator}
onQuoteDetailsIsOpened={quoteDetailsOpened} onQuoteDetailsIsOpened={quoteDetailsOpened}