Skip to main content

Function: storageAdapterFromChromeStorage()

gSwap SDK 2.0.0-rc.4


gSwap SDK 2.0.0-rc.4 / storageAdapterFromChromeStorage

Function: storageAdapterFromChromeStorage()

storageAdapterFromChromeStorage(area): StorageAdapter

Defined in: packages/gswap-sdk/dist/index.d.ts:3639

A StorageAdapter over a chrome.storage area, the shape the wallet stores pending swaps in: the value lands under the key as the structured value it is (the browser clones it; nothing is serialized here). A missing key resolves undefined; a rejection of the area reaches the store, which treats it as "storage unavailable".

Pass a FUNCTION that returns the area to look it up at each call instead of when the adapter is built: a module that is imported where chrome does not exist yet (a test, a closing extension context) then fails only when the store touches storage, and that failure (a throw inside the function) is the same "storage unavailable" rejection.

Parameters​

area​

ChromeStorageAreaLike | (() => ChromeStorageAreaLike)

Returns​

StorageAdapter

Example​

const store = new PendingSwapStore(storageAdapterFromChromeStorage(chrome.storage.local));
const lazy = new PendingSwapStore(storageAdapterFromChromeStorage(() => chrome.storage.local));