aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/controllers
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-05 02:45:22 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-05 02:45:22 +0800
commit89a4fef1e4043323c89bf8aea8600a16353c4d1b (patch)
tree2305525899aa31dd80c3d6bfcfadb6de4cfda783 /app/scripts/controllers
parentfa3df576bcf879904b303c4ed1015d27db64642d (diff)
parentc4cb371ce8ddad10d575b4ddb6cb85fe4689ca59 (diff)
downloadtangerine-wallet-browser-89a4fef1e4043323c89bf8aea8600a16353c4d1b.tar.gz
tangerine-wallet-browser-89a4fef1e4043323c89bf8aea8600a16353c4d1b.tar.zst
tangerine-wallet-browser-89a4fef1e4043323c89bf8aea8600a16353c4d1b.zip
Merge branch 'master' into transactionControllerRefractor
Diffstat (limited to 'app/scripts/controllers')
-rw-r--r--app/scripts/controllers/blacklist.js58
-rw-r--r--app/scripts/controllers/infura.js16
-rw-r--r--app/scripts/controllers/transactions.js3
3 files changed, 59 insertions, 18 deletions
diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js
new file mode 100644
index 000000000..7e01fa386
--- /dev/null
+++ b/app/scripts/controllers/blacklist.js
@@ -0,0 +1,58 @@
+const ObservableStore = require('obs-store')
+const extend = require('xtend')
+const PhishingDetector = require('eth-phishing-detect/src/detector')
+
+// compute phishing lists
+const PHISHING_DETECTION_CONFIG = require('eth-phishing-detect/src/config.json')
+// every ten minutes
+const POLLING_INTERVAL = 10 * 60 * 1000
+
+class BlacklistController {
+
+ constructor (opts = {}) {
+ const initState = extend({
+ phishing: PHISHING_DETECTION_CONFIG,
+ }, opts.initState)
+ this.store = new ObservableStore(initState)
+ // phishing detector
+ this._phishingDetector = null
+ this._setupPhishingDetector(initState.phishing)
+ // polling references
+ this._phishingUpdateIntervalRef = null
+ }
+
+ //
+ // PUBLIC METHODS
+ //
+
+ checkForPhishing (hostname) {
+ if (!hostname) return false
+ const { result } = this._phishingDetector.check(hostname)
+ return result
+ }
+
+ async updatePhishingList () {
+ const response = await fetch('https://api.infura.io/v2/blacklist')
+ const phishing = await response.json()
+ this.store.updateState({ phishing })
+ this._setupPhishingDetector(phishing)
+ return phishing
+ }
+
+ scheduleUpdates () {
+ if (this._phishingUpdateIntervalRef) return
+ this._phishingUpdateIntervalRef = setInterval(() => {
+ this.updatePhishingList()
+ }, POLLING_INTERVAL)
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ _setupPhishingDetector (config) {
+ this._phishingDetector = new PhishingDetector(config)
+ }
+}
+
+module.exports = BlacklistController
diff --git a/app/scripts/controllers/infura.js b/app/scripts/controllers/infura.js
index 97b2ab7e3..10adb1004 100644
--- a/app/scripts/controllers/infura.js
+++ b/app/scripts/controllers/infura.js
@@ -1,16 +1,14 @@
const ObservableStore = require('obs-store')
const extend = require('xtend')
-const recentBlacklist = require('etheraddresslookup/blacklists/domains.json')
// every ten minutes
-const POLLING_INTERVAL = 300000
+const POLLING_INTERVAL = 10 * 60 * 1000
class InfuraController {
constructor (opts = {}) {
const initState = extend({
infuraNetworkStatus: {},
- blacklist: recentBlacklist,
}, opts.initState)
this.store = new ObservableStore(initState)
}
@@ -32,24 +30,12 @@ class InfuraController {
})
}
- updateLocalBlacklist () {
- return fetch('https://api.infura.io/v1/blacklist')
- .then(response => response.json())
- .then((parsedResponse) => {
- this.store.updateState({
- blacklist: parsedResponse,
- })
- return parsedResponse
- })
- }
-
scheduleInfuraNetworkCheck () {
if (this.conversionInterval) {
clearInterval(this.conversionInterval)
}
this.conversionInterval = setInterval(() => {
this.checkInfuraNetworkStatus()
- this.updateLocalBlacklist()
}, POLLING_INTERVAL)
}
}
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index a652c3278..498cac9af 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -6,7 +6,6 @@ const ethUtil = require('ethereumjs-util')
const EthQuery = require('ethjs-query')
const TxProviderUtil = require('../lib/tx-utils')
const PendingTransactionUtils = require('../lib/pending-tx-watchers')
-const getStack = require('../lib/util').getStack
const createId = require('../lib/random-id')
const NonceTracker = require('../lib/nonce-tracker')
@@ -125,8 +124,6 @@ module.exports = class TransactionController extends EventEmitter {
const txMetaForHistory = clone(txMeta)
// dont include previous history in this snapshot
delete txMetaForHistory.history
- // add stack to help understand why tx was updated
- txMetaForHistory.stack = getStack()
// add snapshot to tx history
if (!txMeta.history) txMeta.history = []
txMeta.history.push(txMetaForHistory)