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.
128 lines
3.3 KiB
128 lines
3.3 KiB
4 years ago
|
import { connect } from 'react-redux';
|
||
7 years ago
|
import {
|
||
|
addToAddressBook,
|
||
|
clearSend,
|
||
|
signTokenTx,
|
||
|
signTx,
|
||
|
updateTransaction,
|
||
4 years ago
|
} from '../../../store/actions';
|
||
7 years ago
|
import {
|
||
|
getGasLimit,
|
||
|
getGasPrice,
|
||
|
getGasTotal,
|
||
5 years ago
|
getSendToken,
|
||
7 years ago
|
getSendAmount,
|
||
|
getSendEditingTransactionId,
|
||
|
getSendFromObject,
|
||
|
getSendTo,
|
||
|
getSendToAccounts,
|
||
6 years ago
|
getSendHexData,
|
||
7 years ago
|
getTokenBalance,
|
||
|
getUnapprovedTxs,
|
||
6 years ago
|
getSendErrors,
|
||
7 years ago
|
isSendFormInError,
|
||
5 years ago
|
getGasIsLoading,
|
||
6 years ago
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
||
|
getDefaultActiveButtonIndex,
|
||
4 years ago
|
getNoGasPriceFetched,
|
||
4 years ago
|
} from '../../../selectors';
|
||
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
||
4 years ago
|
import { addHexPrefix } from '../../../../app/scripts/lib/util';
|
||
4 years ago
|
import SendFooter from './send-footer.component';
|
||
5 years ago
|
import {
|
||
|
addressIsNew,
|
||
|
constructTxParams,
|
||
|
constructUpdatedTx,
|
||
4 years ago
|
} from './send-footer.utils';
|
||
7 years ago
|
|
||
4 years ago
|
export default connect(mapStateToProps, mapDispatchToProps)(SendFooter);
|
||
7 years ago
|
|
||
4 years ago
|
function mapStateToProps(state) {
|
||
4 years ago
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state);
|
||
|
const gasPrice = getGasPrice(state);
|
||
|
const activeButtonIndex = getDefaultActiveButtonIndex(
|
||
|
gasButtonInfo,
|
||
|
gasPrice,
|
||
|
);
|
||
4 years ago
|
const gasEstimateType =
|
||
|
activeButtonIndex >= 0
|
||
|
? gasButtonInfo[activeButtonIndex].gasEstimateType
|
||
4 years ago
|
: 'custom';
|
||
|
const editingTransactionId = getSendEditingTransactionId(state);
|
||
5 years ago
|
|
||
7 years ago
|
return {
|
||
7 years ago
|
amount: getSendAmount(state),
|
||
6 years ago
|
data: getSendHexData(state),
|
||
5 years ago
|
editingTransactionId,
|
||
5 years ago
|
from: getSendFromObject(state),
|
||
7 years ago
|
gasLimit: getGasLimit(state),
|
||
|
gasPrice: getGasPrice(state),
|
||
7 years ago
|
gasTotal: getGasTotal(state),
|
||
7 years ago
|
inError: isSendFormInError(state),
|
||
5 years ago
|
sendToken: getSendToken(state),
|
||
7 years ago
|
to: getSendTo(state),
|
||
|
toAccounts: getSendToAccounts(state),
|
||
7 years ago
|
tokenBalance: getTokenBalance(state),
|
||
7 years ago
|
unapprovedTxs: getUnapprovedTxs(state),
|
||
6 years ago
|
sendErrors: getSendErrors(state),
|
||
5 years ago
|
gasEstimateType,
|
||
5 years ago
|
gasIsLoading: getGasIsLoading(state),
|
||
5 years ago
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
||
4 years ago
|
noGasPrice: getNoGasPriceFetched(state),
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
function mapDispatchToProps(dispatch) {
|
||
7 years ago
|
return {
|
||
|
clearSend: () => dispatch(clearSend()),
|
||
5 years ago
|
sign: ({ sendToken, to, amount, from, gas, gasPrice, data }) => {
|
||
7 years ago
|
const txParams = constructTxParams({
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
to,
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
5 years ago
|
sendToken
|
||
|
? dispatch(signTokenTx(sendToken.address, to, amount, txParams))
|
||
4 years ago
|
: dispatch(signTx(txParams));
|
||
7 years ago
|
},
|
||
|
update: ({
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
to,
|
||
|
unapprovedTxs,
|
||
|
}) => {
|
||
|
const editingTx = constructUpdatedTx({
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
to,
|
||
|
unapprovedTxs,
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
return dispatch(updateTransaction(editingTx));
|
||
7 years ago
|
},
|
||
6 years ago
|
|
||
7 years ago
|
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
|
||
4 years ago
|
const hexPrefixedAddress = addHexPrefix(newAddress);
|
||
6 years ago
|
if (addressIsNew(toAccounts, hexPrefixedAddress)) {
|
||
7 years ago
|
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
|
||
4 years ago
|
dispatch(addToAddressBook(hexPrefixedAddress, nickname));
|
||
7 years ago
|
}
|
||
7 years ago
|
},
|
||
4 years ago
|
};
|
||
7 years ago
|
}
|