Skip to content

Commit edd9d06

Browse files
authored
Merge branch 'main' into Ink-Mainnet-Chain-Page-Update
2 parents 62a0237 + fd4664a commit edd9d06

File tree

13 files changed

+864
-346
lines changed

13 files changed

+864
-346
lines changed

apps/dashboard/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"next-seo": "^6.5.0",
7474
"next-themes": "^0.4.4",
7575
"nextjs-toploader": "^1.6.12",
76+
"openapi-types": "^12.1.3",
7677
"papaparse": "^5.4.1",
7778
"pluralize": "^8.0.0",
7879
"posthog-js": "1.67.1",

apps/dashboard/src/@/components/ui/select.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ const SelectValue = SelectPrimitive.Value;
1414

1515
const SelectTrigger = React.forwardRef<
1616
React.ElementRef<typeof SelectPrimitive.Trigger>,
17-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
18-
>(({ className, children, ...props }, ref) => (
17+
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
18+
chevronClassName?: string;
19+
}
20+
>(({ className, children, chevronClassName, ...props }, ref) => (
1921
<SelectPrimitive.Trigger
2022
ref={ref}
2123
className={cn(
@@ -26,7 +28,7 @@ const SelectTrigger = React.forwardRef<
2628
>
2729
{children}
2830
<SelectPrimitive.Icon asChild>
29-
<ChevronDown className="h-4 w-4 opacity-50" />
31+
<ChevronDown className={cn("h-4 w-4 opacity-50", chevronClassName)} />
3032
</SelectPrimitive.Icon>
3133
</SelectPrimitive.Trigger>
3234
));

apps/dashboard/src/@/components/ui/tooltip.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function ToolTipLabel(props: {
3535
rightIcon?: React.ReactNode;
3636
leftIcon?: React.ReactNode;
3737
hoverable?: boolean;
38+
contentClassName?: string;
3839
}) {
3940
if (!props.label) {
4041
return props.children;
@@ -48,7 +49,10 @@ export function ToolTipLabel(props: {
4849
</TooltipTrigger>
4950
<TooltipContent
5051
sideOffset={10}
51-
className="max-w-[400px] whitespace-normal leading-relaxed"
52+
className={cn(
53+
"max-w-[400px] whitespace-normal leading-relaxed",
54+
props.contentClassName,
55+
)}
5256
>
5357
<div className="flex items-center gap-1.5 p-2 text-sm">
5458
{props.leftIcon}

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: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,44 @@ export function ChatPageContent(props: {
2626
const [userHasSubmittedMessage, setUserHasSubmittedMessage] = useState(false);
2727
const [messages, setMessages] = useState<Array<ChatMessage>>(() => {
2828
if (props.session?.history) {
29-
return props.session.history.map((message) => ({
30-
text: message.content,
31-
type: message.role,
32-
request_id: undefined,
33-
}));
29+
const _messages: ChatMessage[] = [];
30+
31+
for (const message of props.session.history) {
32+
if (message.role === "action") {
33+
try {
34+
const content = JSON.parse(message.content) as {
35+
session_id: string;
36+
request_id: string;
37+
data: string;
38+
type: "sign_transaction" | (string & {});
39+
};
40+
41+
if (content.type === "sign_transaction") {
42+
const txData = JSON.parse(content.data);
43+
if (
44+
typeof txData === "object" &&
45+
txData !== null &&
46+
txData.chainId
47+
) {
48+
_messages.push({
49+
type: "send_transaction",
50+
data: txData,
51+
});
52+
}
53+
}
54+
} catch {
55+
// ignore
56+
}
57+
} else {
58+
_messages.push({
59+
text: message.content,
60+
type: message.role,
61+
request_id: undefined,
62+
});
63+
}
64+
}
65+
66+
return _messages;
3467
}
3568
return [];
3669
});

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)