Skip to content

Implement Currency Conversion Rate Hook with Multi-Source Fallbacks #387

Description

@Cjay-Cyber-2

Description — what to implement and the why/impact.

Users incur shared expenses in various fiat currencies and settle in Stellar assets (XLM or USDC). Accurate real-time conversion rates are crucial for fair splits. This issue implements a React Query hook that fetches exchange rates with fallback providers and handles stale-while-revalidate caching.

Context & Requirements — background, constraints, design references, edge cases; grounded in the actual repo (real files, stack, conventions).

Build a custom hook in src/hooks/ using @tanstack/react-query that queries rate APIs and returns normalized conversion ratios. Implement robust error handling and fallback values to prevent UI crashes if pricing APIs experience downtime.

Acceptance Criteria — a checklist ("- [ ] ...") of specific, testable conditions that define "done".

  • Create useExchangeRates.ts in src/hooks/.
  • Implement fallback logic and caching configuration via TanStack Query.
  • Validate rate payloads using Zod schemas matching src/lib/types.ts.
  • Pass npm run typecheck, npm run lint, and npm test.

Implementation Guidance — likely files/modules to touch (use real paths from the repo context) and a suggested approach, without over-prescribing.

  • Inspect existing hooks in src/hooks/.
  • Add unit tests for rate calculation and fallback behavior in src/lib/__tests__/ or src/hooks/__tests__/.

Testing & Validation — how the contributor should prove it works (tests to add/run, manual checks, screenshots for UI).

  • Write unit tests mocking successful and failing API rate responses.
  • Run npm test to execute tests.

Submission Guidelines — must open a PR that includes "Closes #"; assignment is required before starting; follow the repo's existing style and conventions.


Wave complexity: Medium

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions