From 84b3415b4479eb849b69d77a7e178c67fcaaf3fb Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 29 Mar 2017 10:53:43 -0700 Subject: [PATCH] WIP: lost enital call from dapp to getAccounts --- app/scripts/controllers/preferences.js | 1 + app/scripts/metamask-controller.js | 1 + library/controller.js | 12 ++---------- library/example/index.js | 9 +++++---- library/index.js | 5 ++--- library/lib/setup-provider.js | 4 ++-- library/popup.js | 5 ----- library/sw-core.js | 1 + 8 files changed, 14 insertions(+), 24 deletions(-) diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index c7f675a41..dbd5aeaaa 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -24,6 +24,7 @@ class PreferencesController { } getSelectedAddress (_address) { + console.log('PREFERNCES: getSelectedAddress was called') return this.store.getState().selectedAddress } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 0393caeab..db80d5f1b 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -165,6 +165,7 @@ module.exports = class MetamaskController extends EventEmitter { rpcUrl: this.configManager.getCurrentRpcAddress(), // account mgmt getAccounts: (cb) => { + console.log('METAMASK CONTROLLER: getAccounts was called') let selectedAddress = this.preferencesController.getSelectedAddress() let result = selectedAddress ? [selectedAddress] : [] cb(null, result) diff --git a/library/controller.js b/library/controller.js index cbba9584a..c3f2fa5fa 100644 --- a/library/controller.js +++ b/library/controller.js @@ -6,17 +6,17 @@ const background = new SWcontroller({ fileName: '/popup/sw-build.js', }) -background.on('ready', (readSw) => { +background.on('ready', (_) => { // var inpageProvider = new MetamaskInpageProvider(SwStream(background.controller)) let pageStream = new ParentStream() let swStream = SwStream(background.controller) pageStream.pipe(swStream).pipe(pageStream) + console.log('********************WOOP*********************') }) background.on('error', console.error) background.startWorker() -console.log('hello from controller') /* const urlUtil = require('url') const extend = require('xtend') @@ -167,14 +167,6 @@ function initializeZeroClient() { window.localStorage[STORAGE_KEY] = JSON.stringify(data) } - function getParentHref(){ - try { - var parentLocation = window.parent.location - return parentLocation.hostname + ':' + parentLocation.port - } catch (err) { - return 'unknown' - } - } } diff --git a/library/example/index.js b/library/example/index.js index 329302a4d..aae7ccd19 100644 --- a/library/example/index.js +++ b/library/example/index.js @@ -1,4 +1,5 @@ window.addEventListener('load', web3Detect) +window.addEventListener('message', console.warn) function web3Detect() { if (global.web3) { @@ -12,18 +13,18 @@ function web3Detect() { function startApp(){ console.log('app started') - var primaryAccount = null + var primaryAccount console.log('getting main account...') - web3.eth.getAccounts(function(err, addresses){ - if (err) throw err + web3.eth.getAccounts((err, addresses) => { + if (err) console.error(err) console.log('set address', addresses[0]) - debugger primaryAccount = addresses[0] }) document.querySelector('.action-button-1').addEventListener('click', function(){ console.log('saw click') console.log('sending tx') + primaryAccount web3.eth.sendTransaction({ from: primaryAccount, to: primaryAccount, diff --git a/library/index.js b/library/index.js index 44ee401d8..3503d15cc 100644 --- a/library/index.js +++ b/library/index.js @@ -5,13 +5,12 @@ const setupProvider = require('./lib/setup-provider.js') // setup web3 // var provider = setupProvider() -hijackProvider(provider) +// hijackProvider(provider) var web3 = new Web3(provider) web3.setProvider = function(){ console.log('MetaMask - overrode web3.setProvider') } -console.log('metamask lib hijacked provider') - +// // // export web3 // diff --git a/library/lib/setup-provider.js b/library/lib/setup-provider.js index 68be99c9e..a99fc1c68 100644 --- a/library/lib/setup-provider.js +++ b/library/lib/setup-provider.js @@ -10,15 +10,15 @@ function getProvider(){ console.log('MetaMask ZeroClient - using environmental web3 provider') return global.web3.currentProvider } - console.log('MetaMask ZeroClient - injecting zero-client iframe!') var iframeStream = setupIframe({ - zeroClientProvider: 'http://127.0.0.1:9001', + zeroClientProvider: 'http://localhost:9001', sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], container: document.body, }) var inpageProvider = new MetamaskInpageProvider(iframeStream) + console.log('ABOUT TO RETURN INPAGE') return inpageProvider } diff --git a/library/popup.js b/library/popup.js index d956dc0b1..bb7051055 100644 --- a/library/popup.js +++ b/library/popup.js @@ -13,11 +13,6 @@ injectCss(css) var name = 'popup' window.METAMASK_UI_TYPE = name -var iframeStream = setupIframe({ - zeroClientProvider: 'http://localhost:9001', - sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], - container: document.body, -}) console.log('outside:open') const background = new SWcontroller({ diff --git a/library/sw-core.js b/library/sw-core.js index 1d31b2acd..4d95898d9 100644 --- a/library/sw-core.js +++ b/library/sw-core.js @@ -116,6 +116,7 @@ function setupController (initState, client) { need to write a service worker stream for this */ connectionListener.on('remote', (portStream, messageEvent) => { + console.log('REMOTE CONECTION FOUND***********') connectRemote(portStream, messageEvent.origin) })