aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-03-10 13:53:49 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-03-10 13:53:49 +0800
commit60f00a950cbe90edda4d9de4a67c3e0c528f6638 (patch)
treed4a6846de4322c25e5757006b8a773d97d0ce15b
parent9f3445252c766053b7a773d75dceb1c1bbfdc6f5 (diff)
downloadtangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar.gz
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar.bz2
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar.lz
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar.xz
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.tar.zst
tangerine-wallet-browser-60f00a950cbe90edda4d9de4a67c3e0c528f6638.zip
notes and clean up
-rw-r--r--library/controller.js162
-rw-r--r--library/controllers/index-db-controller.js4
-rw-r--r--library/sw-core.js20
3 files changed, 7 insertions, 179 deletions
diff --git a/library/controller.js b/library/controller.js
index ba97da93c..bad8d33cd 100644
--- a/library/controller.js
+++ b/library/controller.js
@@ -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')
console.log('outside:open')
const background = new SWcontroller({
diff --git a/library/controllers/index-db-controller.js b/library/controllers/index-db-controller.js
index 8b90db066..4c53e1094 100644
--- a/library/controllers/index-db-controller.js
+++ b/library/controllers/index-db-controller.js
@@ -72,11 +72,7 @@ module.exports = class IndexDbController extends EventEmitter {
}
migrate () {
- // this.migrations
-
// Place holder for future migrations eg:
- this.db.deleteObjectStore('meta')
- this.db.deleteObjectStore('data')
this.db.createObjectStore('dataStore')
}
diff --git a/library/sw-core.js b/library/sw-core.js
index e018dff0f..1afcc3cff 100644
--- a/library/sw-core.js
+++ b/library/sw-core.js
@@ -11,7 +11,6 @@ const PortStream = require('../app/scripts/lib/port-stream.js')
const DbController = require('./controllers/index-db-controller')
-// // all this will go in service worker
const MetamaskController = require('../app/scripts/metamask-controller')
// const extension = require('../app/scripts/lib/extension')
// const LocalStorageStore = require('obs-store/lib/localStorage')
@@ -53,7 +52,7 @@ let diskStore
const dbController = new DbController({
key: STORAGE_KEY,
global: self,
- version: 6,
+ version: 2,
initialState: {
dataStore: {
meta: 2,
@@ -95,6 +94,9 @@ function loadStateFromPersistence() {
return Promise.resolve(data.data)
})
.catch((err) => console.error(err))
+ /*
+ need to get migrations working
+ */
// return asyncQ.waterfall([
// // read from disk
@@ -143,10 +145,11 @@ function setupController (initState, client) {
//
// connect to other contexts
//
+ /*
+ need to write a service worker stream for this
+ */
var connectionStream //= new ParentStream()
SWGlobal.onmessage = (message) => {
-
- debugger
connectRemote(connectionStream, message.origin)
}
@@ -192,12 +195,3 @@ function setupController (initState, client) {
function triggerUi () {
if (!popupIsOpen) notification.show()
}
-
-// function getParentHref(){
-// try {
-// var parentLocation = window.parent.location
-// return parentLocation.hostname + ':' + parentLocation.port
-// } catch (err) {
-// return 'unknown'
-// }
-// }