walletconnect-monorepo icon indicating copy to clipboard operation
walletconnect-monorepo copied to clipboard

handle storage entry being null

Open StanislavSava opened this issue 2 years ago • 3 comments

This call will fail when the storage entry is null (for example, on React Native) because typeof null === "object"

StanislavSava avatar Jun 28 '22 17:06 StanislavSava

@StanislavSava why would this be null? Could you describe a scenario?

pedrouid avatar Jul 15 '22 10:07 pedrouid

If you run a get on a key that has nothing under it, for example, if the setItem hasn't run before the get, on first load, you will get null, not undefined, and the check against === 'undefined" will fail

StanislavSava avatar Jul 15 '22 11:07 StanislavSava

Are you using your own custom KeyValueStorage? It should be compatible with this interface

export class IKeyValueStorage {
  public getKeys(): Promise<string[]>;
  public getEntries<T = any>(): Promise<[string, T][]>;
  public getItem<T = any>(key: string): Promise<T | undefined>;
  public setItem<T = any>(key: string, value: T): Promise<void>;
  public removeItem(key: string): Promise<void>;
}

Source: https://github.com/WalletConnect/walletconnect-utils/tree/master/misc/keyvaluestorage#api

pedrouid avatar Jul 16 '22 11:07 pedrouid

closing as stale

ganchoradkov avatar Jun 28 '23 08:06 ganchoradkov