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.
143 lines
3.6 KiB
143 lines
3.6 KiB
7 years ago
|
import React, { Component } from 'react'
|
||
|
import PropTypes from 'prop-types'
|
||
6 years ago
|
import PageContainerFooter from '../../../components/ui/page-container/page-container-footer'
|
||
|
import { CONFIRM_TRANSACTION_ROUTE, DEFAULT_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,
|
||
7 years ago
|
disabled: PropTypes.bool,
|
||
7 years ago
|
editingTransactionId: PropTypes.string,
|
||
7 years ago
|
errors: PropTypes.object,
|
||
7 years ago
|
from: PropTypes.object,
|
||
|
gasLimit: PropTypes.string,
|
||
|
gasPrice: PropTypes.string,
|
||
|
gasTotal: PropTypes.string,
|
||
|
history: PropTypes.object,
|
||
7 years ago
|
inError: PropTypes.bool,
|
||
7 years ago
|
selectedToken: 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,
|
||
6 years ago
|
gasChangedLabel: PropTypes.string,
|
||
6 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
static contextTypes = {
|
||
|
t: PropTypes.func,
|
||
6 years ago
|
metricsEvent: PropTypes.func,
|
||
|
};
|
||
7 years ago
|
|
||
7 years ago
|
onCancel () {
|
||
|
this.props.clearSend()
|
||
|
this.props.history.push(DEFAULT_ROUTE)
|
||
|
}
|
||
|
|
||
7 years ago
|
onSubmit (event) {
|
||
|
event.preventDefault()
|
||
|
const {
|
||
|
addToAddressBookIfNew,
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
|
from: {address: from},
|
||
|
gasLimit: gas,
|
||
|
gasPrice,
|
||
|
selectedToken,
|
||
|
sign,
|
||
|
to,
|
||
|
unapprovedTxs,
|
||
|
// updateTx,
|
||
|
update,
|
||
|
toAccounts,
|
||
7 years ago
|
history,
|
||
6 years ago
|
gasChangedLabel,
|
||
7 years ago
|
} = this.props
|
||
6 years ago
|
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
|
||
|
addToAddressBookIfNew(to, toAccounts)
|
||
7 years ago
|
const promise = editingTransactionId
|
||
7 years ago
|
? update({
|
||
|
amount,
|
||
6 years ago
|
data,
|
||
7 years ago
|
editingTransactionId,
|
||
|
from,
|
||
7 years ago
|
gas,
|
||
|
gasPrice,
|
||
|
selectedToken,
|
||
7 years ago
|
to,
|
||
7 years ago
|
unapprovedTxs,
|
||
|
})
|
||
6 years ago
|
: sign({ data, selectedToken, to, amount, from, gas, gasPrice })
|
||
7 years ago
|
|
||
7 years ago
|
Promise.resolve(promise)
|
||
6 years ago
|
.then(() => {
|
||
|
metricsEvent({
|
||
|
eventOpts: {
|
||
|
category: 'Transactions',
|
||
|
action: 'Edit Screen',
|
||
|
name: 'Complete',
|
||
|
},
|
||
6 years ago
|
customVariables: {
|
||
|
gasChanged: gasChangedLabel,
|
||
|
},
|
||
6 years ago
|
})
|
||
|
history.push(CONFIRM_TRANSACTION_ROUTE)
|
||
|
})
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
formShouldBeDisabled () {
|
||
6 years ago
|
const { data, inError, selectedToken, tokenBalance, gasTotal, to } = this.props
|
||
7 years ago
|
const missingTokenBalance = selectedToken && !tokenBalance
|
||
6 years ago
|
const shouldBeDisabled = inError || !gasTotal || missingTokenBalance || !(data || to)
|
||
|
return shouldBeDisabled
|
||
|
}
|
||
|
|
||
|
componentDidUpdate (prevProps) {
|
||
|
const { inError, sendErrors } = this.props
|
||
|
const { metricsEvent } = this.context
|
||
|
if (!prevProps.inError && inError) {
|
||
|
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,
|
||
|
},
|
||
|
})
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
render () {
|
||
|
return (
|
||
|
<PageContainerFooter
|
||
7 years ago
|
onCancel={() => this.onCancel()}
|
||
7 years ago
|
onSubmit={e => this.onSubmit(e)}
|
||
7 years ago
|
disabled={this.formShouldBeDisabled()}
|
||
7 years ago
|
/>
|
||
7 years ago
|
)
|
||
7 years ago
|
}
|
||
|
|
||
|
}
|