Skip to content

feat: add USDC price converter utility and PriceTag component - #1173

Open
Dami24-hub wants to merge 1 commit into
Agora-Events:mainfrom
Dami24-hub:feature/usdc-price-tag-widget
Open

feat: add USDC price converter utility and PriceTag component#1173
Dami24-hub wants to merge 1 commit into
Agora-Events:mainfrom
Dami24-hub:feature/usdc-price-tag-widget

Conversation

@Dami24-hub

Copy link
Copy Markdown
Contributor

Description
This pull request introduces the new PriceTag display component along with a reliable USDC fiat rate-fetching utility, fulfilling the requirements for the Utilities module.

Changes Made
USDC Rate Fetching Utility: Implemented a robust function to fetch live USDC-to-fiat exchange rates (USD/EUR) with built-in fallback handling for network errors or API failures.

PriceTag Component (PriceTag.tsx):

Displays the primary amount in USDC formatted consistently to two decimal places (e.g., 25.00 USDC).

Renders a secondary, smaller conversion text showing the value in fiat beneath it.

Includes a graceful fallback display note if rate fetching fails.

Precision & Formatting: Ensured precise decimal handling to completely eliminate rounding errors.

Acceptance Criteria Checklist
[x] Implemented function to fetch current USDC rate relative to fiat currencies.

[x] Created PriceTag.tsx component receiving an amount in USDC.

[x] Displays primary price in USDC and secondary fiat conversion beneath.

[x] Conversion handling avoids rounding errors (prices formatted to two decimal points).

[x] Displays a fallback conversion note if rates fetching fails.

[x] Code is fully typed, formatted, and builds successfully.

[x] Branch created and pushed to GitHub.

closes #1018

- utils/usdc-rate.ts: fetchUsdcRate() hits CoinGecko for live USD/EUR
  rates with a 5-minute in-memory cache; convertUsdcToFiat() applies
  safe fixed-point rounding. Gracefully falls back to 1.00 USD / 0.92 EUR
  when the API is unreachable, propagating an isFallback flag.

- components/ui/PriceTag.tsx: "use client" React component that displays
  an amount in USDC (2 d.p.) with the approximate fiat equivalent beneath
  it. Features a pulse-skeleton loading state, an (est.) annotation when
  rate data is unavailable, and an accessible aria-label.

- __tests__/usdc-rate.test.ts: 12 vitest unit tests covering conversion
  math, successful API responses, and all fallback branches.

- __tests__/price-tag.test.tsx: 11 vitest + Testing Library tests covering
  USDC display, fiat conversion, loading state, fallback annotation, and
  accessibility label.

All 23 tests pass; 0 lint errors; 0 TypeScript errors in new files.
@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

@Dami24-hub is attempting to deploy a commit to the oseh-svg's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Mobile: Local Currency Rate Converter and Price Display

1 participant