Skip to content

Commit

Permalink
Merge branch 'main' into alvrs/explorer-speed
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Nov 7, 2024
2 parents d9c99c3 + d542357 commit e6cbc69
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-lions-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/explorer": patch
---

Transactions in `Observe` tab now display decoded `callFrom` function calls.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { cn } from "../../../../../../utils";
import { Confirmations } from "./Confirmations";
import { TimingRowExpanded } from "./TimingRowExpanded";
import { columns } from "./TransactionsTable";
import { ObservedTransaction } from "./useObservedTransactions";
import { ObservedTransaction } from "./useMergedTransactions";

function TransactionTableRowDataCell({
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BlockExplorerLink } from "./BlockExplorerLink";
import { TimeAgo } from "./TimeAgo";
import { TimingRowHeader } from "./TimingRowHeader";
import { TransactionTableRow } from "./TransactionTableRow";
import { ObservedTransaction, useObservedTransactions } from "./useObservedTransactions";
import { ObservedTransaction, useMergedTransactions } from "./useMergedTransactions";

const columnHelper = createColumnHelper<ObservedTransaction>();
export const columns = [
Expand Down Expand Up @@ -101,7 +101,7 @@ export const columns = [
];

export function TransactionsTable() {
const transactions = useObservedTransactions();
const transactions = useMergedTransactions();
const [expanded, setExpanded] = useState<ExpandedState>({});

const table = useReactTable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function TransactionsWatcher() {
setTransaction({
hash,
writeId: writeId ?? hash,
from: transaction.from,
from: calls[0]?.from ?? transaction.from,
timestamp,
transaction,
calls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { store as worldStore } from "../store";

export type DecodedUserOperationCall = {
to?: Address;
from?: Address;
functionName: string;
args?: readonly unknown[];
value?: bigint;
Expand All @@ -28,7 +29,7 @@ export type ObservedTransaction = {
error?: BaseError;
};

export function useObservedTransactions() {
export function useMergedTransactions() {
const { worldAddress } = useParams<{ worldAddress: string }>();
const transactions = useStore(worldStore, (state) => state.transactions);
const observerWrites = useStore(observerStore, (state) => state.writes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Abi, Address, Hex, decodeFunctionData } from "viem";
import { DecodedUserOperationCall } from "../useObservedTransactions";
import { DecodedUserOperationCall } from "../useMergedTransactions";

export function getDecodedUserOperationCalls({
abi,
Expand Down Expand Up @@ -36,16 +36,27 @@ function getDecodedUserOperationCall({
}): DecodedUserOperationCall {
let functionName: string | undefined;
let args: readonly unknown[] | undefined;
let from: Address | undefined;

try {
const functionData = decodeFunctionData({ abi, data: data });
functionName = functionData.functionName;
args = functionData.args;

if (functionName === "callFrom") {
const [delegator, , data] = args as [Address, Hex, Hex];
const decodedCallData = decodeFunctionData({ abi, data });
functionName = decodedCallData.functionName;
args = decodedCallData.args;
from = delegator;
}
} catch (error) {
functionName = data.length > 10 ? data.slice(0, 10) : "unknown";
}

return {
to: target,
from,
functionName,
args,
value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStore } from "zustand";
import { ObservedTransaction } from "./observe/useObservedTransactions";
import { ObservedTransaction } from "./observe/useMergedTransactions";

export type State = {
transactions: ObservedTransaction[];
Expand Down
4 changes: 3 additions & 1 deletion packages/explorer/src/observer/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa

emit("write", {
writeId,
from: client.account!.address,
// TODO: type as SessionClient once available from entrykit
// eslint-disable-next-line @typescript-eslint/no-explicit-any
from: (client as any).userAddress ?? client.account!.address,
calls,
});
Promise.allSettled([write]).then(([result]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/src/observer/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, Hash } from "viem";
import { UserOperationReceipt } from "viem/account-abstraction";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
import { ReceiptSummary } from "./common";

export type Messages = {
Expand Down
4 changes: 2 additions & 2 deletions packages/explorer/src/observer/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Address, Hash } from "viem";
import { createStore } from "zustand/vanilla";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useObservedTransactions";
import { DecodedUserOperationCall } from "../app/(explorer)/[chainName]/worlds/[worldAddress]/observe/useMergedTransactions";
import { isPromiseFulfilled } from "../utils";
import { relayChannelName } from "./common";
import { debug } from "./debug";
Expand All @@ -12,8 +12,8 @@ export type Write = {
writeId: string;
type: MessageType;
hash?: Hash;
userOpHash?: Hash;
from: Address;
userOpHash?: Hash;
time: number;
calls: DecodedUserOperationCall[];
events: Message<Exclude<MessageType, "ping">>[];
Expand Down

0 comments on commit e6cbc69

Please sign in to comment.