Skip to content

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

@greatest0fallt1me

Description

@greatest0fallt1me

Description

The same formatUsdc / formatUsdShortcut helpers are defined three separate times — src/utils/format.ts:1-12, inline in src/App.tsx:110-121, and again (with 3-decimal precision) in src/ApiUsage.tsx:117-122 — and ApiCard/ApiDetailPage each redefine their own currency = (n) => \$${n.toFixed(3)}` (src/components/ApiCard.tsx:66, src/pages/ApiDetailPage.tsx:237). Config-like values are likewise scattered as literals: EXPLORER_BASE_URL, MIN_DEPOSIT, NETWORK_FEE, PRESET_AMOUNTSinApp.tsx:94-97, the hard-coded loading delays 1500/1200/1000inMarketplacePage/ApiDetailPage/Dashboard, and baseUrl = "https://api.callora.com"` in ApiDetailPage.tsx:244.

This issue consolidates the formatters in src/utils/format.ts and introduces a src/config/constants.ts so these values live in one place.

Requirements and context

  • Make src/utils/format.ts the single source for formatUsdc, formatUsdShortcut, and a shared formatPrice (3-decimal) helper; import it everywhere instead of redefining.
  • Create src/config/constants.ts exporting EXPLORER_BASE_URL, API_BASE_URL, MIN_DEPOSIT, NETWORK_FEE, PRESET_AMOUNTS, and a LOADING_DELAY_MS used by the three simulated loaders (src/pages/MarketplacePage.tsx:26, src/pages/ApiDetailPage.tsx:44, src/components/Dashboard.tsx:27).
  • Remove the inline duplicate formatters from App.tsx (src/App.tsx:110-121) and ApiUsage.tsx (src/ApiUsage.tsx:117-122) and the per-component currency closures.
  • Non-functional: no visual/behavior change; pure refactor that reduces duplication and keeps noUnusedLocals happy (tsconfig.json:15).

Acceptance criteria

  • formatUsdc/formatUsdShortcut/formatPrice are defined once in src/utils/format.ts and imported by App.tsx, ApiUsage.tsx, ApiCard.tsx, ApiDetailPage.tsx.
  • src/config/constants.ts exists and owns the explorer/base URLs, deposit constants, and loading delay.
  • No file redefines formatUsdc or an inline currency closure.
  • Rendered amounts and the simulated loading durations are unchanged.
  • npm run build passes.

Suggested execution

1. Fork the repo and create a branchgit checkout -b improvement/shared-format-constants.

2. Implement changessrc/utils/format.ts, new src/config/constants.ts, and the importing call sites listed above.

3. Write/extend tests — this repo has no test runner configured. Add Vitest + @testing-library/react + jsdom and a "test": "vitest run" script, then unit-test formatUsdc/formatUsdShortcut/formatPrice across zero, small, and ≥100 values.

4. Test and commit

npm install
npm run build
npm run test

Example commit message

refactor(format): centralize currency formatters and app constants

Guidelines

  • The format module must reach ≥90% line coverage.
  • Keep output identical for screen-reader users; document the new config/constants module in the README project layout.
  • Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GRANTFOX OSSGrantFox OSS programMAYBE REWARDEDGrantFox — potentially rewardedOFFICIAL CAMPAIGNGrantFox official campaigndxDeveloper experiencefrontendUI / frontendimprovementRefactor, performance, or tech-debtintermediateModerate complexity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions