diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cbeb74..ea331d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.12] — 2026-11-02 + +### Accounts — clearing a name brings the default back +- **The bug:** clearing a name you gave an account in Settings → Accounts removed it from `State.accountLabels`, but the old name kept showing. FinLens had also copied the typed name into the account's own `name` when you renamed it, imported its CSV, reloaded or imported a JSON export (`setAccountName()`, `wireAccountRename()`, `importParsedCsv()`, `DB.loadAll()`, `_applyImportedSettings()`), and `acctName()` fell back to that copy. On the Overview, an empty name kept the old one. +- **An account's `name` is now always its default:** `Bank Checking`, `Bank Savings`, `Bank Credit Card ()`, or the file name for other CSVs. A name you type lives only in `State.accountLabels`. Importing a CSV writes the default back to the browser database. A JSON import no longer copies the imported names into the accounts (the copy loop in `_applyImportedSettings()`, v1.16.6, is gone): `acctName()` shows them from `State.accountLabels`. +- **`acctName()`** shows the name you typed, else the default, which `defaultAccountName()` (core.js) works out from the account's kind and file. So data saved by older versions, where `name` can still hold a cleared name, shows the default too. +- **Both places that rename go through `setAccountName()`:** Settings → Accounts and the Overview cards (double-click, or Enter). An empty name, or the default name itself, removes the label. On the Overview, a name left as it was saves nothing; before, it was saved as a label. Settings says "Using the default name …" when the label goes. +- **Every place that shows a name uses `acctName()`:** the accounts filter and its tooltip, the import log, the Last import card and the account list in the AI summary (`buildFinancialSummary()`). For accounts with no typed name the summary is unchanged, so the AI eval's requests are byte-identical. With a typed name it shows that name, as before. + +--- + ## [1.16.11] — 2026-11-02 ### AI Analysis diff --git a/CLAUDE.md b/CLAUDE.md index f59a694..1e1d521 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,7 +59,7 @@ Until then, this section is the rule. FinLens is a **single-origin, zero-build, vanilla JavaScript personal finance dashboard** that runs entirely in the browser. There is no server, no npm, no bundler, no framework, and no TypeScript. The entry point is `index.html`; everything else is a plain `.js` file in the `js/` folder. -**Current version:** v1.16.11 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.12 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). **What it does:** Imports CSV exports from a bank (checking + savings) and credit cards, parses and normalizes them into a unified transaction model, and renders a multi-tab financial dashboard with budgeting, debt tracking, savings forecasting, investment planning, and Claude-powered AI analysis. @@ -176,6 +176,7 @@ const State = { csvAutoImportPaused: false, // true after "Clear transactions & accounts" with a folder connected (§20) fileAssignments: {}, // { [filename]: kind } accountOrder: [], // [accountId, ...] — user-defined display order + accountLabels: {}, // { [accountId]: name you typed } — acctName() shows it first; an empty name removes it (§18) currentView: 'overview', }; ``` @@ -273,7 +274,7 @@ Transactions are created by `mkTx()` in `core.js` and never mutated directly — ```js { id: string, // e.g. 'bank_checking', 'bank_savings', 'card_my_card_csv' - name: string, // Display name (user-editable via Data tab) + name: string, // Default name (§18), never the name you typed: that's State.accountLabels[id]. Show acctName(id) kind: 'bank_checking' | 'bank_savings' | 'credit_card' | 'unknown', balance: null, // Not used directly — use currentBalances() or periodEndBalance() limit: null, // Not used directly — use State.manualBalances[id+'_limit'] @@ -538,6 +539,7 @@ autoCategory(description) // Returns category string based on rules + DEFAULT_R txRuleFlag(desc, flag, rules?) // true if a transaction rule for that flag matches; rules default to State.txRules txFlags(desc, ov, rules?) // { isRecurring, isBill, isSubscription }: the edit in ov, else the rules (§4.2) applyTxRulesToAll() // re-works out every loaded transaction's flags (after a rule changes) +defaultAccountName(a) // 'Bank Checking' | 'Bank Savings' | 'Bank Credit Card ()' | the file name, from a.kind + a.sourceFile // Aggregation (aggregation.js — loaded after core.js) byCategory(txs, filter) // { category, amount }[] sorted by amount desc @@ -647,7 +649,7 @@ mergeChartOpts(extra) // Merge extra options into CHART_DEFAULTS // Rendering utilities emptyCard(message) // Returns HTML string for empty-state card fmtSigned(n, zero?) / fmtShort(v) // "+$2,450.00" / "−$65.00" (real minus sign); axis labels "$12.5k" -acctName(id), ordinal(n) // account display name (custom label first; null → "Outside FinLens"); "3rd" +acctName(id), ordinal(n) // account display name (the name you typed, else defaultAccountName(); null → "Outside FinLens"); "3rd" svgLineChart(pts, opts) // inline-SVG line chart: pts [{ v, tip }]; opts { w, h, hue, xLabels, valueAt, hollowLast, ariaLabel } sparkSvg(values, hue, label) // stretchy sparkline dailyHeatmapHtml(txs, start, end) // weeks × days heatmap, six shades by quartile @@ -885,7 +887,7 @@ Views build a fresh DOM on every `showView()` call. This is intentional. Do not - Uses the model in `AI_MODEL` (currently `claude-sonnet-5-5`) via direct browser fetch to `https://api.anthropic.com/v1/messages`. `claude-sonnet-4-20250514` was retired 2026-06-15 — check Anthropic's model deprecations page before changing models. - Requires `anthropic-dangerous-direct-browser-access: true` header (CORS bypass). - API key is stored in `State.apiKey` (localStorage + IndexedDB `app_state` only — **never** in `finlens-state.json`, see §4.5). It is entered in **Settings → General → Anthropic API Key**; the settings card never renders the stored value back into the DOM. **Never log or expose it.** -- `buildFinancialSummary()` assembles a plain-text snapshot of current State. Account balances, total cash and net worth are the balances at the end of the selected period, the numbers the Overview shows (v1.16.11). The starting balance is included (v1.16.10). Debts report `debtBalance(d)`: a debt linked to a card account gives the card's current balance (v1.15.0); others give `d.balance` as before. **It always states its dates (v1.10.2):** +- `buildFinancialSummary()` assembles a plain-text snapshot of current State. Account balances, total cash and net worth are the balances at the end of the selected period, the numbers the Overview shows (v1.16.11). The starting balance is included (v1.16.10). Debts report `debtBalance(d)`: a debt linked to a card account gives the card's current balance (v1.15.0); others give `d.balance` as before. Accounts are listed by `acctName()` (the AI Eval sandbox sets `accountLabels` to `{}`). **It always states its dates (v1.10.2):** - **The period line** gives the span of the transactions it covers (`summarySpan()`), e.g. "Period: All time (transactions from May 1, 2026 to Oct 20, 2026: 173 days, about 5.7 months)". - **A partial month** in the monthly trend is marked (`partialMonthNote()`), e.g. "2026-10 (through Oct 20)". - **Balances on a past range (v1.16.11).** `summaryBalanceEnd()` gives the range end when it is before the last transaction, else null. @@ -1030,9 +1032,11 @@ Up to v1.16.9, `currentBalances()` left the starting balance out, so All time an Multiple credit card files can be loaded simultaneously. Each gets a unique `accountId` derived from the filename: `card_` + sanitized filename, and a default name `Bank Credit Card ()`. +**Names you type** (Settings → Accounts, or double-click a name on the Overview) are saved in `State.accountLabels` by `setAccountName()` (views-data.js). The account's own `name` stays the default (`defaultAccountName()`). An empty name, or the default name itself, removes the label, and the default shows again. Show a name with `acctName(id)`, never `account.name`: data saved by older versions can still hold a cleared name there. + --- -*Last updated: v1.16.11 — 2026-11-02 (AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* +*Last updated: v1.16.12 — 2026-11-02 (account names: §4.1 `accountLabels`; §4.3 an account's `name` is its default; §8 `defaultAccountName()`; §9 `acctName()`; §13 the summary lists accounts by `acctName()`; §18 names you type, and clearing them; v1.16.11: AI summary balances at the end of the selected period: §13 `summaryBalanceEnd()` and the date notes; §21 the parser reads the balance lines by how they start; v1.16.10: starting balance counted in every range: §8 `startingBalance()`, `currentBalances()`; §13 summary balances; §18 one balance rule; v1.16.9: the transaction drawer stores only the flags you change: §4.2 flags, §12 state mutations; v1.16.8: flags from transaction rules are worked out on load, never read from storage: §4.2 flags, §8 `txRuleFlag()` / `txFlags()` / `applyTxRulesToAll()`, §19 flags in the transactions store; v1.16.7: transaction links to budgets, buckets and debts by id: §1 version; §3 migrate.js role; §4.1 the `id` fields, TxOverride and its `link` shape; §8 `PLAN_LINK_TYPES`, `newPlanId()`; §9 `planItem()`, `linkedTransactions()`, `unlinkPlanItems()`, `ensurePlanIds()`; §20 clearing budgets, buckets or debts removes their links; §22 the plan-link migration; v1.16.6: JSON export carries account names and order, Read as, flag rules, transfer keywords and theme: §9 `JSON_EXPORT_KEYS`; §12 adding a persisted field; §20 what the export holds; v1.16.5: a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.5: no section changes: Import Logs race fix; v1.10.4: §8, §13 single `~` is literal; §21 excerpts escape `~`; v1.10.3: §13 refusals; §21 declined runs; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* --- diff --git a/README.md b/README.md index f0d6a07..a5cccb2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money. -**Version:** v1.16.11  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.12  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -104,7 +104,7 @@ FinLens stores all your data — budgets, bills, transaction edits, settings, AI ## Features In Depth ### Overview -Net worth with a trend chart (1M, 3M or all of your history) and the change since the end of last month. The latest month's money in, money out, net and savings rate, next to your 6-month average. A card per account with a balance sparkline (or, for a credit card, how much of the limit you're using). Six months of cash flow with the net for each month, bills due in the next three weeks, and the largest card purchases of the latest month. Double-click an account name to rename it. +Net worth with a trend chart (1M, 3M or all of your history) and the change since the end of last month. The latest month's money in, money out, net and savings rate, next to your 6-month average. A card per account with a balance sparkline (or, for a credit card, how much of the limit you're using). Six months of cash flow with the net for each month, bills due in the next three weeks, and the largest card purchases of the latest month. Double-click an account name to rename it; clear the name to go back to the default. ### Transactions Filter pills across the top: **All**, **Income**, **Spending**, **Bills**, **Payments** and **Transfers**. All and Payments filter the list; the other four open their own screens. The list has search, a category filter, sorting, an amount filter, bulk edits and 50 rows per page. Click a transaction to edit its description, categories, type, notes and flags (Bill, Recurring, Subscription). Edits are kept separately from the imported row, so re-importing never overwrites them. **Transaction rules** flag matching transactions automatically (e.g. "NETFLIX → Subscription"). A flag you tick or untick yourself wins over the rules; one you leave alone keeps following them. **Payments** lists the payments made to your credit cards. @@ -261,4 +261,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.11 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.12 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index a5fd2b6..d187903 100644 --- a/index.html +++ b/index.html @@ -1164,7 +1164,7 @@
-
v1.16.11 · FinLens
+
v1.16.12 · FinLens
diff --git a/js/core.js b/js/core.js index d4f29b8..5327e99 100644 --- a/js/core.js +++ b/js/core.js @@ -427,7 +427,7 @@ const State = { csvAutoImportPaused: lsGet('csvAutoImportPaused', false), fileAssignments: lsGet('fileAssignments', {}), // filename -> kind accountOrder: lsGet('accountOrder', []), // [accountId, ...] display order - accountLabels: lsGet('accountLabels', {}), // accountId -> custom display name (overrides account.name everywhere) + accountLabels: lsGet('accountLabels', {}), // accountId -> name you typed; acctName() shows it first. An empty name removes it (§18) txRules: lsGet('txRules', []), // [{contains, flag:'bill'|'subscription'|'recurring'}] — auto-flag rules transferKeywords: lsGet('transferKeywords', null) || ['transfer','zelle','ach','venmo','paypal','coinbase','savings booster'], customSchemas: lsGet('customSchemas', []), // user-defined schema objects (same shape as BANK_SCHEMAS entries) @@ -666,6 +666,19 @@ function mkTx(o) { }; } +// The name FinLens gives an account (CLAUDE.md §18), from its kind and the CSV it came +// from: 'Bank Checking', 'Bank Savings', 'Bank Credit Card ()', or the file name. +// A name you type is kept apart, in State.accountLabels; clearing it shows this one again. +// '' when the file name it needs isn't known. +function defaultAccountName(a) { + if (!a) return ''; + const file = a.sourceFile || ''; + if (a.kind === 'bank_checking') return 'Bank Checking'; + if (a.kind === 'bank_savings') return 'Bank Savings'; + if (a.kind === 'credit_card') return file ? 'Bank Credit Card (' + file.replace(/\.csv$/i,'') + ')' : ''; + return file; +} + // Reads one CSV file and turns its rows into transactions. It changes nothing: no State, // browser storage or IndexedDB writes (v1.16.2). loadFiles() reads every file this way // first and imports (importParsedCsv()) only when at least one transaction was read. @@ -713,19 +726,18 @@ function parseCsvFile(file, forcedKind) { const kind = schema.id; - // Build accountId and display name (migrate.js maps the ids older versions used) - let accountId, accountName; + // Build accountId and default name (migrate.js maps the ids older versions used) + let accountId; if (kind === 'credit_card') { accountId = 'card_' + file.name.replace(/\.csv$/i,'').toLowerCase().replace(/[^a-z0-9]+/g,'_'); - accountName = 'Bank Credit Card (' + file.name.replace(/\.csv$/i,'') + ')'; } else if (kind === 'bank_savings') { - accountId = 'bank_savings'; accountName = 'Bank Savings'; + accountId = 'bank_savings'; } else if (kind === 'bank_checking') { - accountId = 'bank_checking'; accountName = 'Bank Checking'; + accountId = 'bank_checking'; } else { accountId = 'acct_' + file.name.replace(/\.csv$/i,'').replace(/[^a-z0-9]+/g,'_'); - accountName = file.name; } + const accountName = defaultAccountName({ kind, sourceFile: file.name }); // Normalize all rows. Truly identical rows (same hash inputs) are counted within // this file: the 2nd copy gets an _2 suffix, the 3rd _3, and so on. Counting per @@ -768,15 +780,14 @@ function parseCsvFile(file, forcedKind) { // import carries on, so the transactions still reach memory and finlens-state.json. async function importParsedCsv(p) { const { file, schema, kind, accountId, accountName, txs } = p; - // Initialise account in State (in-memory) + // Initialise account in State (in-memory). Its name is always the default: a name + // you typed stays in State.accountLabels, and acctName() shows that first. (Older + // versions copied the typed name in here; this puts the default back.) State.accounts[accountId] = State.accounts[accountId] || { id: accountId, name: accountName, kind, balance: null, limit: null, sourceFile: file.name }; State.accounts[accountId].sourceFile = file.name; - // Restore persisted custom label if any - if (State.accountLabels && State.accountLabels[accountId]) { - State.accounts[accountId].name = State.accountLabels[accountId]; - } + State.accounts[accountId].name = accountName; // Persist to IndexedDB (if DB is ready) let importResult = null; @@ -1108,7 +1119,7 @@ function buildAccountFilter() { } const all=State.selectedAccounts==='all'; list.innerHTML = accts.length - ? accts.map(a=>``).join('') + ? accts.map(a=>``).join('') : '
No accounts yet. Import CSVs in Settings → Import.
'; if (typeof updateAcctUI==='function') updateAcctUI(); } diff --git a/js/db.js b/js/db.js index bba7a56..8ba995a 100644 --- a/js/db.js +++ b/js/db.js @@ -371,14 +371,11 @@ const DB = { // ── 2. Load accounts ── const dbAccounts = await this.getAccounts(); - // Merge DB accounts into State.accounts (preserving any in-memory ones) + // Merge DB accounts into State.accounts (preserving any in-memory ones). A name you + // typed stays in State.accountLabels: acctName() shows it, so it isn't copied in here. for (const a of dbAccounts) { const existing = State.accounts[a.id]; State.accounts[a.id] = { ...(existing || {}), ...a }; - // Apply any persisted custom label - if (State.accountLabels && State.accountLabels[a.id]) { - State.accounts[a.id].name = State.accountLabels[a.id]; - } } // ── 3. Load transactions + apply overrides ── diff --git a/js/ui.js b/js/ui.js index a1cef64..552835b 100644 --- a/js/ui.js +++ b/js/ui.js @@ -173,7 +173,7 @@ function updateAcctUI() { const all = State.selectedAccounts === 'all'; const names = all ? 'All accounts' : orderedAccounts() .filter(a => State.selectedAccounts.includes(a.id)) - .map(a => State.accountLabels?.[a.id] || a.name).join(', '); + .map(a => acctName(a.id)).join(', '); const label = 'Accounts: ' + (names || 'All accounts'); const btn = $('#acctBtn'); if (btn) { btn.setAttribute('aria-label', label); btn.title = label; btn.classList.toggle('on', !all); } const dot = $('#acctDot'); if (dot) dot.hidden = all; @@ -228,10 +228,14 @@ function fmtShort(v) { return s+'$'+Math.round(a); } const ordinal=(n)=>n+(n%10===1&&n!==11?'st':n%10===2&&n!==12?'nd':n%10===3&&n!==13?'rd':'th'); -// Display name of an account (custom label first). +// Display name of an account: the name you typed (State.accountLabels), else its default +// name (defaultAccountName() in core.js). The default is worked out rather than read from +// account.name: older versions copied the typed name in there, so data they saved can +// still hold a name you've since cleared. function acctName(id) { if (!id) return 'Outside FinLens'; - return State.accountLabels?.[id]||State.accounts[id]?.name||id; + const a=State.accounts[id]; + return State.accountLabels?.[id]||defaultAccountName(a)||a?.name||id; } /* ---------- INLINE SVG CHARTS (v1.14.0) ---------- */ @@ -852,10 +856,9 @@ function importJsonFile(ev) { // Imported settings take effect now, without a reload. Most keys only need the render // that follows. Category rules apply to the next import (or Re-categorize all), "Read as" // choices to the next CSV read, and transaction edits once the page reloads, as before. +// Imported account names need no copying: acctName() reads State.accountLabels, and an +// account's own name stays its default (v1.16.12). function _applyImportedSettings(changed) { - if (changed.has('accountLabels')) { - for (const [id,name] of Object.entries(State.accountLabels)) if (State.accounts[id]&&name) State.accounts[id].name=name; - } if (changed.has('accountLabels')||changed.has('accountOrder')) buildAccountFilter(); if (changed.has('txRules')) applyTxRulesToAll(); if (changed.has('transferKeywords')) reapplyTransferKeywords(); // views-main.js; re-runs transfer detection diff --git a/js/views-ai.js b/js/views-ai.js index 4e4ffd3..7b0d981 100644 --- a/js/views-ai.js +++ b/js/views-ai.js @@ -78,7 +78,7 @@ function buildFinancialSummary() { const expense=sumExpense(txs); const lines=[]; lines.push(`Period: ${describeRange()}${summarySpan(txs)}`); - lines.push(`Accounts${asOf?` at the end of the period (${asOfText})`:''}: ${Object.values(State.accounts).map(a=>`${a.name} (${fmt(balances[a.id])})`).join(', ')}`); + lines.push(`Accounts${asOf?` at the end of the period (${asOfText})`:''}: ${Object.values(State.accounts).map(a=>`${acctName(a.id)} (${fmt(balances[a.id])})`).join(', ')}`); lines.push(`Total Cash: ${fmt(cash)}, Total Debt: ${fmt(debt)}, Net Worth: ${fmt(cash-debt)}${asOf?` (all on ${asOfText})`:''}`); lines.push(`Period Income: ${fmt(income)}, Spending: ${fmt(expense)}, Savings Rate: ${pct(income>0?(income-expense)/income:0)}`); lines.push(''); lines.push('Top spending categories:'); diff --git a/js/views-data.js b/js/views-data.js index d6b9b91..2594d83 100644 --- a/js/views-data.js +++ b/js/views-data.js @@ -150,12 +150,12 @@ registerView('import','Import',(root)=>{ appendHtml(root,`

Last import

${State.lastRefresh?`${escapeHtml(whenText(State.lastRefresh))}`:''}
${_lastImportResults.map(r=>{ - const ir=r.importResult; + const ir=r.importResult, nm=r.accountId&&State.accounts[r.accountId]?acctName(r.accountId):r.account; if (r.problem) return `
${escapeHtml(r.filename)}Not imported: ${escapeHtml(r.problem)}
`; - if (!ir) return `
${escapeHtml(r.account)}${escapeHtml(r.filename)} · imported (the browser database wasn't ready, so no counts)
`; + if (!ir) return `
${escapeHtml(nm)}${escapeHtml(r.filename)} · imported (the browser database wasn't ready, so no counts)
`; const cov=_coverageCache[r.accountId]; const next=ir.dateRangeMax?dayjs(ir.dateRangeMax).add(1,'day').format('MMM D, YYYY'):'—'; - return `
${escapeHtml(r.account)} + return `
${escapeHtml(nm)} ${escapeHtml(r.filename)} · covers ${fmtD(ir.dateRangeMin)} – ${fmtD(ir.dateRangeMax)}${cov?` · ${cov.count.toLocaleString()} in FinLens`:''} · start the next export on ${next}
${ir.inserted.toLocaleString()} new · ${ir.skipped.toLocaleString()} already imported${ir.removed?` · ${ir.removed.toLocaleString()} leftover duplicate cop${ir.removed!==1?'ies':'y'} removed`:''} ${ir.gapWarning?callout('warn',`No data for ${fmtD(ir.gapWarning.from)} – ${fmtD(ir.gapWarning.to)}. Import a file that covers those dates to fill the gap.`):''}
`; @@ -249,7 +249,7 @@ function renderImportLog(container) { const fmtD=d=>d?dayjs(d).format('MMM D, YYYY'):'—'; const rows=_importLogCache.map(e=>{ const acct=State.accounts[e.accountId]; - const name=acct?(State.accountLabels?.[e.accountId]||acct.name):e.accountId; + const name=acct?acctName(e.accountId):e.accountId; return ` ${dayjs(e.timestamp).format('MMM D h:mm A')} ${escapeHtml(e.filename||'')} @@ -286,14 +286,15 @@ function moveAccount(accountId, direction) { } /* ---- Account and card fields (Settings → Accounts, Credit cards): saved as you leave each one ---- */ -// The name you type is kept in State.accountLabels, which wins over the CSV's default -// name everywhere (as renaming on the Overview does). An empty name goes back to it. +// The name you type is kept in State.accountLabels, which wins over the account's default +// name everywhere (acctName()). Renaming on the Overview saves through here too. An empty +// name, or the default name itself, removes the label, so the default shows again. The +// account's own name isn't changed: it stays the default (defaultAccountName()). function setAccountName(id, raw) { const a=State.accounts[id]; if (!a) return ''; const name=String(raw||'').trim(); if (!State.accountLabels) State.accountLabels={}; - if (name) State.accountLabels[id]=name; else delete State.accountLabels[id]; - a.name=name||a.name; + if (name&&name!==defaultAccountName(a)) State.accountLabels[id]=name; else delete State.accountLabels[id]; lsSet('accountLabels',State.accountLabels); buildAccountFilter(); return acctName(id); @@ -735,9 +736,9 @@ registerView('accounts','Accounts',(root)=>{ (same&&!same.disabled?same:other)?.focus(); }); $$('[data-acct-name]',root).forEach(inp=>inp.addEventListener('change',()=>{ - const shown=setAccountName(inp.dataset.acctName, inp.value); + const id=inp.dataset.acctName, shown=setAccountName(id, inp.value); inp.value=shown; - say('good',`Saved the name “${shown}”.`); + say('good',State.accountLabels[id]?`Saved the name “${shown}”.`:`Using the default name “${shown}”.`); })); $$('[data-acct-money]',root).forEach(inp=>inp.addEventListener('change',()=>{ if (!setAccountMoney(inp.dataset.acctMoney, inp.dataset.field, inp.value)) { diff --git a/js/views-main.js b/js/views-main.js index 1fa2491..6f395f8 100644 --- a/js/views-main.js +++ b/js/views-main.js @@ -386,7 +386,9 @@ function accountCardShell(a,name,sub,tile,balHtml,middle,foot) {
`; } // Double-click an account name (or focus it and press Enter) to rename it. The name is -// saved in State.accountLabels and used everywhere. +// saved in State.accountLabels and used everywhere (setAccountName() in views-data.js, as +// Settings → Accounts does): an empty name brings the default name back, and a name left +// as it was saves nothing. function wireAccountRename(scope) { $$('.acct-name',scope).forEach(el=>{ const start=()=>{ @@ -399,12 +401,7 @@ function wireAccountRename(scope) { let done=false; const save=()=>{ if (done) return; done=true; - const newName=inp.value.trim()||cur; - if (!State.accountLabels) State.accountLabels={}; - State.accountLabels[id]=newName; - if (State.accounts[id]) State.accounts[id].name=newName; - lsSet('accountLabels',State.accountLabels); - buildAccountFilter(); + if (inp.value.trim()!==cur) setAccountName(id,inp.value); renderActive(); }; inp.addEventListener('blur',save); diff --git a/js/views-settings.js b/js/views-settings.js index ed163da..a7aa3b0 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -60,7 +60,7 @@ function _renderGeneralSettings(root) { /* ---- About (the Theme row is gone: light only for now) ---- */ appendHtml(root,`

About

-
VersionFinLens v1.16.11
+
VersionFinLens v1.16.12
`); /* ---- Anthropic API key ---- */