mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
conditionally use extension store if supported or enabled
This commit is contained in:
parent
7184db7632
commit
3c6a5b16ad
@ -50,8 +50,12 @@ async function loadStateFromPersistence () {
|
|||||||
// read from disk
|
// read from disk
|
||||||
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
|
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
|
||||||
// fetch from extension store and merge in data
|
// fetch from extension store and merge in data
|
||||||
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
|
|
||||||
versionedData = { ...versionedData, ...extensionData }
|
if (extensionStore.isSupported && extensionStore.isEnabled) {
|
||||||
|
const extensionData = await extensionStore.fetch() // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
|
||||||
|
versionedData = { ...versionedData, ...extensionData }
|
||||||
|
}
|
||||||
|
|
||||||
// migrate data
|
// migrate data
|
||||||
versionedData = await migrator.migrateData(versionedData)
|
versionedData = await migrator.migrateData(versionedData)
|
||||||
// write to disk
|
// write to disk
|
||||||
@ -92,7 +96,9 @@ function setupController (initState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function syncDataWithExtension(state) {
|
function syncDataWithExtension(state) {
|
||||||
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
|
if (extensionStore.isSupported && extensionStore.isEnabled) {
|
||||||
|
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
|
||||||
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@ const handleDisabledSyncAndResolve = (resolve, toResolve) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = class ExtensionStore {
|
module.exports = class ExtensionStore {
|
||||||
|
constructor() {
|
||||||
|
this.isSupported = !!(extension.storage.sync)
|
||||||
|
this.isEnabled = true // TODO: get value from user settings
|
||||||
|
}
|
||||||
async fetch() {
|
async fetch() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
|
extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user