Skip to content

Commit 0639d0d

Browse files
committed
siwa updates and new article (#7197)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the chat functionality within the application by adding a feedback system, updating icons, and improving the knowledge base content related to ERC20 token transfers. ### Detailed summary - Added a new knowledge base entry for "Transfer Amount Exceeds Allowance". - Updated `Header` and `Hero` components to replace `BotIcon` with `MessageCircleIcon`. - Introduced `sendFeedback` function to handle user feedback on chat messages. - Modified `Chat` component to include feedback buttons (thumbs up/down) for messages. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced feedback buttons (thumbs up/down) for assistant messages in the AI chat, allowing users to rate responses. - Added a new "Ask AI" button on the main page, providing quick access to the chat assistant. - Added a new knowledge base article explaining the "ERC20: transfer amount exceeds allowance" error and its resolution. - **Improvements** - Enhanced chat message payloads with source identifiers for better context. - Updated sidebar navigation with a new troubleshooting entry for ERC20 transfer allowance issues. - Updated chat and header icons to use a consistent message circle icon for AI-related features. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 4fed9f4 commit 0639d0d

File tree

8 files changed

+112
-12
lines changed

8 files changed

+112
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function CustomChatContentLoggedIn(props: {
102102
message:
103103
messageToSend.content.find((x) => x.type === "text")?.text ?? "",
104104
conversationId: sessionId,
105+
source: "dashboard-support",
105106
};
106107
const apiUrl = process.env.NEXT_PUBLIC_SIWA_URL;
107108
const response = await fetch(`${apiUrl}/v1/chat`, {

apps/portal/src/app/Header.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
} from "@/components/ui/dropdown-menu";
1111
import clsx from "clsx";
1212
import {
13-
BotIcon,
1413
ChevronDownIcon,
1514
MenuIcon,
15+
MessageCircleIcon,
1616
TableOfContentsIcon,
1717
} from "lucide-react";
1818
import Link from "next/link";
@@ -222,12 +222,11 @@ export function Header() {
222222

223223
<div className="hidden xl:block">
224224
<Button
225-
variant="primary"
226225
onClick={() => {
227226
router.push("/chat");
228227
}}
229228
>
230-
<BotIcon className="mr-2 size-4" />
229+
<MessageCircleIcon className="mr-2 size-4" />
231230
Ask AI
232231
</Button>
233232
</div>
@@ -254,7 +253,7 @@ export function Header() {
254253
className="p-2"
255254
onClick={() => router.push("/chat")}
256255
>
257-
<BotIcon className="size-7" />
256+
<MessageCircleIcon className="size-7" />
258257
</Button>
259258
<Button
260259
variant="ghost"

apps/portal/src/app/knowledge-base/sidebar.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export const sidebar: SideBar = {
7070
name: "Batch Upload",
7171
href: "/knowledge-base/troubleshoot/contracts/batch-upload",
7272
},
73+
{
74+
name: "Transfer Amount Exceeds Allowance",
75+
href: "/knowledge-base/troubleshoot/contracts/erc20-transfer-allowance",
76+
},
7377
],
7478
},
7579
],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ERC20 - Transfer Amount Exceeds Allowance
2+
3+
## What it means
4+
5+
The "ERC20: transfer amount exceeds allowance" error occurs when trying to transfer ERC20 tokens beyond the allowed limit set by the token owner. ERC20 tokens use an allowance system that grants specific addresses permission to transfer a certain amount of tokens on behalf of the owner.
6+
7+
## How to fix it
8+
9+
1. Check allowance: Use the thirdweb Dashboard to verify the current allowance for the sender’s address.
10+
2. Increase allowance: If the allowance is too low, the token owner should call the approve function to increase it.
11+
3. Transfer tokens: Once the allowance is updated, retry the transfer using transferFrom or transfer.
12+
13+
Following these steps should resolve the error. Ensure the allowance covers the transfer amount before initiating.
14+
15+
Can't get this working? [**Contact our support team**](https://thirdweb.com/support) for help.

apps/portal/src/app/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Grid, Heading, SDKCard } from "@/components/Document";
2+
import { Button } from "@/components/ui/button";
3+
import { MessageCircleIcon } from "lucide-react";
24
import Image from "next/image";
35
import Link from "next/link";
46
import { UnityIcon } from "../icons";
@@ -40,6 +42,13 @@ function Hero() {
4042
<p className="mb-8 max-w-md text-lg text-muted-foreground leading-normal">
4143
Development framework for building onchain apps, games, and agents.
4244
</p>
45+
46+
<Link href="/chat">
47+
<Button className="flex items-center gap-2">
48+
<MessageCircleIcon className="size-4" />
49+
Ask AI
50+
</Button>
51+
</Link>
4352
</div>
4453
</div>
4554

apps/portal/src/components/AI/api.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const getChatResponse = async (
1111
const payload = {
1212
message: userMessage,
1313
conversationId: sessionId,
14+
source: "portal",
1415
};
1516
const response = await fetch(`${apiUrl}/v1/chat`, {
1617
method: "POST",
@@ -41,3 +42,31 @@ export const getChatResponse = async (
4142
return null;
4243
}
4344
};
45+
46+
export const sendFeedback = async (
47+
conversationId: string,
48+
feedbackRating: 1 | -1,
49+
) => {
50+
try {
51+
const response = await fetch(`${apiUrl}/v1/chat/feedback`, {
52+
method: "POST",
53+
headers: {
54+
"Content-Type": "application/json",
55+
"x-service-api-key": serviceKey,
56+
},
57+
body: JSON.stringify({ conversationId, feedbackRating }),
58+
});
59+
60+
if (!response.ok) {
61+
const error = await response.text();
62+
throw new Error(`Failed to send feedback: ${response.status} - ${error}`);
63+
}
64+
return true;
65+
} catch (error) {
66+
console.error(
67+
"Feedback API error:",
68+
error instanceof Error ? error.message : "Unknown error",
69+
);
70+
return false;
71+
}
72+
};

apps/portal/src/components/AI/chat.tsx

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { LoadingDots } from "@/components/ui/LoadingDots";
55
import { Button } from "@/components/ui/button";
66
import { AutoResizeTextarea } from "@/components/ui/textarea";
77
import { cn } from "@/lib/utils";
8-
import { ArrowUpIcon, BotIcon } from "lucide-react";
8+
import { MessageCircleIcon } from "lucide-react";
9+
import { ArrowUpIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-react";
910
import { usePostHog } from "posthog-js/react";
1011
import {
1112
type ChangeEvent,
@@ -15,13 +16,14 @@ import {
1516
useRef,
1617
useState,
1718
} from "react";
18-
import { getChatResponse } from "./api";
19+
import { getChatResponse, sendFeedback } from "./api";
1920

2021
interface Message {
2122
id: string;
2223
role: "user" | "assistant";
2324
content: string;
2425
isLoading?: boolean;
26+
feedback?: 1 | -1;
2527
}
2628

2729
const predefinedPrompts = [
@@ -36,7 +38,7 @@ function ChatEmptyState({
3638
}: { onPromptClick: (prompt: string) => void }) {
3739
return (
3840
<div className="flex flex-col items-center justify-center space-y-8 py-16 text-center">
39-
<BotIcon className="size-16" />
41+
<MessageCircleIcon className="size-16" />
4042

4143
<h2 className="font-semibold text-3xl text-foreground">
4244
How can I help you <br />
@@ -153,6 +155,21 @@ export function Chat() {
153155
}
154156
};
155157

158+
const handleFeedback = async (messageId: string, feedback: 1 | -1) => {
159+
if (!conversationId) return; // Don't send feedback if no conversation
160+
161+
try {
162+
await sendFeedback(conversationId, feedback);
163+
setMessages((prevMessages) =>
164+
prevMessages.map((msg) =>
165+
msg.id === messageId ? { ...msg, feedback } : msg,
166+
),
167+
);
168+
} catch (_e) {
169+
// Optionally handle error
170+
}
171+
};
172+
156173
return (
157174
<div
158175
className="mx-auto flex size-full flex-col overflow-hidden lg:min-w-[800px] lg:max-w-5xl"
@@ -183,11 +200,37 @@ export function Chat() {
183200
{message.role === "assistant" && message.isLoading ? (
184201
<LoadingDots />
185202
) : (
186-
<StyledMarkdownRenderer
187-
text={message.content}
188-
isMessagePending={false}
189-
type={message.role}
190-
/>
203+
<>
204+
<StyledMarkdownRenderer
205+
text={message.content}
206+
isMessagePending={false}
207+
type={message.role}
208+
/>
209+
{message.role === "assistant" && !message.isLoading && (
210+
<div className="mt-2 flex gap-2">
211+
{!message.feedback && (
212+
<>
213+
<button
214+
type="button"
215+
aria-label="Thumbs up"
216+
className="text-muted-foreground transition-colors hover:text-green-500"
217+
onClick={() => handleFeedback(message.id, 1)}
218+
>
219+
<ThumbsUpIcon className="size-5" />
220+
</button>
221+
<button
222+
type="button"
223+
aria-label="Thumbs down"
224+
className="text-muted-foreground transition-colors hover:text-red-500"
225+
onClick={() => handleFeedback(message.id, -1)}
226+
>
227+
<ThumbsDownIcon className="size-5" />
228+
</button>
229+
</>
230+
)}
231+
</div>
232+
)}
233+
</>
191234
)}
192235
</div>
193236
</div>

apps/portal/src/icons/siwa-icon.png

1.29 KB
Loading

0 commit comments

Comments
 (0)