1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 15:35:46 +01:00
metamask-extension/ui/pages/send/send-content/send-gas-row/send-gas-row.container.js

112 lines
3.1 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2018-04-11 16:21:54 +02:00
import {
getBasicGasEstimateLoadingStatus,
getRenderableEstimateDataForSmallButtonsFromGWEI,
getDefaultActiveButtonIndex,
getAdvancedInlineGasShown,
} from '../../../../selectors';
import {
getGasTotal,
getGasPrice,
getGasLimit,
gasFeeIsInError,
getGasInputMode,
updateGasPrice,
updateGasLimit,
isSendStateInitialized,
getIsBalanceInsufficient,
getMinimumGasLimitForSend,
useDefaultGas,
} from '../../../../ducks/send';
import {
resetCustomData,
setCustomGasPrice,
setCustomGasLimit,
} from '../../../../ducks/gas/gas.duck';
import { showModal } from '../../../../store/actions';
import { hexToDecimal } from '../../../../helpers/utils/conversions.util';
import SendGasRow from './send-gas-row.component';
2018-04-11 16:21:54 +02:00
2020-11-03 00:41:28 +01:00
export default connect(
mapStateToProps,
mapDispatchToProps,
mergeProps,
)(SendGasRow);
2018-04-11 16:21:54 +02:00
2020-11-03 00:41:28 +01:00
function mapStateToProps(state) {
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state);
const gasPrice = getGasPrice(state);
const gasLimit = getGasLimit(state);
const activeButtonIndex = getDefaultActiveButtonIndex(
gasButtonInfo,
gasPrice,
);
const gasTotal = getGasTotal(state);
const minimumGasLimit = getMinimumGasLimitForSend(state);
2018-04-11 16:21:54 +02:00
return {
gasTotal,
minimumGasLimit: hexToDecimal(minimumGasLimit),
2018-06-29 19:19:40 +02:00
gasFeeError: gasFeeIsInError(state),
gasLoadingError: isSendStateInitialized(state),
gasPriceButtonGroupProps: {
buttonDataLoading: getBasicGasEstimateLoadingStatus(state),
defaultActiveButtonIndex: 1,
newActiveButtonIndex: activeButtonIndex > -1 ? activeButtonIndex : null,
gasButtonInfo,
},
advancedInlineGasShown: getAdvancedInlineGasShown(state),
gasInputMode: getGasInputMode(state),
2019-02-08 14:50:25 +01:00
gasPrice,
gasLimit,
insufficientBalance: getIsBalanceInsufficient(state),
};
2018-04-11 16:21:54 +02:00
}
2020-11-03 00:41:28 +01:00
function mapDispatchToProps(dispatch) {
2018-04-11 16:21:54 +02:00
return {
showLegacyCustomizeGasModal: () =>
dispatch(showModal({ name: 'LEGACY_CUSTOMIZE_GAS', hideBasic: true })),
updateGasPrice: (gasPrice) => {
dispatch(updateGasPrice(gasPrice));
dispatch(setCustomGasPrice(gasPrice));
},
updateGasLimit: (newLimit) => {
dispatch(updateGasLimit(newLimit));
dispatch(setCustomGasLimit(newLimit));
},
resetCustomData: () => dispatch(resetCustomData()),
useDefaultGas: () => dispatch(useDefaultGas()),
};
2018-04-11 16:21:54 +02:00
}
2020-11-03 00:41:28 +01:00
function mergeProps(stateProps, dispatchProps, ownProps) {
const { gasPriceButtonGroupProps } = stateProps;
const { gasButtonInfo } = gasPriceButtonGroupProps;
const {
updateGasPrice: dispatchUpdateGasPrice,
useDefaultGas: dispatchUseDefaultGas,
resetCustomData: dispatchResetCustomData,
...otherDispatchProps
} = dispatchProps;
return {
...stateProps,
...otherDispatchProps,
...ownProps,
gasPriceButtonGroupProps: {
...gasPriceButtonGroupProps,
handleGasPriceSelection: ({ gasPrice }) =>
dispatchUpdateGasPrice(gasPrice),
},
resetGasButtons: () => {
dispatchResetCustomData();
dispatchUpdateGasPrice(gasButtonInfo[1].priceInHexWei);
dispatchUseDefaultGas();
},
updateGasPrice: dispatchUpdateGasPrice,
};
}