Skip to content

Commit

Permalink
Added a default to migration, made variables consistent, added featur…
Browse files Browse the repository at this point in the history
…e flag.
  • Loading branch information
zachwhelchel committed Jan 12, 2024
1 parent 853b0db commit 8e49971
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 50 deletions.
57 changes: 32 additions & 25 deletions packages/desktop-client/src/components/modals/CreateAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { send } from 'loot-core/src/platform/client/fetch';

import { authorizeBank } from '../../gocardless';
import { useActions } from '../../hooks/useActions';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useGoCardlessStatus } from '../../hooks/useGoCardlessStatus';
import { useSimpleFinStatus } from '../../hooks/useSimpleFinStatus';
import { type SyncServerStatus } from '../../hooks/useSyncServerStatus';
Expand Down Expand Up @@ -124,6 +125,8 @@ export function CreateAccount({
title = 'Link Account';
}

const simpleFinSyncFeatureFlag = useFeatureFlag('simpleFinSync');

return (
<Modal title={title} {...modalProps}>
{() => (
Expand Down Expand Up @@ -180,29 +183,33 @@ export function CreateAccount({
to automatically download transactions. GoCardless provides
reliable, up-to-date information from hundreds of banks.
</Text>
<ButtonWithLoading
disabled={syncServerStatus !== 'online'}
loading={loadingSimpleFinAccounts}
style={{
marginTop: '18px',
padding: '10px 0',
fontSize: 15,
fontWeight: 600,
flex: 1,
}}
onClick={onConnectSimpleFin}
>
{isSimpleFinSetupComplete
? 'Link bank account with SimpleFIN'
: 'Set up SimpleFIN for bank sync'}
</ButtonWithLoading>
<Text style={{ lineHeight: '1.4em', fontSize: 15 }}>
<strong>
Link a <u>North American</u> bank account
</strong>{' '}
to automatically download transactions. SimpleFIN provides
reliable, up-to-date information from hundreds of banks.
</Text>
{simpleFinSyncFeatureFlag === true && (
<>
<ButtonWithLoading
disabled={syncServerStatus !== 'online'}
loading={loadingSimpleFinAccounts}
style={{
marginTop: '18px',
padding: '10px 0',
fontSize: 15,
fontWeight: 600,
flex: 1,
}}
onClick={onConnectSimpleFin}
>
{isSimpleFinSetupComplete
? 'Link bank account with SimpleFIN'
: 'Set up SimpleFIN for bank sync'}
</ButtonWithLoading>
<Text style={{ lineHeight: '1.4em', fontSize: 15 }}>
<strong>
Link a <u>North American</u> bank account
</strong>{' '}
to automatically download transactions. SimpleFIN provides
reliable, up-to-date information from hundreds of banks.
</Text>
</>
)}
</>
) : (
<>
Expand All @@ -214,15 +221,15 @@ export function CreateAccount({
fontWeight: 600,
}}
>
Set up GoCardless for bank sync
Set up bank sync
</Button>
<Paragraph style={{ fontSize: 15 }}>
Connect to an Actual server to set up{' '}
<ExternalLink
to="https://actualbudget.org/docs/advanced/bank-sync"
linkColor="muted"
>
automatic syncing with GoCardless
automatic syncing.
</ExternalLink>
.
</Paragraph>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export function ExperimentalFeatures() {
<FeatureToggle flag="experimentalOfxParser">
Experimental OFX parser
</FeatureToggle>
<FeatureToggle flag="simpleFinSync">SimpleFIN sync</FeatureToggle>
</View>
) : (
<LinkButton
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DEFAULT_FEATURE_FLAG_STATE: Record<FeatureFlag, boolean> = {
goalTemplatesEnabled: false,
customReports: false,
experimentalOfxParser: true,
simpleFinSync: false,
};

export function useFeatureFlag(name: FeatureFlag): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ BEGIN TRANSACTION;

ALTER TABLE accounts ADD COLUMN account_sync_source TEXT;

UPDATE accounts SET
account_sync_source = CASE
WHEN account_id THEN 'goCardless'
ELSE NULL
END;

COMMIT;
16 changes: 5 additions & 11 deletions packages/loot-core/src/server/accounts/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,9 @@ export async function syncExternalAccount(userId, userKey, id, acctId, bankId) {

let download;

if (acctRow.account_sync_source === 'simplefin') {
if (acctRow.account_sync_source === 'simpleFin') {
download = await downloadSimpleFinTransactions(acctId, startDate);
} else if (
acctRow.account_sync_source === 'gocardless' ||
acctRow.account_sync_source === null
) {
} else if (acctRow.account_sync_source === 'goCardless') {
download = await downloadGoCardlessTransactions(
userId,
userKey,
Expand Down Expand Up @@ -876,12 +873,9 @@ export async function syncExternalAccount(userId, userKey, id, acctId, bankId) {

let download;

if (acctRow.account_sync_source === 'simplefin') {
if (acctRow.account_sync_source === 'simpleFin') {
download = await downloadSimpleFinTransactions(acctId, startingDay);
} else if (
acctRow.account_sync_source === 'gocardless' ||
acctRow.account_sync_source === null
) {
} else if (acctRow.account_sync_source === 'goCardless') {
download = await downloadGoCardlessTransactions(
userId,
userKey,
Expand All @@ -895,7 +889,7 @@ export async function syncExternalAccount(userId, userKey, id, acctId, bankId) {

let balanceToUse = startingBalance;

if (acctRow.account_sync_source === 'simplefin') {
if (acctRow.account_sync_source === 'simpleFin') {
const currentBalance = startingBalance;
const previousBalance = transactions.reduce((total, trans) => {
return (
Expand Down
18 changes: 5 additions & 13 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ handlers['gocardless-accounts-link'] = async function ({
id,
account_id: account.account_id,
bank: bank.id,
account_sync_source: 'gocardless',
account_sync_source: 'goCardless',
});
} else {
id = uuidv4();
Expand All @@ -680,7 +680,7 @@ handlers['gocardless-accounts-link'] = async function ({
name: account.name,
official_name: account.official_name,
bank: bank.id,
account_sync_source: 'gocardless',
account_sync_source: 'goCardless',
});
await db.insertPayee({
name: '',
Expand Down Expand Up @@ -732,7 +732,7 @@ handlers['simplefin-accounts-link'] = async function ({
id,
account_id: externalAccount.account_id,
bank: bank.id,
account_sync_source: 'simplefin',
account_sync_source: 'simpleFin',
});
} else {
id = uuidv4();
Expand All @@ -742,7 +742,7 @@ handlers['simplefin-accounts-link'] = async function ({
name: externalAccount.name,
official_name: externalAccount.name,
bank: bank.id,
account_sync_source: 'simplefin',
account_sync_source: 'simpleFin',
});
await db.insertPayee({
name: '',
Expand Down Expand Up @@ -1377,15 +1377,7 @@ handlers['account-unlink'] = mutator(async function ({ id }) {

const accRow = await db.first('SELECT * FROM accounts WHERE id = ?', [id]);

let isGoCardless;

if (accRow.account_sync_source === 'gocardless') {
isGoCardless = true;
} else if (accRow.account_sync_source === 'simplefin') {
isGoCardless = false;
} else {
isGoCardless = true;
}
const isGoCardless = accRow.account_sync_source === 'goCardless';

await db.updateAccount({
id,
Expand Down
3 changes: 2 additions & 1 deletion packages/loot-core/src/types/prefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export type FeatureFlag =
| 'reportBudget'
| 'goalTemplatesEnabled'
| 'customReports'
| 'experimentalOfxParser';
| 'experimentalOfxParser'
| 'simpleFinSync';

export type LocalPrefs = Partial<
{
Expand Down

0 comments on commit 8e49971

Please sign in to comment.