Skip to content

Issue: Real Token Holdings Not Displayed in Wallet & Grid Wallet Balance Not Triggered in Chat #93

@Hebx

Description

@Hebx

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:

  1. Real token holdings don't show on the wallet screen
  2. 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/holdings fetches balances from Grid API (https://grid.squads.xyz/api/grid/v1/accounts/${walletAddress}/balances)
  • The client calls this endpoint via WalletDataService.fetchEnrichedHoldings() in apps/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 EnrichedToken format 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), walletBalance is computed from walletData.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 walletData is null or holdings is empty (due to Problem 1), walletBalance will be undefined
  • This undefined value is passed to buildClientContext() and then to the server

  • The server's buildSystemPrompt() function (line 506) checks if (clientContext?.walletBalance), which fails when walletBalance is undefined

  • 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

  1. Open the wallet screen
  2. Observe that token holdings are empty or incorrect
  3. Navigate to chat
  4. Ask the AI to use a Nansen API tool (e.g., "show me my current token balances from Nansen")
  5. 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 walletBalance is always computed when walletData exists, even if holdings is 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.tsx to 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 UI
  • apps/client/contexts/WalletContext.tsx - Wallet data context
  • apps/client/features/wallet/services/data.ts - Wallet data service
  • apps/client/components/chat/ChatManager.tsx - Chat manager with wallet balance computation
  • apps/server/src/routes/wallet/holdings.ts - Server endpoint for fetching holdings
  • apps/server/src/routes/chat/index.ts - Chat endpoint with system prompt generation

Priority

🔴 HIGH — Blocks core wallet functionality and Nansen API integration


Labels

  • bug
  • wallet
  • chat
  • nansen
  • x402
  • high-priority

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions