Skip to content

Commit

Permalink
Flesh out Account typing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-f1 committed Jul 17, 2023
1 parent 4da9952 commit 4f8f306
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useSelector } from 'react-redux';
import { send } from 'loot-core/src/platform/client/fetch';

import { useActions } from '../hooks/useActions';
import useFeatureFlag from '../hooks/useFeatureFlag';
import useSyncServerStatus from '../hooks/useSyncServerStatus';

import BudgetSummary from './modals/BudgetSummary';
Expand All @@ -26,6 +25,7 @@ import PlaidExternalMsg from './modals/PlaidExternalMsg';
import SelectLinkedAccounts from './modals/SelectLinkedAccounts';

export default function Modals() {
useSelector(state => console.log(state));
const modalStack = useSelector(state => state.modals.modalStack);
const isHidden = useSelector(state => state.modals.isHidden);
const accounts = useSelector(state => state.queries.accounts);
Expand All @@ -34,7 +34,6 @@ export default function Modals() {
const budgetId = useSelector(
state => state.prefs.local && state.prefs.local.id,
);
const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
const actions = useActions();

const syncServerStatus = useSyncServerStatus();
Expand Down
4 changes: 2 additions & 2 deletions packages/loot-core/src/client/state-types/queries.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type QueriesState = {
matchedTransactions: unknown[];
lastTransaction: unknown | null;
updatedAccounts: string[];
accounts: unknown[];
accounts: AccountEntity[];
categories: Awaited<ReturnType<Handlers['get-categories']>>;
payees: unknown[];
earliestTransaction: unknown | null;
Expand Down Expand Up @@ -36,7 +36,7 @@ type MarkAccountReadAction = {

type LoadAccountsAction = {
type: typeof constants.LOAD_ACCOUNTS;
accounts: unknown[];
accounts: AccountEntity[];
};

type UpdateAccountAction = {
Expand Down
3 changes: 1 addition & 2 deletions packages/loot-core/src/mocks/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { batchMessages, setSyncingMode } from '../server/sync';
import * as monthUtils from '../shared/months';
import q from '../shared/query';
import type {
AccountEntity,
CategoryGroupEntity,
PayeeEntity,
TransactionEntity,
Expand Down Expand Up @@ -563,7 +562,7 @@ export async function createTestBudget(handlers) {
await db.runQuery('DELETE FROM categories;');
await db.runQuery('DELETE FROM category_groups');

let accounts: AccountEntity[] = [
let accounts: { name: string; offBudget?: 1; id?: string }[] = [
{ name: 'Bank of America' },
{ name: 'Ally Savings' },
{ name: 'Capital One Checking' },
Expand Down
27 changes: 18 additions & 9 deletions packages/loot-core/src/types/models/account.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
export interface AccountEntity {
id?: string;
export type AccountEntity = {
id: string;
name: string;
offbudget?: boolean;
closed?: boolean;
sort_order?: number;
tombstone?: boolean;
// TODO: remove once properly typed
[k: string]: unknown;
}
offbudget: 0 | 1;
closed: 0 | 1;
sort_order: number;
tombstone: 0 | 1;
subtype: string | null; // TODO: remove?
} & (_SyncFields<true> | _SyncFields<false>);

type _SyncFields<T> = {
account_id: T extends true ? string : null;
bank: T extends true ? string : null;
mask: T extends true ? string : null; // end of bank account number
official_name: T extends true ? string : null;
balance_current: T extends true ? number : null;
balance_available: T extends true ? number : null;
balance_limit: T extends true ? number : null;
};
11 changes: 6 additions & 5 deletions packages/loot-core/src/types/server-handlers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { batchUpdateTransactions } from '../server/accounts/transactions';
import { Backup } from '../server/backups';
import { RemoteFile } from '../server/cloud-storage';
import { Message } from '../server/sync';
import { AccountEntity } from './models';

import { EmptyObject } from './util';

Expand Down Expand Up @@ -134,7 +135,7 @@ export interface ServerHandlers {

'account-update': (arg: { id; name }) => Promise<unknown>;

'accounts-get': () => Promise<unknown>;
'accounts-get': () => Promise<AccountEntity[]>;

'account-properties': (arg: {
id;
Expand Down Expand Up @@ -168,10 +169,10 @@ export interface ServerHandlers {
}) => Promise<unknown>;

'account-create': (arg: {
name;
balance;
offBudget;
closed?;
name: string;
balance: number;
offBudget?: boolean;
closed?: 0 | 1;
}) => Promise<string>;

'account-close': (arg: {
Expand Down

0 comments on commit 4f8f306

Please sign in to comment.