nifty-wallet/ui/app/components/pending-tx.js

121 lines
2.9 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript')
const inherits = require('util').inherits
2016-06-24 12:48:52 -07:00
const PendingTxDetails = require('./pending-tx-details')
2017-02-28 16:36:05 -08:00
const extend = require('xtend')
const actions = require('../actions')
2016-06-24 17:22:27 -07:00
module.exports = connect(mapStateToProps)(PendingTx)
function mapStateToProps (state) {
return {
}
}
inherits(PendingTx, Component)
2016-06-21 13:18:32 -07:00
function PendingTx () {
Component.call(this)
2017-03-22 15:14:33 -07:00
this.state = { valid: true }
}
2016-06-21 13:18:32 -07:00
PendingTx.prototype.render = function () {
const props = this.props
2017-03-22 15:14:33 -07:00
const newProps = extend(props, {
ref: 'details',
validChanged: this.validChanged.bind(this),
})
const txData = props.txData
return (
2016-06-22 19:28:11 -07:00
2016-06-24 12:48:52 -07:00
h('div', {
key: txData.id,
}, [
2017-03-22 15:14:33 -07:00
h('form#pending-tx-form', {
onSubmit: (event) => {
event.preventDefault()
const form = document.querySelector('form#pending-tx-form')
const valid = form.checkValidity()
this.setState({ valid })
if (valid && this.refs.details.verifyGasParams()) {
props.sendTransaction(txData, event)
} else {
this.props.dispatch(actions.displayWarning('Invalid Gas Parameters'))
}
2016-07-06 22:51:28 -07:00
},
2016-07-06 21:32:36 -07:00
}, [
2017-03-22 15:14:33 -07:00
// tx info
h(PendingTxDetails, newProps),
h('style', `
.conf-buttons button {
margin-left: 10px;
text-transform: uppercase;
}
`),
txData.simulationFails ?
h('.error', {
style: {
marginLeft: 50,
fontSize: '0.9em',
},
}, 'Transaction Error. Exception thrown in contract code.')
: null,
props.insufficientBalance ?
2017-03-22 15:14:33 -07:00
h('span.error', {
style: {
marginLeft: 50,
fontSize: '0.9em',
},
}, 'Insufficient balance for transaction')
: null,
2016-07-07 12:39:40 -07:00
2017-03-22 15:14:33 -07:00
// send + cancel
h('.flex-row.flex-space-around.conf-buttons', {
style: {
display: 'flex',
justifyContent: 'flex-end',
margin: '14px 25px',
},
2017-03-22 15:14:33 -07:00
}, [
2017-03-22 15:14:33 -07:00
props.insufficientBalance ?
h('button', {
onClick: props.buyEth,
}, 'Buy Ether')
: null,
h('button', {
onClick: () => {
this.refs.details.resetGasFields()
},
}, 'Reset'),
h('input.confirm.btn-green', {
type: 'submit',
value: 'ACCEPT',
style: { marginLeft: '10px' },
disabled: props.insufficientBalance || !this.state.valid,
}),
h('button.cancel.btn-red', {
onClick: props.cancelTransaction,
}, 'Reject'),
]),
2016-06-24 17:27:42 -07:00
]),
])
)
}
2017-03-22 15:14:33 -07:00
PendingTx.prototype.validChanged = function (newValid) {
this.setState({ valid: newValid })
}