synapsecns/sanguine

View on GitHub
packages/widget/src/utils/getTxBlockExplorerLink.ts

Summary

Maintainability
A
3 hrs
Test Coverage
import { ExplorerLinks, ExplorerNames } from '@/constants/explorer'

export const getTxBlockExplorerLink = (chainId: number, txHash: string) => {
  const blockExplorer = ExplorerLinks[chainId]

  if (blockExplorer && txHash) {
    const explorerUrl = `${blockExplorer}/tx/${txHash}`
    const explorerName = ExplorerNames[chainId]

    return [explorerUrl, explorerName]
  }

  console.error(
    '[Synapse Widget] Error retrieving Native Explorer Transaction URL: ChainID or Transaction Hash missing'
  )
  return [null, null]
}