2017-08-29 14:54:58 +02:00
|
|
|
const { inherits } = require('util')
|
2016-08-25 23:10:07 +02:00
|
|
|
const PersistentForm = require('../lib/persistent-form')
|
2016-04-14 00:28:44 +02:00
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const connect = require('react-redux').connect
|
2016-05-18 21:13:19 +02:00
|
|
|
const Identicon = require('./components/identicon')
|
2017-03-01 09:23:49 +01:00
|
|
|
const EnsInput = require('./components/ens-input')
|
2017-08-29 15:55:11 +02:00
|
|
|
const GasTooltip = require('./components/send/gas-tooltip')
|
|
|
|
const CurrencyToggle = require('./components/send/currency-toggle')
|
2017-08-29 16:09:07 +02:00
|
|
|
const GasFeeDisplay = require('./components/send/gas-fee-display')
|
2017-08-22 21:47:48 +02:00
|
|
|
const { getSelectedIdentity } = require('./selectors')
|
2017-08-29 14:54:58 +02:00
|
|
|
|
|
|
|
const {
|
|
|
|
showAccountsPage,
|
|
|
|
backToAccountDetail,
|
|
|
|
displayWarning,
|
|
|
|
hideWarning,
|
|
|
|
addToAddressBook,
|
|
|
|
signTx,
|
2017-09-22 06:15:26 +02:00
|
|
|
estimateGas,
|
|
|
|
getGasPrice,
|
2017-08-29 14:54:58 +02:00
|
|
|
} = require('./actions')
|
2017-08-29 16:50:48 +02:00
|
|
|
const { stripHexPrefix, addHexPrefix } = require('ethereumjs-util')
|
2017-09-20 19:37:12 +02:00
|
|
|
const { isHex, numericBalance, isValidAddress, allNull } = require('./util')
|
|
|
|
const { conversionUtil, conversionGreaterThan } = require('./conversion-util')
|
2017-07-29 22:31:53 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
module.exports = connect(mapStateToProps)(SendTransactionScreen)
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
function mapStateToProps (state) {
|
2017-08-29 14:54:58 +02:00
|
|
|
const {
|
|
|
|
selectedAddress: address,
|
|
|
|
accounts,
|
|
|
|
identities,
|
|
|
|
network,
|
|
|
|
addressBook,
|
|
|
|
conversionRate,
|
|
|
|
currentBlockGasLimit: blockGasLimit,
|
|
|
|
} = state.metamask
|
|
|
|
const { warning } = state.appState
|
|
|
|
const selectedIdentity = getSelectedIdentity(state)
|
|
|
|
const account = accounts[address]
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-08-29 14:54:58 +02:00
|
|
|
return {
|
|
|
|
address,
|
|
|
|
accounts,
|
|
|
|
identities,
|
|
|
|
network,
|
|
|
|
addressBook,
|
|
|
|
conversionRate,
|
|
|
|
blockGasLimit,
|
|
|
|
warning,
|
|
|
|
selectedIdentity,
|
|
|
|
error: warning && warning.split('.')[0],
|
|
|
|
account,
|
|
|
|
identity: identities[address],
|
2017-09-20 19:37:12 +02:00
|
|
|
balance: account ? account.balance : null,
|
2017-08-29 14:54:58 +02:00
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-08-25 23:10:07 +02:00
|
|
|
inherits(SendTransactionScreen, PersistentForm)
|
2016-06-21 22:18:32 +02:00
|
|
|
function SendTransactionScreen () {
|
2016-08-25 23:10:07 +02:00
|
|
|
PersistentForm.call(this)
|
2017-08-23 00:05:23 +02:00
|
|
|
|
|
|
|
// [WIP] These are the bare minimum of tx props needed to sign a transaction
|
|
|
|
// We will need a few more for contract-related interactions
|
|
|
|
this.state = {
|
|
|
|
newTx: {
|
|
|
|
from: '',
|
|
|
|
to: '',
|
2017-09-20 19:37:12 +02:00
|
|
|
amountToSend: '0x0',
|
2017-09-22 06:15:26 +02:00
|
|
|
gasPrice: null,
|
|
|
|
gas: null,
|
|
|
|
amount: '0x0',
|
2017-08-23 00:22:00 +02:00
|
|
|
txData: null,
|
|
|
|
memo: '',
|
2017-08-23 00:05:23 +02:00
|
|
|
},
|
2017-09-13 19:57:15 +02:00
|
|
|
activeCurrency: 'USD',
|
2017-08-25 21:20:23 +02:00
|
|
|
tooltipIsOpen: false,
|
2017-09-20 19:37:12 +02:00
|
|
|
errors: {},
|
|
|
|
isValid: false,
|
2017-08-23 00:05:23 +02:00
|
|
|
}
|
2017-08-28 20:44:56 +02:00
|
|
|
|
|
|
|
this.back = this.back.bind(this)
|
|
|
|
this.closeTooltip = this.closeTooltip.bind(this)
|
|
|
|
this.onSubmit = this.onSubmit.bind(this)
|
2017-09-13 19:57:15 +02:00
|
|
|
this.setActiveCurrency = this.setActiveCurrency.bind(this)
|
2017-08-28 20:44:56 +02:00
|
|
|
this.toggleTooltip = this.toggleTooltip.bind(this)
|
2017-09-20 19:37:12 +02:00
|
|
|
this.validate = this.validate.bind(this)
|
|
|
|
this.getAmountToSend = this.getAmountToSend.bind(this)
|
|
|
|
this.setErrorsFor = this.setErrorsFor.bind(this)
|
|
|
|
this.clearErrorsFor = this.clearErrorsFor.bind(this)
|
2017-09-20 17:45:47 +02:00
|
|
|
|
|
|
|
this.renderFromInput = this.renderFromInput.bind(this)
|
|
|
|
this.renderToInput = this.renderToInput.bind(this)
|
|
|
|
this.renderAmountInput = this.renderAmountInput.bind(this)
|
|
|
|
this.renderGasInput = this.renderGasInput.bind(this)
|
|
|
|
this.renderMemoInput = this.renderMemoInput.bind(this)
|
2017-09-20 19:37:12 +02:00
|
|
|
this.renderErrorMessage = this.renderErrorMessage.bind(this)
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:21:45 +02:00
|
|
|
SendTransactionScreen.prototype.componentWillMount = function () {
|
2017-09-27 03:33:03 +02:00
|
|
|
const { newTx } = this.state
|
2017-09-29 02:39:53 +02:00
|
|
|
const { address } = this.props
|
2017-09-27 03:33:03 +02:00
|
|
|
|
2017-09-27 02:21:45 +02:00
|
|
|
Promise.all([
|
|
|
|
this.props.dispatch(getGasPrice()),
|
2017-09-29 02:39:53 +02:00
|
|
|
this.props.dispatch(estimateGas({
|
|
|
|
from: address,
|
|
|
|
gas: '746a528800',
|
|
|
|
})),
|
2017-09-27 02:21:45 +02:00
|
|
|
])
|
|
|
|
.then(([blockGasPrice, estimatedGas]) => {
|
2017-09-29 02:39:53 +02:00
|
|
|
console.log({ blockGasPrice, estimatedGas})
|
2017-09-27 02:21:45 +02:00
|
|
|
this.setState({
|
2017-09-27 03:33:03 +02:00
|
|
|
newTx: {
|
|
|
|
...newTx,
|
|
|
|
gasPrice: blockGasPrice,
|
|
|
|
gas: estimatedGas,
|
|
|
|
},
|
2017-09-27 02:21:45 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
SendTransactionScreen.prototype.renderErrorMessage = function(errorType, warning) {
|
|
|
|
const { errors } = this.state
|
|
|
|
const errorMessage = errors[errorType];
|
|
|
|
|
|
|
|
return errorMessage || warning
|
|
|
|
? h('div.send-screen-input-wrapper__error-message', [ errorMessage || warning ])
|
|
|
|
: null
|
2017-09-20 17:45:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderFromInput = function (from, identities) {
|
|
|
|
return h('div.send-screen-input-wrapper', [
|
|
|
|
|
|
|
|
h('div', 'From:'),
|
|
|
|
|
|
|
|
h('input.large-input.send-screen-input', {
|
|
|
|
list: 'accounts',
|
|
|
|
placeholder: 'Account',
|
|
|
|
value: from,
|
|
|
|
onChange: (event) => {
|
|
|
|
this.setState({
|
|
|
|
newTx: {
|
|
|
|
...this.state.newTx,
|
|
|
|
from: event.target.value,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2017-09-20 19:37:12 +02:00
|
|
|
onBlur: () => this.setErrorsFor('from'),
|
2017-09-22 23:17:05 +02:00
|
|
|
onFocus: event => {
|
2017-09-26 01:05:14 +02:00
|
|
|
this.clearErrorsFor('from')
|
2017-09-22 23:17:05 +02:00
|
|
|
this.state.newTx.from && event.target.select()
|
2017-09-22 10:28:43 +02:00
|
|
|
},
|
2017-09-20 17:45:47 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
h('datalist#accounts', [
|
|
|
|
Object.entries(identities).map(([key, { address, name }]) => {
|
|
|
|
return h('option', {
|
|
|
|
value: address,
|
|
|
|
label: name,
|
|
|
|
key: address,
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
this.renderErrorMessage('from'),
|
|
|
|
|
2017-09-20 17:45:47 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderToInput = function (to, identities, addressBook) {
|
|
|
|
return h('div.send-screen-input-wrapper', [
|
|
|
|
|
|
|
|
h('div', 'To:'),
|
|
|
|
|
|
|
|
h('input.large-input.send-screen-input', {
|
|
|
|
name: 'address',
|
|
|
|
list: 'addresses',
|
|
|
|
placeholder: 'Address',
|
|
|
|
value: to,
|
|
|
|
onChange: (event) => {
|
|
|
|
this.setState({
|
|
|
|
newTx: {
|
|
|
|
...this.state.newTx,
|
|
|
|
to: event.target.value,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
2017-09-22 06:15:26 +02:00
|
|
|
onBlur: () => {
|
|
|
|
this.setErrorsFor('to')
|
|
|
|
},
|
2017-09-22 23:17:05 +02:00
|
|
|
onFocus: event => {
|
2017-09-22 10:28:43 +02:00
|
|
|
this.clearErrorsFor('to')
|
2017-09-22 23:17:05 +02:00
|
|
|
this.state.newTx.to && event.target.select()
|
2017-09-22 10:28:43 +02:00
|
|
|
},
|
2017-09-20 17:45:47 +02:00
|
|
|
}),
|
|
|
|
|
|
|
|
h('datalist#addresses', [
|
|
|
|
// Corresponds to the addresses owned.
|
|
|
|
...Object.entries(identities).map(([key, { address, name }]) => {
|
|
|
|
return h('option', {
|
|
|
|
value: address,
|
|
|
|
label: name,
|
|
|
|
key: address,
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
// Corresponds to previously sent-to addresses.
|
|
|
|
...addressBook.map(({ address, name }) => {
|
|
|
|
return h('option', {
|
|
|
|
value: address,
|
|
|
|
label: name,
|
|
|
|
key: address,
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
this.renderErrorMessage('to'),
|
|
|
|
|
2017-09-20 17:45:47 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderAmountInput = function (activeCurrency) {
|
|
|
|
return h('div.send-screen-input-wrapper', [
|
|
|
|
|
|
|
|
h('div.send-screen-amount-labels', [
|
|
|
|
h('span', 'Amount'),
|
|
|
|
h(CurrencyToggle, {
|
|
|
|
activeCurrency,
|
|
|
|
onClick: (newCurrency) => this.setActiveCurrency(newCurrency),
|
|
|
|
}), // holding on icon from design
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('input.large-input.send-screen-input', {
|
|
|
|
placeholder: `0 ${activeCurrency}`,
|
|
|
|
type: 'number',
|
|
|
|
onChange: (event) => {
|
2017-09-28 16:10:33 +02:00
|
|
|
const amountToSend = event.target.value
|
|
|
|
? this.getAmountToSend(event.target.value)
|
|
|
|
: '0x0'
|
|
|
|
|
2017-09-20 17:45:47 +02:00
|
|
|
this.setState({
|
|
|
|
newTx: Object.assign(
|
|
|
|
this.state.newTx,
|
|
|
|
{
|
|
|
|
amount: event.target.value,
|
2017-09-28 16:10:33 +02:00
|
|
|
amountToSend: amountToSend,
|
2017-09-20 17:45:47 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
})
|
|
|
|
},
|
2017-09-22 06:15:26 +02:00
|
|
|
onBlur: () => {
|
|
|
|
this.setErrorsFor('amount')
|
|
|
|
},
|
2017-09-20 19:37:12 +02:00
|
|
|
onFocus: () => this.clearErrorsFor('amount'),
|
2017-09-20 17:45:47 +02:00
|
|
|
}),
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
this.renderErrorMessage('amount'),
|
|
|
|
|
2017-09-20 17:45:47 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderGasInput = function (gasPrice, gas, activeCurrency, conversionRate, blockGasLimit) {
|
|
|
|
return h('div.send-screen-input-wrapper', [
|
|
|
|
this.state.tooltipIsOpen && h(GasTooltip, {
|
|
|
|
className: 'send-tooltip',
|
|
|
|
gasPrice,
|
|
|
|
gasLimit: gas,
|
|
|
|
onClose: this.closeTooltip,
|
|
|
|
onFeeChange: ({gasLimit, gasPrice}) => {
|
|
|
|
this.setState({
|
|
|
|
newTx: {
|
|
|
|
...this.state.newTx,
|
|
|
|
gas: gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
|
|
|
|
h('div.send-screen-gas-labels', [
|
|
|
|
h('span', [
|
|
|
|
h('i.fa.fa-bolt'),
|
|
|
|
'Gas fee:',
|
|
|
|
]),
|
|
|
|
h('span', 'What\'s this?'),
|
|
|
|
]),
|
|
|
|
|
|
|
|
// TODO: handle loading time when switching to USD
|
|
|
|
h('div.large-input.send-screen-gas-input', {}, [
|
|
|
|
h(GasFeeDisplay, {
|
|
|
|
activeCurrency,
|
|
|
|
conversionRate,
|
|
|
|
gas,
|
|
|
|
gasPrice,
|
|
|
|
blockGasLimit,
|
|
|
|
}),
|
|
|
|
h('div.send-screen-gas-input-customize', {
|
|
|
|
onClick: this.toggleTooltip,
|
|
|
|
}, [
|
|
|
|
'Customize',
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.renderMemoInput = function () {
|
|
|
|
return h('div.send-screen-input-wrapper', [
|
|
|
|
h('div', 'Transaction memo (optional)'),
|
|
|
|
h('input.large-input.send-screen-input', {
|
|
|
|
onChange: () => {
|
|
|
|
this.setState({
|
|
|
|
newTx: Object.assign(
|
|
|
|
this.state.newTx,
|
|
|
|
{
|
|
|
|
memo: event.target.value,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
])
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
SendTransactionScreen.prototype.render = function () {
|
2016-08-25 23:10:07 +02:00
|
|
|
this.persistentFormParentId = 'send-tx-form'
|
|
|
|
|
2017-05-16 08:12:47 +02:00
|
|
|
const props = this.props
|
|
|
|
const {
|
2017-09-20 19:37:12 +02:00
|
|
|
warning,
|
2017-09-20 17:45:47 +02:00
|
|
|
identities,
|
|
|
|
addressBook,
|
2017-05-16 08:21:46 +02:00
|
|
|
conversionRate,
|
2017-05-16 08:12:47 +02:00
|
|
|
} = props
|
2017-08-30 00:57:00 +02:00
|
|
|
|
2017-09-26 01:30:32 +02:00
|
|
|
const {
|
|
|
|
blockGasLimit,
|
|
|
|
newTx,
|
|
|
|
activeCurrency,
|
|
|
|
isValid,
|
|
|
|
} = this.state
|
2017-08-29 14:51:31 +02:00
|
|
|
const { gas, gasPrice } = newTx
|
2017-08-23 00:05:23 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
return (
|
2016-05-18 21:13:19 +02:00
|
|
|
|
2017-09-14 10:32:24 +02:00
|
|
|
h('div.send-screen-wrapper', [
|
2017-07-30 03:54:21 +02:00
|
|
|
// Main Send token Card
|
2017-09-14 10:32:24 +02:00
|
|
|
h('div.send-screen-card', [
|
2016-05-18 21:13:19 +02:00
|
|
|
|
2017-09-14 10:32:24 +02:00
|
|
|
h('img.send-eth-icon', { src: '../images/eth_logo.svg' }),
|
2017-07-30 03:54:21 +02:00
|
|
|
|
2017-09-14 10:32:24 +02:00
|
|
|
h('div.send-screen__title', 'Send'),
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-09-14 10:32:24 +02:00
|
|
|
h('div.send-screen__subtitle', 'Send Ethereum to anyone with an Ethereum account'),
|
2017-07-30 03:07:58 +02:00
|
|
|
|
2017-09-20 17:45:47 +02:00
|
|
|
this.renderFromInput(this.state.newTx.from, identities),
|
|
|
|
|
|
|
|
this.renderToInput(this.state.newTx.to, identities, addressBook),
|
|
|
|
|
|
|
|
this.renderAmountInput(activeCurrency),
|
|
|
|
|
2017-09-22 06:15:26 +02:00
|
|
|
this.renderGasInput(
|
2017-09-27 03:33:03 +02:00
|
|
|
gasPrice || '0x0',
|
|
|
|
gas || '0x0',
|
2017-09-22 06:15:26 +02:00
|
|
|
activeCurrency,
|
|
|
|
conversionRate,
|
|
|
|
blockGasLimit
|
|
|
|
),
|
2017-09-20 17:45:47 +02:00
|
|
|
|
|
|
|
this.renderMemoInput(),
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
this.renderErrorMessage(null, warning),
|
|
|
|
|
2017-08-03 03:24:48 +02:00
|
|
|
]),
|
|
|
|
|
|
|
|
// Buttons underneath card
|
|
|
|
h('section.flex-column.flex-center', [
|
2017-09-14 10:32:24 +02:00
|
|
|
h('button.btn-secondary.send-screen__send-button', {
|
2017-09-20 19:37:12 +02:00
|
|
|
className: !isValid && 'send-screen__send-button__disabled',
|
|
|
|
onClick: (event) => isValid && this.onSubmit(event),
|
2017-08-03 03:24:48 +02:00
|
|
|
}, 'Next'),
|
2017-09-14 10:32:24 +02:00
|
|
|
h('button.btn-tertiary.send-screen__cancel-button', {
|
2017-08-28 20:44:56 +02:00
|
|
|
onClick: this.back,
|
2017-08-03 03:24:48 +02:00
|
|
|
}, 'Cancel'),
|
2017-07-30 04:37:08 +02:00
|
|
|
]),
|
2016-04-14 00:28:44 +02:00
|
|
|
])
|
2017-07-30 03:54:21 +02:00
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-08-28 19:39:05 +02:00
|
|
|
SendTransactionScreen.prototype.toggleTooltip = function () {
|
|
|
|
this.setState({ tooltipIsOpen: !this.state.tooltipIsOpen })
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.closeTooltip = function () {
|
|
|
|
this.setState({ tooltipIsOpen: false })
|
2017-08-24 21:55:03 +02:00
|
|
|
}
|
|
|
|
|
2017-09-13 19:57:15 +02:00
|
|
|
SendTransactionScreen.prototype.setActiveCurrency = function (newCurrency) {
|
|
|
|
this.setState({ activeCurrency: newCurrency })
|
2017-08-25 22:01:56 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
SendTransactionScreen.prototype.back = function () {
|
2016-04-14 00:28:44 +02:00
|
|
|
var address = this.props.address
|
2017-08-29 14:54:58 +02:00
|
|
|
this.props.dispatch(backToAccountDetail(address))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
SendTransactionScreen.prototype.validate = function (balance, amountToSend, { to, from }) {
|
|
|
|
const sufficientBalance = conversionGreaterThan(
|
|
|
|
{
|
|
|
|
value: balance,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: amountToSend,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
},
|
|
|
|
)
|
2017-08-23 00:05:23 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
const amountLessThanZero = conversionGreaterThan(
|
|
|
|
{
|
|
|
|
value: 0,
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: amountToSend,
|
|
|
|
fromNumericBase: 'hex',
|
|
|
|
},
|
|
|
|
)
|
2017-08-23 00:05:23 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
const errors = {}
|
2017-07-30 04:46:59 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (!sufficientBalance) {
|
|
|
|
errors.amount = 'Insufficient funds.'
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (amountLessThanZero) {
|
|
|
|
errors.amount = 'Can not send negative amounts of ETH.'
|
|
|
|
}
|
2016-05-19 20:28:58 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (!from) {
|
|
|
|
errors.from = 'Required'
|
|
|
|
}
|
2016-06-28 02:07:45 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (from && !isValidAddress(from)) {
|
|
|
|
errors.from = 'Sender address is invalid.'
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (!to) {
|
|
|
|
errors.to = 'Required'
|
2016-10-19 23:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
if (to && !isValidAddress(to)) {
|
|
|
|
errors.to = 'Recipient address is invalid.'
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
// if (txData && !isHex(stripHexPrefix(txData))) {
|
|
|
|
// message = 'Transaction data must be hex string.'
|
|
|
|
// return this.props.dispatch(displayWarning(message))
|
|
|
|
// }
|
|
|
|
|
|
|
|
return {
|
|
|
|
isValid: allNull(errors),
|
|
|
|
errors,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.getAmountToSend = function (amount) {
|
|
|
|
const { activeCurrency } = this.state
|
|
|
|
const { conversionRate } = this.props
|
2017-03-10 00:10:27 +01:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
return conversionUtil(amount, {
|
2017-09-12 22:40:28 +02:00
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
2017-09-20 19:37:12 +02:00
|
|
|
fromCurrency: activeCurrency,
|
2017-09-12 22:40:28 +02:00
|
|
|
toCurrency: 'ETH',
|
2017-09-14 04:20:13 +02:00
|
|
|
toDenomination: 'WEI',
|
2017-10-06 17:21:02 +02:00
|
|
|
conversionRate,
|
|
|
|
invertConversionRate: activeCurrency !== 'ETH',
|
2017-09-12 22:40:28 +02:00
|
|
|
})
|
2017-09-20 19:37:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.setErrorsFor = function (field) {
|
|
|
|
const { balance } = this.props
|
|
|
|
const { newTx, errors: previousErrors } = this.state
|
|
|
|
const { amountToSend } = newTx
|
|
|
|
|
|
|
|
const {
|
|
|
|
isValid,
|
|
|
|
errors: newErrors
|
|
|
|
} = this.validate(balance, amountToSend, newTx)
|
|
|
|
|
|
|
|
const nextErrors = Object.assign({}, previousErrors, {
|
|
|
|
[field]: newErrors[field] || null
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!isValid) {
|
|
|
|
this.setState({
|
|
|
|
errors: nextErrors,
|
|
|
|
isValid,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.clearErrorsFor = function (field) {
|
|
|
|
const { errors: previousErrors } = this.state
|
|
|
|
const nextErrors = Object.assign({}, previousErrors, {
|
|
|
|
[field]: null
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
errors: nextErrors,
|
|
|
|
isValid: allNull(nextErrors),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
SendTransactionScreen.prototype.onSubmit = function (event) {
|
|
|
|
event.preventDefault()
|
2017-09-22 06:15:26 +02:00
|
|
|
const { warning, balance } = this.props
|
2017-09-20 19:37:12 +02:00
|
|
|
const state = this.state || {}
|
|
|
|
|
|
|
|
const recipient = state.newTx.to
|
|
|
|
const sender = state.newTx.from
|
|
|
|
const nickname = state.nickname || ' '
|
|
|
|
|
|
|
|
// TODO: convert this to hex when created and include it in send
|
|
|
|
const txData = state.newTx.memo
|
|
|
|
|
|
|
|
this.props.dispatch(hideWarning())
|
|
|
|
|
|
|
|
this.props.dispatch(addToAddressBook(recipient, nickname))
|
|
|
|
|
2017-08-30 00:57:00 +02:00
|
|
|
var txParams = {
|
|
|
|
from: this.state.newTx.from,
|
|
|
|
to: this.state.newTx.to,
|
2017-08-23 00:05:23 +02:00
|
|
|
|
2017-09-22 06:15:26 +02:00
|
|
|
value: this.state.newTx.amountToSend,
|
2017-08-23 00:05:23 +02:00
|
|
|
|
2017-08-30 00:57:00 +02:00
|
|
|
gas: this.state.newTx.gas,
|
2017-09-12 07:14:09 +02:00
|
|
|
gasPrice: this.state.newTx.gasPrice,
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
2016-04-20 03:56:22 +02:00
|
|
|
|
2017-08-29 14:54:58 +02:00
|
|
|
if (recipient) txParams.to = addHexPrefix(recipient)
|
2016-04-14 00:28:44 +02:00
|
|
|
if (txData) txParams.data = txData
|
2016-10-13 04:35:09 +02:00
|
|
|
|
2017-09-20 19:37:12 +02:00
|
|
|
this.props.dispatch(signTx(txParams))
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|