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
Suggested execution
1. Fork the repo and create a branch — git checkout -b improvement/shared-format-constants.
2. Implement changes — src/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.
Description
The same
formatUsdc/formatUsdShortcuthelpers are defined three separate times —src/utils/format.ts:1-12, inline insrc/App.tsx:110-121, and again (with 3-decimal precision) insrc/ApiUsage.tsx:117-122— andApiCard/ApiDetailPageeach redefine their owncurrency = (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 delays1500/1200/1000inMarketplacePage/ApiDetailPage/Dashboard, andbaseUrl = "https://api.callora.com"` inApiDetailPage.tsx:244.This issue consolidates the formatters in
src/utils/format.tsand introduces asrc/config/constants.tsso these values live in one place.Requirements and context
src/utils/format.tsthe single source forformatUsdc,formatUsdShortcut, and a sharedformatPrice(3-decimal) helper; import it everywhere instead of redefining.src/config/constants.tsexportingEXPLORER_BASE_URL,API_BASE_URL,MIN_DEPOSIT,NETWORK_FEE,PRESET_AMOUNTS, and aLOADING_DELAY_MSused by the three simulated loaders (src/pages/MarketplacePage.tsx:26,src/pages/ApiDetailPage.tsx:44,src/components/Dashboard.tsx:27).App.tsx(src/App.tsx:110-121) andApiUsage.tsx(src/ApiUsage.tsx:117-122) and the per-componentcurrencyclosures.noUnusedLocalshappy (tsconfig.json:15).Acceptance criteria
formatUsdc/formatUsdShortcut/formatPriceare defined once insrc/utils/format.tsand imported byApp.tsx,ApiUsage.tsx,ApiCard.tsx,ApiDetailPage.tsx.src/config/constants.tsexists and owns the explorer/base URLs, deposit constants, and loading delay.formatUsdcor an inlinecurrencyclosure.npm run buildpasses.Suggested execution
1. Fork the repo and create a branch —
git checkout -b improvement/shared-format-constants.2. Implement changes —
src/utils/format.ts, newsrc/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+jsdomand a"test": "vitest run"script, then unit-testformatUsdc/formatUsdShortcut/formatPriceacross zero, small, and ≥100 values.4. Test and commit —
npm install npm run build npm run testExample commit message
Guidelines
formatmodule must reach ≥90% line coverage.config/constantsmodule in the README project layout.