diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt index 990ecc9b..cb6649ed 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/common/viewmodel/WalletViewModel.kt @@ -1,6 +1,8 @@ package co.electriccoin.zcash.ui.common.viewmodel +import android.app.Activity import android.app.Application +import android.content.Intent import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import cash.z.ecc.android.bip39.Mnemonics @@ -25,6 +27,7 @@ import cash.z.ecc.android.sdk.tool.DerivationTool import cash.z.ecc.sdk.type.fromResources import co.electriccoin.zcash.global.getInstance import co.electriccoin.zcash.spackle.Twig +import co.electriccoin.zcash.ui.MainActivity import co.electriccoin.zcash.ui.common.ANDROID_STATE_FLOW_TIMEOUT import co.electriccoin.zcash.ui.common.compose.BalanceState import co.electriccoin.zcash.ui.common.extension.throttle @@ -430,7 +433,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application) } } - fun deleteWalletFlow(): Flow = + fun deleteWalletFlow(activity: Activity): Flow = callbackFlow { Twig.info { "Delete wallet: Requested" } @@ -447,11 +450,15 @@ class WalletViewModel(application: Application) : AndroidViewModel(application) } clearAppStateFlow().collect { isAppErased -> - Twig.info { "Delete wallet: Erase SDK result: $isAppErased" } + Twig.info { "Delete wallet: Erase App result: $isAppErased" } if (!isAppErased) { trySend(false) } else { trySend(true) + activity.run { + finish() + startActivity(Intent(this, MainActivity::class.java)) + } } } } diff --git a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/deletewallet/AndroidDeleteWallet.kt b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/deletewallet/AndroidDeleteWallet.kt index f7f9b0e5..e32140c4 100644 --- a/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/deletewallet/AndroidDeleteWallet.kt +++ b/ui-lib/src/main/java/co/electriccoin/zcash/ui/screen/deletewallet/AndroidDeleteWallet.kt @@ -1,6 +1,6 @@ package co.electriccoin.zcash.ui.screen.deletewallet -import android.content.Context +import android.app.Activity import androidx.activity.compose.BackHandler import androidx.activity.viewModels import androidx.compose.material3.SnackbarHostState @@ -23,7 +23,7 @@ internal fun MainActivity.WrapDeleteWallet(goBack: () -> Unit) { val walletRestoringState = walletViewModel.walletRestoringState.collectAsStateWithLifecycle().value WrapDeleteWallet( - this, + activity = this, goBack = goBack, walletRestoringState = walletRestoringState, walletViewModel = walletViewModel, @@ -32,7 +32,7 @@ internal fun MainActivity.WrapDeleteWallet(goBack: () -> Unit) { @Composable internal fun WrapDeleteWallet( - context: Context, + activity: Activity, goBack: () -> Unit, walletRestoringState: WalletRestoringState, walletViewModel: WalletViewModel, @@ -50,14 +50,14 @@ internal fun WrapDeleteWallet( onBack = goBack, onConfirm = { scope.launch { - walletViewModel.deleteWalletFlow().collect { isWalletDeleted -> + walletViewModel.deleteWalletFlow(activity).collect { isWalletDeleted -> if (isWalletDeleted) { Twig.info { "Wallet deleted successfully" } // The app flows move to the Onboarding screens reactively } else { Twig.error { "Wallet deletion failed" } snackbarHostState.showSnackbar( - message = context.getString(R.string.delete_wallet_failed) + message = activity.getString(R.string.delete_wallet_failed) ) } }