-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from coinbase/alissa.crane/qa
feat: implement redesign
- Loading branch information
Showing
12 changed files
with
340 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useCallback, useMemo, useState } from 'react'; | ||
|
||
// TODO: add assets | ||
export default function AgentAssets() { | ||
const [tab, setTab] = useState('tokens'); | ||
|
||
const tokensClass = useMemo(() => { | ||
if (tab === 'tokens') { | ||
return 'border-b border-[#5788FA] flex items-center justify-center py-1'; | ||
} | ||
return ' flex items-center justify-center py-1'; | ||
}, [tab]); | ||
|
||
const nftsClass = useMemo(() => { | ||
if (tab === 'nft') { | ||
return 'border-b border-[#5788FA] flex items-center justify-center py-1'; | ||
} | ||
return ' flex items-center justify-center py-1'; | ||
}, [tab]); | ||
|
||
const createdClass = useMemo(() => { | ||
if (tab === 'created') { | ||
return 'border-b border-[#5788FA] flex items-center justify-center py-1'; | ||
} | ||
return ' flex items-center justify-center py-1'; | ||
}, [tab]); | ||
|
||
const handleTabChange = useCallback((tab: string) => { | ||
return () => setTab(tab); | ||
}, []); | ||
|
||
return ( | ||
<div className="mr-2 mb-4 rounded-sm bg-black p-4"> | ||
<div className="flex flex-col items-start gap-4"> | ||
<div className="flex w-full grow gap-6 border-zinc-700 border-b"> | ||
<button | ||
type="button" | ||
onClick={handleTabChange('tokens')} | ||
className={tokensClass} | ||
> | ||
Tokens | ||
</button> | ||
<button | ||
type="button" | ||
onClick={handleTabChange('nft')} | ||
className={nftsClass} | ||
> | ||
NFTs | ||
</button> | ||
<button | ||
type="button" | ||
onClick={handleTabChange('created')} | ||
className={createdClass} | ||
> | ||
Created | ||
</button> | ||
</div> | ||
|
||
{tab === 'tokens' ? <div>tokens</div> : <div>nfts</div>} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useBalance } from 'wagmi'; | ||
import { AGENT_WALLET_ADDRESS } from '../constants'; | ||
|
||
export default function AgentBalance() { | ||
const { data } = useBalance({ | ||
address: AGENT_WALLET_ADDRESS, | ||
query: { refetchInterval: 5000 }, | ||
}); | ||
|
||
return ( | ||
<div className="rounded-sm border-zinc-700 border-t bg-black p-4 pt-8"> | ||
<div className="flex flex-col items-start "> | ||
<span className="font-bold text-3xl text-[#5788FA]"> | ||
{`${Number.parseFloat(data?.formatted || '').toFixed(6)} ETH`} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { cn } from '@coinbase/onchainkit/theme'; | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
import { notoSansThai } from '../constants'; | ||
import useChat from '../hooks/useChat'; | ||
import type { AgentMessage, Language, StreamEntry } from '../types'; | ||
import ChatInput from './ChatInput'; | ||
import StreamItem from './StreamItem'; | ||
|
||
type ChatProps = { | ||
currentLanguage: Language; | ||
enableLiveStream?: boolean; | ||
className?: string; | ||
}; | ||
|
||
export default function Chat({ className, currentLanguage }: ChatProps) { | ||
const [userInput, setUserInput] = useState(''); | ||
const [streamEntries, setStreamEntries] = useState<StreamEntry[]>([]); | ||
|
||
const bottomRef = useRef<HTMLDivElement>(null); | ||
|
||
// TODO: revisit this logic | ||
const handleSuccess = useCallback((messages: AgentMessage[]) => { | ||
// const message = messages.find((res) => res.event === "agent"); | ||
const filteredMessages = messages.filter( | ||
(msg) => msg.event !== 'completed', | ||
); | ||
const streams = filteredMessages.map((msg) => { | ||
return { | ||
timestamp: new Date(), | ||
content: msg?.data || '', | ||
type: msg?.event, | ||
}; | ||
}); | ||
// const streamEntry = { | ||
// timestamp: new Date(), | ||
// content: message?.data || "", | ||
// }; | ||
setStreamEntries((prev) => [...prev, ...streams]); | ||
}, []); | ||
|
||
const { postChat, isLoading } = useChat({ onSuccess: handleSuccess }); | ||
|
||
const handleSubmit = useCallback( | ||
async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
if (!userInput.trim()) { | ||
return; | ||
} | ||
|
||
setUserInput(''); | ||
|
||
const userMessage: StreamEntry = { | ||
timestamp: new Date(), | ||
type: 'user', | ||
content: userInput.trim(), | ||
}; | ||
|
||
setStreamEntries((prev) => [...prev, userMessage]); | ||
|
||
postChat(userInput); | ||
}, | ||
[postChat, userInput], | ||
); | ||
|
||
const handleKeyPress = useCallback( | ||
(e: React.KeyboardEvent<HTMLTextAreaElement>) => { | ||
if (e.key === 'Enter' && !e.shiftKey) { | ||
e.preventDefault(); | ||
handleSubmit(e); | ||
} | ||
}, | ||
[handleSubmit], | ||
); | ||
|
||
// biome-ignore lint/correctness/useExhaustiveDependencies: Dependency is required | ||
useEffect(() => { | ||
// scrolls to the bottom of the chat when messages change | ||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); | ||
}, [streamEntries]); | ||
|
||
return ( | ||
<div className={cn('flex h-full w-1/2 grow flex-col md:flex', className)}> | ||
<div className="flex grow flex-col overflow-y-auto p-4 pb-20"> | ||
<p | ||
className={`text-zinc-500 ${ | ||
currentLanguage === 'th' ? notoSansThai.className : '' | ||
}`} | ||
> | ||
Ask me something... | ||
</p> | ||
<div className="mt-4 space-y-2" role="log" aria-live="polite"> | ||
{streamEntries.map((entry, index) => ( | ||
<StreamItem | ||
key={`${entry.timestamp.toDateString()}-${index}`} | ||
entry={entry} | ||
currentLanguage={currentLanguage} | ||
/> | ||
))} | ||
</div> | ||
|
||
<div className="mt-3" ref={bottomRef} /> | ||
</div> | ||
|
||
<ChatInput | ||
currentLanguage={currentLanguage} | ||
userInput={userInput} | ||
handleKeyPress={handleKeyPress} | ||
handleSubmit={handleSubmit} | ||
setUserInput={setUserInput} | ||
disabled={isLoading} | ||
/> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.