1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01:00
metamask-extension/ui/app/components/send_/send-footer/send-footer.component.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-04-26 18:38:38 +02:00
import React, { Component } from 'react'
import PropTypes from 'prop-types'
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 = {
addToAddressBookIfNew: PropTypes.func,
2018-04-26 18:38:38 +02:00
amount: PropTypes.string,
clearSend: PropTypes.func,
disabled: PropTypes.bool,
2018-04-26 18:38:38 +02:00
editingTransactionId: PropTypes.string,
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,
inError: PropTypes.bool,
2018-04-26 18:38:38 +02:00
selectedToken: PropTypes.object,
sign: PropTypes.func,
2018-04-26 18:38:38 +02:00
to: PropTypes.string,
toAccounts: PropTypes.array,
tokenBalance: PropTypes.string,
unapprovedTxs: PropTypes.object,
update: PropTypes.func,
2018-04-26 18:38:38 +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,
} = this.props
// 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)
editingTransactionId
? update({
amount,
editingTransactionId,
from,
2018-04-26 18:38:38 +02:00
gas,
gasPrice,
selectedToken,
to,
2018-04-26 18:38:38 +02:00
unapprovedTxs,
})
: sign({ selectedToken, to, amount, from, gas, gasPrice })
this.props.history.push(CONFIRM_TRANSACTION_ROUTE)
}
formShouldBeDisabled () {
const { inError, selectedToken, tokenBalance, gasTotal, to } = this.props
const missingTokenBalance = selectedToken && !tokenBalance
return inError || !gasTotal || missingTokenBalance || !to
}
2018-04-26 18:38:38 +02:00
render () {
return (
<PageContainerFooter
onCancel={() => this.onCancel()}
2018-04-26 18:38:38 +02:00
onSubmit={e => this.onSubmit(e)}
disabled={this.formShouldBeDisabled()}
2018-04-26 18:38:38 +02:00
/>
)
2018-04-26 18:38:38 +02:00
}
}
SendFooter.contextTypes = {
t: PropTypes.func,
}