Skip to content

Commit 6799acc

Browse files
committed
Fix wallet delete
1 parent 64be2eb commit 6799acc

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

data/repositories/src/main/kotlin/com/gemwallet/android/data/repositoreis/wallets/DeleteWalletOperator.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.gemwallet.android.cases.wallet.DeleteWallet
66
import com.gemwallet.android.data.repositoreis.session.SessionRepository
77
import com.wallet.core.primitives.WalletType
88
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.async
910
import kotlinx.coroutines.flow.firstOrNull
1011
import kotlinx.coroutines.withContext
1112
import javax.inject.Inject
@@ -25,32 +26,35 @@ class DeleteWalletOperator @Inject constructor(
2526
onBoard: () -> Unit,
2627
onComplete: () -> Unit
2728
) = withContext(Dispatchers.IO) {
29+
val wallets = walletsRepository.getAll().firstOrNull()?.filter { it.id != walletId } ?: emptyList()
30+
async { walletsRepository.getAll().firstOrNull()?.let { syncSubscription.syncSubscription(it) } }
31+
2832
val wallet = walletsRepository.getWallet(walletId).firstOrNull() ?: return@withContext
2933
if (!walletsRepository.removeWallet(walletId = walletId)) {
3034
return@withContext
3135
}
32-
if (wallet.type == WalletType.multicoin) {
36+
if (wallet.type != WalletType.view) {
3337
if (!deleteKeyStoreOperator(walletId)) {
3438
return@withContext
3539
}
3640
}
37-
if (currentWalletId == walletId) {
38-
val wallets = walletsRepository.getAll().firstOrNull() ?: emptyList()
41+
42+
val callback: () -> Unit = if (currentWalletId == walletId) {
3943
val wallet = wallets.sortedBy { it.type }.minByOrNull { it.index }
4044

4145
if (wallet == null) {
4246
sessionRepository.reset()
43-
withContext(Dispatchers.Main) {
44-
onBoard()
45-
}
47+
onBoard
4648
} else {
4749
sessionRepository.setWallet(wallet)
50+
onComplete
4851
}
52+
} else {
53+
onComplete
4954
}
50-
walletsRepository.getAll().firstOrNull()?.let { syncSubscription.syncSubscription(it) }
5155

5256
withContext(Dispatchers.Main) {
53-
onComplete()
57+
callback()
5458
}
5559
}
5660
}

0 commit comments

Comments
 (0)