Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add more concrete types to loot-core #1186

Merged
merged 25 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ReactNode, useState } from 'react';
import { useSelector } from 'react-redux';

import type { FeatureFlag } from 'loot-core/src/client/state-types/prefs';
import type { FeatureFlag } from 'loot-core/src/types/prefs';

import { useActions } from '../../hooks/useActions';
import useFeatureFlag from '../../hooks/useFeatureFlag';
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from 'react-redux';

import { type FeatureFlag } from 'loot-core/src/client/state-types/prefs';
import type { FeatureFlag } from 'loot-core/src/types/prefs';

const DEFAULT_FEATURE_FLAG_STATE: Record<FeatureFlag, boolean> = {
reportBudget: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/style/theme.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSelector } from 'react-redux';

import type { Theme } from 'loot-core/src/client/state-types/prefs';
import type { Theme } from 'loot-core/src/types/prefs';

import * as darkTheme from './themes/dark';
import * as lightTheme from './themes/light';
Expand Down
60 changes: 3 additions & 57 deletions packages/loot-core/src/client/state-types/prefs.d.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,6 @@
import { type numberFormats } from '../../shared/util';
import type { LocalPrefs, GlobalPrefs } from '../../types/prefs';
import type * as constants from '../constants';

export type FeatureFlag =
| 'reportBudget'
| 'goalTemplatesEnabled'
| 'privacyMode'
| 'themes';

type NullableValues<T> = { [K in keyof T]: T[K] | null };

export type LocalPrefs = NullableValues<
{
firstDayOfWeekIdx: `${0 | 1 | 2 | 3 | 4 | 5 | 6}`;
dateFormat: string;
numberFormat: (typeof numberFormats)[number]['value'];
hideFraction: boolean;
hideClosedAccounts: boolean;
hideMobileMessage: boolean;
isPrivacyEnabled: boolean;
budgetName: string;
'ui.showClosedAccounts': boolean;
'expand-splits': boolean;
[key: `show-extra-balances-${string}`]: boolean;
[key: `hide-cleared-${string}`]: boolean;
'budget.collapsed': boolean;
'budget.summaryCollapsed': boolean;
'budget.showHiddenCategories': boolean;
// TODO: pull from src/components/modals/ImportTransactions.js
[key: `parse-date-${string}-${'csv' | 'qif'}`]: string;
[key: `csv-mappings-${string}`]: string;
[key: `csv-delimiter-${string}`]: ',' | ';' | '\t';
[key: `csv-has-header-${string}`]: boolean;
[key: `flip-amount-${string}-${'csv' | 'qif'}`]: boolean;
'flags.updateNotificationShownForVersion': string;
id: string;
isCached: boolean;
lastUploaded: string;
cloudFileId: string;
groupId: string;
budgetType: 'report' | 'rollover';
encryptKeyId: string;
lastSyncedTimestamp: string;
userId: string;
resetClock: boolean;
lastScheduleRun: string;
} & Record<`flags.${FeatureFlag}`, boolean>
>;

export type Theme = 'light' | 'dark';
export type GlobalPrefs = NullableValues<{
floatingSidebar: boolean;
maxMonths: number;
theme: Theme;
documentDir: string; // Electron only
}>;

export type PrefsState = {
local: LocalPrefs | null;
global: GlobalPrefs | null;
Expand All @@ -68,12 +14,12 @@ export type SetPrefsAction = {

export type MergeLocalPrefsAction = {
type: typeof constants.MERGE_LOCAL_PREFS;
prefs: Partial<LocalPrefs>;
prefs: LocalPrefs;
};

export type MergeGlobalPrefsAction = {
type: typeof constants.MERGE_GLOBAL_PREFS;
globalPrefs: Partial<GlobalPrefs>;
globalPrefs: GlobalPrefs;
};

export type PrefsActions =
Expand Down
11 changes: 7 additions & 4 deletions packages/loot-core/src/mocks/budget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ async function createBudget(accounts, payees, groups) {
}

function setBudgetIfSpent(month, cat) {
let spent = sheet.getCellValue(
let spent: number = sheet.getCellValue(
j-f1 marked this conversation as resolved.
Show resolved Hide resolved
monthUtils.sheetForMonth(month),
`sum-amount-${cat.id}`,
);
) as number;

if (spent < 0) {
setBudget(month, cat, -spent);
Expand Down Expand Up @@ -514,7 +514,10 @@ async function createBudget(accounts, payees, groups) {
month <= monthUtils.currentMonth()
) {
let sheetName = monthUtils.sheetForMonth(month);
let toBudget = sheet.getCellValue(sheetName, 'to-budget');
let toBudget: number = sheet.getCellValue(
sheetName,
'to-budget',
) as number;
let available = toBudget - prevSaved;

if (available - 403000 > 0) {
Expand All @@ -533,7 +536,7 @@ async function createBudget(accounts, payees, groups) {
await sheet.waitOnSpreadsheet();

let sheetName = monthUtils.sheetForMonth(monthUtils.currentMonth());
let toBudget = sheet.getCellValue(sheetName, 'to-budget');
let toBudget: number = sheet.getCellValue(sheetName, 'to-budget') as number;
j-f1 marked this conversation as resolved.
Show resolved Hide resolved
if (toBudget < 0) {
await addTransactions(primaryAccount.id, [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/accounts/parse-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function parseOFX(filepath): Promise<ParseFileResult> {
transactions: data.map(trans => ({
amount: trans.amount,
imported_id: trans.fi_id,
date: trans.date ? dayFromDate(trans.date * 1000) : null,
date: trans.date ? dayFromDate(new Date(trans.date * 1000)) : null,
payee_name: useName ? trans.name : trans.memo,
imported_payee: useName ? trans.name : trans.memo,
notes: useName ? trans.memo || null : null, //memo used for payee
Expand Down
20 changes: 10 additions & 10 deletions packages/loot-core/src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ handlers['api/budget-month'] = async function ({ month }) {
// different (for now)
return {
month,
incomeAvailable: value('available-funds'),
lastMonthOverspent: value('last-month-overspent'),
forNextMonth: value('buffered'),
totalBudgeted: value('total-budgeted'),
toBudget: value('to-budget'),

fromLastMonth: value('from-last-month'),
totalIncome: value('total-income'),
totalSpent: value('total-spent'),
totalBalance: value('total-leftover'),
incomeAvailable: value('available-funds') as number,
lastMonthOverspent: value('last-month-overspent') as number,
forNextMonth: value('buffered') as number,
totalBudgeted: value('total-budgeted') as number,
toBudget: value('to-budget') as number,

fromLastMonth: value('from-last-month') as number,
totalIncome: value('total-income') as number,
totalSpent: value('total-spent') as number,
totalBalance: value('total-leftover') as number,

categoryGroups: groups.map(group => {
if (group.is_income) {
Expand Down
Loading
Loading