synapsecns/sanguine

View on GitHub
packages/explorer-ui/utils/validateAndParseHash.ts

Summary

Maintainability
A
0 mins
Test Coverage
import _ from 'lodash'

/**
 * gives undefined if hash invalid/ not 64 len
 *
 * @param {string} hash
 * */
export const validateAndParseHash = (hash) => {
  try {
    if (/^0x([A-Fa-f0-9]{64})$/.test(hash)) {
      return _.toLower(hash)
    }
  } catch (error) {
    console.error(error)
    console.error(`${hash} is not a valid txnhash/hash.`)
  }
}