1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/test/lib/mock-config-manager.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-06-25 01:13:27 +02:00
var ConfigManager = require('../../app/scripts/lib/config-manager')
const STORAGE_KEY = 'metamask-config'
2016-06-25 01:13:27 +02:00
const extend = require('xtend')
module.exports = function() {
return new ConfigManager({ loadData, setData })
}
function loadData () {
var oldData = getOldStyleData()
var newData
2016-06-25 01:13:27 +02:00
try {
newData = JSON.parse(window.localStorage[STORAGE_KEY])
} catch (e) {}
var data = extend({
meta: {
version: 0,
},
data: {
config: {
provider: {
type: 'testnet',
},
},
},
}, oldData || null, newData || null)
return data
}
function getOldStyleData () {
var config, wallet, seedWords
var result = {
meta: { version: 0 },
data: {},
}
try {
config = JSON.parse(window.localStorage['config'])
result.data.config = config
} catch (e) {}
try {
wallet = JSON.parse(window.localStorage['lightwallet'])
result.data.wallet = wallet
} catch (e) {}
try {
seedWords = window.localStorage['seedWords']
result.data.seedWords = seedWords
} catch (e) {}
return result
}
function setData (data) {
window.localStorage[STORAGE_KEY] = JSON.stringify(data)
}