Skip to content

Implement multi-currency protocol for international business scenarios - #97

Closed
hotlong with Copilot wants to merge 5 commits into
mainfrom
copilot/implement-multi-currency-solution
Closed

Implement multi-currency protocol for international business scenarios#97
hotlong with Copilot wants to merge 5 commits into
mainfrom
copilot/implement-multi-currency-solution

Conversation

CopilotAI commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Adds Salesforce-pattern multi-currency support: compound value storage (native + converted), configurable aggregation/sorting strategies, and Intl-compatible formatting.

Implementation

System Protocol (src/system/currency.zod.ts)

  • ISO 4217 currency definitions with conversion rates, decimal places
  • Organization-wide settings: corporate currency, active currencies, dated exchange rates
  • Aggregation strategies: convert_to_corporate | convert_to_user | group_by_currency
  • Sorting strategies: convert_to_corporate | convert_to_user | native_value
  • User-level currency preferences and formatting

Data Protocol (src/data/currency.zod.ts)

  • Compound value schema storing native + converted amounts with exchange rate audit trail
  • Field-level config: default currency, restrictions, mutability, rounding modes
  • Cross-currency calculation results with source tracking
  • Type-safe helpers using CurrencyCode for compile-time validation

Field Enhancement (src/data/field.zod.ts)

  • Currency field properties: currencyCode, allowCurrencyChange, restrictedCurrencies, showConversion, roundingMode

Usage

// Organization setupconstsettings: CurrencySettings={enabled: true,corporateCurrency: 'USD',activeCurrencies: [Currency.USD(),{ ...Currency.EUR(),conversionRate: 0.85},],aggregationStrategy: 'convert_to_corporate',};// Field definitionconstamount=Field.currency({name: 'amount',currencyCode: 'USD',restrictedCurrencies: ['USD','EUR','GBP'],roundingMode: 'half_up',});// Value storage (native + converted for report performance)constvalue: CurrencyValue={amount: 50000.00,currency: 'EUR',convertedAmount: 58823.53,// Pre-computed for aggregationsconvertedCurrency: 'USD',exchangeRate: 1.176471,conversionDate: newDate(),};

Design Decisions

  • Storage: Denormalized storage of converted values avoids real-time conversion in reports/aggregations
  • Type Safety: CurrencyCode type (ISO 4217 validated) used throughout, not strings
  • Rounding: 5 modes (half_up, half_down, half_even, up, down) following financial best practices
  • Historical Accuracy: Optional dated exchange rates with effective/expiry dates

Test Coverage: 60 tests (31 system + 29 data), validates edge cases (JPY 0-decimal, negatives, cross-currency calculations)

Original prompt

Role:
You are a Senior System Architect specializing in Low-Code platforms, Enterprise SaaS patterns (like Salesforce), and Schema-Driven UI development.
Context:
I am rebuilding a metadata-driven Form and Grid system. I currently use Zod to define my schemas. I need to implement a robust Multi-Currency (多币种) solution that supports international business scenarios.
I want to adopt a "Salesforce-like" approach, specifically handling:

  1. Storage: How to store value, currency code, and potentially exchange rates.
  2. Display: Proper formatting (Intl) and user-specific currency conversion.
  3. Logic: How to handle sorting and aggregation when rows have different currencies.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel

vercelBot commented Jan 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentReviewUpdated (UTC)
specErrorErrorJan 24, 2026 7:59am

Request Review

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
CopilotAIand others added 2 commits January 24, 2026 07:53
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
CopilotAI changed the title [WIP] Implement robust multi-currency solution for forms and gridsImplement multi-currency protocol for international business scenariosJan 24, 2026
CopilotAI requested a review from hotlongJanuary 24, 2026 07:59
@hotlonghotlong closed this Jan 24, 2026
Sign up for freeto 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

@hotlong