HomePhabricator

[Cashtab] Standardize getter and setter functions for db and state

Description

[Cashtab] Standardize getter and setter functions for db and state

Summary:
Initialize a standardized function to load data from storage and pass it to wallet context on app startup. Initialize a standardized function to update state (and localforage) when this data changes.

Implement with contactList localforage key.

We have too many getter and setter functions for the various keys. Should have one. All state and storage mgmt should be handled the same way.

This will make migration and updates to the storage schema easier. Will also make it easier to migrate the extension to use the extension storage API instead of indexedDb.

Arguably we should just store cashtabState itself as a key in localforage. Consideration for a later diff. However, hard to say this would optimize, and could complicate the validation / migration functions specific to each key.

Background

Existing functions that get and set data from localforage and wallet context have been added incrementally and diverge in quality and purpose. We should have consistent primitives here.

We only want to get items from localforage on Cashtab startup. We then set these items in state to be used by the app while the user has Cashtab open.

We periodically write to localforage as state items change to ensure they will be available to the user if the browser closes.

Test Plan: npm test

Reviewers: #bitcoin_abc, emack

Reviewed By: #bitcoin_abc, emack

Subscribers: emack

Differential Revision: https://reviews.bitcoinabc.org/D15419

Details

Provenance
bytesofmanAuthored on Feb 11 2024, 01:00
bytesofmanPushed on Feb 19 2024, 22:33
Reviewer
Restricted Project
Differential Revision
D15419: [Cashtab] Standardize getter and setter functions for db and state
Parents
rABC3fba786e754d: [Cashtab] Apply best practices to improve BalanceHeader integration tests
Branches
Unknown
Tags
Unknown