Skip to content

Commit

Permalink
Merge branch 'master' into reload-app
Browse files Browse the repository at this point in the history
  • Loading branch information
TimQuelch authored Aug 28, 2024
2 parents 03dfd2c + d9adb75 commit 51a9b8b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/desktop-client/src/components/accounts/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1113,10 +1113,10 @@ class AccountInternal extends PureComponent {
);
};

onConditionsOpChange = (value, conditions) => {
onConditionsOpChange = value => {
this.setState({ filterConditionsOp: value });
this.setState({ filterId: { ...this.state.filterId, status: 'changed' } });
this.applyFilters([...conditions]);
this.applyFilters([...this.state.filterConditions]);
if (this.state.search !== '') {
this.onSearch(this.state.search);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function FiltersStack({
onReloadSavedFilter: (savedFilter: SavedFilter, value?: string) => void;
filterId: SavedFilter;
savedFilters: TransactionFilterEntity[];
onConditionsOpChange: () => void;
onConditionsOpChange: (value: 'and' | 'or') => void;
}) {
return (
<View>
Expand Down
12 changes: 8 additions & 4 deletions packages/desktop-client/src/components/modals/EditRule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function FieldSelect({ fields, style, value, onChange }) {
bare
options={fields}
value={value}
onChange={value => onChange('field', value)}
onChange={onChange}
buttonStyle={{ color: theme.pageTextPositive }}
/>
</View>
Expand Down Expand Up @@ -260,7 +260,11 @@ function ConditionEditor({

return (
<Editor style={editorStyle} error={error}>
<FieldSelect fields={conditionFields} value={field} onChange={onChange} />
<FieldSelect
fields={conditionFields}
value={field}
onChange={value => onChange('field', value)}
/>
<OpSelect ops={ops} value={op} type={type} onChange={onChange} />

<View style={{ flex: 1 }}>{valueEditor}</View>
Expand Down Expand Up @@ -373,7 +377,7 @@ function ActionEditor({ action, editorStyle, onChange, onDelete, onAdd }) {
<FieldSelect
fields={options?.splitIndex ? splitActionFields : actionFields}
value={field}
onChange={onChange}
onChange={value => onChange('field', value)}
/>

<View style={{ flex: 1 }}>
Expand Down Expand Up @@ -838,7 +842,7 @@ export function EditRule({ defaultRule, onSave: originalOnSave }) {
setStage(stage);
}

function onChangeConditionsOp(name, value) {
function onChangeConditionsOp(value) {
setConditionsOp(value);
}

Expand Down
45 changes: 25 additions & 20 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ function getAccountBalance(account) {
}
}

async function updateAccountBalance(id, balance) {
await db.runQuery('UPDATE accounts SET balance_current = ? WHERE id = ?', [
amountToInteger(balance),
id,
]);
}

export async function getGoCardlessAccounts(userId, userKey, id) {
const userToken = await asyncStorage.getItem('user-token');
if (!userToken) return;
Expand Down Expand Up @@ -92,6 +85,7 @@ async function downloadGoCardlessTransactions(
acctId,
bankId,
since,
includeBalance = true,
) {
const userToken = await asyncStorage.getItem('user-token');
if (!userToken) return;
Expand All @@ -106,6 +100,7 @@ async function downloadGoCardlessTransactions(
requisitionId: bankId,
accountId: acctId,
startDate: since,
includeBalance,
},
{
'X-ACTUAL-TOKEN': userToken,
Expand All @@ -116,19 +111,27 @@ async function downloadGoCardlessTransactions(
throw BankSyncError(res.error_type, res.error_code);
}

const {
transactions: { all },
balances,
startingBalance,
} = res;
if (includeBalance) {
const {
transactions: { all },
balances,
startingBalance,
} = res;

console.log('Response:', res);
console.log('Response:', res);

return {
transactions: all,
accountBalance: balances,
startingBalance,
};
return {
transactions: all,
accountBalance: balances,
startingBalance,
};
} else {
console.log('Response:', res);

return {
transactions: res.transactions.all,
};
}
}

async function downloadSimpleFinTransactions(acctId, since) {
Expand Down Expand Up @@ -683,14 +686,15 @@ export async function syncAccount(
acctId,
bankId,
startDate,
false,
);
} else {
throw new Error(
`Unrecognized bank-sync provider: ${acctRow.account_sync_source}`,
);
}

const { transactions: originalTransactions, accountBalance } = download;
const { transactions: originalTransactions } = download;

if (originalTransactions.length === 0) {
return { added: [], updated: [] };
Expand All @@ -708,7 +712,7 @@ export async function syncAccount(
true,
useStrictIdChecking,
);
await updateAccountBalance(id, accountBalance);

return result;
});
} else {
Expand All @@ -726,6 +730,7 @@ export async function syncAccount(
acctId,
bankId,
startingDay,
true,
);
}

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3278.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [lelemm]
---

Filter fix when alternating all <-> any
6 changes: 6 additions & 0 deletions upcoming-release-notes/3279.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [matt-fidd]
---

Optimise GoCardless sync to reduce API usage by removing balance information when unneeded

0 comments on commit 51a9b8b

Please sign in to comment.