|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { isEqual } from 'lodash';
|
|
|
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer';
|
|
|
|
import { CONFIRM_TRANSACTION_ROUTE } from '../../../helpers/constants/routes';
|
|
|
|
|
|
|
|
export default class SendFooter extends Component {
|
|
|
|
static propTypes = {
|
|
|
|
addToAddressBookIfNew: PropTypes.func,
|
|
|
|
resetSendState: PropTypes.func,
|
|
|
|
disabled: PropTypes.bool.isRequired,
|
|
|
|
history: PropTypes.object,
|
|
|
|
sign: PropTypes.func,
|
|
|
|
to: PropTypes.string,
|
|
|
|
toAccounts: PropTypes.array,
|
|
|
|
sendErrors: PropTypes.object,
|
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.
5 years ago
|
|
|
gasEstimateType: PropTypes.string,
|
|
|
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
metricsEvent: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
onCancel() {
|
|
|
|
const { resetSendState, history, mostRecentOverviewPage } = this.props;
|
|
|
|
resetSendState();
|
|
|
|
history.push(mostRecentOverviewPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
async onSubmit(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
const {
|
|
|
|
addToAddressBookIfNew,
|
|
|
|
sign,
|
|
|
|
to,
|
|
|
|
toAccounts,
|
|
|
|
history,
|
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.
5 years ago
|
|
|
gasEstimateType,
|
|
|
|
} = this.props;
|
|
|
|
const { metricsEvent } = this.context;
|
|
|
|
|
|
|
|
// TODO: add nickname functionality
|
|
|
|
await addToAddressBookIfNew(to, toAccounts);
|
|
|
|
const promise = sign();
|
|
|
|
|
|
|
|
Promise.resolve(promise).then(() => {
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Complete',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
gasChanged: gasEstimateType,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
history.push(CONFIRM_TRANSACTION_ROUTE);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { sendErrors } = this.props;
|
|
|
|
const { metricsEvent } = this.context;
|
|
|
|
if (
|
|
|
|
Object.keys(sendErrors).length > 0 &&
|
|
|
|
isEqual(sendErrors, prevProps.sendErrors) === false
|
|
|
|
) {
|
|
|
|
const errorField = Object.keys(sendErrors).find((key) => sendErrors[key]);
|
|
|
|
const errorMessage = sendErrors[errorField];
|
|
|
|
|
|
|
|
metricsEvent({
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Transactions',
|
|
|
|
action: 'Edit Screen',
|
|
|
|
name: 'Error',
|
|
|
|
},
|
|
|
|
customVariables: {
|
|
|
|
errorField,
|
|
|
|
errorMessage,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<PageContainerFooter
|
|
|
|
onCancel={() => this.onCancel()}
|
|
|
|
onSubmit={(e) => this.onSubmit(e)}
|
|
|
|
disabled={this.props.disabled}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|