Skip to content

feat(rates): use XRC as primary ICP/USD exchange rate source#365

Open
yhabib wants to merge 7 commits intomainfrom
feat/xrc-source
Open

feat(rates): use XRC as primary ICP/USD exchange rate source#365
yhabib wants to merge 7 commits intomainfrom
feat/xrc-source

Conversation

@yhabib
Copy link
Copy Markdown
Collaborator

@yhabib yhabib commented Apr 1, 2026

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.

Screenshot 2026-04-01 at 18 53 02

Changes

  • Removed KongSwap as a price provider (including hooks, types, fixtures, end-to-end stubs, tests, and environment configuration).
  • Added the useExchangeRate hook, which calls get_icp_to_usd_exchange_rate on the backend canister.
  • Updated useTickerPrices to use the backend canister as the primary source, with IcpSwap as a fallback.
  • Modified useTvlValue to utilize the unified useTickerPrices hook instead of calling IcpSwap directly.
  • Added an optional previousUsd field to the TokenPrices type, populated from the backend's one_day_ago rate.
  • Enhanced IcpPriceCard to display the 24-hour price change with a directional triangle indicator.

@yhabib yhabib requested a review from Copilot April 1, 2026 16:53
@yhabib yhabib changed the title feat(frontend): use XRC as primary ICP/USD exchange rate source feat(rates): use XRC as primary ICP/USD exchange rate source Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

📊 Build Bundle Stats

The latest build generated the following assets:

dist/index.html                                           1.92 kB │ gzip:   0.68 kB
dist/assets/index-D5Qot_eu.css                          129.73 kB │ gzip:  20.46 kB
dist/assets/neuron-BzfhhNec.js                            0.08 kB │ gzip:   0.09 kB
dist/assets/externalServices-B9hWFV-7.js                  0.21 kB │ gzip:   0.17 kB
dist/assets/useTvlValue-PRLcbuBe.js                       0.58 kB │ gzip:   0.39 kB
dist/assets/Spinner-DbzLKkdb.js                           0.58 kB │ gzip:   0.40 kB
dist/assets/service-BS9ZMmaX.js                           0.60 kB │ gzip:   0.39 kB
dist/assets/useHideBalances-DlLgtjQO.js                   0.61 kB │ gzip:   0.40 kB
dist/assets/numbers-j8Te9vci.js                           0.61 kB │ gzip:   0.37 kB
dist/assets/PageHeader-Cr3cEbbs.js                        0.75 kB │ gzip:   0.44 kB
dist/assets/Separator-qFc66HTK.js                         0.77 kB │ gzip:   0.46 kB
dist/assets/CertifiedBadge-B3LponJT.js                    0.80 kB │ gzip:   0.48 kB
dist/assets/useIcpIndex-BDdTu14B.js                       1.08 kB │ gzip:   0.63 kB
dist/assets/addressBook-1Sqow7y4.js                       1.09 kB │ gzip:   0.70 kB
dist/assets/Switch-DCtprmt6.js                            1.65 kB │ gzip:   0.82 kB
dist/assets/CopyButton-BRXO7puS.js                        1.86 kB │ gzip:   0.95 kB
dist/assets/AnimatedNumber-Bl1uv8PQ.js                    1.86 kB │ gzip:   1.04 kB
dist/assets/useGovernanceAppCanister-DqerxgtM.js          1.92 kB │ gzip:   0.97 kB
dist/assets/useInfiniteQueryThenUpdateCall-CWEEcWY7.js    1.93 kB │ gzip:   0.97 kB
dist/assets/ToggleGroup-Dk_2sM5s.js                       3.05 kB │ gzip:   1.33 kB
dist/assets/useTickerPrices-0Tlm1O5Z.js                   3.16 kB │ gzip:   1.50 kB
dist/assets/_auth-2p5oR8Kn.js                             4.19 kB │ gzip:   2.01 kB
dist/assets/AmountInput-tI7cKpb8.js                       6.37 kB │ gzip:   2.91 kB
dist/assets/useSpamFilterCanister-BF0pQbuP.js             7.20 kB │ gzip:   3.24 kB
dist/assets/QueryStates-DfeEThjN.js                       7.94 kB │ gzip:   2.27 kB
dist/assets/index-Bf1AhUSk.js                             8.72 kB │ gzip:   3.38 kB
dist/assets/Input-DTJe29JC.js                             9.40 kB │ gzip:   3.35 kB
dist/assets/TopicFollowingAccordion-BIj_zVBO.js          10.05 kB │ gzip:   4.00 kB
dist/assets/types-CrI-tKp8.js                            10.70 kB │ gzip:   4.56 kB
dist/assets/index-DsWcZQze.js                            14.30 kB │ gzip:   4.54 kB
dist/assets/index-QpYy_g8_.js                            23.48 kB │ gzip:   8.05 kB
dist/assets/DepositICPModal-DR-dWzzF.js                  39.67 kB │ gzip:  13.88 kB
dist/assets/index-Cyk8ovnq.js                            40.94 kB │ gzip:  11.78 kB
dist/assets/index-DQlndKer.js                            49.00 kB │ gzip:  14.72 kB
dist/assets/index-maqCjS-H.js                            67.12 kB │ gzip:  20.60 kB
dist/assets/vendor-md-KelhpvMd.js                        89.32 kB │ gzip:  25.51 kB
dist/assets/index-DVW4bTq7.js                           120.53 kB │ gzip:  38.83 kB
dist/assets/index-ObnhYrSR.js                           121.98 kB │ gzip:  34.50 kB
dist/assets/vendor-tanstack-DNwsJOPx.js                 126.65 kB │ gzip:  39.34 kB
dist/assets/vendor-core-react-By6K7kM9.js               193.24 kB │ gzip:  60.69 kB
dist/assets/vendor-recharts-L2KVWzi1.js                 228.10 kB │ gzip:  65.92 kB
dist/assets/vendor-icp-BoXv3tub.js                      402.37 kB │ gzip: 100.05 kB
dist/assets/vendor-libs-C4Nvvb3f.js                     541.61 kB │ gzip: 179.11 kB

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 useExchangeRate to fetch get_icp_to_usd_exchange_rate from the backend canister and parse current + 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.

@yhabib yhabib marked this pull request as ready for review April 2, 2026 11:27
@yhabib yhabib requested a review from a team as a code owner April 2, 2026 11:27
@yhabib yhabib force-pushed the feat/xrc-source branch from 78c17fd to b686346 Compare April 2, 2026 11:27
yhabib added 6 commits April 7, 2026 15:24
…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
@yhabib yhabib force-pushed the feat/xrc-source branch from b686346 to e54c3bc Compare April 7, 2026 13:24
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.

2 participants