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.
96 lines
2.4 KiB
96 lines
2.4 KiB
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,
|
|
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,
|
|
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}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|