aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-08-16 01:50:53 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-08-16 01:50:53 +0800
commit6895d330ffdf0f071e4df3fb9da47f2ea6fc7491 (patch)
tree64e170d2bd39434674e0c92bb637fd1d2c57debc /app/scripts/lib
parentcb0c1f25bacab5f6ee9348dbc3dc112f4d77560f (diff)
parent271e3c4fdf1a86a989d642c18815d7f6537ed951 (diff)
downloadtangerine-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/scripts/lib')
-rw-r--r--app/scripts/lib/auto-reload.js2
-rw-r--r--app/scripts/lib/config-manager.js12
-rw-r--r--app/scripts/lib/ensnare.js24
-rw-r--r--app/scripts/lib/idStore.js9
-rw-r--r--app/scripts/lib/inpage-provider.js47
-rw-r--r--app/scripts/lib/local-message-stream.js56
6 files changed, 18 insertions, 132 deletions
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 () {}