Handles errors with to field and renders warnings from backend in send token.

feature/default_network_editable
Dan 7 years ago committed by Chi Kei Chan
parent 04da22db08
commit 97810acb53
  1. 28
      ui/app/components/send-token/index.js

@ -6,6 +6,7 @@ const classnames = require('classnames')
const inherits = require('util').inherits const inherits = require('util').inherits
const actions = require('../../actions') const actions = require('../../actions')
const selectors = require('../../selectors') const selectors = require('../../selectors')
const { isValidAddress } = require('../../util')
// const BalanceComponent = require('./balance-component') // const BalanceComponent = require('./balance-component')
const Identicon = require('../identicon') const Identicon = require('../identicon')
@ -14,12 +15,12 @@ const CurrencyToggle = require('../send/currency-toggle')
const GasTooltip = require('../send/gas-tooltip') const GasTooltip = require('../send/gas-tooltip')
const GasFeeDisplay = require('../send/gas-fee-display') const GasFeeDisplay = require('../send/gas-fee-display')
module.exports = connect(mapStateToProps, mapDispatchToProps)(SendTokenScreen) module.exports = connect(mapStateToProps, mapDispatchToProps)(SendTokenScreen)
function mapStateToProps (state) { function mapStateToProps (state) {
// const sidebarOpen = state.appState.sidebarOpen // const sidebarOpen = state.appState.sidebarOpen
const { warning } = state.appState
const identities = state.metamask.identities const identities = state.metamask.identities
const addressBook = state.metamask.addressBook const addressBook = state.metamask.addressBook
const conversionRate = state.metamask.conversionRate const conversionRate = state.metamask.conversionRate
@ -34,6 +35,7 @@ function mapStateToProps (state) {
const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {} const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {}
// const checksumAddress = selectedAddress && ethUtil.toChecksumAddress(selectedAddress) // const checksumAddress = selectedAddress && ethUtil.toChecksumAddress(selectedAddress)
// const identity = identities[selectedAddress] // const identity = identities[selectedAddress]
return { return {
// sidebarOpen, // sidebarOpen,
selectedAddress, selectedAddress,
@ -45,6 +47,7 @@ function mapStateToProps (state) {
tokenExchangeRate, tokenExchangeRate,
currentBlockGasLimit, currentBlockGasLimit,
selectedToken, selectedToken,
warning,
// selectedToken: selectors.getSelectedToken(state), // selectedToken: selectors.getSelectedToken(state),
// identity, // identity,
// network, // network,
@ -106,13 +109,6 @@ SendTokenScreen.prototype.validate = function () {
const gasLimit = parseInt(hexGasLimit, 16) / 1000000000 const gasLimit = parseInt(hexGasLimit, 16) / 1000000000
const amount = Number(stringAmount) const amount = Number(stringAmount)
if (to && amount && gasPrice && gasLimit) {
return {
isValid: true,
errors: {},
}
}
const errors = { const errors = {
to: !to ? 'Required' : null, to: !to ? 'Required' : null,
amount: !amount ? 'Required' : null, amount: !amount ? 'Required' : null,
@ -120,9 +116,14 @@ SendTokenScreen.prototype.validate = function () {
gasLimit: !gasLimit ? 'Gas Limit Required' : null, gasLimit: !gasLimit ? 'Gas Limit Required' : null,
} }
if(to && !isValidAddress(to)) {
errors.to = 'Invalid address'
}
const isValid = Object.entries(errors).every(([key, value]) => value === null)
return { return {
isValid: false, isValid,
errors, errors: isValid ? {} : errors,
} }
} }
@ -145,7 +146,6 @@ SendTokenScreen.prototype.submit = function () {
} = this.props } = this.props
const { nickname = ' ' } = identities[to] || {} const { nickname = ' ' } = identities[to] || {}
const { isValid, errors } = this.validate() const { isValid, errors } = this.validate()
if (!isValid) { if (!isValid) {
@ -340,6 +340,7 @@ SendTokenScreen.prototype.render = function () {
const { const {
selectedTokenAddress, selectedTokenAddress,
selectedToken, selectedToken,
warning,
} = this.props } = this.props
return h('div.send-token', [ return h('div.send-token', [
@ -359,6 +360,11 @@ SendTokenScreen.prototype.render = function () {
this.renderAmountInput(), this.renderAmountInput(),
this.renderGasInput(), this.renderGasInput(),
this.renderMemoInput(), this.renderMemoInput(),
warning && h('div.send-screen-input-wrapper--error', {},
h('div.send-screen-input-wrapper__error-message', [
warning,
])
),
]), ]),
this.renderButtons(), this.renderButtons(),
]) ])

Loading…
Cancel
Save