Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 97872a0

Browse files
committed
removed hardcoded funcName in api/decode
1 parent e6e275c commit 97872a0

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

apps/web/src/modules/proposal/components/ProposalDescription/DecodedTransactions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const DecodedTransactions: React.FC<DecodedTransactionProps> = ({
4646

4747
return (
4848
<Stack gap={'x1'} key={arg.name}>
49-
<Flex>_controller: {clientAddress}</Flex>
49+
<Flex>_client: {clientAddress}</Flex>
5050
<Flex>_resolver: {resolverAddress}</Flex>
5151
<Flex>_providerRecipient: {providerRecipientAddress}</Flex>
5252
<Flex>_clientRecipient: {clientRecipientAddress}</Flex>

apps/web/src/pages/api/decode.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as Sentry from '@sentry/nextjs'
22
import { NextApiRequest, NextApiResponse } from 'next'
3-
import { decodeFunctionData, getAbiItem } from 'viem'
3+
import { decodeFunctionData, getAbiItem, isHex } from 'viem'
44

55
import { CACHE_TIMES } from 'src/constants/cacheTimes'
66
import { getContractABIByAddress } from 'src/services/abiService'
@@ -14,20 +14,24 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
1414
if (!calldata) return res.status(404).json({ error: 'no calldata request' })
1515
if (!chain) return res.status(404).json({ error: 'no chain request' })
1616

17+
if (!isHex(calldata, { strict: true }))
18+
return res.status(400).json({ error: 'bad calldata input' })
19+
1720
const chainInt = parseInt(chain)
1821

1922
try {
20-
const { abi } = await getContractABIByAddress(chainInt as CHAIN_ID, contract)
21-
const decodeResult = decodeFunctionData({ abi: JSON.parse(abi), data: calldata })
23+
const { abi: abiJsonString } = await getContractABIByAddress(
24+
chainInt as CHAIN_ID,
25+
contract
26+
)
27+
const abi = JSON.parse(abiJsonString)
28+
const decodeResult = decodeFunctionData({ abi, data: calldata })
29+
const functionSig = calldata.slice(0, 10)
2230
const functionInfo = getAbiItem({
23-
abi: JSON.parse(abi),
24-
name:
25-
decodeResult.functionName !== 'release'
26-
? decodeResult.functionName
27-
: '0x37bdc99b', // manually set function signature for release(_milestone) instead of release()
31+
abi,
32+
name: functionSig,
2833
})
2934

30-
3135
const argMapping = functionInfo.inputs.reduce(
3236
(last: any, input: any, index: number) => {
3337
last[input.name] = {
@@ -50,6 +54,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
5054
res.status(200).json({
5155
args: argMapping,
5256
functionName: decodeResult.functionName,
57+
functionSig: functionSig,
5358
decoded: decodeResult.args.map((x: any) => x.toString()),
5459
})
5560
} catch (error) {

0 commit comments

Comments
 (0)