Skip to content

michaelh03/Stocks-Valdi

Repository files navigation

Valdi Stocks Demo

A cross-platform demo application showcasing the Valdi framework with a modern stock portfolio experience. Built with TypeScript/TSX, this app demonstrates native performance on iOS, Android, and macOS while providing real-time stock data integration.

About Valdi

Valdi is a cross-platform UI framework that compiles declarative TypeScript components directly to native views—no web views, no JavaScript bridges. Write your UI once and get true native performance on iOS, Android, and macOS.

Features

  • Cross-platform native UI - Single codebase runs natively on iOS, Android, and macOS
  • Stock portfolio management - Add, view, and track stock holdings with live market data
  • Symbol search - Real-time autocomplete powered by Alpha Vantage API
  • Stock details - View detailed ticker information and historical charts
  • Redux-like state management - Predictable state flow with async thunks
  • Hot reload - Instant updates during development without rebuilding
  • Type-safe API integration - Polygon.io for ticker details, Alpha Vantage for search and charts

Demos

iOS demo Android demo

Project Structure

modules/stocks/src/
├── App.tsx                    # Root component with navigation
├── components/
│   ├── PortfolioScreen.tsx    # Main portfolio view with holdings list
│   ├── StockDetailsScreen.tsx  # Detailed stock view with charts
│   └── SparklineChart.tsx      # Chart visualization component
├── state/
│   ├── portfolioStore.ts       # Redux-like store with async thunks
│   └── portfolioTypes.ts       # Type definitions and actions
├── services/
│   └── stocksService.ts        # API clients for Polygon and Alpha Vantage
└── config/
    ├── appConfig.ts            # Configuration management
    └── appConfig.local.ts      # API keys (gitignored)

Project Setup

Prerequisites

  • Valdi CLI installed and available on PATH
  • Node.js and npm
  • Xcode (for iOS/macOS development)
  • Android Studio (for Android development)

Initial Setup

  1. Clone the repository

    git clone <repository-url>
    cd stocks
  2. Install Valdi CLI (if not already installed)

    cd path/to/valdi/npm_modules/cli
    npm run cli:install
  3. Setup development environment

    valdi dev_setup
  4. Sync project configuration

    valdi projectsync

    This generates IDE files and syncs project dependencies.

API Configuration

The app requires API keys from two services:

  1. Polygon.io - Real-time and historical stock data
  2. Alpha Vantage - Symbol search and chart data

Getting API Keys

  1. Polygon.io

    • Sign up at polygon.io
    • Navigate to your dashboard to get your API key
    • Free tier available with rate limits
  2. Alpha Vantage

    • Sign up at alphavantage.co
    • Get your free API key from the dashboard
    • Free tier includes 5 API calls per minute

Configuring API Keys

  1. Copy the example config file

    cp modules/stocks/src/config/appConfig.local.example.ts \
       modules/stocks/src/config/appConfig.local.ts
  2. Edit appConfig.local.ts and add your API keys:

    export const localAppConfig: Partial<AppConfig> = {
        polygonApiKey: 'your-polygon-api-key-here',
        alphaVantageApiKey: 'your-alphavantage-api-key-here',
    };

    Note: The appConfig.local.ts file is gitignored and will not be committed to version control.

  3. Verify configuration The app will use these keys automatically. If keys are missing, API calls will fail with appropriate error messages.

Development Workflow

Building and Running

iOS:

valdi install ios

Android:

valdi install android

macOS:

valdi install macos

Hot Reload

For instant updates during development, start the hot reload server:

valdi hotreload

Changes to TypeScript files will be reflected immediately without rebuilding.

IDE Setup

Get auto-completion and IntelliSense in VSCode:

valdi projectsync

This generates the stocks.code-workspace file and updates IDE configuration.

Common Commands

# Sync project after changing dependencies
valdi projectsync

# Build specific targets with Bazel
bazel build //modules/stocks:stocks

# Run tests
bazel test //modules/stocks:tests

# Clean build cache
bazel clean

Architecture

State Management

The app uses a Redux-like store pattern (portfolioStore.ts) with:

  • Actions - Synchronous state updates
  • Async Thunks - Side effects and API calls
  • Reducer - Pure state transformation functions
  • Subscriptions - Component-level state updates

API Integration

  • Polygon.io - Fetches ticker details, company information, and market data
  • Alpha Vantage - Provides symbol search autocomplete and daily time series for charts

Both services are abstracted through StocksService which handles:

  • HTTP requests via valdi_http
  • Error handling and retries
  • Response parsing and type safety
  • Mock data fallback for development

Component Structure

Components follow Valdi's class-based pattern:

import { StatefulComponent } from 'valdi_core/src/Component';

class MyComponent extends StatefulComponent<ViewModel, State> {
  onCreate(): void {
    // Initialize component
  }
  
  onRender(): void {
    // Render TSX/JSX-like syntax
    <view>
      <label value="Hello Valdi" />
    </view>;
  }
  
  onDestroy(): void {
    // Cleanup
  }
}

Debugging

  • VSCode Integration - Set breakpoints and debug TypeScript code directly
  • Hermes Debugger - Use Chrome DevTools for JavaScript debugging
  • Hot Reload - See changes instantly without rebuilding
  • Native Debugging - Use Xcode or Android Studio for platform-specific issues

See Valdi debugging documentation for detailed instructions.

Key Technologies

  • Valdi - Cross-platform UI framework
  • TypeScript/TSX - Type-safe component syntax
  • Bazel - Build system for reproducible builds
  • Flexbox - Layout system with automatic RTL support
  • valdi_http - Promise-based HTTP client
  • valdi_core - Core component and runtime APIs

Troubleshooting

Build Issues

  • Always run valdi projectsync after changing dependencies or config files
  • If builds seem stuck, try bazel clean to clear the build cache
  • Ensure Valdi CLI is up to date: cd path/to/valdi/npm_modules/cli && npm install

API Issues

  • Verify API keys are correctly set in appConfig.local.ts
  • Check API rate limits (especially Alpha Vantage free tier: 5 calls/minute)
  • Review error messages in the app UI for specific API failures

Hot Reload Issues

  • Restart valdi hotreload if changes aren't appearing
  • Ensure the app is running and connected to the hot reload server
  • Check for TypeScript compilation errors

Resources

License

This demo app is provided as-is for educational purposes. Valdi is licensed under the MIT License.


Built with Valdi - Native performance without sacrificing developer velocity.

About

Cross‑platform Valdi demo that builds a native stock portfolio app

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published