Skip to content

refactor(format): centralize currency formatters and app constants#144

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
mrnetwork0001:improvement/shared-format-constants
Jun 19, 2026
Merged

refactor(format): centralize currency formatters and app constants#144
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
mrnetwork0001:improvement/shared-format-constants

Conversation

@mrnetwork0001

Copy link
Copy Markdown
Contributor

Closes #138

Centralizes duplicated currency formatters and scattered magic config values into shared modules, eliminating inline redefinitions across 6 files.

Changes

  • Move formatUsdc, formatUsdShortcut to src/utils/format.ts (single source of truth)
  • Add formatPrice (3-decimal) helper for per-request pricing
  • Create src/config/constants.ts for EXPLORER_BASE_URL, API_BASE_URL, MIN_DEPOSIT, NETWORK_FEE, PRESET_AMOUNTS, LOADING_DELAY_MS
  • Remove inline duplicate formatters from App.tsx and ApiUsage.tsx
  • Remove per-component currency closures from ApiCard.tsx and ApiDetailPage.tsx
  • Replace hard-coded loading delays with LOADING_DELAY_MS constant
  • Add Vitest + unit tests for format module (22 tests, 100% coverage)
  • Fix pre-existing build errors: duplicate Dashboard import, duplicate statusFilter, missing Skeleton import
  • Update README project layout to document new modules

Verification

  • npm run build
  • npm run test - 22/22 passed ✅
  • Rendered output is unchanged across all affected components

Note on LOADING_DELAY_MS

The issue asks for a single shared LOADING_DELAY_MS constant, but also states that simulated loading durations should remain unchanged. These are slightly contradictory since Dashboard previously used 1200ms while MarketplacePage and ApiDetailPage both used 1500ms. I unified all three to 1500ms to keep a single constant as requested - this means the Dashboard skeleton shows for 300ms longer, which is imperceptible to users. Happy to split into per-component constants if preferred.

Closes #138

- Move formatUsdc, formatUsdShortcut to src/utils/format.ts (single source)

- Add formatPrice (3-decimal) helper for per-request pricing

- Create src/config/constants.ts for EXPLORER_BASE_URL, API_BASE_URL, MIN_DEPOSIT, NETWORK_FEE, PRESET_AMOUNTS, LOADING_DELAY_MS

- Remove inline duplicate formatters from App.tsx and ApiUsage.tsx

- Remove per-component currency closures from ApiCard.tsx and ApiDetailPage.tsx

- Replace hard-coded loading delays with LOADING_DELAY_MS constant

- Add Vitest + unit tests for format module (22 tests, 100% coverage)

- Fix pre-existing build errors: duplicate Dashboard import, duplicate statusFilter, missing Skeleton import

- Update README project layout to document new modules

Closes CalloraOrg#138
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

yep, the formatUsdc copies scattered across files were overdue for this. one source of truth plus the new format tests is exactly what i wanted. merging.

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.

Centralize duplicated currency formatters and magic config values into a shared constants/format module

2 participants