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.
159 lines
3.9 KiB
159 lines
3.9 KiB
4 years ago
|
import React, { Component } from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer';
|
||
|
import { CONFIRM_TRANSACTION_ROUTE } from '../../../helpers/constants/routes';
|
||
7 years ago
|
|
||
|
export default class SendFooter extends Component {
|
||
|
static propTypes = {
|
||
7 years ago
|
addToAddressBookIfNew: PropTypes.func,
|
||
7 years ago
|
amount: PropTypes.string,
|
||
6 years ago
|
data: PropTypes.string,
|
||
7 years ago
|
clearSend: PropTypes.func,
|
||
|
editingTransactionId: PropTypes.string,
|
||
|
from: PropTypes.object,
|
||
|
gasLimit: PropTypes.string,
|
||
|
gasPrice: PropTypes.string,
|
||
|
gasTotal: PropTypes.string,
|
||
|
history: PropTypes.object,
|
||
7 years ago
|
inError: PropTypes.bool,
|
||
5 years ago
|
sendToken: PropTypes.object,
|
||
7 years ago
|
sign: PropTypes.func,
|
||
7 years ago
|
to: PropTypes.string,
|
||
|
toAccounts: PropTypes.array,
|
||
|
tokenBalance: PropTypes.string,
|
||
|
unapprovedTxs: PropTypes.object,
|
||
7 years ago
|
update: PropTypes.func,
|
||
6 years ago
|
sendErrors: PropTypes.object,
|
||
5 years ago
|
gasEstimateType: PropTypes.string,
|
||
5 years ago
|
gasIsLoading: PropTypes.bool,
|
||
5 years ago
|
mostRecentOverviewPage: PropTypes.string.isRequired,
|
||
4 years ago
|
noGasPrice: PropTypes.bool,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
6 years ago
|
metricsEvent: PropTypes.func,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
onCancel() {
|
||
4 years ago
|
const { clearSend, history, mostRecentOverviewPage } = this.props;
|
||
|
clearSend();
|
||
|
history.push(mostRecentOverviewPage);
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
async onSubmit(event) {
|
||
4 years ago
|
event.preventDefault();
|
||
7 years ago
|
const {
|
||
|
addToAddressBookIfNew,
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
5 years ago
|
from: { address: from },
|
||
7 years ago
|
gasLimit: gas,
|
||
|
gasPrice,
|
||
5 years ago
|
sendToken,
|
||
7 years ago
|
sign,
|
||
|
to,
|
||
|
unapprovedTxs,
|
||
|
update,
|
||
|
toAccounts,
|
||
7 years ago
|
history,
|
||
5 years ago
|
gasEstimateType,
|
||
4 years ago
|
} = this.props;
|
||
|
const { metricsEvent } = this.context;
|
||
7 years ago
|
|
||
7 years ago
|
// Should not be needed because submit should be disabled if there are errors.
|
||
7 years ago
|
// const noErrors = !amountError && toError === null
|
||
|
|
||
|
// if (!noErrors) {
|
||
|
// return
|
||
|
// }
|
||
|
|
||
|
// TODO: add nickname functionality
|
||
4 years ago
|
await addToAddressBookIfNew(to, toAccounts);
|
||
7 years ago
|
const promise = editingTransactionId
|
||
7 years ago
|
? update({
|
||
4 years ago
|
amount,
|
||
|
data,
|
||
|
editingTransactionId,
|
||
|
from,
|
||
|
gas,
|
||
|
gasPrice,
|
||
|
sendToken,
|
||
|
to,
|
||
|
unapprovedTxs,
|
||
|
})
|
||
4 years ago
|
: sign({ data, sendToken, to, amount, from, gas, gasPrice });
|
||
7 years ago
|
|
||
4 years ago
|
Promise.resolve(promise).then(() => {
|
||
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Transactions',
|
||
|
action: 'Edit Screen',
|
||
|
name: 'Complete',
|
||
|
},
|
||
|
customVariables: {
|
||
|
gasChanged: gasEstimateType,
|
||
|
},
|
||
4 years ago
|
});
|
||
|
history.push(CONFIRM_TRANSACTION_ROUTE);
|
||
|
});
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
formShouldBeDisabled() {
|
||
|
const {
|
||
|
data,
|
||
|
inError,
|
||
|
sendToken,
|
||
|
tokenBalance,
|
||
|
gasTotal,
|
||
|
to,
|
||
|
gasLimit,
|
||
|
gasIsLoading,
|
||
4 years ago
|
noGasPrice,
|
||
4 years ago
|
} = this.props;
|
||
|
const missingTokenBalance = sendToken && !tokenBalance;
|
||
|
const gasLimitTooLow = gasLimit < 5208; // 5208 is hex value of 21000, minimum gas limit
|
||
4 years ago
|
const shouldBeDisabled =
|
||
|
inError ||
|
||
|
!gasTotal ||
|
||
|
missingTokenBalance ||
|
||
|
!(data || to) ||
|
||
|
gasLimitTooLow ||
|
||
4 years ago
|
gasIsLoading ||
|
||
|
noGasPrice;
|
||
4 years ago
|
return shouldBeDisabled;
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
componentDidUpdate(prevProps) {
|
||
4 years ago
|
const { inError, sendErrors } = this.props;
|
||
|
const { metricsEvent } = this.context;
|
||
6 years ago
|
if (!prevProps.inError && inError) {
|
||
4 years ago
|
const errorField = Object.keys(sendErrors).find((key) => sendErrors[key]);
|
||
|
const errorMessage = sendErrors[errorField];
|
||
6 years ago
|
|
||
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Transactions',
|
||
|
action: 'Edit Screen',
|
||
|
name: 'Error',
|
||
|
},
|
||
|
customVariables: {
|
||
|
errorField,
|
||
|
errorMessage,
|
||
|
},
|
||
4 years ago
|
});
|
||
6 years ago
|
}
|
||
7 years ago
|
}
|
||
|
|
||
4 years ago
|
render() {
|
||
7 years ago
|
return (
|
||
|
<PageContainerFooter
|
||
7 years ago
|
onCancel={() => this.onCancel()}
|
||
5 years ago
|
onSubmit={(e) => this.onSubmit(e)}
|
||
7 years ago
|
disabled={this.formShouldBeDisabled()}
|
||
7 years ago
|
/>
|
||
4 years ago
|
);
|
||
7 years ago
|
}
|
||
|
}
|