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.
137 lines
3.9 KiB
137 lines
3.9 KiB
4 years ago
|
import { connect } from 'react-redux';
|
||
|
import { withRouter } from 'react-router-dom';
|
||
|
import { compose } from 'redux';
|
||
6 years ago
|
|
||
7 years ago
|
import {
|
||
7 years ago
|
getBlockGasLimit,
|
||
7 years ago
|
getConversionRate,
|
||
|
getGasLimit,
|
||
|
getGasPrice,
|
||
|
getGasTotal,
|
||
|
getPrimaryCurrency,
|
||
5 years ago
|
getSendToken,
|
||
|
getSendTokenContract,
|
||
7 years ago
|
getSendAmount,
|
||
|
getSendEditingTransactionId,
|
||
6 years ago
|
getSendHexDataFeatureFlagState,
|
||
7 years ago
|
getSendFromObject,
|
||
7 years ago
|
getSendTo,
|
||
5 years ago
|
getSendToNickname,
|
||
7 years ago
|
getTokenBalance,
|
||
6 years ago
|
getQrCodeData,
|
||
5 years ago
|
getSelectedAddress,
|
||
5 years ago
|
getAddressBook,
|
||
4 years ago
|
getSendTokenAddress,
|
||
4 years ago
|
isCustomPriceExcessive,
|
||
4 years ago
|
getCurrentChainId,
|
||
4 years ago
|
} from '../../selectors';
|
||
5 years ago
|
|
||
7 years ago
|
import {
|
||
6 years ago
|
updateSendTo,
|
||
7 years ago
|
updateSendTokenBalance,
|
||
7 years ago
|
updateGasData,
|
||
7 years ago
|
setGasTotal,
|
||
6 years ago
|
showQrScanner,
|
||
6 years ago
|
qrCodeDetected,
|
||
5 years ago
|
updateSendEnsResolution,
|
||
|
updateSendEnsResolutionError,
|
||
4 years ago
|
} from '../../store/actions';
|
||
|
import { resetSendState, updateSendErrors } from '../../ducks/send/send.duck';
|
||
|
import { fetchBasicGasEstimates } from '../../ducks/gas/gas.duck';
|
||
|
import { getTokens } from '../../ducks/metamask/metamask';
|
||
|
import { isValidDomainName } from '../../helpers/utils/util';
|
||
|
import { calcGasTotal } from './send.utils';
|
||
|
import SendEther from './send.component';
|
||
7 years ago
|
|
||
4 years ago
|
function mapStateToProps(state) {
|
||
4 years ago
|
const editingTransactionId = getSendEditingTransactionId(state);
|
||
5 years ago
|
|
||
7 years ago
|
return {
|
||
5 years ago
|
addressBook: getAddressBook(state),
|
||
7 years ago
|
amount: getSendAmount(state),
|
||
7 years ago
|
blockGasLimit: getBlockGasLimit(state),
|
||
7 years ago
|
conversionRate: getConversionRate(state),
|
||
5 years ago
|
editingTransactionId,
|
||
5 years ago
|
from: getSendFromObject(state),
|
||
7 years ago
|
gasLimit: getGasLimit(state),
|
||
|
gasPrice: getGasPrice(state),
|
||
|
gasTotal: getGasTotal(state),
|
||
4 years ago
|
chainId: getCurrentChainId(state),
|
||
7 years ago
|
primaryCurrency: getPrimaryCurrency(state),
|
||
5 years ago
|
qrCodeData: getQrCodeData(state),
|
||
7 years ago
|
selectedAddress: getSelectedAddress(state),
|
||
5 years ago
|
sendToken: getSendToken(state),
|
||
6 years ago
|
showHexData: getSendHexDataFeatureFlagState(state),
|
||
7 years ago
|
to: getSendTo(state),
|
||
5 years ago
|
toNickname: getSendToNickname(state),
|
||
|
tokens: getTokens(state),
|
||
7 years ago
|
tokenBalance: getTokenBalance(state),
|
||
5 years ago
|
tokenContract: getSendTokenContract(state),
|
||
4 years ago
|
sendTokenAddress: getSendTokenAddress(state),
|
||
4 years ago
|
gasIsExcessive: isCustomPriceExcessive(state, true),
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
function mapDispatchToProps(dispatch) {
|
||
7 years ago
|
return {
|
||
6 years ago
|
updateAndSetGasLimit: ({
|
||
7 years ago
|
blockGasLimit,
|
||
7 years ago
|
editingTransactionId,
|
||
|
gasLimit,
|
||
|
gasPrice,
|
||
|
selectedAddress,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
to,
|
||
|
value,
|
||
6 years ago
|
data,
|
||
7 years ago
|
}) => {
|
||
4 years ago
|
editingTransactionId
|
||
|
? dispatch(setGasTotal(calcGasTotal(gasLimit, gasPrice)))
|
||
4 years ago
|
: dispatch(
|
||
|
updateGasData({
|
||
|
gasPrice,
|
||
|
selectedAddress,
|
||
|
sendToken,
|
||
|
blockGasLimit,
|
||
|
to,
|
||
|
value,
|
||
|
data,
|
||
|
}),
|
||
4 years ago
|
);
|
||
7 years ago
|
},
|
||
5 years ago
|
updateSendTokenBalance: ({ sendToken, tokenContract, address }) => {
|
||
4 years ago
|
dispatch(
|
||
|
updateSendTokenBalance({
|
||
|
sendToken,
|
||
|
tokenContract,
|
||
|
address,
|
||
|
}),
|
||
4 years ago
|
);
|
||
7 years ago
|
},
|
||
5 years ago
|
updateSendErrors: (newError) => dispatch(updateSendErrors(newError)),
|
||
7 years ago
|
resetSendState: () => dispatch(resetSendState()),
|
||
5 years ago
|
scanQrCode: () => dispatch(showQrScanner()),
|
||
6 years ago
|
qrCodeDetected: (data) => dispatch(qrCodeDetected(data)),
|
||
6 years ago
|
updateSendTo: (to, nickname) => dispatch(updateSendTo(to, nickname)),
|
||
6 years ago
|
fetchBasicGasEstimates: () => dispatch(fetchBasicGasEstimates()),
|
||
4 years ago
|
updateSendEnsResolution: (ensResolution) =>
|
||
|
dispatch(updateSendEnsResolution(ensResolution)),
|
||
|
updateSendEnsResolutionError: (message) =>
|
||
|
dispatch(updateSendEnsResolutionError(message)),
|
||
5 years ago
|
updateToNicknameIfNecessary: (to, toNickname, addressBook) => {
|
||
5 years ago
|
if (isValidDomainName(toNickname)) {
|
||
4 years ago
|
const addressBookEntry =
|
||
4 years ago
|
addressBook.find(({ address }) => to === address) || {};
|
||
5 years ago
|
if (!addressBookEntry.name !== toNickname) {
|
||
4 years ago
|
dispatch(updateSendTo(to, addressBookEntry.name || ''));
|
||
5 years ago
|
}
|
||
|
}
|
||
|
},
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|
||
5 years ago
|
|
||
|
export default compose(
|
||
|
withRouter,
|
||
4 years ago
|
connect(mapStateToProps, mapDispatchToProps),
|
||
4 years ago
|
)(SendEther);
|