-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2359048
commit 71e81b6
Showing
11 changed files
with
300 additions
and
177 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,54 @@ | ||
import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import getNfts from '../hooks/useGetNfts'; | ||
|
||
// 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); | ||
}, []); | ||
|
||
useEffect(() => { | ||
getNfts(); | ||
}, []); | ||
|
||
return ( | ||
<div className="mr-2 mb-4 rounded-sm bg-black p-4"> | ||
<div className="flex flex-col items-start gap-4"> | ||
<div className="gap-6 flex border-b border-zinc-700 grow w-full"> | ||
<button onClick={handleTabChange('tokens')} className={tokensClass}> | ||
Tokens | ||
</button> | ||
<button onClick={handleTabChange('nft')} className={nftsClass}> | ||
NFTs | ||
</button> | ||
<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 bg-black border-t p-4 pt-8 border-zinc-700"> | ||
<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,112 @@ | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
import { AgentMessage, Language, StreamEntry } from '../types'; | ||
import ChatInput from './ChatInput'; | ||
import useChat from '../hooks/useChat'; | ||
import StreamItem from './StreamItem'; | ||
import { notoSansThai } from '../constants'; | ||
import { cn } from '@coinbase/onchainkit/theme'; | ||
|
||
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], | ||
); | ||
|
||
useEffect(() => { | ||
// scrolls to the bottom of the chat when messages change | ||
bottomRef.current?.scrollIntoView({ behavior: 'smooth' }); | ||
}, [streamEntries]); | ||
|
||
return ( | ||
<div className={cn('flex flex-col w-1/2 grow md:flex h-full', className)}> | ||
<div className="flex flex-col overflow-y-auto p-4 pb-20 grow"> | ||
<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} | ||
/> | ||
</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
Oops, something went wrong.