Skip to content

wallet storage adapter butchers objects in node #138

Description

@dashameter

The SDK should support a wallet storage adapter without the enduser having to wrap it, see:

So locaforage butchers objects it stores, and returns not what was passed to it. To make it work, there's a small wrapper needed
Here's the wrapper code:

  constructor() {
    this.forage = localforage;
    this.isConfig = false;
  }

  config() {
    this.isConfig = true;
  }

  async setItem(key, item) {
    console.log('setItem', key, item);
    if (typeof item === 'object') {
      await this.forage.setItem(key, JSON.stringify(item));
    } else {
      await this.forage.setItem(key, item);
    }

    return item;
  }

  async getItem(key) {
    console.log('get item', key);
    const item = await this.forage.getItem(key);
    let res;
    try {
      res = JSON.parse(item);
    } catch (e) {
      res = item;
    }
    return res || null;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions