Skip to content

Commit 7011e24

Browse files
authored
feat: EIP-5792 (#94)
1 parent b8c1828 commit 7011e24

17 files changed

+1434
-348
lines changed

bun.lockb

0 Bytes
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"remeda": "^1.14.0",
7171
"sonner": "^0.7.2",
7272
"use-sync-external-store": "^1.2.0",
73-
"viem": "^2.9.13",
73+
"viem": "^2.10.1",
7474
"zustand": "^4.3.8"
7575
},
7676
"devDependencies": {

src/components/abi/DecodedCalldata.tsx

+37-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ export function DecodedCalldata({
2424
address,
2525
data,
2626
labelRight,
27-
}: { address?: Address | null; data: Hex; labelRight?: ReactNode }) {
27+
showRawData,
28+
}: {
29+
address?: Address | null
30+
data: Hex
31+
labelRight?: ReactNode
32+
showRawData?: boolean
33+
}) {
2834
const selector = slice(data, 0, 4)
2935

3036
// Try extract ABI from whatsabi autoloading (etherscan, 4byte dbs, etc)
@@ -107,7 +113,7 @@ export function DecodedCalldata({
107113
</Text>
108114
</Box>
109115
)}
110-
<LabelledContent label="Function">
116+
<LabelledContent label="Signature">
111117
<Box
112118
backgroundColor="surface/primary"
113119
paddingHorizontal="8px"
@@ -128,32 +134,41 @@ export function DecodedCalldata({
128134
)}
129135
</>
130136
)}
131-
{abiItem && <Separator />}
132-
<LabelledContent label="Raw Data" labelRight={labelRight}>
133-
<Box
134-
backgroundColor="surface/primary"
135-
paddingHorizontal="8px"
136-
paddingVertical="12px"
137-
>
138-
{selector && rawArgs ? (
139-
<Text family="mono" size="11px">
140-
<Text color="text/tertiary">{selector}</Text>
141-
{rawArgs.replace('0x', '')}
142-
</Text>
143-
) : (
144-
<Text family="mono" size="11px">
145-
{data}
146-
</Text>
147-
)}
148-
</Box>
149-
</LabelledContent>
137+
{showRawData && abiItem && <Separator />}
138+
{showRawData && (
139+
<LabelledContent label="Raw Data" labelRight={labelRight}>
140+
<Box
141+
backgroundColor="surface/primary"
142+
paddingHorizontal="8px"
143+
paddingVertical="12px"
144+
>
145+
{selector && rawArgs ? (
146+
<Text family="mono" size="11px">
147+
<Text color="text/tertiary">{selector}</Text>
148+
{rawArgs.replace('0x', '')}
149+
</Text>
150+
) : (
151+
<Text family="mono" size="11px">
152+
{data}
153+
</Text>
154+
)}
155+
</Box>
156+
</LabelledContent>
157+
)}
150158
</Stack>
151159
)
152160
}
153161

154162
function getAbiItem({ abi, selector }: { abi: Abi; selector: Hex }) {
155163
const abiItem =
156-
(getAbiItem_viem({ abi, name: selector }) as AbiItem) ||
164+
(getAbiItem_viem({
165+
abi: abi.map((x) => ({
166+
...x,
167+
inputs: (x as any).inputs || [],
168+
outputs: (x as any).outputs || [],
169+
})),
170+
name: selector,
171+
}) as AbiItem) ||
157172
abi.find((x: any) => x.name === selector) ||
158173
abi.find((x: any) => x.selector === selector)
159174
if (!abiItem) return
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useMemo } from 'react'
2+
import { type Hex, parseAbiItem, slice } from 'viem'
3+
4+
import { Text } from '~/design-system'
5+
import { useLookupSignature } from '../../hooks/useLookupSignature'
6+
7+
import { FormattedAbiItem } from './FormattedAbiItem'
8+
9+
export function FormattedAbiFunctionName({ data }: { data: Hex }) {
10+
const selector = slice(data, 0, 4)
11+
const { data: signature } = useLookupSignature({
12+
selector,
13+
})
14+
15+
const abiItem = useMemo(() => {
16+
if (!signature) return
17+
const abiItem = parseAbiItem(`function ${signature}`)
18+
if (abiItem.type !== 'function') return
19+
return abiItem
20+
}, [signature])
21+
22+
return (
23+
<Text family="mono" size="11px" wrap={false}>
24+
{abiItem ? (
25+
<FormattedAbiItem
26+
abiItem={abiItem}
27+
compact
28+
showIndexed={false}
29+
showParameters={false}
30+
showType={false}
31+
/>
32+
) : (
33+
selector
34+
)}
35+
</Text>
36+
)
37+
}

src/components/abi/FormattedAbiItem.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function FormattedAbiItem({
1010
compact,
1111
showIndexed = true,
1212
showParameterNames = true,
13+
showParameters = true,
1314
showStateMutability = true,
1415
showReturns = true,
1516
showType = true,
@@ -19,6 +20,7 @@ export function FormattedAbiItem({
1920
compact?: boolean
2021
showIndexed?: boolean
2122
showParameterNames?: boolean
23+
showParameters?: boolean
2224
showStateMutability?: boolean
2325
showReturns?: boolean
2426
showType?: boolean
@@ -30,7 +32,7 @@ export function FormattedAbiItem({
3032
<>
3133
{showType && <Text color="text/tertiary">function </Text>}
3234
{abiItem.name && <Text>{abiItem.name}</Text>}(
33-
{abiItem.inputs && (
35+
{showParameters && abiItem.inputs && (
3436
<FormattedAbiParameters
3537
params={abiItem.inputs}
3638
showNames={showParameterNames}

0 commit comments

Comments
 (0)