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
|
||||
let versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
|
||||
// fetch from extension store and merge in data
|
||||
|
||||
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
|
||||
versionedData = await migrator.migrateData(versionedData)
|
||||
// write to disk
|
||||
@ -92,7 +96,9 @@ function setupController (initState) {
|
||||
}
|
||||
|
||||
function syncDataWithExtension(state) {
|
||||
if (extensionStore.isSupported && extensionStore.isEnabled) {
|
||||
extensionStore.sync(state) // TODO: handle possible exceptions (https://developer.chrome.com/apps/runtime#property-lastError)
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@ const handleDisabledSyncAndResolve = (resolve, toResolve) => {
|
||||
}
|
||||
|
||||
module.exports = class ExtensionStore {
|
||||
constructor() {
|
||||
this.isSupported = !!(extension.storage.sync)
|
||||
this.isEnabled = true // TODO: get value from user settings
|
||||
}
|
||||
async fetch() {
|
||||
return new Promise((resolve) => {
|
||||
extension.storage.sync.get(KEYS_TO_SYNC, (data) => {
|
||||
|
Loading…
Reference in New Issue
Block a user