Repository: horizontalsystems/unstoppable-wallet-android
Issue: Transactions Tab: displays transactions from previously restored accounts

That bug was spotted on IOS first. I heaven't tested it on Android as such but it should be an issue on Android as well. https://github.com/horizontalsystems/unstoppable-wallet-ios/issues/809



Been testing EOS restore feature and have repeatedly noticed the case when the transactions list for EOS displayed transactions from both account but should have been one.

Upon further testing it seems to be a bug with GUI cache. The GUI controller cache is not being cleared upon unlinking. If the users adds a new account before the GUI is cleared then a transactions list for the coin will be displaying transactions from the newly linked as well as the unlinked accounts.

Killing the app displays the GUI properly

Changed files:
app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsLoader.kt
app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/PoolRepo.kt
app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionRecordDataSource.kt
app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsPresenter.kt

diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/PoolRepo.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/PoolRepo.kt
index abd11ae64..171a0f0c9 100644
--- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/PoolRepo.kt
+++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/PoolRepo.kt
@@ -14,14 +14,6 @@ class PoolRepo {
     private var activePoolCoinCodes = listOf<Coin>()
 
     fun activatePools(coinCodes: List<Coin>) {
-
-        // remove pools for unused coins
-        pools.map { it.key }.forEach { poolCoin ->
-            if (!coinCodes.contains(poolCoin)) {
-                pools.remove(poolCoin)
-            }
-        }
-
         coinCodes.forEach { coinCode ->
             if (!pools.containsKey(coinCode)) {
                 pools[coinCode] = Pool(Pool.State(coinCode))
@@ -31,6 +23,10 @@ class PoolRepo {
         this.activePoolCoinCodes = coinCodes
     }
 
+    fun deactivatePools(coins: List<Coin>) {
+        coins.forEach { pools.remove(it) }
+    }
+
     fun getPool(coin: Coin): Pool? {
         return pools[coin]
     }
diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionRecordDataSource.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionRecordDataSource.kt
index 9103e6b4f..bd4f5f150 100644
--- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionRecordDataSource.kt
+++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionRecordDataSource.kt
@@ -103,5 +103,14 @@ class TransactionRecordDataSource(
         poolRepo.activatePools(coins)
         itemsDataSource.clear()
     }
+
+    fun handleUpdatedCoins(coins: List<Coin>) {
+        val unusedCoins = poolRepo.allPools.map { it.coin }.filter { !coins.contains(it) }
+
+        poolRepo.deactivatePools(unusedCoins)
+
+        setCoinCodes(coins)
+    }
+
 }
 
diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsLoader.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsLoader.kt
index 19f4317d6..c00fea5cd 100644
--- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsLoader.kt
+++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsLoader.kt
@@ -29,6 +29,10 @@ class TransactionsLoader(private val dataSource: TransactionRecordDataSource) {
         dataSource.setCoinCodes(coins)
     }
 
+    fun handleUpdate(coins: List<Coin>) {
+        dataSource.handleUpdatedCoins(coins)
+    }
+
     fun loadNext(initial: Boolean = false) {
         if (loading) return
         loading = true
diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsPresenter.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsPresenter.kt
index fb02c6f97..8e654ee9f 100644
--- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsPresenter.kt
+++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/transactions/TransactionsPresenter.kt
@@ -61,8 +61,6 @@ class TransactionsPresenter(
     override fun onUpdateCoinsData(allCoinData: List<Triple<Coin, Int, Int?>>) {
         val coins = allCoinData.map { it.first }
 
-        loader.setCoinCodes(coins)
-
         allCoinData.forEach { (coinCode, confirmationThreshold, lastBlockHeight) ->
             metadataDataSource.setConfirmationThreshold(confirmationThreshold, coinCode)
             lastBlockHeight?.let {
@@ -70,7 +68,7 @@ class TransactionsPresenter(
             }
         }
 
-        loader.loadNext(true)
+        interactor.fetchLastBlockHeights()
 
         val filters = when {
             coins.size < 2 -> listOf()
@@ -79,7 +77,8 @@ class TransactionsPresenter(
 
         view?.showFilters(filters)
 
-        interactor.fetchLastBlockHeights()
+        loader.handleUpdate(coins)
+        loader.loadNext(true)
     }
 
     override fun onUpdateSelectedCoinCodes(selectedCoins: List<Coin>) {