Skip to content

Commit

Permalink
Strip even more Plaid code
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis committed Apr 3, 2024
1 parent d0f0b92 commit 7095f1c
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 139 deletions.
20 changes: 0 additions & 20 deletions packages/loot-core/src/client/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,6 @@ export function linkAccountSimpleFin(externalAccount, upgradingId) {
};
}

// TODO: type correctly or remove (unused)
export function connectAccounts(
institution,
publicToken,
accountIds,
offbudgetIds,
) {
return async (dispatch: Dispatch) => {
const ids = await send('accounts-connect', {
institution,
publicToken,
accountIds,
offbudgetIds,
});
await dispatch(getPayees());
await dispatch(getAccounts());
return ids;
};
}

export function syncAccounts(id?: string) {
return async (dispatch: Dispatch, getState: GetState) => {
// Disallow two parallel sync operations
Expand Down
42 changes: 0 additions & 42 deletions packages/loot-core/src/server/accounts/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,6 @@ export async function findOrCreateBank(institution, requisitionId) {
return bankData;
}

export async function addAccounts(bankId, accountIds, offbudgetIds = []) {
const [[, userId], [, userKey]] = await asyncStorage.multiGet([
'user-id',
'user-key',
]);

// Get all the available accounts
let accounts = await bankSync.getAccounts(userId, userKey, bankId);

// Only add the selected accounts
accounts = accounts.filter(acct => accountIds.includes(acct.account_id));

return Promise.all(
accounts.map(async acct => {
const id = await runMutator(async () => {
const id = await db.insertAccount({
account_id: acct.account_id,
name: acct.name,
official_name: acct.official_name,
balance_current: amountToInteger(acct.balances.current),
mask: acct.mask,
bank: bankId,
offbudget: offbudgetIds.includes(acct.account_id) ? 1 : 0,
});

// Create a transfer payee
await db.insertPayee({
name: '',
transfer_acct: id,
});

return id;
});

// Do an initial sync
await bankSync.syncAccount(userId, userKey, id, acct.account_id, bankId);

return id;
}),
);
}

export async function addGoCardlessAccounts(
bankId,
accountIds,
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ export async function syncAccount(
);
}

const transactions = download.transactions;
const { transactions } = download;
let balanceToUse = download.startingBalance;

if (acctRow.account_sync_source === 'simpleFin') {
Expand Down
58 changes: 0 additions & 58 deletions packages/loot-core/src/server/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
disableGlobalMutations,
enableGlobalMutations,
} from './mutators';
import { post } from './post';
import * as prefs from './prefs';
import * as sheet from './sheet';

Expand Down Expand Up @@ -103,63 +102,6 @@ describe('Budgets', () => {
});

describe('Accounts', () => {
test('create accounts with correct starting balance', async () => {
prefs.loadPrefs();
prefs.savePrefs({ groupId: 'group' });

await runMutator(async () => {
// An income category is required because the starting balance is
// categorized to it. Create one now.
await db.insertCategoryGroup({
id: 'group1',
name: 'income',
is_income: 1,
});
await db.insertCategory({
name: 'income',
cat_group: 'group1',
is_income: 1,
});
});

// Get accounts from the server. This isn't the normal API call,
// we know that the mock server just returns hardcoded accounts
const { accounts } = await post('/plaid/accounts', {});

// Create the accounts for the bank (bank is generally ignored in tests)
await runHandler(handlers['accounts-connect'], {
institution: { institution_id: 1, name: 'Jamesy Bank' },
publicToken: 'foo',
accountIds: accounts.map(acct => acct.account_id),
});

// Import transactions for all accounts
await runHandler(handlers['accounts-sync'], {});

// Go through each account and make sure the starting balance was
// created correctly
const res = await db.all('SELECT * FROM accounts');
for (const account of res) {
const sum = await db.first(
'SELECT sum(amount) as sum FROM transactions WHERE acct = ? AND starting_balance_flag = 0',
[account.id],
);
const starting = await db.first(
'SELECT * FROM transactions WHERE acct = ? AND starting_balance_flag = 1',
[account.id],
);
expect(account.balance_current - sum.sum).toBe(starting.amount);

// Also ensure that the starting balance has the earliest date
// possible
const earliestTrans = await db.first(
'SELECT p.name as payee_name FROM transactions t LEFT JOIN payees p ON p.id = t.description WHERE acct = ? ORDER BY date LIMIT 1',
[account.id],
);
expect(earliestTrans.payee_name).toBe('Starting Balance');
}
});

test('Transfers are properly updated', async () => {
await runMutator(async () => {
await db.insertAccount({ id: 'one', name: 'one' });
Expand Down
11 changes: 0 additions & 11 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,17 +720,6 @@ handlers['simplefin-accounts-link'] = async function ({
return 'ok';
};

handlers['accounts-connect'] = async function ({
institution,
publicToken,
accountIds,
offbudgetIds,
}) {
const bankId = await link.handoffPublicToken(institution, publicToken);
const ids = await link.addAccounts(bankId, accountIds, offbudgetIds);
return ids;
};

handlers['gocardless-accounts-connect'] = async function ({
institution,
publicToken,
Expand Down
7 changes: 0 additions & 7 deletions packages/loot-core/src/types/server-handlers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ export interface ServerHandlers {
upgradingId;
}) => Promise<'ok'>;

'accounts-connect': (arg: {
institution;
publicToken;
accountIds;
offbudgetIds?;
}) => Promise<unknown>;

'gocardless-accounts-connect': (arg: {
institution;
publicToken;
Expand Down

0 comments on commit 7095f1c

Please sign in to comment.