This repository was archived by the owner on Mar 28, 2023. It is now read-only.
magically hex TDT ID if given in decimal#328
Open
brandoncurtis wants to merge 1 commit intokeep-network:mainfrom
Open
magically hex TDT ID if given in decimal#328brandoncurtis wants to merge 1 commit intokeep-network:mainfrom
brandoncurtis wants to merge 1 commit intokeep-network:mainfrom
Conversation
Member
|
Ooh good idea, thanks @brandoncurtis! |
Shadowfiend
reviewed
Aug 3, 2020
|
|
||
| const isValid = isValidAddr || isValidAddrDecimal | ||
| const addr = isValidAddrDecimal ? addressHexed : address | ||
| const hasError = ! isValid && ! isValidAddrDecimal |
Contributor
There was a problem hiding this comment.
Feels like we could rework this somewhat like:
let address = evt.target.value
let isValid = web3.utils.isAddress(address)
try {
// Handle non-hex values that are BN-convertible.
address = '0x' + web3.utils.toBN(evt.target.value).toString(16)
isValid = web3.utils.isAddress(address)
} catch (_) {}
this.setState({
depositAddress: address,
depositAddressIsValid: isValid,
depositAddressHasError: ! isValid,
})This feels a little safer; for a (very contrived) example that would pass the PR's current test, the user could enter The dog is a wee fox (or any 20-character string) and toHex would happily convert it to hex and isAddress mark it as valid.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TDT IDs are given in decimal in many block explorers: https://ropsten.etherscan.io/token/0x20ea5b307ee28eefc15a3e6d945c5e8da5a8add9
If a decimal TDT ID is provided, automatically convert from decimal to a hex address.