Skip to content

Commit

Permalink
add parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
karooolis committed Oct 28, 2024
1 parent 4836170 commit 2b5baa6
Showing 1 changed file with 81 additions and 82 deletions.
163 changes: 81 additions & 82 deletions packages/explorer/src/observer/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,95 +25,94 @@ export function observer({ explorerUrl = "http://localhost:13690", waitForTransa
const emit = createBridge({ url: `${explorerUrl}/internal/observer-relay` });

return (client) => ({
async sendUserOperation(args) {
const writeId = `${client.uid}-${++writeCounter}`;
const write = getAction(client, sendUserOperation, "sendUserOperation")(args);
if (!("calls" in args) || !args.calls) return write;

const calls = args.calls
.map((call) => {
if (!call || typeof call !== "object") return undefined;
if (!("to" in call) || typeof call.to !== "string") return undefined;
if (!("functionName" in call) || typeof call.functionName !== "string") return undefined;
if (!("args" in call) || !Array.isArray(call.args)) return undefined;

return {
to: call.to as Address,
functionName: call.functionName,
args: call.args,
...("value" in call && typeof call.value === "bigint" && { value: call.value }),
};
})
.filter(isDefined);
if (calls.length === 0) return write;

emit("write", {
writeId,
from: client.account!.address,
calls,
async sendUserOperation(args) {
const writeId = `${client.uid}-${++writeCounter}`;
const write = getAction(client, sendUserOperation, "sendUserOperation")(args);
if (!("calls" in args) || !args.calls) return write;

const calls = args.calls
.map((call) => {
if (!call || typeof call !== "object") return undefined;
if (!("to" in call) || typeof call.to !== "string") return undefined;
if (!("functionName" in call) || typeof call.functionName !== "string") return undefined;
if (!("args" in call) || !Array.isArray(call.args)) return undefined;

return {
to: call.to as Address,
functionName: call.functionName,
args: call.args,
...("value" in call && typeof call.value === "bigint" && { value: call.value }),
};
})
.filter(isDefined);
if (calls.length === 0) return write;

emit("write", {
writeId,
from: client.account!.address,
calls,
});
Promise.allSettled([write]).then(([result]) => {
emit("write:result", { ...result, writeId });
});

write.then((userOpHash) => {
const receipt = getAction(
client,
waitForUserOperationReceipt,
"waitForUserOperationReceipt",
)({ hash: userOpHash });

emit("waitForUserOperationReceipt", { writeId, userOpHash });
Promise.allSettled([receipt]).then(([result]) => {
emit("waitForUserOperationReceipt:result", { ...result, writeId });
});
Promise.allSettled([write]).then(([result]) => {
emit("write:result", { ...result, writeId });
});

write.then((userOpHash) => {
const receipt = getAction(
client,
waitForUserOperationReceipt,
"waitForUserOperationReceipt",
)({ hash: userOpHash });

emit("waitForUserOperationReceipt", { writeId, userOpHash });
Promise.allSettled([receipt]).then(([result]) => {
emit("waitForUserOperationReceipt:result", { ...result, writeId });
});
});

return write;
},

async writeContract(args) {
const writeId = `${client.uid}-${++writeCounter}`;
const write = getAction(client, writeContract, "writeContract")(args);

emit("write", {
writeId,
from: client.account!.address,
calls: [
{
to: args.address,
functionName: args.functionName,
args: (args.args ?? []) as never,
...(args.value && { value: args.value }),
},
],
});
Promise.allSettled([write]).then(([result]) => {
emit("write:result", { ...result, writeId });
});

return write;
},

async writeContract(args) {
const writeId = `${client.uid}-${++writeCounter}`;
const write = getAction(client, writeContract, "writeContract")(args);

emit("write", {
writeId,
from: client.account!.address,
calls: [
{
to: args.address,
functionName: args.functionName,
args: (args.args ?? []) as never,
...(args.value && { value: args.value }),
},
],
});
Promise.allSettled([write]).then(([result]) => {
emit("write:result", { ...result, writeId });
});

write.then((hash) => {
const receipt = getAction(client, waitForTransactionReceipt, "waitForTransactionReceipt")({ hash });

emit("waitForTransactionReceipt", { writeId, hash });
Promise.allSettled([receipt]).then(([result]) => {
emit("waitForTransactionReceipt:result", { ...result, writeId });
});
});

if (waitForTransaction) {
write.then((hash) => {
const receipt = getAction(client, waitForTransactionReceipt, "waitForTransactionReceipt")({ hash });
const receipt = waitForTransaction(hash);

emit("waitForTransactionReceipt", { writeId, hash });
emit("waitForTransaction", { writeId });
Promise.allSettled([receipt]).then(([result]) => {
emit("waitForTransactionReceipt:result", { ...result, writeId });
emit("waitForTransaction:result", { ...result, writeId });
});
});
}

if (waitForTransaction) {
write.then((hash) => {
const receipt = waitForTransaction(hash);

emit("waitForTransaction", { writeId });
Promise.allSettled([receipt]).then(([result]) => {
emit("waitForTransaction:result", { ...result, writeId });
});
});
}

return write;
},
};
};
return write;
},
});
}

0 comments on commit 2b5baa6

Please sign in to comment.