Improve delete wallet app state reset (#1438)

This commit is contained in:
Honza Rychnovský 2024-05-06 19:29:50 +02:00 committed by GitHub
parent c3cf711ee6
commit 6c3307748a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -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<Boolean> =
fun deleteWalletFlow(activity: Activity): Flow<Boolean> =
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))
}
}
}
}

View File

@ -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)
)
}
}