Skip to content

Commit

Permalink
fix: consider income in recent envelopes (#1739)
Browse files Browse the repository at this point in the history
  • Loading branch information
morremeyer authored Aug 4, 2024
1 parent dccdbbd commit 2e6e472
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/components/TransactionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,19 @@ const TransactionForm = ({ budget, setNotification }: Props) => {
// Fetch the recent envelopes and suggest the first one
// as the Envelope to use for this transaction
envelopePromises.push(
get(account.links.recentEnvelopes).then(data => {
setRecentEnvelopes(data)
if (data.length) {
valuesToUpdate.envelopeId = data[0].id
get(account.links.recentEnvelopes).then(
(data: RecentEnvelope[]) => {
// We use the first envelope in recent envelopes as suggestion
// if its ID is not null. If its ID is null, income is the most
// common "envelope" for this account, so we don't set it.
if (data.length && data[0].id !== null) {
valuesToUpdate.envelopeId = data[0].id
}

// Remove income from the recent envelopes
setRecentEnvelopes(data.filter(e => e.id !== null))
}
})
)
)
} else if (!account.external) {
setRecentEnvelopes([])
Expand Down
2 changes: 1 addition & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ export type QuickAllocationMode =

export type RecentEnvelope = {
name: string
id: UUID
id: UUID | null
}

0 comments on commit 2e6e472

Please sign in to comment.