Function: webStorageAdapter()
gSwap SDK 2.0.0-rc.4 / webStorageAdapter
Function: webStorageAdapter()
webStorageAdapter(
area):StorageAdapter
Defined in: packages/gswap-sdk/dist/index.d.ts:3668
A StorageAdapter over a Web Storage area (localStorage, sessionStorage), the shape
a web app stores pending swaps in: the value lands under the key as JSON text. A missing key
resolves undefined. CORRUPT JSON resolves as the raw string, never a rejection (the store
reads a value that is not an array as "no entries" and the next write repairs it, whereas a
get that rejects forever would make every remember a no-op). A throwing area (storage blocked
by the browser, quota exceeded on setItem) rejects, which the store treats as "storage
unavailable".
Pass a FUNCTION that returns the area to look it up at each call instead of when the adapter is
built: where localStorage does not exist (server rendering, a test, a blocked context)
the access throws inside the function, which is the same "storage unavailable" rejection, and
the module that builds the adapter still loads.
Parameters
area
WebStorageLike | (() => WebStorageLike)
Returns
Example
const store = new PendingSwapStore(webStorageAdapter(() => localStorage));