Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 36 additions & 25 deletions apps/web/app/(finance)/account/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,30 +200,41 @@ export default function EditAccountPage() {
</div>
);
return (
<AccountFormScreen
mode="edit"
createdAt={account.createdAt}
activity={deriveFormActivity(transactions, categories, records, account, 'accountId', userId)}
onOpenTransaction={(id) => router.push(`/transaction/${encodeURIComponent(id)}`)}
onViewTransactions={() => router.push(`/account/${encodeURIComponent(routeId)}`)}
isPrimary={
primaryDraft ??
Boolean(
profile &&
[account.id, account._id, account.cloudId].includes(profile.defaultAccountId as string),
)
}
onPrimaryChange={profile ? setPrimaryDraft : undefined}
title={form.name.trim() || 'Edit account'}
subtitle="Update your account details and settings."
value={form}
currencies={currencies}
saving={saving}
error={formError}
onChange={setForm}
onSubmit={save}
onBack={() => router.back()}
submitLabel="Save changes"
/>
<div className="finance-page finance-page--narrow">
<AccountFormScreen
mode="edit"
createdAt={account.createdAt}
activity={deriveFormActivity(
transactions,
categories,
records,
account,
'accountId',
userId,
)}
onOpenTransaction={(id) => router.push(`/transaction/${encodeURIComponent(id)}`)}
onViewTransactions={() => router.push(`/account/${encodeURIComponent(routeId)}`)}
isPrimary={
primaryDraft ??
Boolean(
profile &&
[account.id, account._id, account.cloudId].includes(
profile.defaultAccountId as string,
),
)
}
onPrimaryChange={profile ? setPrimaryDraft : undefined}
title={form.name.trim() || 'Edit account'}
subtitle="Update your account details and settings."
value={form}
currencies={currencies}
saving={saving}
error={formError}
onChange={setForm}
onSubmit={save}
onBack={() => router.back()}
submitLabel="Save changes"
/>
</div>
);
}
6 changes: 5 additions & 1 deletion apps/web/app/(finance)/account/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export default function PersonalAccountDetailPage() {
: item.type === 'expense'
? -(item.accountAmountMinor === undefined ? amountMinor : asMinor(item.accountAmountMinor))
: amountMinor;
const rowAmountMinor =
item.type === 'expense' && item.accountAmountMinor !== undefined
? asMinor(item.accountAmountMinor)
: amountMinor;
const rowType: TransactionType = isTransfer
? isOutgoing
? 'expense'
Expand All @@ -158,7 +162,7 @@ export default function PersonalAccountDetailPage() {
? formatTransactionDate(item.occurredAt, item.hasTime, timeZone)
: 'Date unavailable',
status: item.status,
amountMinor,
amountMinor: rowAmountMinor,
currency: item.currency ?? account?.currency ?? 'INR',
type: rowType,
semanticType: item.groupId ? 'split' : isTransfer ? 'transfer' : undefined,
Expand Down
19 changes: 17 additions & 2 deletions apps/web/app/(finance)/analytics/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,30 @@ export default function AnalyticsPage() {
const spentMinor = transactionState.records.reduce((sum, record) => {
const at = Number(record.occurredAt ?? 0);
if (
(record.status !== undefined && record.status !== 'posted') ||
record.type !== 'expense' ||
record.deletedAt !== undefined ||
record.currency !== currency ||
at < limitMonth.startAt ||
at >= limitMonth.endAt ||
!keys.includes(String(record.categoryId ?? ''))
!keys.includes(String(record.categoryId ?? '')) ||
accountById.get(String(record.accountId ?? ''))?.includeInAnalytics === false ||
(accountFilter !== 'all' &&
!(
accountById.get(accountFilter)
? idAliases(accountById.get(accountFilter)!)
: [accountFilter]
).includes(String(record.accountId ?? '')))
)
return sum;
return sum + amountAsBigInt(record.amountMinor);
return (
sum +
amountAsBigInt(
accountFilter !== 'all' && record.accountAmountMinor !== undefined
? record.accountAmountMinor
: record.amountMinor,
)
);
}, 0n);
return {
category,
Expand Down
17 changes: 14 additions & 3 deletions apps/web/app/(finance)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { currencies } from '@convex/shared/validators';
import { FinanceSignedOut } from '@/components/finance/FinanceSignedOut';
import { useBrowserSync } from '@/lib/offline/BrowserSyncProvider';
import { useLocalRecords } from '@/lib/offline/hooks';
import { commitLocalWrite, type LocalRecord } from '@/lib/offline/repository';
import { clearLocalData, commitLocalWrite, type LocalRecord } from '@/lib/offline/repository';

type Profile = LocalRecord & {
displayName?: string;
Expand Down Expand Up @@ -106,8 +106,19 @@ export default function ProfilePage() {
}
}
async function leave() {
await signOut();
router.replace('/sign-in');
setMessage('');
try {
if (!userId) throw new Error('AUTH_REQUIRED');
await clearLocalData(userId);
await signOut();
Comment on lines +112 to +113

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop active sync before clearing sign-out data

When the user signs out while BrowserSyncProvider is syncing, clearLocalData can finish before an in-flight bootstrap or pull writes its response to IndexedDB. Signing out does not cancel those operations, which retain the user ID they started with, so they can repopulate finance records after this deletion and leave private data in the browser despite the sign-out guarantee. Coordinate shutdown of active sync before clearing, or perform a final clear after synchronization can no longer write.

Useful? React with 👍 / 👎.

Comment on lines +112 to +113

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Complete sign-out when local cleanup fails

If IndexedDB is unavailable, blocked, or fails while clearLocalData opens or commits its transaction, the exception jumps to this function’s catch before signOut() runs. The user therefore cannot terminate their authenticated session from this button precisely when browser storage is unhealthy, which is particularly risky on a shared browser. Local cleanup failure should be reported, but it must not prevent the authentication sign-out from being attempted.

Useful? React with 👍 / 👎.

router.replace('/sign-in');
} catch (cause) {
setMessage(
cause instanceof Error
? cause.message
: 'Could not clear this browser’s saved data and sign out.',
);
}
}
const name = profile?.displayName ?? 'Your profile';
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(finance)/settings/appearance/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function AppearanceSettingsPage() {
/>
}
title={`${options.find((option) => option.value === appearance)?.label ?? 'System'} theme`}
description="Changes apply right away on this device and follow you to your other devices."
description="Changes apply right away and are saved on this device."
/>

<SettingsGroup title="Theme">
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(finance)/settings/privacy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default function PrivacySettingsPage() {
<SettingsItem
icon={<HardDrive size={19} />}
title="Copy in this browser"
description="Finapp keeps a copy here so it works offline. It isn’t encrypted separately, so anyone using this browser profile could read it. Signing out removes it."
description="Finapp keeps a copy here so it works offline. It isn’t encrypted separately, so anyone using this browser profile could read it. Use Profile → Sign out to clear this account’s saved finance records from this browser."
/>
<SettingsLink
icon={<Trash2 size={19} />}
Expand Down
98 changes: 84 additions & 14 deletions apps/web/app/(finance)/settings/sync/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,24 @@ export default function SyncSettingsPage() {
failedEntries,
conflicts,
retryNow,
retryEntry,
resolveConflict,
} = useBrowserSync();
const [saving, setSaving] = React.useState(false);
const [error, setError] = React.useState('');
const [resolvingConflict, setResolvingConflict] = React.useState<string | null>(null);

async function chooseConflict(conflictId: string, winner: 'local' | 'cloud') {
setResolvingConflict(conflictId);
setError('');
try {
await resolveConflict(conflictId, winner);
} catch (cause) {
setError(cause instanceof Error ? cause.message : 'Could not resolve this conflict.');
} finally {
setResolvingConflict(null);
}
}

async function selectWindow(value: LocalSyncWindow) {
if (saving || value === syncWindow) return;
Expand All @@ -57,6 +72,7 @@ export default function SyncSettingsPage() {
);

const problems = failedEntries.length + conflicts.length;
const needsAttention = problems > 0 || Boolean(syncError);
return (
<SettingsShell
title="Sync"
Expand All @@ -67,7 +83,7 @@ export default function SyncSettingsPage() {
icon={
!isConnected ? (
<CloudOff size={22} />
) : problems ? (
) : needsAttention ? (
<TriangleAlert size={22} />
) : (
<Cloud size={22} />
Expand All @@ -78,15 +94,17 @@ export default function SyncSettingsPage() {
? 'Offline'
: isSyncing
? 'Syncing…'
: problems
? `${problems} change${problems === 1 ? '' : 's'} need attention`
: needsAttention
? problems
? `${problems} change${problems === 1 ? '' : 's'} need attention`
: 'Sync needs attention'
: 'Everything is synced'
}
description={
!isConnected
syncError ??
(!isConnected
? 'Changes save in this browser and sync when you reconnect.'
: (syncError ??
'Finapp keeps a copy in this browser so it opens fast and works offline.')
: 'Finapp keeps a copy in this browser so it opens fast and works offline.')
}
action={
<Button
Expand All @@ -99,15 +117,67 @@ export default function SyncSettingsPage() {
</Button>
}
/>
{problems ? (
{needsAttention ? (
<SettingsGroup title="Needs attention">
<SettingsLink
icon={<TriangleAlert size={19} />}
tone="warning"
title={`${failedEntries.length} failed, ${conflicts.length} conflicting`}
description="Review and retry or choose which version to keep"
onPress={() => router.push('/notifications')}
/>
{syncError ? (
<p role="alert" style={{ margin: 0, color: 'var(--finapp-destructive)' }}>
{syncError}
</p>
) : null}
{failedEntries.map((entry) => (
<div
key={entry.localId}
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: 12,
}}
>
<span>{entry.lastError ?? `${entry.operation} could not sync`}</span>
<Button
size="sm"
variant="outline"
disabled={!isConnected || isSyncing}
onPress={() =>
void retryEntry(entry.localId).catch((cause: unknown) =>
setError(
cause instanceof Error ? cause.message : 'Could not retry this change.',
),
)
}
>
Retry
</Button>
</div>
))}
{conflicts.map((conflict) => (
<div key={conflict.id} style={{ display: 'grid', gap: 8, paddingBlock: 8 }}>
<p style={{ margin: 0 }}>
{conflict.entityType} {conflict.recordId} has a local and cloud version. Choose
which to keep.
</p>
Comment on lines +155 to +159

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Show both versions before resolving a conflict

For every sync conflict, this page displays only the entity type and record ID before offering destructive “Keep this device” and “Keep cloud” actions. Since conflict.localRecord and conflict.cloudRecord are available but never rendered, users cannot tell which name, amount, or other value each action will preserve and may overwrite the desired edit. Present the differing values, as the existing local sync sheet does, before allowing either resolution.

Useful? React with 👍 / 👎.

<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8 }}>
<Button
size="sm"
variant="outline"
disabled={resolvingConflict !== null}
onPress={() => void chooseConflict(conflict.id, 'local')}
Comment on lines +161 to +165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable local conflict resolution during active sync

If “Keep this device” is pressed while a background sync is already running, conflict resolution creates a pending outbox entry and then calls flush(), but flush() immediately returns because its running guard is set. When the current sync has already passed syncOutbox, the chosen local version can remain pending until another sync trigger, and a subsequent pull in the current run can recreate the conflict. The existing sync sheet avoids this race by disabling these actions while isSyncing; this page should do the same.

Useful? React with 👍 / 👎.

>
Keep this device
</Button>
<Button
size="sm"
variant="outline"
disabled={resolvingConflict !== null}
onPress={() => void chooseConflict(conflict.id, 'cloud')}
>
Keep cloud
</Button>
</div>
</div>
))}
{error ? <p role="alert">{error}</p> : null}
</SettingsGroup>
) : null}
<SettingsGroup
Expand Down
15 changes: 6 additions & 9 deletions packages/ui/src/finance/web/GroupSettleParts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ export function SuggestedTransfers({
/** Sends a payment reminder for transfers someone owes you. */
onRemind?: (transfer: SettleTransfer) => void;
}) {
// Your own transfers (to settle or to remind) come first, so a limit never hides them.
const ordered = [
...transfers.filter((t) => t.fromUserId === meId || t.toUserId === meId),
...transfers.filter((t) => t.fromUserId !== meId && t.toUserId !== meId),
];
const shown = limit ? ordered.slice(0, limit) : ordered;
const ownTransfers = transfers.filter((t) => t.fromUserId === meId || t.toUserId === meId);
const otherTransfers = transfers.filter((t) => t.fromUserId !== meId && t.toUserId !== meId);
const unrelatedLimit = limit ? Math.max(0, limit - ownTransfers.length) : otherTransfers.length;
const shown = [...ownTransfers, ...otherTransfers.slice(0, unrelatedLimit)];
const hiddenCount = otherTransfers.length - Math.min(otherTransfers.length, unrelatedLimit);
return (
<div className={styles.timeline}>
{shown.map((transfer) => {
Expand Down Expand Up @@ -327,9 +326,7 @@ export function SuggestedTransfers({
</div>
);
})}
{limit && transfers.length > limit ? (
<p className={styles.muted}>+{transfers.length - limit} more suggested</p>
) : null}
{hiddenCount > 0 ? <p className={styles.muted}>+{hiddenCount} more suggested</p> : null}
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/finance/web/ProfileEditScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export function ProfileEditScreen({
setSaveError('');
try {
const result = await onSave(draft, editor.changes);
editor.commit(draft);
if (result.tone !== 'warning') editor.commit(draft);
setToast(result);
} catch (cause) {
setSaveError(cause instanceof Error ? cause.message : 'Could not save your profile.');
Expand Down
25 changes: 17 additions & 8 deletions packages/ui/src/home/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ export function buildHomeDashboard(input: HomeDashboardInput): HomeDashboardData
(input.accountId ? hasAlias(account, input.accountId) : account.isIncludedInTotal !== false),
);
const selectedAccountAliases = new Set(selectedAccounts.flatMap(aliases));
const transactions = input.transactions.filter(
const accountTransactions = input.transactions.filter(
(transaction) =>
transaction.currency === input.currency &&
(!input.accountId ||
selectedAccountAliases.has(String(transaction.accountId ?? '')) ||
(transaction.type === 'transfer' &&
selectedAccountAliases.has(String(transaction.transferAccountId ?? '')))),
!input.accountId ||
selectedAccountAliases.has(String(transaction.accountId ?? '')) ||
(transaction.type === 'transfer' &&
selectedAccountAliases.has(String(transaction.transferAccountId ?? ''))),
);
const transactions = accountTransactions.filter(
(transaction) => transaction.currency === input.currency,
);
const periodTransactions = transactions.filter(
(transaction) =>
Expand Down Expand Up @@ -256,7 +258,7 @@ export function buildHomeDashboard(input: HomeDashboardInput): HomeDashboardData
const currency =
typeof category.limitCurrency === 'string' ? category.limitCurrency : input.currency;
const keys = aliases(category);
const spent = input.transactions.reduce((total, transaction) => {
const spent = accountTransactions.reduce((total, transaction) => {
const occurredAt = Number(transaction.occurredAt ?? 0);
if (
!isPosted(transaction) ||
Expand All @@ -267,7 +269,14 @@ export function buildHomeDashboard(input: HomeDashboardInput): HomeDashboardData
!keys.includes(String(transaction.categoryId ?? ''))
)
return total;
return total + amount(transaction.amountMinor);
return (
total +
amount(
input.accountId && transaction.accountAmountMinor !== undefined
? transaction.accountAmountMinor
: transaction.amountMinor,
)
);
}, 0n);
return {
id: recordId(category),
Expand Down
Loading
Loading