diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-08-16 01:50:53 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-08-16 01:50:53 +0800 |
commit | 6895d330ffdf0f071e4df3fb9da47f2ea6fc7491 (patch) | |
tree | 64e170d2bd39434674e0c92bb637fd1d2c57debc /app | |
parent | cb0c1f25bacab5f6ee9348dbc3dc112f4d77560f (diff) | |
parent | 271e3c4fdf1a86a989d642c18815d7f6537ed951 (diff) | |
download | tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar.gz tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar.bz2 tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar.lz tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar.xz tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.tar.zst tangerine-wallet-browser-6895d330ffdf0f071e4df3fb9da47f2ea6fc7491.zip |
Merge master.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/background.js | 1 | ||||
-rw-r--r-- | app/scripts/config.js | 5 | ||||
-rw-r--r-- | app/scripts/contentscript.js | 2 | ||||
-rw-r--r-- | app/scripts/inpage.js | 2 | ||||
-rw-r--r-- | app/scripts/lib/auto-reload.js | 2 | ||||
-rw-r--r-- | app/scripts/lib/config-manager.js | 12 | ||||
-rw-r--r-- | app/scripts/lib/ensnare.js | 24 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 9 | ||||
-rw-r--r-- | app/scripts/lib/inpage-provider.js | 47 | ||||
-rw-r--r-- | app/scripts/lib/local-message-stream.js | 56 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 10 |
11 files changed, 30 insertions, 140 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 34c994ab7..e04309e74 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -13,6 +13,7 @@ const extension = require('./lib/extension') const STORAGE_KEY = 'metamask-config' + const controller = new MetamaskController({ // User confirmation callbacks: showUnconfirmedMessage, diff --git a/app/scripts/config.js b/app/scripts/config.js index 5f6ffd936..04e2907d4 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -1,14 +1,13 @@ const MAINET_RPC_URL = 'https://mainnet.infura.io/' const TESTNET_RPC_URL = 'https://morden.infura.io/' const DEFAULT_RPC_URL = TESTNET_RPC_URL -const CLASSIC_RPC_URL = 'https://mainnet-nf.infura.io/' + +global.METAMASK_DEBUG = false module.exports = { network: { default: DEFAULT_RPC_URL, mainnet: MAINET_RPC_URL, testnet: TESTNET_RPC_URL, - classic: CLASSIC_RPC_URL, }, } - diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1eb04059d..de2cf263b 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -1,4 +1,4 @@ -const LocalMessageDuplexStream = require('./lib/local-message-stream.js') +const LocalMessageDuplexStream = require('post-message-stream') const PortStream = require('./lib/port-stream.js') const ObjectMultiplex = require('./lib/obj-multiplex') const extension = require('./lib/extension') diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 055235671..7c508c66f 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -1,7 +1,7 @@ /*global Web3*/ cleanContextForImports() require('web3/dist/web3.min.js') -const LocalMessageDuplexStream = require('./lib/local-message-stream.js') +const LocalMessageDuplexStream = require('post-message-stream') const setupDappAutoReload = require('./lib/auto-reload.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index b45f02009..c4c8053f0 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -1,5 +1,5 @@ const once = require('once') -const ensnare = require('./ensnare.js') +const ensnare = require('ensnare') module.exports = setupDappAutoReload diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 49eb7be4f..f3164ec09 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -5,7 +5,6 @@ const rp = require('request-promise') const TESTNET_RPC = MetamaskConfig.network.testnet const MAINNET_RPC = MetamaskConfig.network.mainnet -const CLASSIC_RPC = MetamaskConfig.network.classic /* The config-manager is a convenience object * wrapping a pojo-migrator. @@ -146,9 +145,6 @@ ConfigManager.prototype.getCurrentRpcAddress = function () { case 'testnet': return TESTNET_RPC - case 'classic': - return CLASSIC_RPC - default: return provider && provider.rpcTarget ? provider.rpcTarget : TESTNET_RPC } @@ -320,9 +316,13 @@ ConfigManager.prototype.getConversionDate = function () { return ('conversionDate' in data) && data.conversionDate } -ConfigManager.prototype.setShouldntShowWarning = function (confirmed) { +ConfigManager.prototype.setShouldntShowWarning = function () { var data = this.getData() - data.isEthConfirmed = confirmed + if (data.isEthConfirmed) { + data.isEthConfirmed = !data.isEthConfirmed + } else { + data.isEthConfirmed = true + } this.setData(data) } diff --git a/app/scripts/lib/ensnare.js b/app/scripts/lib/ensnare.js deleted file mode 100644 index 6100f7c79..000000000 --- a/app/scripts/lib/ensnare.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = ensnare - -// creates a proxy object that calls cb everytime the obj's properties/fns are accessed -function ensnare (obj, cb) { - var proxy = {} - Object.keys(obj).forEach(function (key) { - var val = obj[key] - switch (typeof val) { - case 'function': - proxy[key] = function () { - cb() - val.apply(obj, arguments) - } - return - default: - Object.defineProperty(proxy, key, { - get: function () { cb(); return obj[key] }, - set: function (val) { cb(); obj[key] = val; return val }, - }) - return - } - }) - return proxy -} diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 9d8012d54..3272f2d1a 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -156,8 +156,9 @@ IdentityStore.prototype.getNetwork = function (err) { this._currentState.network = 'loading' return this._didUpdate() } - - console.log('web3.getNetwork returned ' + network) + if (global.METAMASK_DEBUG) { + console.log('web3.getNetwork returned ' + network) + } this._currentState.network = network this._didUpdate() }) @@ -478,7 +479,9 @@ IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey) keyStore.generateNewAddress(derivedKey, 3) configManager.setWallet(keyStore.serialize()) - console.log('restored from seed. saved to keystore') + if (global.METAMASK_DEBUG) { + console.log('restored from seed. saved to keystore') + } return keyStore } diff --git a/app/scripts/lib/inpage-provider.js b/app/scripts/lib/inpage-provider.js index e387be895..b3ed3d9e2 100644 --- a/app/scripts/lib/inpage-provider.js +++ b/app/scripts/lib/inpage-provider.js @@ -1,9 +1,7 @@ -const HttpProvider = require('web3/lib/web3/httpprovider') const Streams = require('mississippi') const ObjectMultiplex = require('./obj-multiplex') const StreamProvider = require('web3-stream-provider') const RemoteStore = require('./remote-store.js').RemoteStore -const MetamaskConfig = require('../config.js') module.exports = MetamaskInpageProvider @@ -27,13 +25,6 @@ function MetamaskInpageProvider (connectionStream) { }) self.publicConfigStore = publicConfigStore - // connect to sync provider - self.syncProvider = createSyncProvider(publicConfigStore.get('provider')) - // subscribe to publicConfig to update the syncProvider on change - publicConfigStore.subscribe(function (state) { - self.syncProvider = createSyncProvider(state.provider) - }) - // connect to async provider var asyncProvider = new StreamProvider() Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) { @@ -48,9 +39,9 @@ function MetamaskInpageProvider (connectionStream) { MetamaskInpageProvider.prototype.send = function (payload) { const self = this + let selectedAddress - - var result = null + let result = null switch (payload.method) { case 'eth_accounts': @@ -65,9 +56,10 @@ MetamaskInpageProvider.prototype.send = function (payload) { result = selectedAddress || '0x0000000000000000000000000000000000000000' break - // fallback to normal rpc + // throw not-supported Error default: - return self.syncProvider.send(payload) + var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#all-async---think-of-metamask-as-a-light-client for details.' + throw new Error(message) } @@ -89,35 +81,6 @@ MetamaskInpageProvider.prototype.isConnected = function () { // util -function createSyncProvider (providerConfig) { - providerConfig = providerConfig || {} - let syncProviderUrl - - if (providerConfig.rpcTarget) { - syncProviderUrl = providerConfig.rpcTarget - } else { - switch (providerConfig.type) { - case 'testnet': - syncProviderUrl = MetamaskConfig.network.testnet - break - case 'mainnet': - syncProviderUrl = MetamaskConfig.network.mainnet - break - default: - syncProviderUrl = MetamaskConfig.network.default - } - } - - const provider = new HttpProvider(syncProviderUrl) - // Stubbing out the send method to throw on sync methods: - provider.send = function() { - var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq#all-async---think-of-metamask-as-a-light-client for details.' - throw new Error(message) - } - - return provider -} - function remoteStoreWithLocalStorageCache (storageKey) { // read local cache var initState = JSON.parse(localStorage[storageKey] || '{}') diff --git a/app/scripts/lib/local-message-stream.js b/app/scripts/lib/local-message-stream.js deleted file mode 100644 index 821e51046..000000000 --- a/app/scripts/lib/local-message-stream.js +++ /dev/null @@ -1,56 +0,0 @@ -const Duplex = require('readable-stream').Duplex -const inherits = require('util').inherits - -module.exports = LocalMessageDuplexStream - -inherits(LocalMessageDuplexStream, Duplex) - -function LocalMessageDuplexStream (opts) { - Duplex.call(this, { - objectMode: true, - }) - - // this._origin = opts.origin - this._name = opts.name - this._target = opts.target - - // console.log('LocalMessageDuplexStream ('+this._name+') - initialized...') - window.addEventListener('message', this._onMessage.bind(this), false) -} - -// private - -LocalMessageDuplexStream.prototype._onMessage = function (event) { - var msg = event.data - // console.log('LocalMessageDuplexStream ('+this._name+') - heard message...', event) - // validate message - if (event.origin !== location.origin) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (event.origin !== location.origin) ') - if (typeof msg !== 'object') return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (typeof msg !== "object") ') - if (msg.target !== this._name) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (msg.target !== this._name) ', msg.target, this._name) - if (!msg.data) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (!msg.data) ') - // console.log('LocalMessageDuplexStream ('+this._name+') - accepted', msg.data) - // forward message - try { - this.push(msg.data) - } catch (err) { - this.emit('error', err) - } -} - -// stream plumbing - -LocalMessageDuplexStream.prototype._read = noop - -LocalMessageDuplexStream.prototype._write = function (data, encoding, cb) { - // console.log('LocalMessageDuplexStream ('+this._name+') - sending message...') - var message = { - target: this._target, - data: data, - } - window.postMessage(message, location.origin) - cb() -} - -// util - -function noop () {} diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b5052e438..6dbc5e50e 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -99,7 +99,9 @@ module.exports = class MetamaskController { function logger (err, request, response) { if (err) return console.error(err) if (!request.isMetamaskInternal) { - console.log(`RPC (${originDomain}):`, request, '->', response) + if (global.METAMASK_DEBUG) { + console.log(`RPC (${originDomain}):`, request, '->', response) + } if (response.error) { console.error('Error in RPC response:\n', response.error) } @@ -223,7 +225,9 @@ module.exports = class MetamaskController { // Log blocks processBlock (block) { - console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) + if (global.METAMASK_DEBUG) { + console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) + } this.verifyNetwork() } @@ -274,7 +278,7 @@ module.exports = class MetamaskController { agreeToEthWarning (cb) { try { - this.configManager.setShouldntShowWarning(true) + this.configManager.setShouldntShowWarning() cb() } catch (e) { cb(e) |