Skip to content

Conversation

@ADITYATIWARI342005
Copy link

What does this PR change?

  • Adds functional currency selection dropdown to all cost pages (Allocations, CloudCosts, ExternalCosts)
  • Wires currency dropdowns to backend API, passing currency parameter in all cost queries
  • Implements URL-based currency persistence (?currency=EUR) for shareable links
  • Updates all service layers to include currency parameter in API requests
  • Prepares UI infrastructure for OpenCost v1.120+ currency conversion feature

Does this PR relate to any other PRs?

  • Related to opencost/opencost#3315 - "feat: Add generic currency conversion package" (merged Sept 4, 2025)
  • That PR added the backend currency conversion infrastructure to the main branch
  • This PR completes the integration by providing the UI layer

How will this PR impact users?

  • Immediate impact (v1.119): Users can select their preferred currency from dropdown. Currency parameter is sent to backend and persisted in URL for sharing.
  • Future impact (v1.120+): When backend currency conversion is released, costs will automatically convert to the selected currency using live exchange rates. No additional UI changes needed.
  • User experience: Currency preference stored in URL enables shareable cost reports with currency preference pre-selected.

Does this PR address any GitHub or Zendesk issues?

  • Closes bug: Exchange rate not working #5 - "bug: Exchange rate not working"
  • The issue reported that currency selection wasn't functional. This PR makes it fully functional and ready for backend conversion when available.

How was this PR tested?

  • Manual testing on local kind cluster with OpenCost v1.119.1

  • Functional verification:

    • ✅ Currency dropdown visible on all 3 pages (Allocations, CloudCosts, ExternalCosts)
    • ✅ Selecting currency updates URL: ?currency=EUR
    • ✅ Currency parameter included in all API requests (verified via network tab)
    • ✅ URL refresh preserves currency selection
    • ✅ Browser back/forward navigation works correctly
    • ✅ Currency symbols display correctly (€, ₹, $, £, etc.)
  • Backend verification:

  # Verified currency parameter is sent to backend
  curl "http://localhost:9003/allocation/compute?window=today&currency=EUR"
  # Response includes currency in query parameters
  
  # Tested multiple currencies
  # USD, EUR, INR all return values (conversion pending v1.120)
  • Version compatibility testing:

    • Confirmed v1.119.1 accepts currency parameter but doesn't convert (expected behavior)
    • Backend logs show: INF Unsupported provider, falling back to default
    • See detailed testing logs in PR comments
  • Code review: Verified consistent patterns across all modified files

    • All service layers conditionally add currency parameter
    • All pages properly update useEffect dependencies
    • Component prop passing follows existing patterns

Does this PR require changes to documentation?

  • README/User Docs: Yes - should document:
    • How to use currency selection dropdown
    • Currency selection persists in URL
    • Backend conversion requires OpenCost v1.120+ with configured exchange rate provider
    • Configuration steps for enabling conversion (when v1.120 is released):
    CURRENCY_PROVIDER=exchangerateapi
    CURRENCY_API_KEY=<your_api_key>
  • Developer Docs: No - implementation follows existing patterns

  • API Docs: No - UI only change, no API modifications

Have you labeled this PR and its corresponding Issue as "next release" if it should be part of the next OpenCost release? If not, why not?

  • Yes, this should be part of the next release because:
    • Completes the currency conversion feature that was merged to backend (PR #3315)
    • Provides immediate value (functional currency selection with URL persistence)
    • Unblocks v1.120 release which includes backend conversion
    • No breaking changes - fully backward compatible with all versions
    • Small, focused change (~65 lines modified across 12 files)
    • Well-tested and production-ready

Additional Context

Backend Currency Conversion Status:
The backend currency conversion package (PR #3315) was merged on September 4, 2025, but is not yet included in a release. It provides:

  • Support for all 161 ISO 4217 currencies
  • Exchange rate caching (24-hour TTL)
  • Integration with exchangerate-api.com
  • Thread-safe implementation

Current Behavior (v1.119.1):

  • UI functional, currency parameter sent to backend
  • Backend accepts parameter but returns: INF Unsupported provider, falling back to default
  • All currencies return identical values (no conversion)

Future Behavior (v1.120+):

  • Currency conversion will work automatically
  • No UI changes required
  • Requires backend configuration with exchange rate API key

Testing Evidence:

Click to expand terminal output showing backend verification ```bash adityatiwari@DeathNote:~/opencost-ui$ # Check OpenCost backend version kubectl get deployment -n opencost opencost -o yaml | grep "image:" image: ghcr.io/opencost/opencost:1.119.1@sha256:43fbd73e2d13f79c07801511877b6c9d70896bc10e2cadcf6a04f4c5d37f6ed3 image: ghcr.io/opencost/opencost-ui:1.119.1@sha256:ae134411a088658d003a06bb3cdfe03336abfc861c2fbe2e7cb54dd54b26714b

adityatiwari@DeathNote:~/opencost-ui$ # Verify latest OpenCost release
curl -s https://api.github.com/repos/opencost/opencost/releases/latest | jq -r '.tag_name'
v1.119.1

adityatiwari@DeathNote:~/opencost-ui$ # Check for currency-related logs in backend
kubectl logs -n opencost deployment/opencost --tail=200 | grep -i "currency|exchange|provider"
Defaulted container "opencost" out of: opencost, opencost-ui
2026-01-17T03:07:57.611848613Z INF Unsupported provider, falling back to default
2026-01-17T03:07:57.611960736Z INF Prometheus Client Max Concurrency set to 5

adityatiwari@DeathNote:~/opencost-ui$ # Test currency parameter with different currencies
echo "Testing USD:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=USD&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing USD:
0.09659

adityatiwari@DeathNote:~/opencost-ui$ echo "Testing EUR:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=EUR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing EUR:
0.09659

adityatiwari@DeathNote:~/opencost-ui$ echo "Testing INR:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=INR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing INR:
0.09659

adityatiwari@DeathNote:~/opencost-ui$ # All three currencies return identical values - no conversion happening

Expected: USD=0.09659, EUR≈0.082 (0.85x), INR≈8.69 (90x)

Actual: All return 0.09659

adityatiwari@DeathNote:~/opencost-ui$ # Search for currency conversion PR in OpenCost repository
curl -s "https://api.github.com/search/commits?q=repo:opencost/opencost+currency&sort=committer-date&order=desc"
-H "Accept: application/vnd.github.cloak-preview+json" |
jq -r '.items[0:5] | .[] | "(.commit.author.date | split("T")[0]) - (.commit.message | split("\n")[0])"'
2025-09-04 - feat: Add generic currency conversion package (#3315)
2023-05-24 - Merge pull request #1940 from saifullah619/feat/multipleCurrencySupport
2023-05-23 - [UI]-Added the support for multiple currencies

adityatiwari@DeathNote:~/opencost-ui$ # Get details of the currency conversion PR
curl -s "https://api.github.com/repos/opencost/opencost/pulls/3315" |
jq '{title: .title, state: .state, merged: .merged, merged_at: .merged_at}'
{
"title": "feat: Add generic currency conversion package",
"state": "closed",
"merged": true,
"merged_at": "2025-09-04T20:51:53Z"
}

adityatiwari@DeathNote:~/opencost-ui$ # Backend accepts currency parameter but doesn't convert
curl -s "http://localhost:9003/allocation/compute?window=today&currency=USD" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
0.01073

adityatiwari@DeathNote:~/opencost-ui$ curl -s "http://localhost:9003/allocation/compute?window=today&currency=INR" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
0.01073

adityatiwari@DeathNote:~/opencost-ui$ # Same value (0.01073) for both USD and INR

Expected INR value: 0.01073 * 90 ≈ 0.9657

Backend accepts parameter but does not perform conversion


</details>

**References**:
- Backend Currency Package: https://github.com/opencost/opencost/pull/3315
- Package Documentation: `pkg/currency` in opencost/opencost repository
- Exchange Rate Provider: https://www.exchangerate-api.com/ (free tier: 1,500 requests/month)

@netlify
Copy link

netlify bot commented Jan 17, 2026

Deploy Preview for opencost-ui ready!

Name Link
🔨 Latest commit 61981a6
🔍 Latest deploy log https://app.netlify.com/projects/opencost-ui/deploys/697121e9f743db00071b28f6
😎 Deploy Preview https://deploy-preview-158--opencost-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

- Wire currency dropdowns to backend API
- Add currency parameter to all cost endpoints
- Persist currency preference in URL
- Prepare UI for OpenCost v1.120 currency conversion

Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
@ADITYATIWARI342005
Copy link
Author

Hi @ameijer, this PR fixes #5, the currency conversion feature. I have tested the functionality locally; however, I could not verify backward compatibility as that version is yet to be released.

these are the logs that verified it.

Terminal logs (click to expand) adityatiwari@DeathNote:~/opencost-ui$ # Check OpenCost backend version kubectl get deployment -n opencost opencost -o yaml | grep "image:" image: ghcr.io/opencost/opencost:1.119.1@sha256:43fbd73e2d13f79c07801511877b6c9d70896bc10e2cadcf6a04f4c5d37f6ed3 image: ghcr.io/opencost/opencost-ui:1.119.1@sha256:ae134411a088658d003a06bb3cdfe03336abfc861c2fbe2e7cb54dd54b26714b

adityatiwari@DeathNote:~/opencost-ui$ # Verify latest OpenCost release
curl -s https://api.github.com/repos/opencost/opencost/releases/latest | jq -r '.tag_name'
v1.119.1

adityatiwari@DeathNote:~/opencost-ui$ # Check for currency-related logs in backend
kubectl logs -n opencost deployment/opencost --tail=200 | grep -i "currency|exchange|provider"
Defaulted container "opencost" out of: opencost, opencost-ui
2026-01-17T03:07:57.611848613Z INF Unsupported provider, falling back to default
2026-01-17T03:07:57.611960736Z INF Prometheus Client Max Concurrency set to 5

adityatiwari@DeathNote:~/opencost-ui$ # Test currency parameter with different currencies
kubectl port-forward -n opencost deployment/opencost 9003:9003 > /dev/null 2>&1 &
[1] 13696
sleep 3

adityatiwari@DeathNote:~/opencost-ui$ echo "Testing USD:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=USD&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing USD:
Handling connection for 9003
0.09659

adityatiwari@DeathNote:~/opencost-ui$ echo "Testing EUR:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=EUR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing EUR:
Handling connection for 9003
0.09659

adityatiwari@DeathNote:~/opencost-ui$ echo "Testing INR:"
curl -s "http://localhost:9003/allocation/compute?window=today&currency=INR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing INR:
Handling connection for 9003
0.09659

adityatiwari@DeathNote:~/opencost-ui$ # All three currencies return identical values - no conversion happening
# Expected: USD=0.09659, EUR≈0.082 (0.85x), INR≈8.69 (90x)
# Actual: All return 0.09659

adityatiwari@DeathNote:~/opencost-ui$ # Search for currency conversion PR in OpenCost repository
curl -s "https://api.github.com/search/commits?q=repo:opencost/opencost+currency&sort=committer-date&order=desc"
-H "Accept: application/vnd.github.cloak-preview+json" |
jq -r '.items[0:5] | .[] | "(.commit.author.date | split("T")[0]) - (.commit.message | split("\n")[0])"'
2025-09-04 - feat: Add generic currency conversion package (#3315)
2023-05-24 - Merge pull request #1940 from saifullah619/feat/multipleCurrencySupport
2023-05-23 - [UI]-Added the support for multiple currencies
2020-09-08 - Merge pull request #529 from kubecost/cw-update-gcpprovider-for-currency-conversion
2019-10-30 - Add currency code to custom pricing setting cache

adityatiwari@DeathNote:~/opencost-ui$ # Get details of the currency conversion PR
curl -s "https://api.github.com/repos/opencost/opencost/pulls/3315" |
jq '{title: .title, state: .state, merged: .merged, merged_at: .merged_at}'
{
"title": "feat: Add generic currency conversion package",
"state": "closed",
"merged": true,
"merged_at": "2025-09-04T20:51:53Z"
}

adityatiwari@DeathNote:~/opencost-ui$ # Check if PR #3315 is in current release
# PR merged: September 4, 2025
# Latest release: v1.119.1
# Conclusion: Currency conversion merged to main branch but not yet released

adityatiwari@DeathNote:~/opencost-ui$ # Verify backend accepts currency parameter but doesn't convert
curl -s "http://localhost:9003/allocation/compute?window=today&currency=USD" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
Handling connection for 9003
0.01073

adityatiwari@DeathNote:~/opencost-ui$ curl -s "http://localhost:9003/allocation/compute?window=today&currency=INR" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
Handling connection for 9003
0.01073

adityatiwari@DeathNote:~/opencost-ui$ # Same value (0.01073) for both USD and INR
# Expected INR value: 0.01073 * 90 ≈ 0.9657
# Backend accepts parameter but does not perform conversion

adityatiwari@DeathNote:~/opencost-ui$ pkill -f port-forward

adityatiwari@DeathNote:/opencost-ui$ # Summary of findings:
# OpenCost v1.119.1 is the latest release
# Currency conversion package merged Sept 4, 2025 (PR #3315)
# Backend logs show "Unsupported provider, falling back to default"
# API accepts currency parameter but returns identical values
# Currency conversion awaiting v1.120+ release
adityatiwari@DeathNote:
/opencost-ui$

@ADITYATIWARI342005
Copy link
Author

@ameijer Please review it!

@ADITYATIWARI342005
Copy link
Author

Also fixes #3 .

Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
@ADITYATIWARI342005
Copy link
Author

Hi @ameijer Apologies for bothering you, but I require your review on this, as it addresses 2 issues and cannot be verified on Netlify preview to be functional because the latest released version of OpenCost is v1.119.1, which was released on January 6, 2025, and the backend integration of currency conversion was done by opencost/opencost#3315, (merged Sept 5, 2025).

Any suggestions on how to proceed? (I have tested the fix on localhost backend by curl.)

@ameijer
Copy link
Member

ameijer commented Jan 21, 2026

@ADITYATIWARI342005 want to implement BE currency conversion?

@ADITYATIWARI342005
Copy link
Author

@ADITYATIWARI342005 want to implement BE currency conversion?

I have attempted to, based on your feedback on the earlier PR on that issue and comment #5 (comment)

@ameijer Should I refactor the approach? Whatever you prefer.

@ADITYATIWARI342005
Copy link
Author

@ADITYATIWARI342005 want to implement BE currency conversion?

@ameijer After reading it again, I am not sure. Did it mean implementation in opencost/opencost and not opencost/opencost-ui?

@ameijer
Copy link
Member

ameijer commented Jan 22, 2026

yes, that's right. if you inspect opencost/opencost, you will see that recently a community member contributed code that implements forex conversion. however, that code isn't called anywhere. we need an enhancement on that repo that reads the params you send here, then jams all costs into the converter before returning.

@ADITYATIWARI342005
Copy link
Author

yes, that's right. if you inspect opencost/opencost, you will see that recently a community member contributed code that implements forex conversion. however, that code isn't called anywhere. we need an enhancement on that repo that reads the params you send here, then jams all costs into the converter before returning.

@ameijer Thanks for the descriptive explanation. I have a high-level overview about what is to be done. I am looking into this.

@ADITYATIWARI342005
Copy link
Author

yes, that's right. if you inspect opencost/opencost, you will see that recently a community member contributed code that implements forex conversion. however, that code isn't called anywhere. we need an enhancement on that repo that reads the params you send here, then jams all costs into the converter before returning.

Hi @ameijer At first it seemed tough, but given your description and guidance, I attempted to successfully implement it, I have tested the build and functionality thoroughly.

Looking forward to your valuable reviews! on opencost/opencost#3553

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Exchange rate not working

2 participants