-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Issue: Real Token Holdings Not Displayed in Wallet & Grid Wallet Balance Not Triggered in Chat
Problem Summary
Two related issues prevent users from seeing their real token holdings and using Nansen API features:
- Real token holdings don't show on the wallet screen
- Real wallet balance is not triggered in chat, preventing Nansen API calls
Problem 1: Real Token Holdings Not Displayed
Location: apps/client/app/(main)/wallet.tsx and apps/server/src/routes/wallet/holdings.ts
Symptoms
- Wallet screen shows empty holdings or incorrect token balances
- Token holdings fetched from Grid API are not displayed correctly
- Users cannot see their actual SOL, USDC, or other token balances
Root Cause Analysis
- The server endpoint
/api/wallet/holdingsfetches balances from Grid API (https://grid.squads.xyz/api/grid/v1/accounts/${walletAddress}/balances) - The client calls this endpoint via
WalletDataService.fetchEnrichedHoldings()inapps/client/features/wallet/services/data.ts - Potential issues:
- Grid API may not be returning real token balances
- Wallet address may not be correctly passed to the server
- Data transformation from Grid API response to
EnrichedTokenformat may be failing - Cache may be serving stale/empty data
Expected Behavior
- Wallet screen should display all tokens held in the user's Grid wallet
- Token balances should reflect real blockchain balances
- Holdings should update when tokens are received/sent
Problem 2: Wallet Balance Not Triggered in Chat
Location: apps/client/components/chat/ChatManager.tsx and apps/server/src/routes/chat/index.ts
Symptoms
- Chat AI doesn't know the user's wallet balance
- Nansen API tools cannot be called because the AI thinks the user has insufficient balance
- System prompt doesn't include wallet balance context
- Low balance warnings don't appear even when balance is sufficient
Root Cause Analysis
-
In
ChatManager.tsx(lines 49-60),walletBalanceis computed fromwalletData.holdings:script
const walletBalance = React.useMemo(() => {
if (!walletData?.holdings) return undefined;const solHolding = walletData.holdings.find(h => h.tokenSymbol === 'SOL');
const usdcHolding = walletData.holdings.find(h => h.tokenSymbol === 'USDC');return {
sol: solHolding?.holdings,
usdc: usdcHolding?.holdings,
totalUsd: walletData.totalBalance
};
}, [walletData]);- If
walletDataisnullorholdingsis empty (due to Problem 1),walletBalancewill beundefined
- If
-
This
undefinedvalue is passed tobuildClientContext()and then to the server -
The server's
buildSystemPrompt()function (line 506) checksif (clientContext?.walletBalance), which fails whenwalletBalanceisundefined -
Result: The AI never receives wallet balance context, so it can't:
- Check if user has sufficient USDC for x402 payments
- Warn about low balances
- Trigger Nansen API calls that require payment
Expected Behavior
- Chat should always receive wallet balance context when available
- AI should be able to check balance thresholds for Nansen API calls
- System prompt should include wallet balance information
- Low balance warnings should appear when SOL < 0.01 or USDC < 0.01
Impact
- ❌ Users cannot see their real token holdings in the wallet screen
- ❌ Users cannot use Nansen API features because the AI doesn't know their balance
- ❌ Poor UX: users may think the app is broken or their tokens are missing
- ❌ Feature blocking: x402 payment flows for Nansen endpoints are non-functional
Steps to Reproduce
- Open the wallet screen
- Observe that token holdings are empty or incorrect
- Navigate to chat
- Ask the AI to use a Nansen API tool (e.g., "show me my current token balances from Nansen")
- AI will not be able to check wallet balance and may refuse or fail
Proposed Solutions
1. Fix Grid API Integration
- Verify Grid API is returning real token balances
- Add error handling and logging for Grid API failures
- Ensure wallet address is correctly passed to the server
- Add validation for Grid API response structure
2. Fix Wallet Balance Propagation to Chat
- Ensure
walletBalanceis always computed whenwalletDataexists, even ifholdingsis empty - Add fallback values (0 for SOL/USDC) instead of returning
undefined - Update
buildSystemPrompt()to handle cases where balance is 0 vs undefined - Add defensive checks in
ChatManager.tsxto handle edge cases
3. Add Debugging & Monitoring
- Log Grid API responses in server endpoint
- Log wallet balance computation in
ChatManager - Log system prompt generation to verify wallet balance context is included
- Add error boundaries for wallet data fetching failures
Related Files
apps/client/app/(main)/wallet.tsx- Wallet screen UIapps/client/contexts/WalletContext.tsx- Wallet data contextapps/client/features/wallet/services/data.ts- Wallet data serviceapps/client/components/chat/ChatManager.tsx- Chat manager with wallet balance computationapps/server/src/routes/wallet/holdings.ts- Server endpoint for fetching holdingsapps/server/src/routes/chat/index.ts- Chat endpoint with system prompt generation
Priority
🔴 HIGH — Blocks core wallet functionality and Nansen API integration
Labels
bugwalletchatnansenx402high-priority