Skip to content

Commit d542357

Browse files
authored
feat(explorer): decoded callFrom transactions (#3364)
1 parent 0facee0 commit d542357

File tree

10 files changed

+30
-11
lines changed

10 files changed

+30
-11
lines changed

.changeset/mighty-lions-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
Transactions in `Observe` tab now display decoded `callFrom` function calls.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionTableRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { cn } from "../../../../../../utils";
88
import { Confirmations } from "./Confirmations";
99
import { TimingRowExpanded } from "./TimingRowExpanded";
1010
import { columns } from "./TransactionsTable";
11-
import { ObservedTransaction } from "./useObservedTransactions";
11+
import { ObservedTransaction } from "./useMergedTransactions";
1212

1313
function TransactionTableRowDataCell({
1414
label,

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BlockExplorerLink } from "./BlockExplorerLink";
1212
import { TimeAgo } from "./TimeAgo";
1313
import { TimingRowHeader } from "./TimingRowHeader";
1414
import { TransactionTableRow } from "./TransactionTableRow";
15-
import { ObservedTransaction, useObservedTransactions } from "./useObservedTransactions";
15+
import { ObservedTransaction, useMergedTransactions } from "./useMergedTransactions";
1616

1717
const columnHelper = createColumnHelper<ObservedTransaction>();
1818
export const columns = [
@@ -101,7 +101,7 @@ export const columns = [
101101
];
102102

103103
export function TransactionsTable() {
104-
const transactions = useObservedTransactions();
104+
const transactions = useMergedTransactions();
105105
const [expanded, setExpanded] = useState<ExpandedState>({});
106106

107107
const table = useReactTable({

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/TransactionsWatcher.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export function TransactionsWatcher() {
7474
setTransaction({
7575
hash,
7676
writeId: writeId ?? hash,
77-
from: transaction.from,
77+
from: calls[0]?.from ?? transaction.from,
7878
timestamp,
7979
transaction,
8080
calls,

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions.ts renamed to packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { store as worldStore } from "../store";
88

99
export type DecodedUserOperationCall = {
1010
to?: Address;
11+
from?: Address;
1112
functionName: string;
1213
args?: readonly unknown[];
1314
value?: bigint;
@@ -28,7 +29,7 @@ export type ObservedTransaction = {
2829
error?: BaseError;
2930
};
3031

31-
export function useObservedTransactions() {
32+
export function useMergedTransactions() {
3233
const { worldAddress } = useParams<{ worldAddress: string }>();
3334
const transactions = useStore(worldStore, (state) => state.transactions);
3435
const observerWrites = useStore(observerStore, (state) => state.writes);

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/observe/utils/getDecodedUserOperationCalls.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Abi, Address, Hex, decodeFunctionData } from "viem";
2-
import { DecodedUserOperationCall } from "../useObservedTransactions";
2+
import { DecodedUserOperationCall } from "../useMergedTransactions";
33

44
export function getDecodedUserOperationCalls({
55
abi,
@@ -36,16 +36,27 @@ function getDecodedUserOperationCall({
3636
}): DecodedUserOperationCall {
3737
let functionName: string | undefined;
3838
let args: readonly unknown[] | undefined;
39+
let from: Address | undefined;
40+
3941
try {
4042
const functionData = decodeFunctionData({ abi, data: data });
4143
functionName = functionData.functionName;
4244
args = functionData.args;
45+
46+
if (functionName === "callFrom") {
47+
const [delegator, , data] = args as [Address, Hex, Hex];
48+
const decodedCallData = decodeFunctionData({ abi, data });
49+
functionName = decodedCallData.functionName;
50+
args = decodedCallData.args;
51+
from = delegator;
52+
}
4353
} catch (error) {
4454
functionName = data.length > 10 ? data.slice(0, 10) : "unknown";
4555
}
4656

4757
return {
4858
to: target,
59+
from,
4960
functionName,
5061
args,
5162
value,

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createStore } from "zustand";
2-
import { ObservedTransaction } from "./observe/useObservedTransactions";
2+
import { ObservedTransaction } from "./observe/useMergedTransactions";
33

44
export type State = {
55
transactions: ObservedTransaction[];

packages/explorer/src/observer/decorator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa
4949

5050
emit("write", {
5151
writeId,
52-
from: client.account!.address,
52+
// TODO: type as SessionClient once available from entrykit
53+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54+
from: (client as any).userAddress ?? client.account!.address,
5355
calls,
5456
});
5557
Promise.allSettled([write]).then(([result]) => {

packages/explorer/src/observer/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Address, Hash } from "viem";
22
import { UserOperationReceipt } from "viem/account-abstraction";
3-
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
3+
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
44
import { ReceiptSummary } from "./common";
55

66
export type Messages = {

packages/explorer/src/observer/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { Address, Hash } from "viem";
44
import { createStore } from "zustand/vanilla";
5-
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
5+
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
66
import { isPromiseFulfilled } from "../utils";
77
import { relayChannelName } from "./common";
88
import { debug } from "./debug";
@@ -12,8 +12,8 @@ export type Write = {
1212
writeId: string;
1313
type: MessageType;
1414
hash?: Hash;
15-
userOpHash?: Hash;
1615
from: Address;
16+
userOpHash?: Hash;
1717
time: number;
1818
calls: DecodedUserOperationCall[];
1919
events: Message<Exclude<MessageType, "ping">>[];

0 commit comments

Comments
 (0)