-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Updated Jira Ticket
Title: Implement Locale-Specific Number Formatting for Amount Display
Description
Currently, AlgoKit Lora displays all numerical amounts (ALGO balances, asset amounts, transaction values, etc.) using a hardcoded US English format. This creates a suboptimal user experience for international users who are accustomed to their local number formatting conventions.
This ticket involves implementing locale-aware number formatting throughout the application to display amounts according to the user's locale preferences, improving accessibility and user experience for our global user base.
Examples of locale-specific formatting:
- US:
100,000,000
- Germany:
100.000.000
- France:
100 000 000
- India:
10,00,00,000
- Switzerland:
100'000'000
Acceptance Criteria
Must Have:
- ✅ All amount displays should respect user's browser locale by default
- ✅ Large numbers (1000+) should be formatted with appropriate thousand separators for the locale
- ✅ Decimal numbers should use the correct decimal separator for the locale
- ✅ Form inputs should accept numbers in the user's locale format
- ✅ The implementation should work for both ALGO amounts and custom asset amounts
- ✅ Compact number formatting (e.g., "1.2M") should respect locale conventions
Should Have:
- ✅ Consistent formatting across all number display components
Testing:
- ✅ Unit tests covering different locale scenarios
- ✅ Manual testing with at least 3 different locales (US, DE, FR)
Technical Details
Implementation Plan
Phase 1: Create Locale-Aware Formatting Utilities
-
Create new utility file:
src/utils/number-format.ts
// New utility functions to be created export const formatNumber = (value: number | Decimal, locale?: string) => { ... } export const formatAmount = (value: number | Decimal, options?: NumberFormatOptions) => { ... } export const getLocale = () => { ... } // Get user's locale from browser
-
Extend existing format utility: Update
src/utils/format.ts
to include number formatting alongside date formatting
Phase 2: Update Core Display Components
Files to modify:
-
src/utils/compact-amount.ts
- Replace hardcoded'en-US'
with dynamic locale:// Current: numberAmount.toLocaleString('en-US', { notation: 'compact' }) // New: numberAmount.toLocaleString(getLocale(), { notation: 'compact' })
-
src/features/common/components/display-algo.tsx
- Update amount display:// Current: amount.algos.toString() // New: formatNumber(amount.algos)
-
src/features/common/components/display-asset-amount.tsx
- Update theasAssetDisplayAmount
function:// Current: displayAmount.toString() // New: formatNumber(displayAmount)
Phase 3: Update Form Components
src/features/forms/components/number-form-item.tsx
- Enhancereact-number-format
configuration:// Add locale-specific thousand and decimal separators thousandSeparator={getThousandSeparator(locale)} decimalSeparator={getDecimalSeparator(locale)}
Phase 4: Update Transaction and Asset Display
Key components to update:
src/features/transactions/components/transactions-table-columns.tsx
src/features/assets/components/asset-details.tsx
src/features/applications/components/application-global-state-table.tsx
- All transaction wizard form components that display amounts
Phase 5: Testing & Documentation
- Add tests in
src/tests/utils/
for the new formatting utilities - Update existing tests that expect hardcoded US formatting
Technical Considerations
- Backward Compatibility: Ensure existing functionality isn't broken
- Fallback Strategy: Default to
'en-US'
if locale detection fails
Libraries & Dependencies
- Current: Already using
react-number-format
(no additional dependencies needed) - Browser API:
Intl.NumberFormat
andnavigator.language
for locale detection - Testing: Vitest with locale mocking capabilities