Commit 587b6598 authored by Ian Lapham's avatar Ian Lapham Committed by GitHub

catch error in bytes32 string parsing (#1253)

parent 5388cab7
......@@ -8,6 +8,7 @@ import { isAddress } from '../utils'
import { useActiveWeb3React } from './index'
import { useBytes32TokenContract, useTokenContract } from './useContract'
import { arrayify } from 'ethers/lib/utils'
export function useAllTokens(): { [address: string]: Token } {
const { chainId } = useActiveWeb3React()
......@@ -40,10 +41,12 @@ export function useIsUserAddedToken(currency: Currency): boolean {
// parse a name or symbol from a token response
const BYTES32_REGEX = /^0x[a-fA-F0-9]{64}$/
function parseStringOrBytes32(str: string | undefined, bytes32: string | undefined, defaultValue: string): string {
return str && str.length > 0
? str
: bytes32 && BYTES32_REGEX.test(bytes32)
: // need to check for proper bytes string and valid terminator
bytes32 && BYTES32_REGEX.test(bytes32) && arrayify(bytes32)[31] === 0
? parseBytes32String(bytes32)
: defaultValue
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment