mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Tighten up data loading code
This commit is contained in:
parent
b97ac5106f
commit
64fcd27102
@ -68,10 +68,10 @@ async function initialize () {
|
||||
async function loadStateFromPersistence () {
|
||||
// migrations
|
||||
const migrator = new Migrator({ migrations })
|
||||
// read from disk
|
||||
versionedData = diskStore.getState() || migrator.generateInitialState(firstTimeState)
|
||||
// fetch from extension store and merge in data
|
||||
|
||||
// read from disk
|
||||
// first from preferred, async API:
|
||||
let localStoreData
|
||||
if (localStore.isSupported) {
|
||||
let localData
|
||||
try {
|
||||
@ -82,10 +82,14 @@ async function loadStateFromPersistence () {
|
||||
|
||||
// If localStore is supported but has not been written to yet, ignore:
|
||||
if (Object.keys(localData).length > 0) {
|
||||
versionedData = localData
|
||||
localStoreData = localData
|
||||
}
|
||||
}
|
||||
|
||||
versionedData = localStoreData ||
|
||||
diskStore.getState() ||
|
||||
migrator.generateInitialState(firstTimeState)
|
||||
|
||||
// migrate data
|
||||
versionedData = await migrator.migrateData(versionedData)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user