diff options
background - move pojo migrator to outside of metamask controller
Diffstat (limited to 'mock-dev.js')
-rw-r--r-- | mock-dev.js | 94 |
1 files changed, 33 insertions, 61 deletions
diff --git a/mock-dev.js b/mock-dev.js index dfd0b4961..a404c64b0 100644 --- a/mock-dev.js +++ b/mock-dev.js @@ -12,6 +12,9 @@ * To use, run `npm run mock`. */ +// pollyfill localStorage for non-browser environments +if (!global.localStorage) global.localStorage + const extend = require('xtend') const render = require('react-dom').render const h = require('react-hyperscript') @@ -21,93 +24,62 @@ const actions = require('./ui/app/actions') const states = require('./development/states') const Selector = require('./development/selector') const MetamaskController = require('./app/scripts/metamask-controller') +const firstTimeState = require('./app/scripts/first-time-state') +const LocalStorageStore = require('./app/scripts/lib/observable/local-storage') +const synchronizeStore = require('./app/scripts/lib/observable/util/sync') const extension = require('./development/mockExtension') +const noop = function () {} + +const STORAGE_KEY = 'metamask-config' +// // Query String +// + const qs = require('qs') let queryString = qs.parse(window.location.href.split('#')[1]) let selectedView = queryString.view || 'first time' const firstState = states[selectedView] updateQueryParams(selectedView) +function updateQueryParams(newView) { + queryString.view = newView + const params = qs.stringify(queryString) + window.location.href = window.location.href.split('#')[0] + `#${params}` +} + +// // CSS +// + const MetaMaskUiCss = require('./ui/css') const injectCss = require('inject-css') +// +// MetaMask Controller +// -function updateQueryParams(newView) { - queryString.view = newView - const params = qs.stringify(queryString) - window.location.href = window.location.href.split('#')[0] + `#${params}` +let dataStore = new LocalStorageStore({ storageKey: STORAGE_KEY }) +// initial state for first time users +if (!dataStore.get()) { + dataStore.put(firstTimeState) } -const noop = function () {} const controller = new MetamaskController({ // User confirmation callbacks: showUnconfirmedMessage: noop, unlockAccountMessage: noop, showUnapprovedTx: noop, // initial state - initState: loadData(), + initState: dataStore.get(), }) // setup state persistence -controller.store.subscribe(setData) - -// Stub out localStorage for non-browser environments -if (!window.localStorage) { - window.localStorage = {} -} -const STORAGE_KEY = 'metamask-config' -function loadData () { - var oldData = getOldStyleData() - var newData - 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 setData (data) { - window.localStorage[STORAGE_KEY] = JSON.stringify(data) -} - -function getOldStyleData () { - var config, wallet, seedWords +synchronizeStore(controller.store, dataStore) - 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 -} +// +// User Interface +// actions._setBackgroundConnection(controller.getApi()) actions.update = function(stateName) { |