Skip to content

[Dashboard] siwa chat widget #7128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { supportedERCs } from "./_utils/detectedFeatures/supportedERCs";
import { getContractPageParamsInfo } from "./_utils/getContractFromParams";
import { getContractPageMetadata } from "./_utils/getContractPageMetadata";
import { getContractPageSidebarLinks } from "./_utils/getContractPageSidebarLinks";
import { examplePrompts } from "../../../../../nebula-app/(app)/data/examplePrompts";

export default async function Layout(props: {
params: Promise<{
Expand Down Expand Up @@ -94,14 +95,6 @@ Users may be considering integrating the contract into their applications. Discu

The following is the user's message:`;

const examplePrompts: string[] = [
"What does this contract do?",
"What permissions or roles exist in this contract?",
"Which functions are used the most?",
"Has this contract been used recently?",
"Who are the largest holders/users of this?",
];

return (
<ContractPageLayout
chainMetadata={chainMetadata}
Expand All @@ -124,10 +117,7 @@ The following is the user's message:`;
chainIds: [chainId],
wallet: accountAddress ?? undefined,
}}
examplePrompts={examplePrompts.map((prompt) => ({
title: prompt,
message: prompt,
}))}
examplePrompts={examplePrompts}
/>
{props.children}
</ContractPageLayout>
Expand Down
39 changes: 16 additions & 23 deletions apps/dashboard/src/app/(app)/(dashboard)/support/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
import { BookOpenIcon, ChevronRightIcon } from "lucide-react";
import type { Metadata } from "next";
import Image from "next/image";
Expand All @@ -10,7 +9,8 @@ import contractsIcon from "../../../../../public/assets/support/contracts.png";
import engineIcon from "../../../../../public/assets/support/engine.png";
import miscIcon from "../../../../../public/assets/support/misc.svg";
import connectIcon from "../../../../../public/assets/support/wallets.png";
import { NebulaChatButton } from "../../../nebula-app/(app)/components/FloatingChat/FloatingChat";
import { getTeams } from "../../../../@/api/team";
import { CustomChatButton } from "../../../nebula-app/(app)/components/CustomChat/CustomChatButton";
import {
getAuthToken,
getAuthTokenWalletAddress,
Expand Down Expand Up @@ -118,25 +118,21 @@ const HELP_PRODUCTS = [
},
] as const;

export const siwaExamplePrompts = [
"I see thirdweb support reference # in my console log please help me",
"What does this contract revert error mean",
"I want to add inapp wallet with sign in with X/twitter auth to my react app",
"Here is my code can you tell me why i'm seeing this error",
];

export default async function SupportPage() {
const [authToken, accountAddress] = await Promise.all([
getAuthToken(),
getAuthTokenWalletAddress(),
]);

const client = getClientThirdwebClient({
jwt: authToken,
teamId: undefined,
});

const supportPromptPrefix =
"You are a Customer Success Agent at thirdweb, assisting customers with blockchain and Web3-related issues. Use the following details to craft a professional, empathetic response: ";
const examplePrompts = [
"ERC20 - Transfer Amount Exceeds Allowance",
"Replacement transaction underpriced / Replacement fee too low",
"Nonce too low: next nonce #, tx nonce #",
"Nonce too high",
];
const teams = await getTeams();
const teamId = teams?.[0]?.id ?? undefined;

return (
<main className="flex flex-col gap-12 pb-12">
Expand All @@ -157,22 +153,19 @@ export default async function SupportPage() {
team.
</p>
<div className="mt-6 flex w-full flex-col items-center gap-3">
<NebulaChatButton
<CustomChatButton
isLoggedIn={!!accountAddress}
networks="all"
isFloating={false}
pageType="support"
label="Ask Nebula AI for support"
client={client}
nebulaParams={{
messagePrefix: supportPromptPrefix,
chainIds: [],
wallet: accountAddress ?? undefined,
}}
label="Ask AI for support"
examplePrompts={examplePrompts.map((prompt) => ({
title: prompt,
message: prompt,
}))}
authToken={authToken || undefined}
teamId={teamId}
clientId={undefined}
/>

<Link
Expand Down
15 changes: 15 additions & 0 deletions apps/dashboard/src/app/(app)/team/[team_slug]/(team)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { AppFooter } from "@/components/blocks/app-footer";
import { TabPathLinks } from "@/components/ui/tabs";
import { AnnouncementBanner } from "components/notices/AnnouncementBanner";
import { redirect } from "next/navigation";
import { siwaExamplePrompts } from "../../../(dashboard)/support/page";
import { getClientThirdwebClient } from "../../../../../@/constants/thirdweb-client.client";
import { CustomChatButton } from "../../../../nebula-app/(app)/components/CustomChat/CustomChatButton";
import { getValidAccount } from "../../../account/settings/getAccount";
import {
getAuthToken,
Expand Down Expand Up @@ -91,6 +93,19 @@ export default async function TeamLayout(props: {
</div>

<main className="flex grow flex-col">{props.children}</main>
<div className="fixed right-6 bottom-6 z-50">
<CustomChatButton
clientId={undefined}
isLoggedIn={true}
networks="all"
isFloating={true}
pageType="support"
label="Ask AI Assistant"
examplePrompts={siwaExamplePrompts}
teamId={team.id}
authToken={authToken}
/>
</div>
<AppFooter />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import { TeamHeaderLoggedIn } from "../../components/TeamHeader/team-header-logged-in.client";
import { ProjectSidebarLayout } from "./components/ProjectSidebarLayout";
import { SaveLastUsedProject } from "./components/SaveLastUsedProject";
import { CustomChatButton } from "../../../../nebula-app/(app)/components/CustomChat/CustomChatButton";
import { siwaExamplePrompts } from "../../../(dashboard)/support/page";

export default async function ProjectLayout(props: {
children: React.ReactNode;
Expand Down Expand Up @@ -78,6 +80,19 @@ export default async function ProjectLayout(props: {
{props.children}
</ProjectSidebarLayout>
</div>
<div className="fixed right-6 bottom-6 z-50">
<CustomChatButton
isLoggedIn={true}
networks="all"
isFloating={true}
pageType="support"
label="Ask AI Assistant"
examplePrompts={siwaExamplePrompts}
teamId={team.id}
clientId={project.publishableKey}
authToken={authToken}
/>
</div>
<SaveLastUsedProject projectId={project.id} teamId={team.id} />
</SidebarProvider>
);
Expand Down
6 changes: 6 additions & 0 deletions apps/dashboard/src/app/(app)/team/[team_slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ArrowRightIcon } from "lucide-react";
import Link from "next/link";
import { redirect } from "next/navigation";
import { Suspense } from "react";
import { getAuthToken } from "../../api/lib/getAuthToken";
import { EnsureValidConnectedWalletLoginServer } from "../../components/EnsureValidConnectedWalletLogin/EnsureValidConnectedWalletLoginServer";
import { isTeamOnboardingComplete } from "../../login/onboarding/isOnboardingRequired";
import { SaveLastVisitedTeamPage } from "../components/last-visited-page/SaveLastVisitedPage";
Expand All @@ -18,12 +19,17 @@ export default async function RootTeamLayout(props: {
params: Promise<{ team_slug: string }>;
}) {
const { team_slug } = await props.params;
const authToken = await getAuthToken();
const team = await getTeamBySlug(team_slug).catch(() => null);

if (!team) {
redirect("/team");
}

if (!authToken) {
redirect("/login");
}

if (!isTeamOnboardingComplete(team)) {
redirect(`/get-started/team/${team.slug}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function ChatBar(props: {
isConnectingWallet: boolean;
allowImageUpload: boolean;
onLoginClick: undefined | (() => void);
placeholder: string;
}) {
const [message, setMessage] = useState(props.prefillMessage || "");
const selectedChainIds = props.context?.chainIds?.map((x) => Number(x)) || [];
Expand Down Expand Up @@ -142,7 +143,7 @@ export function ChatBar(props: {
<div className="p-2">
<div className="max-h-[200px] overflow-y-auto">
<AutoResizeTextarea
placeholder={"Ask Nebula"}
placeholder={props.placeholder}
value={message}
onChange={(e) => setMessage(e.target.value)}
onKeyDown={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export function ChatPageContent(props: {

{messages.length > 0 && (
<Chats
teamId={undefined}
messages={messages}
isChatStreaming={isChatStreaming}
authToken={props.authToken}
Expand All @@ -353,6 +354,7 @@ export function ChatPageContent(props: {

<div className="container max-w-[800px]">
<ChatBar
placeholder="Ask Nebula"
isConnectingWallet={connectionStatus === "connecting"}
showContextSelector={true}
connectedWallets={connectedWalletsMeta}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Variant(props: {
return (
<BadgeContainer label={props.label}>
<ChatBar
placeholder={"Ask Nebula"}
isConnectingWallet={props.isConnectingWallet || false}
client={storybookThirdwebClient}
abortChatStream={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function Variant(props: {
}) {
return (
<Chats
teamId={undefined}
enableAutoScroll={false}
setEnableAutoScroll={() => {}}
client={storybookThirdwebClient}
Expand Down
Loading
Loading