feat: add USDC price converter utility and PriceTag component - #1173
Open
Dami24-hub wants to merge 1 commit into
Open
feat: add USDC price converter utility and PriceTag component#1173Dami24-hub wants to merge 1 commit into
Dami24-hub wants to merge 1 commit into
Conversation
- 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.
|
@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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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