Skip to content

Commit

Permalink
fix: use func isHex from web3-utils insteadof homemade
Browse files Browse the repository at this point in the history
  • Loading branch information
tiendn committed Mar 31, 2023
1 parent 8986195 commit 2b5157a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/Card/CardInfo/Components/RawInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/react'
import CopyButton from 'components/Button/CopyButton'
import Tabs from 'components/Tabs/Tabs'
import web3 from 'web3'
import { isHex } from 'web3-utils'
import styles from '../style.module.scss'

type RawInputProps = {
Expand All @@ -23,15 +24,14 @@ const Copy = ({ text }) => {

export default function RawInput({ text }: RawInputProps) {
let utf8Text = text
const regex = /0[xX][0-9a-fA-F]+/g
const isHex = !!utf8Text.match(regex)
const isHexString = isHex(text)
try {
utf8Text = web3.utils.toAscii(text)
} catch (e) {
Sentry.captureException(e)
}

if (!isHex) {
if (!isHexString) {
return (
<div style={{ maxWidth: '885px', maxHeight: '200px', overflowY: 'auto' }}>
<Copy text={utf8Text} />
Expand All @@ -44,11 +44,11 @@ export default function RawInput({ text }: RawInputProps) {
<Tabs
tabs={[
{ title: 'Hex', id: 'hex', padding: ' ' },
{ title: 'UTF-8', id: 'utf8', padding: ' ' }
utf8Text && { title: 'UTF-8', id: 'utf8', padding: ' ' }
]}
contents={{
hex: <Copy text={text} />,
utf8: <Copy text={utf8Text} />
utf8: utf8Text && <Copy text={utf8Text} />
}}
classes="padding-top-xs"
headerBorder={false}
Expand Down

0 comments on commit 2b5157a

Please sign in to comment.