@@ -6,6 +6,7 @@ import com.gemwallet.android.cases.wallet.DeleteWallet
66import com.gemwallet.android.data.repositoreis.session.SessionRepository
77import com.wallet.core.primitives.WalletType
88import kotlinx.coroutines.Dispatchers
9+ import kotlinx.coroutines.async
910import kotlinx.coroutines.flow.firstOrNull
1011import kotlinx.coroutines.withContext
1112import 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