diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-03-24 02:41:32 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-03-24 02:41:32 +0800 |
commit | 197e6e0b77868b0bec76cef303b2eeffda5797bf (patch) | |
tree | 510fb27393318dcbcaaccb5331ad7d57088345fe /library/controllers/index-db-controller.js | |
parent | 45ab81fb45ec1043d617f66c308e2e7911c8e0ad (diff) | |
download | tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar.gz tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar.bz2 tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar.lz tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar.xz tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.tar.zst tangerine-wallet-browser-197e6e0b77868b0bec76cef303b2eeffda5797bf.zip |
WIP: indexdb is at an err state "provider is undefined"
Diffstat (limited to 'library/controllers/index-db-controller.js')
-rw-r--r-- | library/controllers/index-db-controller.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/library/controllers/index-db-controller.js b/library/controllers/index-db-controller.js index 3373de113..f7225c00b 100644 --- a/library/controllers/index-db-controller.js +++ b/library/controllers/index-db-controller.js @@ -51,19 +51,35 @@ module.exports = class IndexDbController extends EventEmitter { return this.requestObjectStore(key) .then((dataObject)=> { return new Promise((resolve, reject) => { - const getRequest = dataObject.get(key) - getRequest.onsuccess = (event) => resolve(event.currentTarget.result) - getRequest.onerror = (event) => reject(event) + const getRequest = dataObject.get(key) + getRequest.onsuccess = (event) => { + const serialized = event.currentTarget.result + try { + console.log('serialized:',serialized) + const state = serialized ? JSON.parse(serialized) : {} + resolve(state) + } catch (err) { + reject(err) + } + } + getRequest.onerror = (event) => reject(event) + }) }) - }) } - put (key, store) { + put (key, state) { return this.requestObjectStore(key, 'readwrite') .then((dataObject)=> { - const putRequest = dataObject.put(store) - putRequest.onsuccess = (event) => Promise.resolve(event.currentTarget.result) - putRequest.onerror = (event) => Promise.reject(event) + return new Promise((resolve, reject) => { + try { + const serialized = JSON.stringify(state) + const putRequest = dataObject.put(serialized) + putRequest.onsuccess = (event) => resolve(event.currentTarget.result) + putRequest.onerror = (event) => reject(event) + } catch (err) { + reject(err) + } + }) }) } |