Move checkExistingAddresses to helpers/utils/util and stop its use of ramda (#8868)

feature/default_network_editable
Dan J Miller 4 years ago committed by GitHub
parent 429af23ea0
commit ac525572eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      ui/app/helpers/utils/util.js
  2. 29
      ui/app/helpers/utils/util.test.js
  3. 2
      ui/app/pages/add-token/add-token.component.js
  4. 2
      ui/app/pages/add-token/token-list/token-list.component.js
  5. 13
      ui/app/pages/add-token/util.js
  6. 4
      ui/app/pages/send/send-content/add-recipient/add-recipient.js

@ -333,3 +333,23 @@ export function isExtensionUrl (urlLike) {
}
return false
}
/**
* Checks whether an address is in a passed list of objects with address properties. The check is performed on the
* lowercased version of the addresses.
*
* @param {string} address - The hex address to check
* @param {array} list - The array of objects to check
* @returns {boolean} Whether or not the address is in the list
*/
export function checkExistingAddresses (address, list = []) {
if (!address) {
return false
}
const matchesAddress = (obj) => {
return obj.address.toLowerCase() === address.toLowerCase()
}
return list.some(matchesAddress)
}

@ -319,4 +319,33 @@ describe('util', function () {
})
})
})
describe('checkExistingAddresses', function () {
const tokenList = [
{ address: 'A' },
{ address: 'n' },
{ address: 'Q' },
{ address: 'z' },
]
it('should return true when a lowercase address matches an uppercase address in the passed list', function () {
assert(util.checkExistingAddresses('q', tokenList) === true)
})
it('should return true when an uppercase address matches a lowercase address in the passed list', function () {
assert(util.checkExistingAddresses('N', tokenList) === true)
})
it('should return true when a lowercase address matches a lowercase address in the passed list', function () {
assert(util.checkExistingAddresses('z', tokenList) === true)
})
it('should return true when an uppercase address matches an uppercase address in the passed list', function () {
assert(util.checkExistingAddresses('Q', tokenList) === true)
})
it('should return false when the passed address is not in the passed list', function () {
assert(util.checkExistingAddresses('b', tokenList) === false)
})
})
})

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import ethUtil from 'ethereumjs-util'
import { checkExistingAddresses } from './util'
import { checkExistingAddresses } from '../../helpers/utils/util'
import { tokenInfoGetter } from '../../helpers/utils/token-util'
import { CONFIRM_ADD_TOKEN_ROUTE } from '../../helpers/constants/routes'
import TextField from '../../components/ui/text-field'

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { checkExistingAddresses } from '../util'
import { checkExistingAddresses } from '../../../helpers/utils/util'
import TokenListPlaceholder from './token-list-placeholder'
export default class InfoBox extends Component {

@ -1,13 +0,0 @@
import R from 'ramda'
export function checkExistingAddresses (address, tokenList = []) {
if (!address) {
return false
}
const matchesAddress = (existingToken) => {
return existingToken.address.toLowerCase() === address.toLowerCase()
}
return R.any(matchesAddress)(tokenList)
}

@ -5,9 +5,7 @@ import {
INVALID_RECIPIENT_ADDRESS_NOT_ETH_NETWORK_ERROR,
} from '../../send.constants'
import { isValidAddress, isEthNetwork } from '../../../../helpers/utils/util'
import { checkExistingAddresses } from '../../../add-token/util'
import { isValidAddress, isEthNetwork, checkExistingAddresses } from '../../../../helpers/utils/util'
import ethUtil from 'ethereumjs-util'
import contractMap from 'eth-contract-metadata'

Loading…
Cancel
Save