Skip to content

Commit 4fa3eb7

Browse files
committed
[TOOL-2807] Nebula: Fix incorrect prepared transaction object, Fix sign_transaction action not shown properly on page reload
1 parent b5ff31e commit 4fa3eb7

File tree

4 files changed

+58
-18
lines changed

4 files changed

+58
-18
lines changed

apps/dashboard/src/app/nebula-app/(app)/api/chat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NEXT_PUBLIC_NEBULA_URL } from "@/constants/env";
22
// TODO - copy the source of this library to dashboard
33
import { stream } from "fetch-event-stream";
4-
import type { SendTransactionOption } from "thirdweb/dist/types/wallets/interfaces/wallet";
4+
import type { NebulaTxData } from "../components/Chats";
55
import type { ExecuteConfig } from "./types";
66

77
export type ContextFilters = {
@@ -140,7 +140,7 @@ type ChatStreamedResponse =
140140
| {
141141
event: "action";
142142
type: "sign_transaction" & (string & {});
143-
data: SendTransactionOption;
143+
data: NebulaTxData;
144144
};
145145

146146
type ChatStreamedEvent =

apps/dashboard/src/app/nebula-app/(app)/api/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type SessionInfo = {
3535
created_at: string;
3636
deleted_at: string | null;
3737
history: Array<{
38-
role: "user" | "assistant"; // role: action is coming up
38+
role: "user" | "assistant" | "action";
3939
content: string;
4040
timestamp: number;
4141
}> | null;

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,51 @@ export function ChatPageContent(props: {
2020
account: Account;
2121
initialPrompt: string | undefined;
2222
}) {
23+
console.log("session", props.session);
2324
const address = useActiveAccount()?.address;
2425
const activeChain = useActiveWalletChain();
2526
const client = useThirdwebClient(props.authToken);
2627
const [userHasSubmittedMessage, setUserHasSubmittedMessage] = useState(false);
2728
const [messages, setMessages] = useState<Array<ChatMessage>>(() => {
2829
if (props.session?.history) {
29-
return props.session.history.map((message) => ({
30-
text: message.content,
31-
type: message.role,
32-
request_id: undefined,
33-
}));
30+
const _messages: ChatMessage[] = [];
31+
32+
for (const message of props.session.history) {
33+
if (message.role === "action") {
34+
try {
35+
const content = JSON.parse(message.content) as {
36+
session_id: string;
37+
request_id: string;
38+
data: string;
39+
type: "sign_transaction" | (string & {});
40+
};
41+
42+
if (content.type === "sign_transaction") {
43+
const txData = JSON.parse(content.data);
44+
if (
45+
typeof txData === "object" &&
46+
txData !== null &&
47+
txData.chainId
48+
) {
49+
_messages.push({
50+
type: "send_transaction",
51+
data: txData,
52+
});
53+
}
54+
}
55+
} catch {
56+
// ignore
57+
}
58+
} else {
59+
_messages.push({
60+
text: message.content,
61+
type: message.role,
62+
request_id: undefined,
63+
});
64+
}
65+
}
66+
67+
return _messages;
3468
}
3569
return [];
3670
});

apps/dashboard/src/app/nebula-app/(app)/components/Chats.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ import {
1515
} from "lucide-react";
1616
import { useEffect, useRef, useState } from "react";
1717
import { toast } from "sonner";
18-
import type { ThirdwebClient } from "thirdweb";
18+
import { type ThirdwebClient, prepareTransaction } from "thirdweb";
1919
import { useSendTransaction } from "thirdweb/react";
20-
import type { Account } from "thirdweb/wallets";
2120
import { TransactionButton } from "../../../../components/buttons/TransactionButton";
2221
import { MarkdownRenderer } from "../../../../components/contract-components/published-contract/markdown-renderer";
2322
import { useV5DashboardChain } from "../../../../lib/v5-adapter";
2423
import { submitFeedback } from "../api/feedback";
2524
import { NebulaIcon } from "../icons/NebulaIcon";
2625

27-
type SendTransactionOption = Parameters<Account["sendTransaction"]>[0];
26+
export type NebulaTxData = {
27+
chainId: number;
28+
data: `0x${string}`;
29+
to: string;
30+
value: string;
31+
};
2832

2933
export type ChatMessage =
3034
| {
@@ -39,7 +43,7 @@ export type ChatMessage =
3943
}
4044
| {
4145
type: "send_transaction";
42-
data: SendTransactionOption | null;
46+
data: NebulaTxData | null;
4347
};
4448

4549
export function Chats(props: {
@@ -203,7 +207,7 @@ export function Chats(props: {
203207
}
204208

205209
function ExecuteTransaction(props: {
206-
txData: SendTransactionOption | null;
210+
txData: NebulaTxData | null;
207211
twAccount: TWAccount;
208212
client: ThirdwebClient;
209213
}) {
@@ -319,7 +323,7 @@ function MessageActions(props: {
319323
}
320324

321325
function SendTransactionButton(props: {
322-
txData: SendTransactionOption;
326+
txData: NebulaTxData;
323327
twAccount: TWAccount;
324328
client: ThirdwebClient;
325329
}) {
@@ -333,14 +337,16 @@ function SendTransactionButton(props: {
333337
transactionCount={1}
334338
txChainID={txData.chainId}
335339
onClick={() => {
336-
const promise = sendTransaction.mutateAsync({
337-
...props.txData,
338-
nonce: Number(txData.nonce),
339-
to: txData.to || undefined, // Get rid of the potential null value
340+
const tx = prepareTransaction({
340341
chain: chain,
341342
client: props.client,
343+
data: txData.data,
344+
to: txData.to,
345+
value: BigInt(txData.value),
342346
});
343347

348+
const promise = sendTransaction.mutateAsync(tx);
349+
344350
toast.promise(promise, {
345351
success: "Transaction sent successfully",
346352
error: "Failed to send transaction",

0 commit comments

Comments
 (0)