Fix #631: respect user and group default currency when creating expenses#647
Merged
Conversation
Closes oss-apps#631 The expense form always defaulted to USD regardless of the user's or group's configured default currency. The user/group defaults were fetched but never applied to the form's currency field. Changes: - src/pages/add.tsx: set currency from user.defaultCurrency for non-group expenses, and from group.defaultCurrency (falling back to the user's) when entering a group context. The setCurrentUser effect is gated on router.isReady so the first render (before Next.js populates router.query) does not falsely treat a group page as a non-group page and apply the wrong default. - src/store/addStore.ts: resetState now restores the user's default currency on unmount so navigating away and back lands on the correct default instead of stale state. Disclaimer: parts of this change were drafted with the help of Claude Opus 4.7.
krokosik
requested changes
May 17, 2026
Collaborator
krokosik
left a comment
There was a problem hiding this comment.
The fix is appropriate but not quite there yet. It omits the core of the regression, which is the missing functionality of defaulting to last used currency. It is kept in currency field in the currentUser object. The correct preference chain is:
currentUser.currencygroup.defaultCurrencycurrentUser.defaultCurrency
Address review feedback on oss-apps#647: prefer the user's last-used currency (User.currency) before falling back to the group default and the user's defaultCurrency setting. Also drop the currency override in resetState so that resetting the form keeps the last-used currency. Preference chain when initializing the add-expense page: 1. currentUser.currency (last used) 2. group.defaultCurrency (when in a group context) 3. currentUser.defaultCurrency Disclaimer: parts of this change were drafted with the help of Claude Opus 4.7.
phof
added a commit
to phof/split-pro
that referenced
this pull request
May 17, 2026
Address review feedback on oss-apps#647: prefer the user's last-used currency (User.currency) before falling back to the group default and the user's defaultCurrency setting. Also drop the currency override in resetState so that resetting the form keeps the last-used currency. Preference chain when initializing the add-expense page: 1. currentUser.currency (last used) 2. group.defaultCurrency (when in a group context) 3. currentUser.defaultCurrency Disclaimer: parts of this change were drafted with the help of Claude Opus 4.7.
When picking a currency, also update currentUser.currency in the add-expense store so the preference chain on the next /add mount sees the just-picked value without waiting for the async next-auth session update to settle. On mount, the AddPage effect also preserves the stored currency for the same user id instead of overwriting it with potentially stale session data. Disclaimer: parts of this change were drafted with the help of Claude Opus 4.7.
Replace the previous remount-time currency preservation with a simpler fix: in the expense submit handler, await the next-auth session update (which writes the just-picked currency back into the session) BEFORE navigating away. This guarantees that any subsequent /add mount reads the up-to-date currentUser.currency without local-store overrides. Reverts the in-store overwrite from 49b9778 so currentUser in the add-expense store keeps mirroring the session user as-is. Disclaimer: parts of this change were drafted with the help of Claude Opus 4.7.
Contributor
Author
|
@krokosik Thank you, see if the latest changes make sense now |
krokosik
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #631.
The expense form always defaulted to USD regardless of the user's or group's configured default currency. The defaults were fetched from the backend but never applied to the form's currency field.
Changes
src/pages/add.tsx:Test plan
Disclaimer
Parts of this change were drafted with the help of Claude Opus 4.7.