mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #3565 from MetaMask/local-store-fix
Fix local store promisification
This commit is contained in:
commit
19b553907c
@ -3,7 +3,6 @@
|
|||||||
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
|
||||||
|
|
||||||
const extension = require('extensionizer')
|
const extension = require('extensionizer')
|
||||||
const { promisify } = require('util')
|
|
||||||
|
|
||||||
module.exports = class ExtensionStore {
|
module.exports = class ExtensionStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -11,9 +10,6 @@ module.exports = class ExtensionStore {
|
|||||||
if (!this.isSupported) {
|
if (!this.isSupported) {
|
||||||
log.error('Storage local API not available.')
|
log.error('Storage local API not available.')
|
||||||
}
|
}
|
||||||
const local = extension.storage.local
|
|
||||||
this._get = promisify(local.get).bind(local)
|
|
||||||
this._set = promisify(local.set).bind(local)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async get() {
|
async get() {
|
||||||
@ -31,6 +27,34 @@ module.exports = class ExtensionStore {
|
|||||||
async set(state) {
|
async set(state) {
|
||||||
return this._set(state)
|
return this._set(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_get() {
|
||||||
|
const local = extension.storage.local
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
local.get(null, (result) => {
|
||||||
|
const err = extension.runtime.lastError
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_set(obj) {
|
||||||
|
const local = extension.storage.local
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
local.set(obj, () => {
|
||||||
|
const err = extension.runtime.lastError
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isEmpty(obj) {
|
function isEmpty(obj) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { promisify } = require('util')
|
const promisify = require('pify')
|
||||||
|
|
||||||
start().catch(console.error)
|
start().catch(console.error)
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { promisify } = require('util')
|
const promisify = require('pify')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const readFile = promisify(fs.readFile)
|
const readFile = promisify(fs.readFile)
|
||||||
const writeFile = promisify(fs.writeFile)
|
const writeFile = promisify(fs.writeFile)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const versionBump = require('../../../development/version-bump')
|
const versionBump = require('../../../development/version-bump')
|
||||||
const { promisify } = require('util')
|
const promisify = require('pify')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const readFile = promisify(fs.readFile)
|
const readFile = promisify(fs.readFile)
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
@ -41,5 +41,3 @@ describe('version bumper', function () {
|
|||||||
assert.ok(result.changelog.includes(expected))
|
assert.ok(result.changelog.includes(expected))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user