mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-22 09:23:21 +01:00
Move checkExistingAddresses to helpers/utils/util and stop its use of ramda (#8868)
This commit is contained in:
parent
429af23ea0
commit
ac525572eb
@ -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…
Reference in New Issue
Block a user