mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Remove extension-store since we aren't using it yet
This commit is contained in:
parent
dd80bd48ba
commit
f09d72fa2a
@ -1,39 +0,0 @@
|
||||
const extension = require('extensionizer')
|
||||
|
||||
const KEYS_TO_SYNC = ['KeyringController', 'PreferencesController']
|
||||
const FIREFOX_SYNC_DISABLED_MESSAGE = 'Please set webextensions.storage.sync.enabled to true in about:config'
|
||||
|
||||
const handleDisabledSyncAndResolve = (resolve, toResolve) => {
|
||||
// Firefox 52 has sync available on extension.storage, but it is disabled by default
|
||||
const lastError = extension.runtime.lastError
|
||||
if (lastError && lastError.message.includes(FIREFOX_SYNC_DISABLED_MESSAGE)) {
|
||||
resolve({})
|
||||
} else {
|
||||
resolve(toResolve)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = class ExtensionStore {
|
||||
constructor() {
|
||||
this.isSupported = !!(extension.storage && extension.storage.sync)
|
||||
this.isEnabled = true // TODO: get value from user settings
|
||||
}
|
||||
async fetch() {
|
||||
return new Promise((resolve) => {
|
||||
extension.storage && extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
|
||||
handleDisabledSyncAndResolve(resolve, data)
|
||||
})
|
||||
})
|
||||
}
|
||||
async sync(state) {
|
||||
const dataToSync = KEYS_TO_SYNC.reduce((result, key) => {
|
||||
result[key] = state.data[key]
|
||||
return result
|
||||
}, {})
|
||||
return new Promise((resolve) => {
|
||||
extension.storage && extension.storage.sync.set(dataToSync, () => {
|
||||
handleDisabledSyncAndResolve(resolve)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
const assert = require('assert')
|
||||
const sinon = require('sinon')
|
||||
|
||||
const KEYS_TO_SYNC = ['KeyringController', 'PreferencesController']
|
||||
const mockSyncGetResult = 123
|
||||
const syncGetStub = sinon.stub().callsFake((str, cb) => cb(mockSyncGetResult))
|
||||
const syncSetStub = sinon.stub().callsFake((str, cb) => cb())
|
||||
|
||||
window.storage = {
|
||||
sync: {
|
||||
get: syncGetStub,
|
||||
set: syncSetStub,
|
||||
},
|
||||
}
|
||||
window.runtime = {}
|
||||
const ExtensionStore = require('../../app/scripts/lib/extension-store')
|
||||
|
||||
describe('Extension Store', function () {
|
||||
let extensionStore
|
||||
|
||||
beforeEach(function () {
|
||||
extensionStore = new ExtensionStore()
|
||||
})
|
||||
|
||||
describe('#fetch', function () {
|
||||
it('should return a promise', function () {
|
||||
const extensionStoreFetchResult = extensionStore.fetch()
|
||||
assert.ok(Promise.resolve(extensionStoreFetchResult) === extensionStoreFetchResult)
|
||||
})
|
||||
it('after promise resolution, should have loaded the proper data from the extension', function (done) {
|
||||
extensionStore.fetch()
|
||||
.then((result) => {
|
||||
assert.deepEqual(syncGetStub.getCall(0).args[0], KEYS_TO_SYNC.slice(0))
|
||||
assert.equal(result, mockSyncGetResult)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('#sync', function () {
|
||||
it('should return a promise', function () {
|
||||
const extensionStoreSyncResult = extensionStore.sync()
|
||||
assert.ok(Promise.resolve(extensionStoreSyncResult) === extensionStoreSyncResult)
|
||||
})
|
||||
it('after promise resolution, should have synced the proper data from the extension', function (done) {
|
||||
const mockState = {
|
||||
data: {
|
||||
KeyringController: 5,
|
||||
PreferencesController: 6,
|
||||
someOtherData: 7
|
||||
},
|
||||
someOtherProp: {
|
||||
evenMoreData: 8,
|
||||
},
|
||||
}
|
||||
const expectedDataToSync = {
|
||||
KeyringController: 5,
|
||||
PreferencesController: 6,
|
||||
}
|
||||
extensionStore.sync(mockState)
|
||||
.then(() => {
|
||||
assert.deepEqual(syncSetStub.getCall(0).args[0], expectedDataToSync)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user