1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Use constants for send screen errors messages.

This commit is contained in:
Dan 2018-04-30 14:00:01 -02:30
parent bc145dc6a6
commit 4a8c3194c2
4 changed files with 29 additions and 9 deletions

View File

@ -10,5 +10,5 @@ function getToDropdownOpen (state) {
} }
function sendToIsInError (state) { function sendToIsInError (state) {
return Boolean(state.metamask.send.errors.to) return Boolean(state.send.errors.to)
} }

View File

@ -1,12 +1,16 @@
const {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
} = require('../../send.constants')
const { isValidAddress } = require('../../../../util') const { isValidAddress } = require('../../../../util')
function getToErrorObject (to) { function getToErrorObject (to) {
let toError = null let toError = null
if (!to) { if (!to) {
toError = 'required' toError = REQUIRED_ERROR
} else if (!isValidAddress(to)) { } else if (!isValidAddress(to)) {
toError = 'invalidAddressRecipient' toError = INVALID_RECIPIENT_ADDRESS_ERROR
} }
return { to: toError } return { to: toError }

View File

@ -22,12 +22,23 @@ const MIN_GAS_TOTAL = multiplyCurrencies(MIN_GAS_LIMIT_HEX, MIN_GAS_PRICE_HEX, {
const TOKEN_TRANSFER_FUNCTION_SIGNATURE = '0xa9059cbb' const TOKEN_TRANSFER_FUNCTION_SIGNATURE = '0xa9059cbb'
const INSUFFICIENT_FUNDS_ERROR = 'insufficientFunds'
const INSUFFICIENT_TOKENS_ERROR = 'insufficientTokens'
const NEGATIVE_ETH_ERROR = 'negativeETH'
const INVALID_RECIPIENT_ADDRESS_ERROR = 'invalidAddressRecipient'
const REQUIRED_ERROR = 'required'
module.exports = { module.exports = {
INSUFFICIENT_FUNDS_ERROR,
INSUFFICIENT_TOKENS_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
MIN_GAS_LIMIT_DEC,
MIN_GAS_LIMIT_HEX,
MIN_GAS_PRICE_DEC,
MIN_GAS_PRICE_GWEI, MIN_GAS_PRICE_GWEI,
MIN_GAS_PRICE_HEX, MIN_GAS_PRICE_HEX,
MIN_GAS_PRICE_DEC,
MIN_GAS_LIMIT_HEX,
MIN_GAS_LIMIT_DEC,
MIN_GAS_TOTAL, MIN_GAS_TOTAL,
NEGATIVE_ETH_ERROR,
REQUIRED_ERROR,
TOKEN_TRANSFER_FUNCTION_SIGNATURE, TOKEN_TRANSFER_FUNCTION_SIGNATURE,
} }

View File

@ -10,6 +10,11 @@ const {
const { const {
conversionGreaterThan, conversionGreaterThan,
} = require('../../conversion-util') } = require('../../conversion-util')
const {
INSUFFICIENT_FUNDS_ERROR,
INSUFFICIENT_TOKENS_ERROR,
NEGATIVE_ETH_ERROR,
} = require('./send.constants')
module.exports = { module.exports = {
calcGasTotal, calcGasTotal,
@ -125,11 +130,11 @@ function getAmountErrorObject ({
let amountError = null let amountError = null
if (insufficientFunds) { if (insufficientFunds) {
amountError = 'insufficientFunds' amountError = INSUFFICIENT_FUNDS_ERROR
} else if (inSufficientTokens) { } else if (inSufficientTokens) {
amountError = 'insufficientTokens' amountError = INSUFFICIENT_TOKENS_ERROR
} else if (amountLessThanZero) { } else if (amountLessThanZero) {
amountError = 'negativeETH' amountError = NEGATIVE_ETH_ERROR
} }
return { amount: amountError } return { amount: amountError }