diff --git a/apps/web/app/(finance)/account/[id]/edit/page.tsx b/apps/web/app/(finance)/account/[id]/edit/page.tsx index 82a4c868..ea6766b8 100644 --- a/apps/web/app/(finance)/account/[id]/edit/page.tsx +++ b/apps/web/app/(finance)/account/[id]/edit/page.tsx @@ -200,30 +200,41 @@ export default function EditAccountPage() { ); return ( - 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" - /> +
+ 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" + /> +
); } diff --git a/apps/web/app/(finance)/account/[id]/page.tsx b/apps/web/app/(finance)/account/[id]/page.tsx index 514f3ef0..96cb1d4f 100644 --- a/apps/web/app/(finance)/account/[id]/page.tsx +++ b/apps/web/app/(finance)/account/[id]/page.tsx @@ -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' @@ -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, diff --git a/apps/web/app/(finance)/analytics/page.tsx b/apps/web/app/(finance)/analytics/page.tsx index 9879294e..27327331 100644 --- a/apps/web/app/(finance)/analytics/page.tsx +++ b/apps/web/app/(finance)/analytics/page.tsx @@ -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, diff --git a/apps/web/app/(finance)/profile/page.tsx b/apps/web/app/(finance)/profile/page.tsx index beed1afb..94340ccb 100644 --- a/apps/web/app/(finance)/profile/page.tsx +++ b/apps/web/app/(finance)/profile/page.tsx @@ -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; @@ -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(); + 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 ( diff --git a/apps/web/app/(finance)/settings/appearance/page.tsx b/apps/web/app/(finance)/settings/appearance/page.tsx index eae16a52..a084b60d 100644 --- a/apps/web/app/(finance)/settings/appearance/page.tsx +++ b/apps/web/app/(finance)/settings/appearance/page.tsx @@ -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." /> diff --git a/apps/web/app/(finance)/settings/privacy/page.tsx b/apps/web/app/(finance)/settings/privacy/page.tsx index c02d418d..742f75ac 100644 --- a/apps/web/app/(finance)/settings/privacy/page.tsx +++ b/apps/web/app/(finance)/settings/privacy/page.tsx @@ -191,7 +191,7 @@ export default function PrivacySettingsPage() { } 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." /> } diff --git a/apps/web/app/(finance)/settings/sync/page.tsx b/apps/web/app/(finance)/settings/sync/page.tsx index 8e4c8762..78ffd927 100644 --- a/apps/web/app/(finance)/settings/sync/page.tsx +++ b/apps/web/app/(finance)/settings/sync/page.tsx @@ -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(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; @@ -57,6 +72,7 @@ export default function SyncSettingsPage() { ); const problems = failedEntries.length + conflicts.length; + const needsAttention = problems > 0 || Boolean(syncError); return ( - ) : problems ? ( + ) : needsAttention ? ( ) : ( @@ -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={ + + ))} + {conflicts.map((conflict) => ( +
+

+ {conflict.entityType} {conflict.recordId} has a local and cloud version. Choose + which to keep. +

+
+ + +
+
+ ))} + {error ?

{error}

: null}
) : null} 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 (
{shown.map((transfer) => { @@ -327,9 +326,7 @@ export function SuggestedTransfers({
); })} - {limit && transfers.length > limit ? ( -

+{transfers.length - limit} more suggested

- ) : null} + {hiddenCount > 0 ?

+{hiddenCount} more suggested

: null} ); } diff --git a/packages/ui/src/finance/web/ProfileEditScreen.tsx b/packages/ui/src/finance/web/ProfileEditScreen.tsx index ae9524d2..74537348 100644 --- a/packages/ui/src/finance/web/ProfileEditScreen.tsx +++ b/packages/ui/src/finance/web/ProfileEditScreen.tsx @@ -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.'); diff --git a/packages/ui/src/home/model.ts b/packages/ui/src/home/model.ts index b14aea9d..73a48be3 100644 --- a/packages/ui/src/home/model.ts +++ b/packages/ui/src/home/model.ts @@ -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) => @@ -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) || @@ -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), diff --git a/tests/shared/home-dashboard.test.ts b/tests/shared/home-dashboard.test.ts new file mode 100644 index 00000000..f28077ec --- /dev/null +++ b/tests/shared/home-dashboard.test.ts @@ -0,0 +1,41 @@ +import { describe, expect, it } from 'vitest'; +import { buildHomeDashboard } from '../../packages/ui/src/home/model'; + +const now = Date.UTC(2026, 5, 15, 12); + +function dashboard(accountId?: string) { + return buildHomeDashboard({ + now, + startAt: now - 30 * 86_400_000, + endAt: now + 1, + currency: 'INR', + ...(accountId ? { accountId } : {}), + accounts: [{ id: 'wallet', currency: 'INR', balanceMinor: 0n, openingBalanceMinor: 0n }], + transactions: [ + { + id: 'shared-expense', + accountId: 'wallet', + categoryId: 'food', + type: 'expense', + status: 'posted', + currency: 'INR', + occurredAt: now, + amountMinor: 1000n, + accountAmountMinor: 250n, + }, + ], + categories: [{ id: 'food', name: 'Food', monthlyLimitMinor: 2000n, limitCurrency: 'INR' }], + groups: [], + groupMembers: [], + recurringRules: [], + goals: [], + goalContributions: [], + }); +} + +describe('home dashboard category limits', () => { + it('uses the selected account share for shared expenses', () => { + expect(dashboard('wallet').categoryLimits[0]?.spentMinor).toBe(250n); + expect(dashboard().categoryLimits[0]?.spentMinor).toBe(1000n); + }); +}); diff --git a/tests/web/account-routes-and-icons.test.ts b/tests/web/account-routes-and-icons.test.ts index bb62fbba..fb8ff1d1 100644 --- a/tests/web/account-routes-and-icons.test.ts +++ b/tests/web/account-routes-and-icons.test.ts @@ -1,7 +1,7 @@ import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { describe, expect, it } from 'vitest'; -import { AccountDetailView, AccountsIndexView } from '@finapp/ui/finance'; +import { AccountDetailView, AccountsIndexView, SuggestedTransfers } from '@finapp/ui/finance'; import { ThemeProvider } from '@finapp/ui/web'; import { matchesRouteId, routeIdFor } from '../../apps/web/app/(finance)/_personal'; @@ -28,6 +28,37 @@ describe('personal account routes', () => { expect(matchesRouteId(account, account.id)).toBe(true); }); }); +describe('suggested transfers', () => { + it("keeps every signed-in user's transfer visible before limiting unrelated suggestions", () => { + const markup = renderWithTheme( + React.createElement(SuggestedTransfers, { + transfers: [ + { fromUserId: 'me', toUserId: 'a', amountMinor: 100n }, + { fromUserId: 'b', toUserId: 'me', amountMinor: 200n }, + { fromUserId: 'c', toUserId: 'd', amountMinor: 300n }, + { fromUserId: 'e', toUserId: 'f', amountMinor: 400n }, + ], + currency: 'USD', + people: [ + { id: 'me', name: 'Me' }, + { id: 'a', name: 'Alex' }, + { id: 'b', name: 'Blair' }, + { id: 'c', name: 'Casey' }, + { id: 'd', name: 'Devon' }, + { id: 'e', name: 'Emery' }, + { id: 'f', name: 'Finley' }, + ], + meId: 'me', + limit: 1, + }), + ); + + expect(markup).toContain('You pay'); + expect(markup).toContain('Blair pays'); + expect(markup).not.toContain('Casey pays'); + expect(markup).toContain('+2 more suggested'); + }); +}); describe('account icons', () => { it('renders visible contrasting icons on both account list and detail surfaces', () => {