Skip to content

Commit

Permalink
Merge branch 'main' into Ink-Mainnet-Chain-Page-Update
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinTurska authored Dec 19, 2024
2 parents 62a0237 + fd4664a commit edd9d06
Show file tree
Hide file tree
Showing 13 changed files with 864 additions and 346 deletions.
1 change: 1 addition & 0 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"next-seo": "^6.5.0",
"next-themes": "^0.4.4",
"nextjs-toploader": "^1.6.12",
"openapi-types": "^12.1.3",
"papaparse": "^5.4.1",
"pluralize": "^8.0.0",
"posthog-js": "1.67.1",
Expand Down
8 changes: 5 additions & 3 deletions apps/dashboard/src/@/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const SelectValue = SelectPrimitive.Value;

const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
chevronClassName?: string;
}
>(({ className, children, chevronClassName, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
Expand All @@ -26,7 +28,7 @@ const SelectTrigger = React.forwardRef<
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
<ChevronDown className={cn("h-4 w-4 opacity-50", chevronClassName)} />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
Expand Down
6 changes: 5 additions & 1 deletion apps/dashboard/src/@/components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function ToolTipLabel(props: {
rightIcon?: React.ReactNode;
leftIcon?: React.ReactNode;
hoverable?: boolean;
contentClassName?: string;
}) {
if (!props.label) {
return props.children;
Expand All @@ -48,7 +49,10 @@ export function ToolTipLabel(props: {
</TooltipTrigger>
<TooltipContent
sideOffset={10}
className="max-w-[400px] whitespace-normal leading-relaxed"
className={cn(
"max-w-[400px] whitespace-normal leading-relaxed",
props.contentClassName,
)}
>
<div className="flex items-center gap-1.5 p-2 text-sm">
{props.leftIcon}
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/nebula-app/(app)/api/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NEXT_PUBLIC_NEBULA_URL } from "@/constants/env";
// TODO - copy the source of this library to dashboard
import { stream } from "fetch-event-stream";
import type { SendTransactionOption } from "thirdweb/dist/types/wallets/interfaces/wallet";
import type { NebulaTxData } from "../components/Chats";
import type { ExecuteConfig } from "./types";

export type ContextFilters = {
Expand Down Expand Up @@ -140,7 +140,7 @@ type ChatStreamedResponse =
| {
event: "action";
type: "sign_transaction" & (string & {});
data: SendTransactionOption;
data: NebulaTxData;
};

type ChatStreamedEvent =
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/nebula-app/(app)/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type SessionInfo = {
created_at: string;
deleted_at: string | null;
history: Array<{
role: "user" | "assistant"; // role: action is coming up
role: "user" | "assistant" | "action";
content: string;
timestamp: number;
}> | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,44 @@ export function ChatPageContent(props: {
const [userHasSubmittedMessage, setUserHasSubmittedMessage] = useState(false);
const [messages, setMessages] = useState<Array<ChatMessage>>(() => {
if (props.session?.history) {
return props.session.history.map((message) => ({
text: message.content,
type: message.role,
request_id: undefined,
}));
const _messages: ChatMessage[] = [];

for (const message of props.session.history) {
if (message.role === "action") {
try {
const content = JSON.parse(message.content) as {
session_id: string;
request_id: string;
data: string;
type: "sign_transaction" | (string & {});
};

if (content.type === "sign_transaction") {
const txData = JSON.parse(content.data);
if (
typeof txData === "object" &&
txData !== null &&
txData.chainId
) {
_messages.push({
type: "send_transaction",
data: txData,
});
}
}
} catch {
// ignore
}
} else {
_messages.push({
text: message.content,
type: message.role,
request_id: undefined,
});
}
}

return _messages;
}
return [];
});
Expand Down
26 changes: 16 additions & 10 deletions apps/dashboard/src/app/nebula-app/(app)/components/Chats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ import {
} from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import type { ThirdwebClient } from "thirdweb";
import { type ThirdwebClient, prepareTransaction } from "thirdweb";
import { useSendTransaction } from "thirdweb/react";
import type { Account } from "thirdweb/wallets";
import { TransactionButton } from "../../../../components/buttons/TransactionButton";
import { MarkdownRenderer } from "../../../../components/contract-components/published-contract/markdown-renderer";
import { useV5DashboardChain } from "../../../../lib/v5-adapter";
import { submitFeedback } from "../api/feedback";
import { NebulaIcon } from "../icons/NebulaIcon";

type SendTransactionOption = Parameters<Account["sendTransaction"]>[0];
export type NebulaTxData = {
chainId: number;
data: `0x${string}`;
to: string;
value: string;
};

export type ChatMessage =
| {
Expand All @@ -39,7 +43,7 @@ export type ChatMessage =
}
| {
type: "send_transaction";
data: SendTransactionOption | null;
data: NebulaTxData | null;
};

export function Chats(props: {
Expand Down Expand Up @@ -203,7 +207,7 @@ export function Chats(props: {
}

function ExecuteTransaction(props: {
txData: SendTransactionOption | null;
txData: NebulaTxData | null;
twAccount: TWAccount;
client: ThirdwebClient;
}) {
Expand Down Expand Up @@ -319,7 +323,7 @@ function MessageActions(props: {
}

function SendTransactionButton(props: {
txData: SendTransactionOption;
txData: NebulaTxData;
twAccount: TWAccount;
client: ThirdwebClient;
}) {
Expand All @@ -333,14 +337,16 @@ function SendTransactionButton(props: {
transactionCount={1}
txChainID={txData.chainId}
onClick={() => {
const promise = sendTransaction.mutateAsync({
...props.txData,
nonce: Number(txData.nonce),
to: txData.to || undefined, // Get rid of the potential null value
const tx = prepareTransaction({
chain: chain,
client: props.client,
data: txData.data,
to: txData.to,
value: BigInt(txData.value),
});

const promise = sendTransaction.mutateAsync(tx);

toast.promise(promise, {
success: "Transaction sent successfully",
error: "Failed to send transaction",
Expand Down
Loading

0 comments on commit edd9d06

Please sign in to comment.