1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

notes and clean up

This commit is contained in:
frankiebee 2017-03-09 21:53:49 -08:00
parent 9f3445252c
commit 60f00a950c
3 changed files with 7 additions and 179 deletions

View File

@ -1,165 +1,3 @@
/*
const urlUtil = require('url')
const extend = require('xtend')
const Dnode = require('dnode')
const eos = require('end-of-stream')
const ParentStream = require('iframe-stream').ParentStream
const PortStream = require('../app/scripts/lib/port-stream.js')
const notification = require('../app/scripts/lib/notifications.js')
const messageManager = require('../app/scripts/lib/message-manager')
const setupMultiplex = require('../app/scripts/lib/stream-utils.js').setupMultiplex
const MetamaskController = require('../app/scripts/metamask-controller')
const extension = require('../app/scripts/lib/extension')
const STORAGE_KEY = 'metamask-config'
initializeZeroClient()
function initializeZeroClient() {
const controller = new MetamaskController({
// User confirmation callbacks:
showUnconfirmedMessage,
unlockAccountMessage,
showUnapprovedTx,
// Persistence Methods:
setData,
loadData,
})
const idStore = controller.idStore
function unlockAccountMessage () {
console.log('notif stub - unlockAccountMessage')
}
function showUnconfirmedMessage (msgParams, msgId) {
console.log('notif stub - showUnconfirmedMessage')
}
function showUnapprovedTx (txParams, txData, onTxDoneCb) {
console.log('notif stub - showUnapprovedTx')
}
//
// connect to other contexts
//
var connectionStream = new ParentStream()
connectRemote(connectionStream, getParentHref())
function connectRemote (connectionStream, originDomain) {
var isMetaMaskInternalProcess = (originDomain === '127.0.0.1:9001')
if (isMetaMaskInternalProcess) {
// communication with popup
setupTrustedCommunication(connectionStream, 'MetaMask')
} else {
// communication with page
setupUntrustedCommunication(connectionStream, originDomain)
}
}
function setupUntrustedCommunication (connectionStream, originDomain) {
// setup multiplexing
var mx = setupMultiplex(connectionStream)
// connect features
controller.setupProviderConnection(mx.createStream('provider'), originDomain)
controller.setupPublicConfig(mx.createStream('publicConfig'))
}
function setupTrustedCommunication (connectionStream, originDomain) {
// setup multiplexing
var mx = setupMultiplex(connectionStream)
// connect features
setupControllerConnection(mx.createStream('controller'))
controller.setupProviderConnection(mx.createStream('provider'), originDomain)
}
//
// remote features
//
function setupControllerConnection (stream) {
controller.stream = stream
var api = controller.getApi()
var dnode = Dnode(api)
stream.pipe(dnode).pipe(stream)
dnode.on('remote', (remote) => {
// push updates to popup
controller.ethStore.on('update', controller.sendUpdate.bind(controller))
controller.listeners.push(remote)
idStore.on('update', controller.sendUpdate.bind(controller))
// teardown on disconnect
eos(stream, () => {
controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller))
})
})
}
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 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)
}
function getParentHref(){
try {
var parentLocation = window.parent.location
return parentLocation.hostname + ':' + parentLocation.port
} catch (err) {
return 'unknown'
}
}
}
*/
const SWcontroller = require('./sw-controller') const SWcontroller = require('./sw-controller')
console.log('outside:open') console.log('outside:open')
const background = new SWcontroller({ const background = new SWcontroller({

View File

@ -72,11 +72,7 @@ module.exports = class IndexDbController extends EventEmitter {
} }
migrate () { migrate () {
// this.migrations
// Place holder for future migrations eg: // Place holder for future migrations eg:
this.db.deleteObjectStore('meta')
this.db.deleteObjectStore('data')
this.db.createObjectStore('dataStore') this.db.createObjectStore('dataStore')
} }

View File

@ -11,7 +11,6 @@ const PortStream = require('../app/scripts/lib/port-stream.js')
const DbController = require('./controllers/index-db-controller') const DbController = require('./controllers/index-db-controller')
// // all this will go in service worker
const MetamaskController = require('../app/scripts/metamask-controller') const MetamaskController = require('../app/scripts/metamask-controller')
// const extension = require('../app/scripts/lib/extension') // const extension = require('../app/scripts/lib/extension')
// const LocalStorageStore = require('obs-store/lib/localStorage') // const LocalStorageStore = require('obs-store/lib/localStorage')
@ -53,7 +52,7 @@ let diskStore
const dbController = new DbController({ const dbController = new DbController({
key: STORAGE_KEY, key: STORAGE_KEY,
global: self, global: self,
version: 6, version: 2,
initialState: { initialState: {
dataStore: { dataStore: {
meta: 2, meta: 2,
@ -95,6 +94,9 @@ function loadStateFromPersistence() {
return Promise.resolve(data.data) return Promise.resolve(data.data)
}) })
.catch((err) => console.error(err)) .catch((err) => console.error(err))
/*
need to get migrations working
*/
// return asyncQ.waterfall([ // return asyncQ.waterfall([
// // read from disk // // read from disk
@ -143,10 +145,11 @@ function setupController (initState, client) {
// //
// connect to other contexts // connect to other contexts
// //
/*
need to write a service worker stream for this
*/
var connectionStream //= new ParentStream() var connectionStream //= new ParentStream()
SWGlobal.onmessage = (message) => { SWGlobal.onmessage = (message) => {
debugger
connectRemote(connectionStream, message.origin) connectRemote(connectionStream, message.origin)
} }
@ -192,12 +195,3 @@ function setupController (initState, client) {
function triggerUi () { function triggerUi () {
if (!popupIsOpen) notification.show() if (!popupIsOpen) notification.show()
} }
// function getParentHref(){
// try {
// var parentLocation = window.parent.location
// return parentLocation.hostname + ':' + parentLocation.port
// } catch (err) {
// return 'unknown'
// }
// }