From 296827a62f3809fa2800cb900fbe5d0396149ba4 Mon Sep 17 00:00:00 2001 From: Alissa Crane Date: Tue, 5 Nov 2024 15:05:10 -0800 Subject: [PATCH 01/11] add formatting --- app/components/Agent.tsx | 44 ++++---- app/components/AgentProfile.tsx | 22 ++-- app/components/AgentStats.tsx | 26 ++--- app/components/ChatInput.tsx | 20 ++-- app/components/Footer.tsx | 2 +- app/components/LanguageSelector.tsx | 20 ++-- app/components/Navbar.tsx | 16 +-- app/components/Stream.tsx | 22 ++-- app/components/TimeDisplay.tsx | 22 ++-- app/constants.ts | 10 +- app/hooks/useChat.ts | 18 ++-- app/page.tsx | 4 +- app/providers.tsx | 10 +- app/translations.ts | 160 ++++++++++++++-------------- app/types.ts | 16 +-- app/utils.tsx | 48 ++++----- biome.json | 66 ++++++++++++ bun.lockb | Bin 454819 -> 458329 bytes next.config.js | 28 ++--- package.json | 6 +- tailwind.config.ts | 12 +-- 21 files changed, 321 insertions(+), 251 deletions(-) create mode 100644 biome.json diff --git a/app/components/Agent.tsx b/app/components/Agent.tsx index b4c82fc..3a544a3 100644 --- a/app/components/Agent.tsx +++ b/app/components/Agent.tsx @@ -1,29 +1,29 @@ -import { useState, useEffect, useCallback } from "react"; +import { useState, useEffect, useCallback } from 'react'; -import Navbar from "./Navbar"; -import { ActionEntry, AgentMessage, Language, StreamEntry } from "../types"; -import Stream from "./Stream"; -import ChatInput from "./ChatInput"; -import Footer from "./Footer"; -import AgentProfile from "./AgentProfile"; -import AgentStats from "./AgentStats"; -import useChat from "../hooks/useChat"; +import Navbar from './Navbar'; +import { ActionEntry, AgentMessage, Language, StreamEntry } from '../types'; +import Stream from './Stream'; +import ChatInput from './ChatInput'; +import Footer from './Footer'; +import AgentProfile from './AgentProfile'; +import AgentStats from './AgentStats'; +import useChat from '../hooks/useChat'; export default function Agent() { const [streamEntries, setStreamEntries] = useState([]); - const [userInput, setUserInput] = useState(""); + const [userInput, setUserInput] = useState(''); const [isThinking, setIsThinking] = useState(true); - const [loadingDots, setLoadingDots] = useState(""); + const [loadingDots, setLoadingDots] = useState(''); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); - const [currentLanguage, setCurrentLanguage] = useState("en"); + const [currentLanguage, setCurrentLanguage] = useState('en'); const [isLiveDotVisible, setIsLiveDotVisible] = useState(true); const [isChatMode, setIsChatMode] = useState(false); const handleSuccess = useCallback((messages: AgentMessage[]) => { - const message = messages.find((res) => res.event === "agent"); + const message = messages.find((res) => res.event === 'agent'); const streamEntry = { timestamp: new Date(), - content: message?.data || "", + content: message?.data || '', }; setIsThinking(false); setStreamEntries((prev) => [...prev, streamEntry]); @@ -38,7 +38,7 @@ export default function Agent() { useEffect(() => { const streamInterval = setInterval(() => { if (!isLoading && !isChatMode) { - postChat("same a one liner that is inspiring"); + postChat('same a one liner that is inspiring'); } }, 1500); @@ -50,7 +50,7 @@ export default function Agent() { // enables dot animation for "agent is thinking..." useEffect(() => { const dotsInterval = setInterval(() => { - setLoadingDots((prev) => (prev.length >= 3 ? "" : prev + ".")); + setLoadingDots((prev) => (prev.length >= 3 ? '' : prev + '.')); }, 500); return () => clearInterval(dotsInterval); @@ -72,11 +72,11 @@ export default function Agent() { // disable live stream setIsChatMode(true); - setUserInput(""); + setUserInput(''); const userMessage: ActionEntry = { timestamp: new Date(), - type: "user", + type: 'user', content: userInput.trim(), }; @@ -84,17 +84,17 @@ export default function Agent() { postChat(userInput); }, - [postChat, userInput] + [postChat, userInput], ); const handleKeyPress = useCallback( (e: React.KeyboardEvent) => { - if (e.key === "Enter" && !e.shiftKey) { + if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(e); } }, - [handleSubmit] + [handleSubmit], ); const handleLanguageChange = useCallback((lang: Language) => { @@ -115,7 +115,7 @@ export default function Agent() {
setShowToast(false), 2000); // Hide toast after 2 seconds }) .catch((err) => { - console.error("Failed to copy wallet address: ", err); + console.error('Failed to copy wallet address: ', err); }); }, []); @@ -37,24 +37,24 @@ export default function AgentProfile({ currentLanguage }: AgentProfileProps) { const normalizedX = Math.min( Math.max((dx / maxDistance) * 30 + 50, 20), - 80 + 80, ); const normalizedY = Math.min( Math.max((dy / maxDistance) * 30 + 50, 20), - 80 + 80, ); setEyePosition({ x: normalizedX, y: normalizedY }); } }; - window.addEventListener("mousemove", handleMouseMove); - return () => window.removeEventListener("mousemove", handleMouseMove); + window.addEventListener('mousemove', handleMouseMove); + return () => window.removeEventListener('mousemove', handleMouseMove); }, []); const formattedAddress = useMemo(() => { return `${AGENT_WALLET_ADDRESS.slice(0, 6)}...${AGENT_WALLET_ADDRESS.slice( - -4 + -4, )}`; }, []); @@ -100,7 +100,7 @@ export default function AgentProfile({ currentLanguage }: AgentProfileProps) {

{translations[currentLanguage].profile.bio} diff --git a/app/components/AgentStats.tsx b/app/components/AgentStats.tsx index d4417ec..cf9975e 100644 --- a/app/components/AgentStats.tsx +++ b/app/components/AgentStats.tsx @@ -1,7 +1,7 @@ -import { AGENT_WALLET_ADDRESS, notoSansThai } from "../constants"; -import { translations } from "../translations"; -import { Language } from "../types"; -import { useBalance } from "wagmi"; +import { AGENT_WALLET_ADDRESS, notoSansThai } from '../constants'; +import { translations } from '../translations'; +import { Language } from '../types'; +import { useBalance } from 'wagmi'; type AgentStats = { currentLanguage: Language; @@ -25,38 +25,38 @@ export default function AgentStats({ currentLanguage }: AgentStats) {

- {`${parseFloat(data?.formatted || "").toFixed(6)} ETH`} + {`${parseFloat(data?.formatted || '').toFixed(6)} ETH`} {/* TODO: update with actual data */}
  • {translations[currentLanguage].profile.stats.earned}: $ {dummyStats.earned.toFixed(2)}
  • {translations[currentLanguage].profile.stats.spent}: $ {dummyStats.spent.toFixed(2)}
  • - {translations[currentLanguage].profile.stats.nfts}:{" "} + {translations[currentLanguage].profile.stats.nfts}:{' '} {dummyStats.nftsOwned}
  • - {translations[currentLanguage].profile.stats.tokens}:{" "} + {translations[currentLanguage].profile.stats.tokens}:{' '} {dummyStats.tokensOwned}
  • - {translations[currentLanguage].profile.stats.transactions}:{" "} + {translations[currentLanguage].profile.stats.transactions}:{' '} {dummyStats.transactions}
diff --git a/app/components/ChatInput.tsx b/app/components/ChatInput.tsx index 287e7d3..45d428f 100644 --- a/app/components/ChatInput.tsx +++ b/app/components/ChatInput.tsx @@ -1,8 +1,8 @@ -import { ChangeEvent, useCallback } from "react"; -import { Language } from "../types"; -import { notoSansThai } from "../constants"; -import { translations } from "../translations"; -import SendSvg from "../svg/SendSvg"; +import { ChangeEvent, useCallback } from 'react'; +import { Language } from '../types'; +import { notoSansThai } from '../constants'; +import { translations } from '../translations'; +import SendSvg from '../svg/SendSvg'; type PremadeChatInputProps = { text: string; @@ -19,7 +19,7 @@ function PremadeChatInput({ {showToast && ( -
+
Copied
)} @@ -99,7 +99,7 @@ export default function AgentProfile({ currentLanguage }: AgentProfileProps) {

diff --git a/app/components/AgentStats.tsx b/app/components/AgentStats.tsx index 3fe8300..4861219 100644 --- a/app/components/AgentStats.tsx +++ b/app/components/AgentStats.tsx @@ -22,9 +22,9 @@ export default function AgentStats({ currentLanguage }: AgentStats) { query: { refetchInterval: 5000 }, }); return ( -

+
- + {`${Number.parseFloat(data?.formatted || '').toFixed(6)} ETH`} {/* TODO: update with actual data */} diff --git a/app/components/ChatInput.tsx b/app/components/ChatInput.tsx index db8b1bf..11afd96 100644 --- a/app/components/ChatInput.tsx +++ b/app/components/ChatInput.tsx @@ -18,7 +18,7 @@ function PremadeChatInput({ return (