Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getVisibleOptions = value => {
const { accounts, addressBook, network } = this.props;
const allAddresses = { ...addressBook[network], ...accounts };
if (typeof value !== 'undefined' && value.toString().length > 0) {
// If it's a valid address we don't show any suggestion
if (isValidAddress(value)) {
return allAddresses;
}
const filteredAddresses = {};
Object.keys(allAddresses).forEach(address => {
if (
address.toLowerCase().indexOf(value.toLowerCase()) !== -1 ||
(allAddresses[address].name &&
allAddresses[address].name.toLowerCase().indexOf(value.toLowerCase()) !== -1)
) {
filteredAddresses[address] = allAddresses[address];
}
});
if (filteredAddresses.length > 0) {
return filteredAddresses;
handleUpdateToAddress = async (to, ensRecipient) => {
const {
transaction: { data, assetType }
} = this.props;
// If ETH transaction, there is no need to generate new data
if (assetType === 'ETH') {
const { gas } = await this.estimateGas({ data, to });
this.props.setTransactionObject({ to, gas: hexToBN(gas), ensRecipient });
}
// If selectedAsset defined, generates data
else if (to && isValidAddress(to)) {
const { data, gas } = await this.handleDataGeneration({ to });
this.props.setTransactionObject({ to, gas: hexToBN(gas), data, ensRecipient });
} else {
this.props.setTransactionObject({ to, data: undefined, ensRecipient });
}
};
_validateTransaction (rawTx, cb) {
// Validate 'from' address
if (!rawTx.from) return new Error(`Missing 'from' address`)
if (!isValidAddress(rawTx.from)) return cb(new Error(`Invalid 'from' address`))
// Ensure that transaction params are valid hex strings
const enforcedKeys = ['value', 'data', 'to', 'from', 'gas', 'gasPrice', 'gasLimit', 'nonce']
const keys = Object.keys(rawTx)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (enforcedKeys.indexOf(key) > -1 && !this._isValidHexString(rawTx[key])) {
// Break on first error
cb(new Error(`Transaction parameter '${key}' is not a valid hex string`))
break
}
}
return cb(null)
}
handleCustomAddressChange (value) {
const customAddress = value.trim()
this.setState({
customAddress,
customAddressError: null,
tokenSelectorError: null,
autoFilled: false,
})
const isValidAddress = ethUtil.isValidAddress(customAddress)
const standardAddress = ethUtil.addHexPrefix(customAddress).toLowerCase()
switch (true) {
case !isValidAddress:
this.setState({
customAddressError: this.context.t('invalidAddress'),
customSymbol: '',
customDecimals: 0,
customSymbolError: null,
customDecimalsError: null,
})
break
case Boolean(this.props.identities[standardAddress]):
this.setState({
customAddressError: this.context.t('personalAddressDetected'),
keys.isAccount = (_map) => {
return (Map.isMap(_map) &&
_map.get('privateString' ) &&
_map.get('publicString' ) &&
_map.get('addressString' ) &&
_map.get('privatePrefixed') &&
_map.get('publicPrefixed' ) &&
_map.get('addressPrefixed') &&
utils.isValidPrivate(Buffer.from(_map.get('privateString'), 'hex')) &&
utils.isValidPublic(Buffer.from(_map.get('publicString'), 'hex')) &&
utils.isValidAddress(_map.get('addressPrefixed'))
)
}
Helpers.isEtherAddress = function (address) {
return (
ethUtil.isValidChecksumAddress(address) ||
(
ethUtil.isValidAddress(address) &&
ethUtil.stripHexPrefix(address).toLowerCase() === ethUtil.stripHexPrefix(address)
) ||
(
ethUtil.isValidAddress(address) &&
ethUtil.stripHexPrefix(address).toUpperCase() === ethUtil.stripHexPrefix(address)
)
);
};
function validateRecipient (txParams) {
if (txParams.to === '0x' || txParams.to === null) {
if (txParams.data) {
delete txParams.to
} else {
throw new Error('Invalid recipient address')
}
} else if (txParams.to !== undefined && !isValidAddress(txParams.to)) {
throw new Error('Invalid recipient address')
}
return txParams
}
AddTokenScreen.prototype.tokenAddressDidChange = function (event) {
const el = event.target
const address = el.value.trim()
if (ethUtil.isValidAddress(address) && address !== emptyAddr) {
this.setState({ address })
this.attemptToAutoFillTokenParams(address)
}
}
validateCustomCollectibleAddress = async () => {
let validated = true;
const address = this.state.address;
const isValidEthAddress = isValidAddress(address);
if (address.length === 0) {
this.setState({ warningAddress: strings('collectible.address_cant_be_empty') });
validated = false;
} else if (!isValidEthAddress) {
this.setState({ warningAddress: strings('collectible.address_must_be_valid') });
validated = false;
} else if (!(await isSmartContractAddress(address))) {
this.setState({ warningAddress: strings('collectible.address_must_be_smart_contract') });
validated = false;
} else {
this.setState({ warningAddress: `` });
}
return validated;
};
_validateERC20AssetParams (opts) {
const { rawAddress, symbol, decimals } = opts
if (!rawAddress || !symbol || typeof decimals === 'undefined') throw new Error(`Cannot suggest token without address, symbol, and decimals`)
if (!(symbol.length < 7)) throw new Error(`Invalid symbol ${symbol} more than six characters`)
const numDecimals = parseInt(decimals, 10)
if (isNaN(numDecimals) || numDecimals > 36 || numDecimals < 0) {
throw new Error(`Invalid decimals ${decimals} must be at least 0, and not over 36`)
}
if (!isValidAddress(rawAddress)) throw new Error(`Invalid address ${rawAddress}`)
}
}