feat(rates): use XRC as primary ICP/USD exchange rate source#365
Open
feat(rates): use XRC as primary ICP/USD exchange rate source#365
Conversation
📊 Build Bundle StatsThe latest build generated the following assets: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the frontend price-fetching flow to use the backend canister’s XRC-sourced ICP/USD exchange rate as the primary source (including 24h change), while removing KongSwap as a provider and keeping IcpSwap as a fallback.
Changes:
- Removed KongSwap integration across typings, hooks, fixtures, e2e stubs, tests, and env config.
- Added
useExchangeRateto fetchget_icp_to_usd_exchange_ratefrom the backend canister and parsecurrent+one_day_ago. - Updated UI and consumers (
useTickerPrices,useTvlValue,IcpPriceCard) to use the new unified flow and display 24h change.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/governance-app-frontend/tests/fixtures/kongSwap.ts | Removes KongSwap fixtures used in unit/e2e tests. |
| src/governance-app-frontend/tests/e2e/utils/app.ts | Updates e2e bootstrap stubbing (removes KongSwap stub). |
| src/governance-app-frontend/tests/e2e/stubs/kongSwap.ts | Removes KongSwap network stub for Playwright. |
| src/governance-app-frontend/src/i18n/en/home.json | Adds a new label for the 24h change indicator. |
| src/governance-app-frontend/src/features/dashboard/components/IcpPriceCard.tsx | Displays ICP 24h change based on previousUsd from backend. |
| src/governance-app-frontend/src/common/utils/query.ts | Removes KongSwap query key and adds backend exchange-rate query key. |
| src/governance-app-frontend/src/common/typings/tokenPrices.ts | Extends TokenPrices with optional previousUsd. |
| src/governance-app-frontend/src/common/typings/kongSwap.ts | Removes KongSwap response typings. |
| src/governance-app-frontend/src/common/hooks/useTvlValue.ts | Switches TVL calculation to use unified useTickerPrices. |
| src/governance-app-frontend/src/common/hooks/tickers/useTickerPrices.ts | Makes backend exchange rate primary; IcpSwap becomes fallback. |
| src/governance-app-frontend/src/common/hooks/tickers/useKongSwapPrices.ts | Removes KongSwap price hook and parsing logic. |
| src/governance-app-frontend/src/common/hooks/tickers/useKongSwapPrices.test.tsx | Removes unit tests for KongSwap parsing. |
| src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts | Adds backend-driven exchange rate hook + parser (with previousUsd). |
| src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.test.tsx | Adds unit tests for exchange-rate response parsing. |
| src/governance-app-frontend/src/common/hooks/tickers/index.ts | Exports new exchange-rate hook; removes KongSwap exports. |
| src/governance-app-frontend/src/common/constants/externalServices.ts | Removes KongSwap URL env var reference. |
| scripts/config.sh | Removes EXTRA_KONG_SWAP_URL from generated config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts
Outdated
Show resolved
Hide resolved
src/governance-app-frontend/src/common/hooks/tickers/useExchangeRate.ts
Outdated
Show resolved
Hide resolved
…ve KongSwap price provider IcpSwap is now the sole exchange rate provider, simplifying the ticker price fetching logic before introducing the backend canister as the primary source.
…end canister as primary ICP/USD exchange rate source Call get_icp_to_usd_exchange_rate from the backend canister which fetches rates from the XRC canister and caches them. IcpSwap is kept as a fallback if the backend call fails.
…lures - Format IcpPriceCard.tsx (prettier) - Add vitest alias + mock stub for governance-app-backend declarations, which are DFX-generated and not committed to git
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.
Motivation
The ICP/USD exchange rate was previously obtained from external DEX APIs (IcpSwap as the primary source and KongSwap as a fallback). The backend canister now queries the XRC (Exchange Rate Canister) directly and caches the result, allowing us to use it as the primary source and display the 24-hour price change.
Changes
useExchangeRatehook, which callsget_icp_to_usd_exchange_rateon the backend canister.useTickerPricesto use the backend canister as the primary source, with IcpSwap as a fallback.useTvlValueto utilize the unifieduseTickerPriceshook instead of calling IcpSwap directly.previousUsdfield to theTokenPricestype, populated from the backend'sone_day_agorate.IcpPriceCardto display the 24-hour price change with a directional triangle indicator.