aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-09-21 07:04:03 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-09-22 07:41:52 +0800
commit97810acb5355be575914a2e1e57a1cacd9fbccfa (patch)
treed1fe6c63c9627bb5afd711f9b8728aaace01a641 /ui/app/components
parent04da22db0863a9a361a0f414d9cc37bf3bb3a392 (diff)
downloadtangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar.gz
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar.bz2
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar.lz
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar.xz
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.tar.zst
tangerine-wallet-browser-97810acb5355be575914a2e1e57a1cacd9fbccfa.zip
Handles errors with to field and renders warnings from backend in send token.
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/send-token/index.js28
1 files changed, 17 insertions, 11 deletions
diff --git a/ui/app/components/send-token/index.js b/ui/app/components/send-token/index.js
index 72fb593be..7adbf48dc 100644
--- a/ui/app/components/send-token/index.js
+++ b/ui/app/components/send-token/index.js
@@ -6,6 +6,7 @@ const classnames = require('classnames')
const inherits = require('util').inherits
const actions = require('../../actions')
const selectors = require('../../selectors')
+const { isValidAddress } = require('../../util')
// const BalanceComponent = require('./balance-component')
const Identicon = require('../identicon')
@@ -14,12 +15,12 @@ const CurrencyToggle = require('../send/currency-toggle')
const GasTooltip = require('../send/gas-tooltip')
const GasFeeDisplay = require('../send/gas-fee-display')
-
module.exports = connect(mapStateToProps, mapDispatchToProps)(SendTokenScreen)
function mapStateToProps (state) {
// const sidebarOpen = state.appState.sidebarOpen
+ const { warning } = state.appState
const identities = state.metamask.identities
const addressBook = state.metamask.addressBook
const conversionRate = state.metamask.conversionRate
@@ -34,6 +35,7 @@ function mapStateToProps (state) {
const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {}
// const checksumAddress = selectedAddress && ethUtil.toChecksumAddress(selectedAddress)
// const identity = identities[selectedAddress]
+
return {
// sidebarOpen,
selectedAddress,
@@ -45,6 +47,7 @@ function mapStateToProps (state) {
tokenExchangeRate,
currentBlockGasLimit,
selectedToken,
+ warning,
// selectedToken: selectors.getSelectedToken(state),
// identity,
// network,
@@ -106,13 +109,6 @@ SendTokenScreen.prototype.validate = function () {
const gasLimit = parseInt(hexGasLimit, 16) / 1000000000
const amount = Number(stringAmount)
- if (to && amount && gasPrice && gasLimit) {
- return {
- isValid: true,
- errors: {},
- }
- }
-
const errors = {
to: !to ? 'Required' : null,
amount: !amount ? 'Required' : null,
@@ -120,9 +116,14 @@ SendTokenScreen.prototype.validate = function () {
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 {
- isValid: false,
- errors,
+ isValid,
+ errors: isValid ? {} : errors,
}
}
@@ -145,7 +146,6 @@ SendTokenScreen.prototype.submit = function () {
} = this.props
const { nickname = ' ' } = identities[to] || {}
-
const { isValid, errors } = this.validate()
if (!isValid) {
@@ -340,6 +340,7 @@ SendTokenScreen.prototype.render = function () {
const {
selectedTokenAddress,
selectedToken,
+ warning,
} = this.props
return h('div.send-token', [
@@ -359,6 +360,11 @@ SendTokenScreen.prototype.render = function () {
this.renderAmountInput(),
this.renderGasInput(),
this.renderMemoInput(),
+ warning && h('div.send-screen-input-wrapper--error', {},
+ h('div.send-screen-input-wrapper__error-message', [
+ warning,
+ ])
+ ),
]),
this.renderButtons(),
])