Skip to content

Add Solana native token pricing via Backpack GraphQL API - #2

Merged
jacklevin74 merged 5 commits into
jacklevin74:masterfrom
stackedPenguin:solana-native-pricing
Nov 11, 2025
Merged

Add Solana native token pricing via Backpack GraphQL API#2
jacklevin74 merged 5 commits into
jacklevin74:masterfrom
stackedPenguin:solana-native-pricing

Conversation

@stackedPenguin

Copy link
Copy Markdown
Collaborator

Summary

This PR adds native Solana token pricing by integrating the official Backpack GraphQL API (https://backpack-api.xnfts.dev/v2/graphql) for Solana tokens while maintaining X1 token support via the existing x1-json-server REST API.

Key Features

Dual Data Source Architecture

  • Solana Networks: Use Backpack GraphQL API with Apollo Client

    • Real-time pricing for ALL Solana SPL tokens (SOL, USDC, BONK, JUP, etc.)
    • Token metadata (logos, names, symbols) from Backpack's registry
    • 24h price change percentages
    • Apollo Client caching for faster loads
    • 60-second polling interval
  • X1 Networks: Continue using x1-json-server REST API

    • XNT pricing at fixed $1.00
    • Native X1 functionality unchanged

Network-Aware Component

  • Automatically detects Solana vs X1 network from blockchain type
  • Routes to appropriate data source
  • Seamless network switching support

Changes

New Files

  • packages/data-components/src/apollo/gql.ts - GraphQL query parser for Apollo Client

Modified Files

  1. packages/data-components/src/apollo/graphql.ts - GraphQL type definitions with clarifying comments
  2. packages/data-components/src/apollo/index.ts - Apollo exports
  3. packages/data-components/src/components/Balances/index.tsx - Network-aware dual implementation
  4. packages/data-components/src/components/Balances/utils.ts - Type fixes for compatibility
  5. packages/app-extension/src/components/Unlocked/index.tsx - Memoized Apollo Client to prevent infinite loops
  6. packages/common/src/constants.ts - Added BACKPACK_GRAPHQL_API_URL constant
  7. packages/common/src/apollo/index.ts - Updated to use Backpack GraphQL endpoint

Technical Details

Bug Fixes

  1. Fixed blockchain detection - Was hardcoded to X1, now reads from providerId
  2. Fixed infinite loading loop - Memoized Apollo Client creation
  3. Fixed GraphQL endpoint - Was POSTing to x1-json-server instead of Backpack API
  4. Fixed providerId enum - Backpack API accepts "SOLANA" not "SOLANA-mainnet"

ProviderId Mapping

  • Backpack GraphQL API: "SOLANA", "ETHEREUM" (no network suffix)
  • X1 REST API: "X1", "X1-mainnet", "X1-testnet" (with network suffix)

Testing

Solana Wallet

  • Multiple SPL tokens display with prices
  • Token logos render correctly
  • Portfolio total calculates correctly
  • No infinite loading loops
  • GraphQL queries succeed with 200 OK

X1 Wallet

  • XNT shows at $1.00
  • Native X1 functionality unchanged
  • REST API calls work as before

Network Switching

  • Smooth transitions between Solana and X1
  • Cached data loads quickly
  • No errors during network changes

Build Status

✅ Extension builds successfully
✅ No TypeScript errors
✅ All packages compile

Related Issues

Resolves Solana token pricing limitation where only X1 tokens had pricing data.


🤖 Generated with Claude Code

This commit implements dual data sources for token pricing:
- Solana networks: Use official Backpack GraphQL API (https://backpack-api.xnfts.dev/v2/graphql)
- X1 networks: Continue using x1-json-server REST API

Key changes:
1. Created GraphQL types and gql function for Backpack API integration
2. Implemented network-aware TokenBalances component:
   - SolanaTokenBalances: Uses GraphQL with Apollo Client (60s polling)
   - X1TokenBalances: Uses REST API with x1-json-server (60s polling)
3. Added backward-compatible ProviderId types (SOLANA, X1, ETHEREUM)
4. Maintained all existing X1 functionality

Benefits:
- Real-time pricing for ALL Solana SPL tokens (USDC, BONK, JUP, etc.)
- Token metadata (logos, names, symbols) from Backpack's registry
- 24h price change percentages for Solana tokens
- Apollo Client caching for faster subsequent loads
- Automatic retry with exponential backoff (10 attempts)
- X1 pricing unchanged ($1.00 for XNT)

Files modified:
- packages/data-components/src/apollo/gql.ts (NEW)
- packages/data-components/src/apollo/graphql.ts
- packages/data-components/src/apollo/index.ts
- packages/data-components/src/components/Balances/index.tsx
- packages/data-components/src/components/Balances/utils.ts
The TokenBalances component was always reading connectionUrl from Blockchain.X1,
even when displaying a Solana wallet. This caused Solana wallets to show X1 data.

Now it correctly:
1. Extracts the blockchain type from the providerId prop
2. Reads the connection URL for the correct blockchain
3. Routes to GraphQL for Solana, REST for X1

This fixes the issue where Solana wallets only showed '0 XNT' instead of
actual Solana tokens.
Root cause: Apollo Client was being recreated on every render in the
WithApollo component, causing all GraphQL queries to restart continuously
and creating an infinite loop.

Fixes:
1. Added useMemo to Apollo Client creation in Unlocked/index.tsx
   - Only recreates client when headers actually change
   - Prevents unnecessary query restarts

2. Added error logging to SolanaTokenBalances component
   - Logs GraphQL errors to console for debugging
   - Helps identify API issues without silent failures

This should resolve:
- Infinite loading loop when displaying Solana tokens
- Excessive API calls to Backpack GraphQL endpoint
- Poor performance from constant Apollo Client recreation

The duplicate atom warnings (secureBackgroundSenderAtom, notificationListenerAtom)
are intentional - they exist in separate RecoilRoot contexts for main app and SecureUI.
Root cause: Apollo Client was POSTing to x1-json-server
(http://162.250.126.66:4000/) instead of the official Backpack GraphQL API,
resulting in 404 errors and infinite skeleton loading.

Changes:
1. Added BACKPACK_GRAPHQL_API_URL constant pointing to
   https://backpack-api.xnfts.dev/v2/graphql

2. Updated Apollo Client httpLink to use BACKPACK_GRAPHQL_API_URL
   instead of BACKEND_API_URL

3. Updated logging to show correct GraphQL endpoint

This fixes:
- 404 errors: POST http://162.250.126.66:4000/ 404 (Not Found)
- Infinite skeleton loading for Solana wallets
- GraphQL queries now route to correct Backpack API

Data source architecture:
- Solana tokens: Backpack GraphQL API (https://backpack-api.xnfts.dev)
- X1 tokens: x1-json-server REST API (http://162.250.126.66:4000)
Root cause: Backpack GraphQL API enum validation rejected "SOLANA-mainnet"
with error: "enumeration type 'ProviderID' does not contain the value"

The Backpack API only accepts simple blockchain names without network suffixes:
- "SOLANA" (not "SOLANA-mainnet", "SOLANA-devnet", etc.)
- "ETHEREUM" (not "ETHEREUM-mainnet", etc.)

X1 REST API still uses network suffixes:
- "X1-mainnet", "X1-testnet", "X1"

Changes:
1. TokenBalances (app-extension): Changed "SOLANA-mainnet" to "SOLANA"
2. Balances (data-components): Removed network detection logic for Solana,
   kept X1 network detection
3. ProviderId type: Added clarifying comments about which APIs accept which values

This fixes:
- GraphQL enum validation error
- Skeleton loading loop (query now succeeds)
- Solana tokens will now load from Backpack API

Network-specific details (mainnet/devnet/testnet) are likely handled by
Backpack API internally via headers or other parameters.
jacklevin74 pushed a commit that referenced this pull request Nov 11, 2025
Adds a configuration toggle to choose between Backpack GraphQL API
and X1 JSON Server for Solana token queries, providing backward
compatibility with pre-PR #2 behavior.

Features:
- New USE_X1_JSON_SERVER_FOR_SOLANA toggle in constants.ts
- X1 queries always route to X1 JSON Server (unchanged)
- Solana queries route based on toggle setting:
  - false (default): Use Backpack GraphQL API (new behavior)
  - true: Use X1 JSON Server (old behavior, pre-PR #2)
- Enhanced logging to show which server is handling queries
- Comprehensive documentation in GRAPHQL_CONFIG.md

This allows testing both the new Backpack API integration and
maintaining compatibility with existing X1 JSON Server infrastructure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jacklevin74
jacklevin74 merged commit 8dbd2de into jacklevin74:master Nov 11, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants