aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2019-08-22 02:42:14 +0800
committerGitHub <noreply@github.com>2019-08-22 02:42:14 +0800
commitef3859ff775e9f36869fcce80eee388039adb2af (patch)
tree981477e4c56f4adb23ce41b5bea73a20af0b718f /app
parentf9c0bdda3205c27c4e96dae53276eba106e660bc (diff)
downloadtangerine-wallet-browser-ef3859ff775e9f36869fcce80eee388039adb2af.tar.gz
tangerine-wallet-browser-ef3859ff775e9f36869fcce80eee388039adb2af.tar.zst
tangerine-wallet-browser-ef3859ff775e9f36869fcce80eee388039adb2af.zip
Add toggle for incoming transactions (#7049)
Diffstat (limited to 'app')
-rw-r--r--app/_locales/en/messages.json6
-rw-r--r--app/scripts/controllers/incoming-transactions.js58
-rw-r--r--app/scripts/controllers/preferences.js1
3 files changed, 60 insertions, 5 deletions
diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json
index 2b957129d..86bc1397b 100644
--- a/app/_locales/en/messages.json
+++ b/app/_locales/en/messages.json
@@ -1,4 +1,10 @@
{
+ "showIncomingTransactions": {
+ "message": "Show Incoming Transactions"
+ },
+ "showIncomingTransactionsDescription": {
+ "message": "Select this to use Etherscan to show incoming transactions in the transactions list"
+ },
"exposeAccounts": {
"message": "Expose Accounts"
},
diff --git a/app/scripts/controllers/incoming-transactions.js b/app/scripts/controllers/incoming-transactions.js
index 1a970cdfe..032ef8a77 100644
--- a/app/scripts/controllers/incoming-transactions.js
+++ b/app/scripts/controllers/incoming-transactions.js
@@ -56,6 +56,35 @@ class IncomingTransactionsController {
}, opts.initState)
this.store = new ObservableStore(initState)
+ this.preferencesController.store.subscribe(pairwise((prevState, currState) => {
+ const { featureFlags: { showIncomingTransactions: prevShowIncomingTransactions } = {} } = prevState
+ const { featureFlags: { showIncomingTransactions: currShowIncomingTransactions } = {} } = currState
+
+ if (currShowIncomingTransactions === prevShowIncomingTransactions) {
+ return
+ }
+
+ if (prevShowIncomingTransactions && !currShowIncomingTransactions) {
+ this.stop()
+ return
+ }
+
+ this.start()
+ }))
+
+ this.preferencesController.store.subscribe(pairwise(async (prevState, currState) => {
+ const { selectedAddress: prevSelectedAddress } = prevState
+ const { selectedAddress: currSelectedAddress } = currState
+
+ if (currSelectedAddress === prevSelectedAddress) {
+ return
+ }
+
+ await this._update({
+ address: currSelectedAddress,
+ })
+ }))
+
this.networkController.on('networkDidChange', async (newType) => {
const address = this.preferencesController.getSelectedAddress()
await this._update({
@@ -63,14 +92,16 @@ class IncomingTransactionsController {
networkType: newType,
})
})
- this.preferencesController.store.subscribe(async ({ selectedAddress }) => {
- await this._update({
- address: selectedAddress,
- })
- })
}
start () {
+ const { featureFlags = {} } = this.preferencesController.store.getState()
+ const { showIncomingTransactions } = featureFlags
+
+ if (!showIncomingTransactions) {
+ return
+ }
+
this.blockTracker.removeListener('latest', this._onLatestBlock)
this.blockTracker.addListener('latest', this._onLatestBlock)
}
@@ -234,3 +265,20 @@ class IncomingTransactionsController {
}
module.exports = IncomingTransactionsController
+
+function pairwise (fn) {
+ let first = true
+ let cache
+ return (value) => {
+ try {
+ if (first) {
+ first = false
+ return fn(value, value)
+ } else {
+ return fn(cache, value)
+ }
+ } finally {
+ cache = value
+ }
+ }
+}
diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js
index f02708d40..4ed3afb6c 100644
--- a/app/scripts/controllers/preferences.js
+++ b/app/scripts/controllers/preferences.js
@@ -41,6 +41,7 @@ class PreferencesController {
// for convenient testing of pre-release features, and should never
// perform sensitive operations.
featureFlags: {
+ showIncomingTransactions: true,
},
knownMethodData: {},
participateInMetaMetrics: null,