Skip to content

Commit

Permalink
pull out of #2314 and #2366
Browse files Browse the repository at this point in the history
  • Loading branch information
tash-2s committed Mar 9, 2024
1 parent 1a82c27 commit 1568ada
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/dev-tools/src/actions/WriteSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { decodeEventLog, AbiEventSignatureNotFoundError, decodeFunctionData, Hex } from "viem";
import {
decodeEventLog,
AbiEventSignatureNotFoundError,
decodeFunctionData,
Hex,
AbiFunctionSignatureNotFoundError,
} from "viem";
import { twMerge } from "tailwind-merge";
import { isDefined } from "@latticexyz/common/utils";
import { PendingIcon } from "../icons/PendingIcon";
Expand Down Expand Up @@ -62,9 +68,20 @@ export function WriteSummary({ write }: Props) {
const functionSelectorAndArgs: Hex = write.request?.args?.length
? (write.request.args[write.request.args.length - 1] as Hex)
: `0x`;
const functionData = decodeFunctionData({ abi: worldAbi, data: functionSelectorAndArgs });
functionName = functionData.functionName;
functionArgs = functionData.args;

// TODO: Since `functionSelectorAndArgs` corresponds to a System's function, decoding it using
// the World ABI may not always be successful. For instance, namespaced system calls could
// result in an error.
// See also https://github.com/latticexyz/mud/issues/2382
try {
const functionData = decodeFunctionData({ abi: worldAbi, data: functionSelectorAndArgs });
functionName = functionData.functionName;
functionArgs = functionData.args;
} catch (error) {
if (!(error instanceof AbiFunctionSignatureNotFoundError)) {
throw error;
}
}
}

return (
Expand Down

0 comments on commit 1568ada

Please sign in to comment.