Adds a "Loss thresholds" panel to the popup backed by the backend's new GET/PATCH /me/settings endpoints, converting between the wire's fractional percentages and whole-number form inputs only at that boundary. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RTorFQXMR9ZQtCKcMTXLHp
42 lines
2.2 KiB
TypeScript
42 lines
2.2 KiB
TypeScript
import type { ConnectionStatus, LockState, ThresholdSettings } from './types';
|
|
|
|
/** browser.storage.local key backing the lock state seam in the background script. */
|
|
export const LOCK_STATE_STORAGE_KEY = 'nexa:lockState';
|
|
|
|
/**
|
|
* Typed message contracts between background <-> content scripts <-> popup.
|
|
* All lock-state reads go through these so no module reaches into storage
|
|
* directly (see src/background/lock-state.ts). There is deliberately no
|
|
* client-writable "set lock state" message: the backend is the sole source
|
|
* of truth for lock state (see the WebSocket protocol's "Ownership" section
|
|
* in ../../CLAUDE.md) — only the WS client (ws-client.ts) may apply a new
|
|
* lock state, and only because the server told it to.
|
|
*/
|
|
export type NexaMessage =
|
|
| { type: 'nexa:get-lock-state' }
|
|
| { type: 'nexa:lock-state-changed'; state: LockState }
|
|
| { type: 'nexa:get-connection-status' }
|
|
| { type: 'nexa:connection-status-changed'; status: ConnectionStatus }
|
|
| { type: 'nexa:open-popup' }
|
|
// Wallet auth (content script <-> background). See
|
|
// content-scripts/wallet-connect.ts and background/wallet-auth.ts.
|
|
| { type: 'nexa:wallet-connected'; walletAddress: string }
|
|
| { type: 'nexa:wallet-disconnected' }
|
|
| { type: 'nexa:wallet-sign-request'; nonce: string }
|
|
| { type: 'nexa:request-wallet-connect' }
|
|
| { type: 'nexa:wallet-disconnect-request' }
|
|
| { type: 'nexa:switch-account-request' }
|
|
// Sign-out / switch account (popup -> background). See entrypoints/popup/App.tsx.
|
|
| { type: 'nexa:sign-out' }
|
|
| { type: 'nexa:switch-account' }
|
|
// Loss-threshold settings (popup -> background -> GET/PATCH /me/settings).
|
|
// See background/settings-client.ts and entrypoints/popup/App.tsx.
|
|
| { type: 'nexa:get-settings' }
|
|
| { type: 'nexa:update-settings'; settings: Partial<ThresholdSettings> };
|
|
|
|
/** Response shape for 'nexa:get-settings'/'nexa:update-settings', returned via sendResponse. */
|
|
export type SettingsResult = { settings: ThresholdSettings } | { error: string };
|
|
|
|
/** Response shape for 'nexa:wallet-sign-request', returned via sendResponse (not a dispatched NexaMessage). */
|
|
export type WalletSignResult = { signature: string } | { error: string };
|