vault.contract declares the vault's interface: a status list under Me and a modal sheet for the browser approval. The timing of the whole package (poll every 2 s, sync every 30 s, countdown, foreground sync) is not in TypeScript but in root tasks in app.contract, written in Contract. The store says so itself: "The root Contract task owns the two-second cadence."
Shapes and helpers
VaultStatus: the fifteen fields answered by the store.
VaultPage: {visibilityState}, the shape read from Exact's reserved exactPage() resource.
vaultName(identity, profiles): profile name, then key name, then short id.
vaultCountdown(ms): m:ss, never below zero.
The file reuses MeIdentity and MeProfile from Me: screens and components and Avatar from Shared components.
Components
VaultScreen
VaultScreen, route vault (/me/vault). Props: eid, active, status, loading, busy, failed, url, ids, profiles, current, and the actions editURL, connect, resume, command, create, importKey, switchTo, askLogout.
Section | Content | testIds |
|---|---|---|
Storage | One of: loading text; the error with Retry; Locked with Unlock; or the mode ( |
|
Identities | Each identity links to its Me identity screen, with |
|
Remote vault, local mode | URL field (placeholder |
|
Remote vault, remote mode | Switch to local; Log out and clear this device |
|
Last section | Lock vault |
|
Dialog | "Your identities remain in your remote vault and on your other devices." |
|
The list's own testId is vault-screen, set only when the screen is active. Identities and remote sections are hidden while there is an error, while locked, or before the first status arrives.
VaultConnectScreen
VaultConnectScreen, route vault-connect (/me/vault/connect), presented as a modal. Props: eid, status, busy, now, and the actions retry, cancel, openBrowser.
It shows a status title (Approve this device, Connected or Connection stopped), and while pending: Open in browser, Link expires in m:ss, the selectable connect link and any poll warning. A connect error and Try again appear when stopped. testIds: vault-connect-screen, vault-connect-cancel, vault-connect-status, vault-open-browser, vault-expiry, vault-connect-link, vault-poll-warning, vault-connect-failed, vault-connect-retry.
Root declarations
Kind | Declaration |
|---|---|
State |
|
Resources |
|
Mutations |
|
Derived |
|
Because vaultStatus takes meIds as an argument, it is asked again whenever the identity list changes (State, refresh and stale-reply patterns).
Tasks
Task | Runs when | Does |
|---|---|---|
| vault open, no error, unlocked; keyed on every identity's id, key name and creation time | after 1 ms, |
| connection pending and page visible | every 2,000 ms, |
| connection pending | every 1,000 ms, |
| connected, unlocked, page visible | every 30,000 ms, |
| same condition | after 1 ms, |
| vault open; keyed on the vault's id list | after 1 ms, |
| connected while the connect sheet is on top | after 2,000 ms, |
Polling and syncing stop while the app is in the background, because both conditions require vaultPage.visibilityState == "visible".
Actions
vaultEditURL(v) edits the URL field.
vaultConnect sends vaultStarted = vaultStart(vaultURL, server, now). vaultAfterStart pushes the connect sheet (once) and calls openURL(connectUrl) when the reply is pending.
vaultResume reopens the sheet; vaultOpenBrowser reopens the URL.
vaultCommand(command), vaultPollTick and vaultSyncTick send vaultChanged = vaultCommand(...), each guarded by not vaultBusy, so ticks never overlap a running operation.
vaultMeChanged sends the queued vaultEdited mutation, which is not guarded by vaultBusy (inferred intent: an edit is queued rather than dropped).
vaultRefreshIdentities refreshes meIds, and when the current account is not in the vault (and the vault is healthy and unlocked) switches currentAccount to the vault's first identity.
vaultCancel sends the cancel command and pops the sheet. vaultAskLogout opens the confirmation dialog.
Every command passes time.epochAtZero + performanceNow() as its time. The view switch wires both components; the screen's Create and Import buttons reuse Me's meOpenCreate and meOpenImport.
Contract tests
vault.test.contract starts at /me/vault with seed 42 and has 3 tests, with "Throwaway fixtures only":
Local empty state, lock, and unlock.
An invalid URL (with credentials) shows Invalid vault URL and stays local.
A pending connection against http://127.0.0.1:4790/vault: the sheet shows Approve this device; fail fetch plus 6,000 ms produces the poll warning; 900,000 ms more gives connection token expired; Cancel returns to Local.
The third test needs the local test server, which mounts the mock vault. A completed approval is not driven here; that path is covered by the Bun tests and by the UI drives in the real vault compatibility suite. See Contract UI tests for the step vocabulary.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime