[PR #4987] [MERGED] Add option to calculate running balances in useTransactions hook #5691

Closed
opened 2026-02-28 21:16:49 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/4987
Author: @joel-jeremy
Created: 5/14/2025
Status: ✅ Merged
Merged: 5/14/2025
Merged by: @joel-jeremy

Base: master ← Head: useTransactions-runningBalances


📝 Commits (5)

📊 Changes

3 files changed (+125 additions, -3 deletions)

View changed files

📝 packages/loot-core/src/client/data-hooks/transactions.ts (+116 -2)
📝 packages/loot-core/src/types/models/transaction.ts (+3 -1)
➕ upcoming-release-notes/4987.md (+6 -0)

📄 Description

How to use:

const { transactions, runningBalances } = useTransactions({
  query,
  options: {
    calculateRunningBalances: true,
  }
})

or

// The default calculation works well when transactions are order by date in descending order, when a custom order
// is needed, it's best to provide a custom calculation function to calculate the running balances.
const customCalculateRunningBalances = (transactions: TransactionEntity[], queryState: QueryState) => {
  // Calculate running balances for each transaction.
  return new Map<TransactionEntity['id'], IntegerAmount>(...);
}

const { transactions, runningBalances } = useTransactions({
  queryWithCustomOrder,
  options: {
    calculateRunningBalances: customCalculateRunningBalances,
  }
})

🔄 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/4987 **Author:** [@joel-jeremy](https://github.com/joel-jeremy) **Created:** 5/14/2025 **Status:** ✅ Merged **Merged:** 5/14/2025 **Merged by:** [@joel-jeremy](https://github.com/joel-jeremy) **Base:** `master` ← **Head:** `useTransactions-runningBalances` --- ### 📝 Commits (5) - [`c1f8c0b`](https://github.com/actualbudget/actual/commit/c1f8c0b02557f8397a021ae9421333ac701ae3e1) Add option to calculate running balances in useTransactions hook - [`4cc7072`](https://github.com/actualbudget/actual/commit/4cc7072d3452301c9e27a29d7ef70e57c33d8f2e) Fix typecheck error - [`d69ba46`](https://github.com/actualbudget/actual/commit/d69ba4611c976d3f1fdc1c7564e636411e7ef145) Fix lint error - [`223e52a`](https://github.com/actualbudget/actual/commit/223e52a468c54045d43b439d4ccaccc87e2c5728) Cleanup - [`c5c4e38`](https://github.com/actualbudget/actual/commit/c5c4e38a8f1bc167ef5af646ae92eb655165af39) retrigger checks ### 📊 Changes **3 files changed** (+125 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/loot-core/src/client/data-hooks/transactions.ts` (+116 -2) 📝 `packages/loot-core/src/types/models/transaction.ts` (+3 -1) ➕ `upcoming-release-notes/4987.md` (+6 -0) </details> ### 📄 Description <!-- Thank you for submitting a pull request! Make sure to follow the instructions to write release notes for your PR — it should only take a minute or two: https://github.com/actualbudget/docs#writing-good-release-notes. Try running yarn generate:release-notes *before* pushing your PR for an interactive experience. --> How to use: ```js const { transactions, runningBalances } = useTransactions({ query, options: { calculateRunningBalances: true, } }) ``` or ```js // The default calculation works well when transactions are order by date in descending order, when a custom order // is needed, it's best to provide a custom calculation function to calculate the running balances. const customCalculateRunningBalances = (transactions: TransactionEntity[], queryState: QueryState) => { // Calculate running balances for each transaction. return new Map<TransactionEntity['id'], IntegerAmount>(...); } const { transactions, runningBalances } = useTransactions({ queryWithCustomOrder, options: { calculateRunningBalances: customCalculateRunningBalances, } }) ``` --- <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-02-28 21:16:49 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#5691