aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.js41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/app.js b/src/app.js
index 5c28326..36de6c3 100644
--- a/src/app.js
+++ b/src/app.js
@@ -1483,7 +1483,7 @@ function armUnlockDeadline() {
const left = until - Date.now();
if (left <= 0) {
try { localStorage.removeItem(UNLOCK_UNTIL_KEY); } catch {}
- if (activeAccount()) lock({ offerPassword: true });
+ if (activeAccount() && !wallet.watchOnly) softLock();
return;
}
_unlockUntilTimer = setTimeout(armUnlockDeadline, Math.min(left, 60_000));
@@ -1736,14 +1736,41 @@ function settingsBtn() {
}));
}
+// Lock in place: the keys leave, the view stays. The wallet remains on screen
+// watch-only (balances and history, no spending), the padlock closes, and
+// tapping it again asks for the password to bring the keys back.
+function softLock() {
+ const watch = loadWatchAccounts();
+ let blankPw = false;
+ try { decryptVault(loadVaultBlob(), ''); blankPw = true; } catch {}
+ // Nothing watchable, or a passwordless vault (locking would mean nothing):
+ // fall back to the classic flow, which offers to set a password.
+ if (!watch.length || !hasVault() || blankPw) { lock({ offerPassword: true }); ui.justLocked = true; return; }
+ const keepId = activeId;
+ for (const f of FEATURES) { try { f.stop && f.stop(); } catch {} }
+ vaultPassword = null;
+ accounts = watch.slice();
+ persistAccounts();
+ const cur = accounts.find((a) => a.id === keepId) || accounts[0];
+ activateAccount(cur, { fresh: true });
+ toast(t('lockedToast'));
+}
+
function lockBtn() {
- // While a wallet is open this shows an OPEN padlock — gold body, steel
- // shackle, a little cartoony on purpose. The tap locks it. (Locked state
- // has no header at all.)
+ const locked = wallet.watchOnly && hasVault();
return h('button', {
- class: 'header-msgs', title: t('lockWallet'), 'aria-label': t('lockWallet'),
- onClick: () => { lock({ offerPassword: true }); ui.justLocked = true; toast(t('lockedToast')); },
- }, h('span', { class: 'hm-ico', style: 'font-size:18px;line-height:1' }, '\u{1F513}'));
+ class: 'header-msgs',
+ title: locked ? t('unlock') : t('lockWallet'),
+ 'aria-label': locked ? t('unlock') : t('lockWallet'),
+ onClick: locked
+ ? () => {
+ if (attemptVaultUnlock('')) {
+ const cur = accounts.find((a) => a.id === activeId) || accounts[0];
+ if (cur) activateAccount(cur, { fresh: true });
+ } else { ui.justLocked = false; ui.screen = 'vault'; render(); }
+ }
+ : () => softLock(),
+ }, h('span', { class: 'hm-ico', style: 'font-size:18px;line-height:1' }, locked ? '\u{1F512}' : '\u{1F513}'));
}
// Messages sit one tap away, left of the wallet selector. The dot is presence,
vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Merge prepared events without inserting between visible posts or evicting
// the reading position. Row geometry comes from the currently rendered feed.
export function mergeFeedWindow(notes, shown, additions, { rows = [], height = 0, keep = 200, page = 20, holdHead = false } = {}) {
  const byId = new Map(rows.map((r) => [r.id, r]));
  const first = rows.find((r) => r.bottom > 0 && r.top < height);
  const seen = new Set(notes.map((e) => e.id));
  const added = [], deferred = [];
  for (const e of additions) {
    if (seen.has(e.id)) continue;
    seen.add(e.id);
    // Equal timestamps sort after existing events. Ignore hidden rows when
    // locating the next rendered post: they cannot serve as an anchor.
    const next = notes.find((n) => n.created_at < e.created_at && byId.has(n.id));
    const row = next && byId.get(next.id);
    // Above the first post on screen is fine even with the header showing:
    // that post is held where it is and the header goes up with the rest,
    // so the scrollbar shows there's more above without anything you're
    // reading moving. holdHead (someone is writing up there) keeps the old
    // rule, so the composer isn't scrolled out from under a typing thumb.
    const inView = row && row.top < height
      && (row === first ? holdHead && row.top > 0 : row.top >= 0);
    (inView ? deferred : added).push(e);
  }
  if (!added.length) return { notes, shown, added, deferred };
  const held = new Set([...notes.slice(0, shown).map((e) => e.id), ...byId.keys()]);
  const merged = [...notes, ...added].sort((a, b) => b.created_at - a.created_at);
  for (let i = 0; i < merged.length; i++) if (held.has(merged[i].id)) shown = Math.max(shown, i + 1);
  // Keep another page beyond the displayed window so paging still advances
  // after the reader has reached the normal in-memory cache limit.
  return { notes: merged.slice(0, Math.max(keep, shown + page)), shown, added, deferred };
}