2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
2018-04-26 18:38:38 +02:00
|
|
|
import {
|
|
|
|
addToAddressBook,
|
|
|
|
clearSend,
|
|
|
|
signTokenTx,
|
|
|
|
signTx,
|
|
|
|
updateTransaction,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../store/actions';
|
2018-04-26 18:38:38 +02:00
|
|
|
import {
|
|
|
|
getGasLimit,
|
|
|
|
getGasPrice,
|
|
|
|
getGasTotal,
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken,
|
2018-04-26 18:38:38 +02:00
|
|
|
getSendAmount,
|
|
|
|
getSendEditingTransactionId,
|
|
|
|
getSendFromObject,
|
|
|
|
getSendTo,
|
|
|
|
getSendToAccounts,
|
2018-07-17 00:50:26 +02:00
|
|
|
getSendHexData,
|
2018-04-26 18:38:38 +02:00
|
|
|
getTokenBalance,
|
|
|
|
getUnapprovedTxs,
|
2019-03-05 16:45:01 +01:00
|
|
|
getSendErrors,
|
2018-05-25 19:09:31 +02:00
|
|
|
isSendFormInError,
|
2020-05-02 21:41:17 +02:00
|
|
|
getGasIsLoading,
|
2019-04-05 06:02:47 +02:00
|
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI,
|
|
|
|
getDefaultActiveButtonIndex,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../../selectors';
|
|
|
|
import { getMostRecentOverviewPage } from '../../../ducks/history/history';
|
|
|
|
import { addHexPrefix } from '../../../../../app/scripts/lib/util';
|
|
|
|
import SendFooter from './send-footer.component';
|
2020-05-04 20:27:14 +02:00
|
|
|
import {
|
|
|
|
addressIsNew,
|
|
|
|
constructTxParams,
|
|
|
|
constructUpdatedTx,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from './send-footer.utils';
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(SendFooter);
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapStateToProps(state) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const gasButtonInfo = getRenderableEstimateDataForSmallButtonsFromGWEI(state);
|
|
|
|
const gasPrice = getGasPrice(state);
|
|
|
|
const activeButtonIndex = getDefaultActiveButtonIndex(
|
|
|
|
gasButtonInfo,
|
|
|
|
gasPrice,
|
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const gasEstimateType =
|
|
|
|
activeButtonIndex >= 0
|
|
|
|
? gasButtonInfo[activeButtonIndex].gasEstimateType
|
2021-02-04 19:15:23 +01:00
|
|
|
: 'custom';
|
|
|
|
const editingTransactionId = getSendEditingTransactionId(state);
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
return {
|
2018-04-27 02:38:14 +02:00
|
|
|
amount: getSendAmount(state),
|
2018-07-17 00:50:26 +02:00
|
|
|
data: getSendHexData(state),
|
2020-03-06 22:34:56 +01:00
|
|
|
editingTransactionId,
|
2020-03-11 19:40:35 +01:00
|
|
|
from: getSendFromObject(state),
|
2018-04-26 18:38:38 +02:00
|
|
|
gasLimit: getGasLimit(state),
|
|
|
|
gasPrice: getGasPrice(state),
|
2018-05-24 22:55:23 +02:00
|
|
|
gasTotal: getGasTotal(state),
|
2018-04-27 02:38:14 +02:00
|
|
|
inError: isSendFormInError(state),
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: getSendToken(state),
|
2018-04-26 18:38:38 +02:00
|
|
|
to: getSendTo(state),
|
|
|
|
toAccounts: getSendToAccounts(state),
|
2018-05-24 22:55:23 +02:00
|
|
|
tokenBalance: getTokenBalance(state),
|
2018-04-27 02:38:14 +02:00
|
|
|
unapprovedTxs: getUnapprovedTxs(state),
|
2019-03-05 16:45:01 +01:00
|
|
|
sendErrors: getSendErrors(state),
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
2019-10-23 14:23:15 +02:00
|
|
|
gasEstimateType,
|
2020-01-10 15:23:54 +01:00
|
|
|
gasIsLoading: getGasIsLoading(state),
|
2020-06-01 19:54:32 +02:00
|
|
|
mostRecentOverviewPage: getMostRecentOverviewPage(state),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
2018-04-26 18:38:38 +02:00
|
|
|
return {
|
|
|
|
clearSend: () => dispatch(clearSend()),
|
2020-05-29 19:46:10 +02:00
|
|
|
sign: ({ sendToken, to, amount, from, gas, gasPrice, data }) => {
|
2018-04-26 18:38:38 +02:00
|
|
|
const txParams = constructTxParams({
|
|
|
|
amount,
|
2018-07-17 00:50:26 +02:00
|
|
|
data,
|
2018-04-26 18:38:38 +02:00
|
|
|
from,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-26 18:38:38 +02:00
|
|
|
to,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken
|
|
|
|
? dispatch(signTokenTx(sendToken.address, to, amount, txParams))
|
2021-02-04 19:15:23 +01:00
|
|
|
: dispatch(signTx(txParams));
|
2018-04-26 18:38:38 +02:00
|
|
|
},
|
|
|
|
update: ({
|
|
|
|
amount,
|
2018-07-17 00:50:26 +02:00
|
|
|
data,
|
2018-04-26 18:38:38 +02:00
|
|
|
editingTransactionId,
|
|
|
|
from,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-26 18:38:38 +02:00
|
|
|
to,
|
|
|
|
unapprovedTxs,
|
|
|
|
}) => {
|
|
|
|
const editingTx = constructUpdatedTx({
|
|
|
|
amount,
|
2018-07-17 00:50:26 +02:00
|
|
|
data,
|
2018-04-26 18:38:38 +02:00
|
|
|
editingTransactionId,
|
|
|
|
from,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken,
|
2018-04-26 18:38:38 +02:00
|
|
|
to,
|
|
|
|
unapprovedTxs,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-04-26 18:38:38 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return dispatch(updateTransaction(editingTx));
|
2018-04-26 18:38:38 +02:00
|
|
|
},
|
2019-03-29 03:18:53 +01:00
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
addToAddressBookIfNew: (newAddress, toAccounts, nickname = '') => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const hexPrefixedAddress = addHexPrefix(newAddress);
|
2019-03-29 03:18:53 +01:00
|
|
|
if (addressIsNew(toAccounts, hexPrefixedAddress)) {
|
2018-04-26 18:38:38 +02:00
|
|
|
// TODO: nickname, i.e. addToAddressBook(recipient, nickname)
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(addToAddressBook(hexPrefixedAddress, nickname));
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
2018-04-27 02:38:14 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|