You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
4.2 KiB
150 lines
4.2 KiB
4 years ago
|
import { connect } from 'react-redux';
|
||
7 years ago
|
import {
|
||
6 years ago
|
getConversionRate,
|
||
|
getGasTotal,
|
||
6 years ago
|
getGasPrice,
|
||
6 years ago
|
getGasLimit,
|
||
|
getSendAmount,
|
||
6 years ago
|
getSendFromBalance,
|
||
|
getTokenBalance,
|
||
5 years ago
|
getSendMaxModeState,
|
||
|
getGasLoadingError,
|
||
|
gasFeeIsInError,
|
||
|
getGasButtonGroupShown,
|
||
5 years ago
|
getAdvancedInlineGasShown,
|
||
|
getCurrentEthBalance,
|
||
5 years ago
|
getSendToken,
|
||
5 years ago
|
getBasicGasEstimateLoadingStatus,
|
||
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
||
|
getDefaultActiveButtonIndex,
|
||
4 years ago
|
getIsMainnet,
|
||
4 years ago
|
getIsEthGasPriceFetched,
|
||
|
getNoGasPriceFetched,
|
||
4 years ago
|
} from '../../../../selectors';
|
||
|
import { isBalanceSufficient, calcGasTotal } from '../../send.utils';
|
||
|
import { calcMaxAmount } from '../send-amount-row/amount-max-button/amount-max-button.utils';
|
||
6 years ago
|
import {
|
||
|
showGasButtonGroup,
|
||
6 years ago
|
updateSendErrors,
|
||
4 years ago
|
} from '../../../../ducks/send/send.duck';
|
||
6 years ago
|
import {
|
||
|
resetCustomData,
|
||
6 years ago
|
setCustomGasPrice,
|
||
|
setCustomGasLimit,
|
||
4 years ago
|
} from '../../../../ducks/gas/gas.duck';
|
||
4 years ago
|
import {
|
||
|
showModal,
|
||
|
setGasPrice,
|
||
|
setGasLimit,
|
||
|
setGasTotal,
|
||
|
updateSendAmount,
|
||
4 years ago
|
} from '../../../../store/actions';
|
||
|
import SendGasRow from './send-gas-row.component';
|
||
7 years ago
|
|
||
4 years ago
|
export default connect(
|
||
|
mapStateToProps,
|
||
|
mapDispatchToProps,
|
||
|
mergeProps,
|
||
4 years ago
|
)(SendGasRow);
|
||
7 years ago
|
|
||
4 years ago
|
function mapStateToProps(state) {
|
||
4 years ago
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state);
|
||
|
const gasPrice = getGasPrice(state);
|
||
|
const gasLimit = getGasLimit(state);
|
||
|
const activeButtonIndex = getDefaultActiveButtonIndex(
|
||
|
gasButtonInfo,
|
||
|
gasPrice,
|
||
|
);
|
||
6 years ago
|
|
||
4 years ago
|
const gasTotal = getGasTotal(state);
|
||
|
const conversionRate = getConversionRate(state);
|
||
|
const balance = getCurrentEthBalance(state);
|
||
6 years ago
|
|
||
|
const insufficientBalance = !isBalanceSufficient({
|
||
5 years ago
|
amount: getSendToken(state) ? '0x0' : getSendAmount(state),
|
||
6 years ago
|
gasTotal,
|
||
|
balance,
|
||
|
conversionRate,
|
||
4 years ago
|
});
|
||
4 years ago
|
const isEthGasPrice = getIsEthGasPriceFetched(state);
|
||
|
const noGasPrice = getNoGasPriceFetched(state);
|
||
6 years ago
|
|
||
7 years ago
|
return {
|
||
6 years ago
|
balance: getSendFromBalance(state),
|
||
6 years ago
|
gasTotal,
|
||
7 years ago
|
gasFeeError: gasFeeIsInError(state),
|
||
|
gasLoadingError: getGasLoadingError(state),
|
||
6 years ago
|
gasPriceButtonGroupProps: {
|
||
|
buttonDataLoading: getBasicGasEstimateLoadingStatus(state),
|
||
|
defaultActiveButtonIndex: 1,
|
||
|
newActiveButtonIndex: activeButtonIndex > -1 ? activeButtonIndex : null,
|
||
|
gasButtonInfo,
|
||
|
},
|
||
|
gasButtonGroupShown: getGasButtonGroupShown(state),
|
||
6 years ago
|
advancedInlineGasShown: getAdvancedInlineGasShown(state),
|
||
6 years ago
|
gasPrice,
|
||
|
gasLimit,
|
||
6 years ago
|
insufficientBalance,
|
||
5 years ago
|
maxModeOn: getSendMaxModeState(state),
|
||
5 years ago
|
sendToken: getSendToken(state),
|
||
6 years ago
|
tokenBalance: getTokenBalance(state),
|
||
4 years ago
|
isMainnet: getIsMainnet(state),
|
||
4 years ago
|
isEthGasPrice,
|
||
|
noGasPrice,
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
function mapDispatchToProps(dispatch) {
|
||
7 years ago
|
return {
|
||
4 years ago
|
showCustomizeGasModal: () =>
|
||
|
dispatch(showModal({ name: 'CUSTOMIZE_GAS', hideBasic: true })),
|
||
4 years ago
|
setGasPrice: ({ gasPrice, gasLimit }) => {
|
||
4 years ago
|
dispatch(setGasPrice(gasPrice));
|
||
|
dispatch(setCustomGasPrice(gasPrice));
|
||
6 years ago
|
if (gasLimit) {
|
||
4 years ago
|
dispatch(setGasTotal(calcGasTotal(gasLimit, gasPrice)));
|
||
6 years ago
|
}
|
||
6 years ago
|
},
|
||
|
setGasLimit: (newLimit, gasPrice) => {
|
||
4 years ago
|
dispatch(setGasLimit(newLimit));
|
||
|
dispatch(setCustomGasLimit(newLimit));
|
||
6 years ago
|
if (gasPrice) {
|
||
4 years ago
|
dispatch(setGasTotal(calcGasTotal(newLimit, gasPrice)));
|
||
6 years ago
|
}
|
||
6 years ago
|
},
|
||
5 years ago
|
setAmountToMax: (maxAmountDataObject) => {
|
||
4 years ago
|
dispatch(updateSendErrors({ amount: null }));
|
||
|
dispatch(updateSendAmount(calcMaxAmount(maxAmountDataObject)));
|
||
6 years ago
|
},
|
||
6 years ago
|
showGasButtonGroup: () => dispatch(showGasButtonGroup()),
|
||
6 years ago
|
resetCustomData: () => dispatch(resetCustomData()),
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
4 years ago
|
function mergeProps(stateProps, dispatchProps, ownProps) {
|
||
4 years ago
|
const { gasPriceButtonGroupProps } = stateProps;
|
||
|
const { gasButtonInfo } = gasPriceButtonGroupProps;
|
||
6 years ago
|
const {
|
||
|
setGasPrice: dispatchSetGasPrice,
|
||
6 years ago
|
showGasButtonGroup: dispatchShowGasButtonGroup,
|
||
|
resetCustomData: dispatchResetCustomData,
|
||
6 years ago
|
...otherDispatchProps
|
||
4 years ago
|
} = dispatchProps;
|
||
6 years ago
|
|
||
|
return {
|
||
|
...stateProps,
|
||
|
...otherDispatchProps,
|
||
|
...ownProps,
|
||
|
gasPriceButtonGroupProps: {
|
||
|
...gasPriceButtonGroupProps,
|
||
|
handleGasPriceSelection: dispatchSetGasPrice,
|
||
|
},
|
||
6 years ago
|
resetGasButtons: () => {
|
||
4 years ago
|
dispatchResetCustomData();
|
||
|
dispatchSetGasPrice(gasButtonInfo[1].priceInHexWei);
|
||
|
dispatchShowGasButtonGroup();
|
||
6 years ago
|
},
|
||
6 years ago
|
setGasPrice: dispatchSetGasPrice,
|
||
4 years ago
|
};
|
||
6 years ago
|
}
|