Skip to content

Commit

Permalink
Merge branch 'master' into zach/simplefin
Browse files Browse the repository at this point in the history
  • Loading branch information
zachwhelchel authored Jan 12, 2024
2 parents 8e49971 + e205344 commit 3cca410
Show file tree
Hide file tree
Showing 995 changed files with 150 additions and 305,227 deletions.
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@ packages/import-ynab5/**/node_modules/*
packages/loot-core/**/node_modules/*
packages/loot-core/**/lib-dist/*
packages/loot-core/**/proto/*

packages/node-libofx/libofx.*.js
packages/node-libofx/libofx/
packages/node-libofx/OpenSP-*/
2 changes: 1 addition & 1 deletion packages/crdt/src/crdt/merkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function diff(trie1: TrieNode, trie2: TrieNode): number | null {
const keys = [...keyset.values()];
keys.sort();

let diffkey = null;
let diffkey: null | '0' | '1' | '2' = null;

// Traverse down the trie through keys that aren't the same. We
// traverse down the keys in order. Stop in two cases: either one
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -743,20 +743,13 @@ export function ImportTransactions({ modalProps, options }) {

const [clearOnImport, setClearOnImport] = useState(true);

const enableExperimentalOfxParser = useFeatureFlag('experimentalOfxParser');

async function parse(filename, options) {
setLoadingState('parsing');

const filetype = getFileType(filename);
setFilename(filename);
setFileType(filetype);

options = {
...options,
enableExperimentalOfxParser,
};

const { errors, transactions } = await parseTransactions(filename, options);
setLoadingState(null);
setError(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ export function ExperimentalFeatures() {
<FeatureToggle flag="goalTemplatesEnabled">
Goal templates
</FeatureToggle>

<FeatureToggle flag="experimentalOfxParser">
Experimental OFX parser
</FeatureToggle>
<FeatureToggle flag="simpleFinSync">SimpleFIN sync</FeatureToggle>
</View>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function Footer({
onSplit,
onAddSplit,
onEmptySplitFound,
editingField,
}) {
const [transaction, ...childTransactions] = transactions;
const onClickRemainingSplit = () => {
Expand Down Expand Up @@ -217,6 +218,7 @@ function Footer({
<Button
type="primary"
style={{ height: 40 }}
disabled={editingField}
onClick={onClickRemainingSplit}
onPointerDown={e => e.preventDefault()}
>
Expand All @@ -237,19 +239,16 @@ function Footer({
</Button>
) : adding ? (
<Button
type="primary"
style={{ height: 40 }}
disabled={editingField}
onClick={onAdd}
onPointerDown={e => e.preventDefault()}
>
<SvgAdd
width={17}
height={17}
style={{ color: theme.formLabelText }}
/>
<SvgAdd width={17} height={17} />
<Text
style={{
...styles.text,
color: theme.formLabelText,
marginLeft: 5,
}}
>
Expand All @@ -258,22 +257,17 @@ function Footer({
</Button>
) : (
<Button
type="primary"
style={{ height: 40 }}
disabled={editingField}
onClick={onSave}
onPointerDown={e => e.preventDefault()}
>
<SvgPencilWriteAlternate
width={16}
height={16}
style={{
color: theme.formLabelText,
}}
/>
<SvgPencilWriteAlternate width={16} height={16} />
<Text
style={{
...styles.text,
marginLeft: 6,
color: theme.formLabelText,
}}
>
Save changes
Expand Down Expand Up @@ -678,6 +672,7 @@ const TransactionEditInner = memo(function TransactionEditInner({
onSplit={onSplit}
onAddSplit={onAddSplit}
onEmptySplitFound={onEmptySplitFound}
editingField={editingField}
/>
}
padding={0}
Expand Down
1 change: 0 additions & 1 deletion packages/desktop-client/src/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const DEFAULT_FEATURE_FLAG_STATE: Record<FeatureFlag, boolean> = {
reportBudget: false,
goalTemplatesEnabled: false,
customReports: false,
experimentalOfxParser: true,
simpleFinSync: false,
};

Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"!**/*.js.map",
"!node_modules/@jlongster/sql.js",
"!node_modules/absurd-sql",
"!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}",
"!node_modules/node-libofx/{OpenSP-1.5.2,libofx,libofx.web.js,libofx.web.wasm,emscripten.cpp,Makefile}"
"!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}"
],
"publish": {
"provider": "github",
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/bin/build-browser
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ if [ $NODE_ENV == 'development' ]; then
fi

cp ../../../node_modules/@jlongster/sql.js/dist/sql-wasm.wasm "$PUBLIC_DIR"/sql-wasm.wasm
cp ../../node-libofx/libofx.web.wasm "$PUBLIC_DIR"/libofx.web.wasm

yarn webpack --config ../webpack/webpack.browser.config.js \
--target "webworker" \
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"md5": "^2.3.0",
"mitt": "^3.0.0",
"node-fetch": "^2.6.9",
"node-libofx": "*",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"reselect": "^4.1.8",
Expand Down
3 changes: 2 additions & 1 deletion packages/loot-core/src/client/actions/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import throttle from 'throttleit';

import { send } from '../../platform/client/fetch';
import { type AccountEntity } from '../../types/models';
import * as constants from '../constants';

import { pushModal } from './modals';
Expand Down Expand Up @@ -260,7 +261,7 @@ export function getAccounts() {
};
}

export function updateAccount(account) {
export function updateAccount(account: AccountEntity) {
return async (dispatch: Dispatch) => {
dispatch({ type: constants.UPDATE_ACCOUNT, account });
await send('account-update', account);
Expand Down
33 changes: 19 additions & 14 deletions packages/loot-core/src/client/reducers/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import memoizeOne from 'memoize-one';

import { groupById } from '../../shared/util';
import { type AccountEntity, type PayeeEntity } from '../../types/models';
import * as constants from '../constants';
import type { Action } from '../state-types';
import type { QueriesState } from '../state-types/queries';
Expand Down Expand Up @@ -59,9 +60,7 @@ export function update(state = initialState, action: Action): QueriesState {
return {
...state,
accounts: state.accounts.map(account => {
// @ts-expect-error Not typed yet
if (account.id === action.account.id) {
// @ts-expect-error Not typed yet
return { ...account, ...action.account };
}
return account;
Expand All @@ -83,8 +82,12 @@ export function update(state = initialState, action: Action): QueriesState {
return state;
}

export const getAccountsById = memoizeOne(accounts => groupById(accounts));
export const getPayeesById = memoizeOne(payees => groupById(payees));
export const getAccountsById = memoizeOne((accounts: AccountEntity[]) =>
groupById(accounts),
);
export const getPayeesById = memoizeOne((payees: PayeeEntity[]) =>
groupById(payees),
);
export const getCategoriesById = memoizeOne(categoryGroups => {
const res = {};
categoryGroups.forEach(group => {
Expand All @@ -95,14 +98,16 @@ export const getCategoriesById = memoizeOne(categoryGroups => {
return res;
});

export const getActivePayees = memoizeOne((payees, accounts) => {
const accountsById = getAccountsById(accounts);
export const getActivePayees = memoizeOne(
(payees: PayeeEntity[], accounts: AccountEntity[]) => {
const accountsById = getAccountsById(accounts);

return payees.filter(payee => {
if (payee.transfer_acct) {
const account = accountsById[payee.transfer_acct];
return account != null && !account.closed;
}
return true;
});
});
return payees.filter(payee => {
if (payee.transfer_acct) {
const account = accountsById[payee.transfer_acct];
return account != null && !account.closed;
}
return true;
});
},
);
3 changes: 2 additions & 1 deletion packages/loot-core/src/client/state-types/queries.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Handlers } from '../../types/handlers';
import { type AccountEntity } from '../../types/models';
import type * as constants from '../constants';

export type QueriesState = {
Expand Down Expand Up @@ -41,7 +42,7 @@ type LoadAccountsAction = {

type UpdateAccountAction = {
type: typeof constants.UPDATE_ACCOUNT;
account: unknown;
account: AccountEntity;
};

type LoadCategoriesAction = {
Expand Down
4 changes: 2 additions & 2 deletions packages/loot-core/src/mocks/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { q } from '../shared/query';
import type { Handlers } from '../types/handlers';
import type {
CategoryGroupEntity,
PayeeEntity,
NewPayeeEntity,
NewTransactionEntity,
} from '../types/models';

import { random } from './random';

type MockPayeeEntity = PayeeEntity & { bill?: boolean };
type MockPayeeEntity = NewPayeeEntity & { bill?: boolean };

function pickRandom<T>(list: T[]): T {
return list[Math.floor(random() * list.length) % list.length];
Expand Down
3 changes: 0 additions & 3 deletions packages/loot-core/src/server/accounts/parse-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async function importFileWithRealTime(
global.restoreDateNow();
const { errors, transactions: originalTransactions } = await parseFile(
filepath,
{
enableExperimentalOfxParser: true,
},
);
global.restoreFakeDateNow();

Expand Down
52 changes: 3 additions & 49 deletions packages/loot-core/src/server/accounts/parse-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import csv2json from 'csv-parse/lib/sync';

import * as fs from '../../platform/server/fs';
import { dayFromDate } from '../../shared/months';
import { looselyParseAmount } from '../../shared/util';

import { ofx2json } from './ofx2json';
Expand All @@ -17,12 +16,11 @@ type ParseFileOptions = {
hasHeaderRow?: boolean;
delimiter?: string;
fallbackMissingPayeeToMemo?: boolean;
enableExperimentalOfxParser?: boolean;
};

export async function parseFile(
filepath: string,
options?: ParseFileOptions,
options: ParseFileOptions = {},
): Promise<ParseFileResult> {
const errors = Array<ParseError>();
const m = filepath.match(/\.[^.]*$/);
Expand Down Expand Up @@ -52,7 +50,7 @@ export async function parseFile(

async function parseCSV(
filepath: string,
options?: ParseFileOptions,
options: ParseFileOptions,
): Promise<ParseFileResult> {
const errors = Array<ParseError>();
const contents = await fs.readFile(filepath);
Expand Down Expand Up @@ -109,12 +107,8 @@ async function parseQIF(filepath: string): Promise<ParseFileResult> {

async function parseOFX(
filepath: string,
options?: ParseFileOptions,
options: ParseFileOptions,
): Promise<ParseFileResult> {
if (!options?.enableExperimentalOfxParser) {
return parseOFXNodeLibOFX(filepath, options);
}

const errors = Array<ParseError>();
const contents = await fs.readFile(filepath);

Expand Down Expand Up @@ -147,43 +141,3 @@ async function parseOFX(
}),
};
}

async function parseOFXNodeLibOFX(
filepath: string,
options: ParseFileOptions,
): Promise<ParseFileResult> {
const { getOFXTransactions, initModule } = await import(
/* webpackChunkName: 'xfo' */ 'node-libofx'
);
await initModule();

const errors = Array<ParseError>();
const contents = await fs.readFile(filepath, 'binary');

let data;
try {
data = getOFXTransactions(contents);
} catch (err) {
errors.push({
message: 'Failed importing file',
internal: err.stack,
});
return { errors };
}

// Banks don't always implement the OFX standard properly
// If no payee is available try and fallback to memo
const useMemoFallback = options.fallbackMissingPayeeToMemo;

return {
errors,
transactions: data.map(trans => ({
amount: trans.amount,
imported_id: trans.fi_id,
date: trans.date ? dayFromDate(new Date(trans.date * 1000)) : null,
payee_name: trans.name || (useMemoFallback ? trans.memo : null),
imported_payee: trans.name || (useMemoFallback ? trans.memo : null),
notes: !!trans.name || !useMemoFallback ? trans.memo || null : null, //memo used for payee
})),
};
}
11 changes: 8 additions & 3 deletions packages/loot-core/src/server/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { v4 as uuidv4 } from 'uuid';
import * as fs from '../../platform/server/fs';
import * as sqlite from '../../platform/server/sqlite';
import { groupById } from '../../shared/util';
import { CategoryEntity, CategoryGroupEntity } from '../../types/models';
import {
CategoryEntity,
CategoryGroupEntity,
PayeeEntity,
} from '../../types/models';
import {
schema,
schemaConfig,
Expand Down Expand Up @@ -478,9 +482,10 @@ export function updatePayee(payee) {
return update('payees', payee);
}

export async function mergePayees(target, ids) {
export async function mergePayees(target: string, ids: string[]) {
// Load in payees so we can check some stuff
const payees = groupById(await all('SELECT * FROM payees'));
const dbPayees: PayeeEntity[] = await all('SELECT * FROM payees');
const payees = groupById(dbPayees);

// Filter out any transfer payees
if (payees[target].transfer_acct != null) {
Expand Down
Loading

0 comments on commit 3cca410

Please sign in to comment.