2018-04-26 18:38:38 +02:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2018-05-01 04:42:57 +02:00
|
|
|
import PageContainerFooter from '../../page-container/page-container-footer'
|
2018-04-26 18:38:38 +02:00
|
|
|
import { CONFIRM_TRANSACTION_ROUTE, DEFAULT_ROUTE } from '../../../routes'
|
|
|
|
|
|
|
|
export default class SendFooter extends Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
2018-04-27 02:38:14 +02:00
|
|
|
addToAddressBookIfNew: PropTypes.func,
|
2018-04-26 18:38:38 +02:00
|
|
|
amount: PropTypes.string,
|
|
|
|
clearSend: PropTypes.func,
|
2018-04-27 02:38:14 +02:00
|
|
|
disabled: PropTypes.bool,
|
2018-04-26 18:38:38 +02:00
|
|
|
editingTransactionId: PropTypes.string,
|
2018-04-27 02:38:14 +02:00
|
|
|
errors: PropTypes.object,
|
2018-04-26 18:38:38 +02:00
|
|
|
from: PropTypes.object,
|
|
|
|
gasLimit: PropTypes.string,
|
|
|
|
gasPrice: PropTypes.string,
|
|
|
|
gasTotal: PropTypes.string,
|
|
|
|
history: PropTypes.object,
|
2018-05-25 02:53:54 +02:00
|
|
|
inError: PropTypes.bool,
|
2018-04-26 18:38:38 +02:00
|
|
|
selectedToken: PropTypes.object,
|
2018-04-27 02:38:14 +02:00
|
|
|
sign: PropTypes.func,
|
2018-04-26 18:38:38 +02:00
|
|
|
to: PropTypes.string,
|
|
|
|
toAccounts: PropTypes.array,
|
|
|
|
tokenBalance: PropTypes.string,
|
|
|
|
unapprovedTxs: PropTypes.object,
|
2018-04-27 02:38:14 +02:00
|
|
|
update: PropTypes.func,
|
2018-04-26 18:38:38 +02:00
|
|
|
};
|
|
|
|
|
2018-05-07 14:03:20 +02:00
|
|
|
onCancel () {
|
|
|
|
this.props.clearSend()
|
|
|
|
this.props.history.push(DEFAULT_ROUTE)
|
|
|
|
}
|
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
onSubmit (event) {
|
|
|
|
event.preventDefault()
|
|
|
|
const {
|
|
|
|
addToAddressBookIfNew,
|
|
|
|
amount,
|
|
|
|
editingTransactionId,
|
|
|
|
from: {address: from},
|
|
|
|
gasLimit: gas,
|
|
|
|
gasPrice,
|
|
|
|
selectedToken,
|
|
|
|
sign,
|
|
|
|
to,
|
|
|
|
unapprovedTxs,
|
|
|
|
// updateTx,
|
|
|
|
update,
|
|
|
|
toAccounts,
|
2018-06-23 08:52:45 +02:00
|
|
|
history,
|
2018-04-26 18:38:38 +02:00
|
|
|
} = this.props
|
|
|
|
|
2018-05-07 14:03:20 +02:00
|
|
|
// Should not be needed because submit should be disabled if there are errors.
|
2018-04-26 18:38:38 +02:00
|
|
|
// const noErrors = !amountError && toError === null
|
|
|
|
|
|
|
|
// if (!noErrors) {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO: add nickname functionality
|
|
|
|
addToAddressBookIfNew(to, toAccounts)
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
const promise = editingTransactionId
|
2018-04-26 18:38:38 +02:00
|
|
|
? update({
|
|
|
|
amount,
|
2018-04-27 02:38:14 +02:00
|
|
|
editingTransactionId,
|
|
|
|
from,
|
2018-04-26 18:38:38 +02:00
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
selectedToken,
|
2018-04-27 02:38:14 +02:00
|
|
|
to,
|
2018-04-26 18:38:38 +02:00
|
|
|
unapprovedTxs,
|
|
|
|
})
|
|
|
|
: sign({ selectedToken, to, amount, from, gas, gasPrice })
|
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
Promise.resolve(promise)
|
|
|
|
.then(() => history.push(CONFIRM_TRANSACTION_ROUTE))
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 02:53:54 +02:00
|
|
|
formShouldBeDisabled () {
|
2018-05-25 19:09:31 +02:00
|
|
|
const { inError, selectedToken, tokenBalance, gasTotal, to } = this.props
|
2018-05-25 02:53:54 +02:00
|
|
|
const missingTokenBalance = selectedToken && !tokenBalance
|
2018-05-25 19:09:31 +02:00
|
|
|
return inError || !gasTotal || missingTokenBalance || !to
|
2018-05-25 02:53:54 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 18:38:38 +02:00
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<PageContainerFooter
|
2018-05-07 14:03:20 +02:00
|
|
|
onCancel={() => this.onCancel()}
|
2018-04-26 18:38:38 +02:00
|
|
|
onSubmit={e => this.onSubmit(e)}
|
2018-05-25 02:53:54 +02:00
|
|
|
disabled={this.formShouldBeDisabled()}
|
2018-04-26 18:38:38 +02:00
|
|
|
/>
|
2018-04-27 02:38:14 +02:00
|
|
|
)
|
2018-04-26 18:38:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SendFooter.contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|