11import { usePrivy } from "@privy-io/react-auth" ;
2- import { useCallback , useEffect , useMemo , useRef , useState } from "react" ;
2+ import { useCallback , useEffect , useRef , useState } from "react" ;
33import { useTranslation } from "react-i18next" ;
44import { useChat } from "../contexts/ChatContext" ;
55import { useModal } from "../contexts/ModalContext" ;
66import { useSettingsStore } from "../store/settingsStore" ;
7- import { useSuggestStore } from "../store/suggestStore" ;
7+ import { useSuggestions } from "../hooks/useSuggestions" ;
8+ import { useSolanaPortfolio } from "../hooks/useSolanaPortfolio" ;
9+ import { useEvmPortfolio } from "../hooks/useEvmPortfolio" ;
10+ import { useWalletStore } from "../store/walletStore" ;
811import {
912 ParToolCallSchema ,
1013 RigToolCall ,
@@ -55,18 +58,45 @@ export function Chat({ selectedChatId }: { selectedChatId?: string }) {
5558 nestedAgentOutput,
5659 } = useChat ( ) ;
5760
61+ const { displaySuggestions, chatType } = useSettingsStore ( ) ;
62+
63+ // Get wallet addresses
5864 const {
59- getSuggestions,
60- isLoading : isSuggestionsLoading ,
61- fetchSuggestions,
62- } = useSuggestStore ( ) ;
65+ solanaAddress,
66+ evmAddress,
67+ eoaSolanaAddress,
68+ eoaEvmAddress,
69+ activeWallet,
70+ } = useWalletStore ( ) ;
71+
72+ // Get current addresses based on active wallet
73+ const currentSolanaAddress =
74+ activeWallet === "listen"
75+ ? solanaAddress
76+ : activeWallet === "eoaSolana"
77+ ? eoaSolanaAddress
78+ : null ;
79+
80+ const currentEvmAddress =
81+ activeWallet === "listen"
82+ ? evmAddress
83+ : activeWallet === "eoaEvm"
84+ ? eoaEvmAddress
85+ : null ;
6386
64- const { displaySuggestions } = useSettingsStore ( ) ;
87+ // Get portfolio data
88+ const { data : solanaPortfolio = [ ] } = useSolanaPortfolio ( currentSolanaAddress ) ;
89+ const { data : evmPortfolio = [ ] } = useEvmPortfolio ( currentEvmAddress ) ;
90+
91+ // Combine portfolios
92+ const combinedPortfolio = [ ...( solanaPortfolio || [ ] ) , ...( evmPortfolio || [ ] ) ] ;
6593
66- // Memoize the suggestions selector
67- const suggestions = useMemo ( ( ) => {
68- return urlParams . chatId ? getSuggestions ( urlParams . chatId ) : [ ] ;
69- } , [ urlParams . chatId , getSuggestions ] ) ;
94+ const {
95+ suggestions,
96+ isLoading : isSuggestionsLoading ,
97+ fetchSuggestions,
98+ clearSuggestions,
99+ } = useSuggestions ( urlParams . chatId || "" ) ;
70100
71101 const lastUserMessageRef = useRef < HTMLDivElement > ( null ) ;
72102 const [ inputMessage , setInputMessage ] = useState ( "" ) ;
@@ -133,10 +163,10 @@ export function Chat({ selectedChatId }: { selectedChatId?: string }) {
133163 }
134164 setInputMessage ( "" ) ;
135165 if ( urlParams . chatId ) {
136- useSuggestStore . getState ( ) . clearSuggestions ( urlParams . chatId ) ;
166+ clearSuggestions ( ) ;
137167 }
138168 } ,
139- [ sendMessage , setMessages , urlParams . chatId ]
169+ [ sendMessage , setMessages , urlParams . chatId , clearSuggestions ]
140170 ) ;
141171
142172 // Focus the input field when creating a new chat
@@ -264,9 +294,9 @@ export function Chat({ selectedChatId }: { selectedChatId?: string }) {
264294
265295 if ( shouldFetchSuggestions ) {
266296 fetchSuggestions (
267- urlParams . chatId ,
268297 messages ,
269- getAccessToken ,
298+ combinedPortfolio ,
299+ chatType ,
270300 i18n . language
271301 ) ;
272302 }
@@ -278,6 +308,10 @@ export function Chat({ selectedChatId }: { selectedChatId?: string }) {
278308 suggestions . length ,
279309 getAccessToken ,
280310 i18n . language ,
311+ fetchSuggestions ,
312+ combinedPortfolio ,
313+ chatType ,
314+ displaySuggestions ,
281315 ] ) ;
282316
283317 if ( IS_DISABLED ) {
0 commit comments