From e7c9620bbe2a4ea37c7c37feecb78095d2a8a92a Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Thu, 28 May 2020 11:53:19 +0200 Subject: [PATCH] Add network namespace for browser cache We want to be able to cache data from multiple networks side-by-side, without them interfering with each other. --- app/services/browser-cache.js | 4 +++- tests/unit/services/browser-cache-test.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/browser-cache.js b/app/services/browser-cache.js index 12506ed..29232dd 100644 --- a/app/services/browser-cache.js +++ b/app/services/browser-cache.js @@ -1,8 +1,10 @@ import Service from '@ember/service'; import * as localforage from 'localforage'; +import config from 'kredits-web/config/environment'; function createStore(name) { - return localforage.createInstance({ name: `kredits:${name}` }); + const networkName = config.web3RequiredNetwork || 'custom'; + return localforage.createInstance({ name: `kredits:${networkName}:${name}` }); } export default class BrowserCacheService extends Service { diff --git a/tests/unit/services/browser-cache-test.js b/tests/unit/services/browser-cache-test.js index 7c77937..a7d6459 100644 --- a/tests/unit/services/browser-cache-test.js +++ b/tests/unit/services/browser-cache-test.js @@ -11,7 +11,7 @@ module('Unit | Service | browser-cache', function(hooks) { test('creates kredits data stores', function(assert) { let cache = this.owner.lookup('service:browser-cache'); - assert.equal(cache.contributors._config.name, "kredits:contributors"); - assert.equal(cache.contributions._config.name, "kredits:contributions"); + assert.equal(cache.contributors._config.name, "kredits:rinkeby:contributors"); + assert.equal(cache.contributions._config.name, "kredits:rinkeby:contributions"); }); });