Rates for currencies the ECB lacks (ALL); only list currencies in circulation #5

Merged
reudy merged 2 commits from fix/currency-rates into main 2026-11-06 19:39:19 +01:00
Member

Fixes two currency problems: no exchange rate for the Albanian lek (ALL), and a picker full of currencies that no longer exist.

Why

  • ALL had no rate because we only used ECB reference rates (~30 currencies), and the ECB doesn't publish ALL.
  • Obsolete currencies came from Intl.supportedValuesOf('currency'), which in Chrome and Firefox includes historical codes (ATS, DEM, …).

What changed

  • Supplementary rate feed. The server also fetches ExchangeRate-API's free EUR-based endpoint (RATES_EXTRA_URL, default https://open.er-api.com/v6/latest/EUR; empty turns it off) on the existing 6-hour schedule.
    • Stored in a separate rates_extra table. The ECB rate always wins for a currency both publish.
    • GET /api/rates merges the two and adds sources: { CODE: "xr:<date>" } for supplementary rates.
    • A snapshot more than a week older than the requested date is not used.
    • Clients still only talk to our server.
  • Rate source label. Expenses using these rates record rateSource: "xr:<date>". The editor shows "Rates By Exchange Rate API, {date}" with a link to exchangerate-api.com, which the free tier requires. Added to both locales.
  • Currency picker. Offers only currencies in ACTIVE_CURRENCIES (packages/core/src/currencies.ts, hand-maintained ISO 4217 list, 154 codes). This also drops recently replaced codes (BGN → EUR 2026, HRK, ANG → XCG, ZWL → ZWG, SLL → SLE, CUC) and non-cash units (XDR, XSU).
    • Groups are now "Daily rate" / "Enter rate manually" instead of "ECB" / "…".
    • A withdrawn currency already in use (e.g. an old BGN group) stays selectable.
  • /api/rates now returns 400 for impossible dates like 2026-13-45; before, the new date math would have thrown a 500 on them.
  • SPEC.md §8.2 and README.md updated.

Limitations

  • The feed has no history, so non-ECB rates build up from the day the server is deployed. Older back-dated expenses in those currencies still need a manual rate.
  • It's a commercial provider's free tier, not a central bank.

Tested

  • npm test: core 26/26, server 15/15 (new: merge and ECB precedence, week staleness cutoff, feed parsing, bad dates, currency list).
  • npm run check: 0 errors, 0 warnings.
  • npm run build && npm run test:e2e: 2/2 pass.
  • Ran the server against both live feeds. /api/rates returned ALL = 90.93754 (xr:2026-11-06) and CZK from the ECB. In Chromium the picker showed 152 currencies under "Daily rate" (ALL included), 2 under manual (KPW, SVC), and no ATS/BGN/non-ISO codes.
  • Not tested by hand: the xr: label in the expense editor. No automated test covers it either.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x

Fixes two currency problems: no exchange rate for the Albanian lek (ALL), and a picker full of currencies that no longer exist. ## Why - **ALL had no rate** because we only used ECB reference rates (~30 currencies), and the ECB doesn't publish ALL. - **Obsolete currencies** came from `Intl.supportedValuesOf('currency')`, which in Chrome and Firefox includes historical codes (ATS, DEM, …). ## What changed - **Supplementary rate feed.** The server also fetches ExchangeRate-API's free EUR-based endpoint (`RATES_EXTRA_URL`, default `https://open.er-api.com/v6/latest/EUR`; empty turns it off) on the existing 6-hour schedule. - Stored in a separate `rates_extra` table. The ECB rate always wins for a currency both publish. - `GET /api/rates` merges the two and adds `sources: { CODE: "xr:<date>" }` for supplementary rates. - A snapshot more than a week older than the requested date is not used. - Clients still only talk to our server. - **Rate source label.** Expenses using these rates record `rateSource: "xr:<date>"`. The editor shows "Rates By Exchange Rate API, {date}" with a link to exchangerate-api.com, which the free tier requires. Added to both locales. - **Currency picker.** Offers only currencies in `ACTIVE_CURRENCIES` (`packages/core/src/currencies.ts`, hand-maintained ISO 4217 list, 154 codes). This also drops recently replaced codes (BGN → EUR 2026, HRK, ANG → XCG, ZWL → ZWG, SLL → SLE, CUC) and non-cash units (XDR, XSU). - Groups are now "Daily rate" / "Enter rate manually" instead of "ECB" / "…". - A withdrawn currency already in use (e.g. an old BGN group) stays selectable. - `/api/rates` now returns 400 for impossible dates like `2026-13-45`; before, the new date math would have thrown a 500 on them. - `SPEC.md` §8.2 and `README.md` updated. ## Limitations - The feed has no history, so non-ECB rates build up from the day the server is deployed. Older back-dated expenses in those currencies still need a manual rate. - It's a commercial provider's free tier, not a central bank. ## Tested - `npm test`: core 26/26, server 15/15 (new: merge and ECB precedence, week staleness cutoff, feed parsing, bad dates, currency list). - `npm run check`: 0 errors, 0 warnings. - `npm run build && npm run test:e2e`: 2/2 pass. - Ran the server against both live feeds. `/api/rates` returned ALL = 90.93754 (`xr:2026-11-06`) and CZK from the ECB. In Chromium the picker showed 152 currencies under "Daily rate" (ALL included), 2 under manual (KPW, SVC), and no ATS/BGN/non-ISO codes. - Not tested by hand: the `xr:` label in the expense editor. No automated test covers it either. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
agent added 2 commits 2026-11-06 19:13:47 +01:00
Browsers' Intl.supportedValuesOf('currency') includes long-withdrawn codes
(ATS, DEM, ...). Use a hand-maintained ACTIVE_CURRENCIES list in core instead,
which also drops recently replaced ones (BGN, HRK, ANG, ZWL, SLL, CUC) and
non-cash units (XDR, XSU). A withdrawn currency already in use stays selectable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
The server also fetches ExchangeRate-API's free EUR-based endpoint
(RATES_EXTRA_URL, empty = off), stored apart from ECB rates; ECB always wins
for a currency both publish. /api/rates returns sources for supplementary
rates, expenses record them as xr:<date>, and the editor shows the required
attribution link. Snapshots older than a week before the requested date are
not used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
reudy merged commit da35509ecd into main 2026-11-06 19:39:19 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/oweme#5
No description provided.