Skip to content

Commit 0faa1fc

Browse files
Add recursive decoding for all calldata in params (#152)
* Add recursive decoding for all calldata in params * Fix chain ID selection in playground * Changeset
1 parent 9f992c6 commit 0faa1fc

29 files changed

+4258
-69
lines changed

.changeset/red-lemons-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@3loop/transaction-decoder': minor
3+
---
4+
5+
Added deep-nested decoding of calldata parameters for all transactions. Added 2 new keys to detect calldata in the parameters: \_data and \_target
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react'
2+
import DecodingForm from '@/app/calldata/form'
3+
4+
export default async function CalldataPage({ params }: { params: { chainID: number } }) {
5+
return <DecodingForm chainID={params.chainID} />
6+
}

apps/web/src/app/decode/[chainID]/[hash]/form.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import { NetworkSelect } from '@/components/ui/network-select'
1010
import { ExampleTransactions } from '@/components/ui/examples'
1111

1212
interface FormProps {
13-
currentChainID: number
13+
chainID: number
1414
decoded?: DecodedTransaction
1515
currentHash?: string
1616
}
1717

1818
const PATH = 'decode'
1919

20-
export default function DecodingForm({ decoded, currentHash, currentChainID }: FormProps) {
20+
export default function DecodingForm({ decoded, currentHash, chainID }: FormProps) {
2121
const router = useRouter()
2222

2323
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
2424
e.preventDefault()
2525
const hash = (e.target as any).hash.value
26-
router.push(`/${PATH}/${currentChainID}/${hash}`)
26+
router.push(`/${PATH}/${chainID}/${hash}`)
2727
}
2828

2929
return (
@@ -33,7 +33,7 @@ export default function DecodingForm({ decoded, currentHash, currentChainID }: F
3333
<div className="flex w-full lg:items-center gap-2 flex-col lg:flex-row">
3434
<div>
3535
<NetworkSelect
36-
defaultValue={currentChainID.toString()}
36+
defaultValue={chainID.toString()}
3737
onValueChange={(value) => {
3838
const hash = currentHash || ''
3939
router.push(`/${PATH}/${value}/${hash}`)

apps/web/src/app/decode/[chainID]/[hash]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default async function TransactionPage({ params }: { params: { hash: stri
99
})
1010

1111
if (!decoded || !decoded.toAddress) {
12-
return <DecodingForm currentHash={params.hash} currentChainID={params.chainID} />
12+
return <DecodingForm currentHash={params.hash} chainID={params.chainID} />
1313
}
1414

15-
return <DecodingForm decoded={decoded} currentHash={params.hash} currentChainID={params.chainID} />
15+
return <DecodingForm decoded={decoded} currentHash={params.hash} chainID={params.chainID} />
1616
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as React from 'react'
2+
import DecodingForm from './[hash]/form'
3+
4+
export default async function TransactionPage({ params }: { params: { chainID: number } }) {
5+
return <DecodingForm chainID={params.chainID} />
6+
}

apps/web/src/app/decode/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import DecodingForm from './[chainID]/[hash]/form'
44
import { DEFAULT_CHAIN_ID } from '../data'
55

66
export default function TransactionsPlayground() {
7-
return <DecodingForm currentChainID={DEFAULT_CHAIN_ID} />
7+
return <DecodingForm chainID={DEFAULT_CHAIN_ID} />
88
}

apps/web/src/app/interpret/[chainID]/[hash]/form.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use client'
22
import * as React from 'react'
33
import { Label } from '@/components/ui/label'
4-
import { DEFAULT_CHAIN_ID, geSidebarNavItems, EXAMPLE_TXS, INTERPRETER_REPO } from '@/app/data'
4+
import { EXAMPLE_TXS, INTERPRETER_REPO } from '@/app/data'
55
import { useLocalStorage } from 'usehooks-ts'
6-
import { SidebarNav } from '@/components/ui/sidebar-nav'
76
import { PlayIcon } from '@radix-ui/react-icons'
87
import { Input } from '@/components/ui/input'
98
import { Button } from '@/components/ui/button'
@@ -16,14 +15,14 @@ import { fallbackInterpreter, getInterpreter } from '@3loop/transaction-interpre
1615
import { ExampleTransactions } from '@/components/ui/examples'
1716

1817
interface FormProps {
19-
currentChainID: number
18+
chainID: number
2019
decoded?: DecodedTransaction
2120
currentHash?: string
2221
}
2322

2423
const PATH = 'interpret'
2524

26-
export default function DecodingForm({ decoded, currentHash, currentChainID }: FormProps) {
25+
export default function DecodingForm({ decoded, currentHash, chainID }: FormProps) {
2726
const [result, setResult] = React.useState<Interpretation>()
2827
const [persistedSchema, setSchema] = useLocalStorage(decoded?.toAddress ?? 'unknown', '')
2928

@@ -44,7 +43,7 @@ export default function DecodingForm({ decoded, currentHash, currentChainID }: F
4443
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
4544
e.preventDefault()
4645
const hash = (e.target as any).hash.value
47-
router.push(`/${PATH}/${currentChainID}/${hash}`)
46+
router.push(`/${PATH}/${chainID}/${hash}`)
4847
}
4948

5049
const onRun = React.useCallback(() => {
@@ -84,7 +83,7 @@ export default function DecodingForm({ decoded, currentHash, currentChainID }: F
8483
<div className="flex w-full lg:items-center gap-2 flex-col lg:flex-row">
8584
<div>
8685
<NetworkSelect
87-
defaultValue={currentChainID.toString()}
86+
defaultValue={chainID.toString()}
8887
onValueChange={(value) => {
8988
const hash = currentHash || ''
9089
router.push(`/${PATH}/${value}/${hash}`)

apps/web/src/app/interpret/[chainID]/[hash]/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default async function TransactionPage({ params }: { params: { hash: stri
99
})
1010

1111
if (!decoded || !decoded.toAddress) {
12-
return <DecodingForm currentHash={params.hash} currentChainID={params.chainID} />
12+
return <DecodingForm currentHash={params.hash} chainID={params.chainID} />
1313
}
1414

15-
return <DecodingForm decoded={decoded} currentHash={params.hash} currentChainID={params.chainID} />
15+
return <DecodingForm decoded={decoded} currentHash={params.hash} chainID={params.chainID} />
1616
}

apps/web/src/app/interpret/[chainID]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import * as React from 'react'
33
import DecodingForm from './[hash]/form'
44

55
export default function TransactionsPlayground({ params }: { params: { chainID: number } }) {
6-
return <DecodingForm currentChainID={params.chainID} />
6+
return <DecodingForm chainID={params.chainID} />
77
}

apps/web/src/app/interpret/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import DecodingForm from './[chainID]/[hash]/form'
44
import { DEFAULT_CHAIN_ID } from '../data'
55

66
export default function TransactionsPlayground() {
7-
return <DecodingForm currentChainID={DEFAULT_CHAIN_ID} />
7+
return <DecodingForm chainID={DEFAULT_CHAIN_ID} />
88
}

0 commit comments

Comments
 (0)