[PR #8064] [MERGED] [AI] feat(currencies): add currency-precision-aware helpers #122300

Closed
opened 2026-06-11 21:05:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/8064
Author: @StephenBrown2
Created: 6/3/2026
Status: Merged
Merged: 6/4/2026
Merged by: @MatissJanis

Base: masterHead: currency-decimal-helpers


📝 Commits (4)

  • ad6b8eb [AI] feat(currencies): add getDecimalPlaces/getCurrencyPrecisionMultiplier helpers, encodeAmount, currency-aware integerToCurrencyWithDecimal
  • 3227986 Fix typo in release note
  • 7a0604e Use it.each in unit tests
  • de3db79 Rename encodeAmount and replace its body; remove getCurrencyPrecisionMultiplier

📊 Changes

5 files changed (+140 additions, -1 deletions)

View changed files

packages/loot-core/src/shared/currencies.test.ts (+44 -0)
📝 packages/loot-core/src/shared/currencies.ts (+4 -0)
📝 packages/loot-core/src/shared/util.test.ts (+67 -0)
📝 packages/loot-core/src/shared/util.ts (+19 -1)
upcoming-release-notes/8064.md (+6 -0)

📄 Description

Description

This PR lays the groundwork for multi-currency support by adding currency-precision-aware helpers to the shared utilities in loot-core.

Overall vision/plan: https://gist.github.com/StephenBrown2/a1c3a0cd19f8f2fac0c76c2b93ed20fc

I envision this being the first of many small PRs, slowly filling out the needed work to enable account-level currency support, at which point, we can then build budget-level support on top of that.

However, the first thing to address is the existing mistakes when handling currencies with zero (and eventually 3+) decimal places. This should eventually get us to the end state of #6954.

Changes:

  • currencies.ts:
    • Added getDecimalPlaces(currencyCode): returns the number of decimal places for a given currency (defaults to 2 for unknown codes)
    • Added getCurrencyPrecisionMultiplier(currencyCode): returns the corresponding power-of-10 multiplier (1 for JPY, 100 for USD, etc.)
  • util.ts:
    • Added optional currencyCode parameter to integerToCurrencyWithDecimal: when supplied it formats using that currency's precision; without it, existing behaviour is unchanged.
    • Added encodeAmount(amount, code): converts a floating-point amount into the integer storage format for a given currency.

Partially implements #6954

Testing

Full unit test coverage added:

  • currencies.test.ts: covers getDecimalPlaces and getCurrencyPrecisionMultiplier for zero-decimal currencies (JPY, KRW, IRR), standard currencies (USD, EUR, GBP), unknown currency codes, and the metadata completeness of the full currencies list.
  • util.test.ts: covers the new currencyCode path in integerToCurrencyWithDecimal, the encodeAmount function, and a round-trip consistency check between encodeAmount and integerToCurrencyWithDecimal across JPY, USD, and IRR.

Checklist

  • Release notes added (see link above)
  • No obvious regressions in affected areas
  • Self-review has been performed - I understand what each change in the code does and why it is needed

Bundle Stats

Bundle Files count Total bundle size % Changed
desktop-client 37 14.05 MB → 14.05 MB (+321 B) +0.00%
loot-core 1 5.28 MB 0%
api 2 3.86 MB 0%
cli 1 7.97 MB 0%
crdt 1 11.12 kB 0%
View detailed bundle stats

desktop-client

Total

Files count Total bundle size % Changed
37 14.05 MB → 14.05 MB (+321 B) +0.00%
Changeset
File Δ Size
home/runner/work/actual/actual/packages/loot-core/src/shared/util.ts 📈 +222 B (+2.46%) 8.82 kB → 9.04 kB
home/runner/work/actual/actual/packages/loot-core/src/shared/currencies.ts 📈 +99 B (+1.53%) 6.33 kB → 6.42 kB
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger

Asset File Size % Changed
static/js/extends.js 501.42 kB → 508.06 kB (+6.64 kB) +1.32%

Smaller

Asset File Size % Changed
static/js/Value.js 5.09 MB → 5.08 MB (-6.33 kB) -0.12%

Unchanged

Asset File Size % Changed
static/js/index.js 1.55 MB 0%
static/js/BackgroundImage.js 121.09 kB 0%
static/js/FormulaEditor.js 962.55 kB 0%
static/js/ManageRules.js 46.64 kB 0%
static/js/PayeeRuleCountLabel.js 7.33 kB 0%
static/js/ReportRouter.js 1.26 MB 0%
static/js/ScheduleEditForm.js 146.44 kB 0%
static/js/SchedulesTable.js 202.7 kB 0%
static/js/TransactionEdit.js 90.63 kB 0%
static/js/TransactionList.js 85.81 kB 0%
static/js/_baseIsEqual.js 98.38 kB 0%
static/js/ca.js 186.63 kB 0%
static/js/client.js 451.37 kB 0%
static/js/da.js 101.02 kB 0%
static/js/de.js 170.87 kB 0%
static/js/en-GB.js 9.25 kB 0%
static/js/en.js 199.45 kB 0%
static/js/es.js 178.57 kB 0%
static/js/fr.js 178.44 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.46 kB 0%
static/js/it.js 164.87 kB 0%
static/js/narrow.js 364.5 kB 0%
static/js/nb-NO.js 147.94 kB 0%
static/js/nl.js 107 kB 0%
static/js/pt-BR.js 188.32 kB 0%
static/js/resize-observer.js 18.06 kB 0%
static/js/th.js 174.31 kB 0%
static/js/theme.js 31.88 kB 0%
static/js/toString.js 705.14 kB 0%
static/js/uk.js 209.01 kB 0%
static/js/useFormatList.js 2.52 kB 0%
static/js/useTransactionBatchActions.js 9.71 kB 0%
static/js/wide.js 299.14 kB 0%
static/js/workbox-window.prod.es5.js 7.33 kB 0%
static/js/zh-Hans.js 117.01 kB 0%

loot-core

Total

Files count Total bundle size % Changed
1 5.28 MB 0%
View detailed bundle breakdown

Added

Asset File Size % Changed
kcab.worker.CCn_Decu.js 0 B → 5.28 MB (+5.28 MB) -

Removed

Asset File Size % Changed
kcab.worker.GgwvIuuL.js 5.28 MB → 0 B (-5.28 MB) -100%

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged
No assets were unchanged


api

Total

Files count Total bundle size % Changed
2 3.86 MB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
index.js 3.86 MB 0%
models.js 0 B 0%

cli

Total

Files count Total bundle size % Changed
1 7.97 MB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
cli.js 7.97 MB 0%

crdt

Total

Files count Total bundle size % Changed
1 11.12 kB 0%
View detailed bundle breakdown

Added
No assets were added

Removed
No assets were removed

Bigger
No assets were bigger

Smaller
No assets were smaller

Unchanged

Asset File Size % Changed
index.js 11.12 kB 0%

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/8064 **Author:** [@StephenBrown2](https://github.com/StephenBrown2) **Created:** 6/3/2026 **Status:** ✅ Merged **Merged:** 6/4/2026 **Merged by:** [@MatissJanis](https://github.com/MatissJanis) **Base:** `master` ← **Head:** `currency-decimal-helpers` --- ### 📝 Commits (4) - [`ad6b8eb`](https://github.com/actualbudget/actual/commit/ad6b8eb9fa2e2d31d964583f4fe28fd231fdf89d) [AI] feat(currencies): add getDecimalPlaces/getCurrencyPrecisionMultiplier helpers, encodeAmount, currency-aware integerToCurrencyWithDecimal - [`3227986`](https://github.com/actualbudget/actual/commit/32279868790b2ff0d75249278b2591b9e1eaaff9) Fix typo in release note - [`7a0604e`](https://github.com/actualbudget/actual/commit/7a0604ed678fd603a8588a6dfe4a2d9bcc1ecc05) Use it.each in unit tests - [`de3db79`](https://github.com/actualbudget/actual/commit/de3db79cbf7c1e2d753ef1d6830989c0f909e895) Rename encodeAmount and replace its body; remove getCurrencyPrecisionMultiplier ### 📊 Changes **5 files changed** (+140 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `packages/loot-core/src/shared/currencies.test.ts` (+44 -0) 📝 `packages/loot-core/src/shared/currencies.ts` (+4 -0) 📝 `packages/loot-core/src/shared/util.test.ts` (+67 -0) 📝 `packages/loot-core/src/shared/util.ts` (+19 -1) ➕ `upcoming-release-notes/8064.md` (+6 -0) </details> ### 📄 Description ## Description This PR lays the groundwork for multi-currency support by adding currency-precision-aware helpers to the shared utilities in `loot-core`. Overall vision/plan: https://gist.github.com/StephenBrown2/a1c3a0cd19f8f2fac0c76c2b93ed20fc I envision this being the first of many small PRs, slowly filling out the needed work to enable account-level currency support, at which point, we can then build budget-level support on top of that. However, the first thing to address is the existing mistakes when handling currencies with zero (and eventually 3+) decimal places. This should eventually get us to the end state of #6954. Changes: - `currencies.ts`: - Added `getDecimalPlaces(currencyCode)`: returns the number of decimal places for a given currency (defaults to 2 for unknown codes) - Added `getCurrencyPrecisionMultiplier(currencyCode)`: returns the corresponding power-of-10 multiplier (1 for JPY, 100 for USD, etc.) - `util.ts`: - Added optional `currencyCode` parameter to `integerToCurrencyWithDecimal`: when supplied it formats using that currency's precision; without it, existing behaviour is unchanged. - Added `encodeAmount(amount, code)`: converts a floating-point amount into the integer storage format for a given currency. ## Related issue(s) Partially implements #6954 ## Testing Full unit test coverage added: - `currencies.test.ts`: covers `getDecimalPlaces` and `getCurrencyPrecisionMultiplier` for zero-decimal currencies (JPY, KRW, IRR), standard currencies (USD, EUR, GBP), unknown currency codes, and the metadata completeness of the full currencies list. - `util.test.ts`: covers the new `currencyCode` path in `integerToCurrencyWithDecimal`, the `encodeAmount` function, and a round-trip consistency check between `encodeAmount` and `integerToCurrencyWithDecimal` across JPY, USD, and IRR. ## Checklist - [x] Release notes added (see link above) - [x] No obvious regressions in affected areas - [x] Self-review has been performed - I understand what each change in the code does and why it is needed <!--- actual-bot-sections ---> <!--- bundlestats-action-comment key:combined start ---> ### Bundle Stats Bundle | Files count | Total bundle size | % Changed ------ | ----------- | ----------------- | --------- desktop-client | 37 | 14.05 MB → 14.05 MB (+321 B) | +0.00% loot-core | 1 | 5.28 MB | 0% api | 2 | 3.86 MB | 0% cli | 1 | 7.97 MB | 0% crdt | 1 | 11.12 kB | 0% <details> <summary>View detailed bundle stats</summary> #### desktop-client **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 37 | 14.05 MB → 14.05 MB (+321 B) | +0.00% <details> <summary>Changeset</summary> File | Δ | Size ---- | - | ---- `home/runner/work/actual/actual/packages/loot-core/src/shared/util.ts` | 📈 +222 B (+2.46%) | 8.82 kB → 9.04 kB `home/runner/work/actual/actual/packages/loot-core/src/shared/currencies.ts` | 📈 +99 B (+1.53%) | 6.33 kB → 6.42 kB </details> <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** Asset | File Size | % Changed ----- | --------- | --------- static/js/extends.js | 501.42 kB → 508.06 kB (+6.64 kB) | +1.32% **Smaller** Asset | File Size | % Changed ----- | --------- | --------- static/js/Value.js | 5.09 MB → 5.08 MB (-6.33 kB) | -0.12% **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- static/js/index.js | 1.55 MB | 0% static/js/BackgroundImage.js | 121.09 kB | 0% static/js/FormulaEditor.js | 962.55 kB | 0% static/js/ManageRules.js | 46.64 kB | 0% static/js/PayeeRuleCountLabel.js | 7.33 kB | 0% static/js/ReportRouter.js | 1.26 MB | 0% static/js/ScheduleEditForm.js | 146.44 kB | 0% static/js/SchedulesTable.js | 202.7 kB | 0% static/js/TransactionEdit.js | 90.63 kB | 0% static/js/TransactionList.js | 85.81 kB | 0% static/js/_baseIsEqual.js | 98.38 kB | 0% static/js/ca.js | 186.63 kB | 0% static/js/client.js | 451.37 kB | 0% static/js/da.js | 101.02 kB | 0% static/js/de.js | 170.87 kB | 0% static/js/en-GB.js | 9.25 kB | 0% static/js/en.js | 199.45 kB | 0% static/js/es.js | 178.57 kB | 0% static/js/fr.js | 178.44 kB | 0% static/js/indexeddb-main-thread-worker-e59fee74.js | 13.46 kB | 0% static/js/it.js | 164.87 kB | 0% static/js/narrow.js | 364.5 kB | 0% static/js/nb-NO.js | 147.94 kB | 0% static/js/nl.js | 107 kB | 0% static/js/pt-BR.js | 188.32 kB | 0% static/js/resize-observer.js | 18.06 kB | 0% static/js/th.js | 174.31 kB | 0% static/js/theme.js | 31.88 kB | 0% static/js/toString.js | 705.14 kB | 0% static/js/uk.js | 209.01 kB | 0% static/js/useFormatList.js | 2.52 kB | 0% static/js/useTransactionBatchActions.js | 9.71 kB | 0% static/js/wide.js | 299.14 kB | 0% static/js/workbox-window.prod.es5.js | 7.33 kB | 0% static/js/zh-Hans.js | 117.01 kB | 0% </div> </details> --- #### loot-core **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 5.28 MB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.CCn_Decu.js | 0 B → 5.28 MB (+5.28 MB) | - **Removed** Asset | File Size | % Changed ----- | --------- | --------- kcab.worker.GgwvIuuL.js | 5.28 MB → 0 B (-5.28 MB) | -100% **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** No assets were unchanged </div> </details> --- #### api **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 2 | 3.86 MB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- index.js | 3.86 MB | 0% models.js | 0 B | 0% </div> </details> --- #### cli **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 7.97 MB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- cli.js | 7.97 MB | 0% </div> </details> --- #### crdt **Total** Files count | Total bundle size | % Changed ----------- | ----------------- | --------- 1 | 11.12 kB | 0% <details> <summary>View detailed bundle breakdown</summary> <div> **Added** No assets were added **Removed** No assets were removed **Bigger** No assets were bigger **Smaller** No assets were smaller **Unchanged** Asset | File Size | % Changed ----- | --------- | --------- index.js | 11.12 kB | 0% </div> </details> </details> <!--- bundlestats-action-comment key:combined end ---> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-06-11 21:05:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#122300