@@ -6,6 +6,7 @@ import androidx.compose.runtime.setValue
66import androidx.lifecycle.ViewModel
77import androidx.lifecycle.viewModelScope
88import dagger.hilt.android.lifecycle.HiltViewModel
9+ import kotlinx.coroutines.CoroutineDispatcher
910import kotlinx.coroutines.Dispatchers
1011import kotlinx.coroutines.delay
1112import kotlinx.coroutines.flow.MutableSharedFlow
@@ -22,8 +23,10 @@ import kotlinx.coroutines.launch
2223import org.lightningdevkit.ldknode.Event
2324import org.lightningdevkit.ldknode.PaymentId
2425import org.lightningdevkit.ldknode.Txid
26+ import to.bitkit.R
2527import to.bitkit.data.SettingsStore
2628import to.bitkit.data.keychain.Keychain
29+ import to.bitkit.di.BgDispatcher
2730import to.bitkit.env.Env
2831import to.bitkit.ext.WatchResult
2932import to.bitkit.ext.removeSpaces
@@ -44,6 +47,7 @@ import to.bitkit.ui.components.BottomSheetType
4447import to.bitkit.ui.screens.wallets.send.SendRoute
4548import to.bitkit.ui.shared.toast.ToastEventBus
4649import to.bitkit.utils.Logger
50+ import to.bitkit.utils.ResourceProvider
4751import uniffi.bitkitcore.Activity
4852import uniffi.bitkitcore.ActivityFilter
4953import uniffi.bitkitcore.LightningInvoice
@@ -54,12 +58,14 @@ import javax.inject.Inject
5458
5559@HiltViewModel
5660class AppViewModel @Inject constructor(
61+ @BgDispatcher private val bgDispatcher : CoroutineDispatcher ,
5762 private val keychain : Keychain ,
5863 private val scannerService : ScannerService ,
5964 private val lightningService : LightningRepo ,
6065 private val coreService : CoreService ,
6166 private val ldkNodeEventBus : LdkNodeEventBus ,
6267 private val settingsStore : SettingsStore ,
68+ private val resourceProvider : ResourceProvider ,
6369) : ViewModel() {
6470 var splashVisible by mutableStateOf(true )
6571 private set
@@ -811,16 +817,18 @@ class AppViewModel @Inject constructor(
811817 return true
812818 }
813819
814- viewModelScope.launch {
820+ viewModelScope.launch(bgDispatcher) {
815821 val newAttempts = pinAttemptsRemaining.value - 1
816822 keychain.upsertString(Keychain .Key .PIN_ATTEMPTS_REMAINING .name, newAttempts.toString())
817823
818824 if (newAttempts <= 0 ) {
819- // TODO: wipeStorage() & return to onboarding
820825 toast(
821- type = Toast .ToastType .WARNING ,
822- title = " TODO: Wipe App data" ,
826+ type = Toast .ToastType .SUCCESS ,
827+ title = resourceProvider.getString(R .string.security__wiped_title),
828+ description = resourceProvider.getString(R .string.security__wiped_message),
823829 )
830+ delay(250 ) // small delay for UI feedback
831+ mainScreenEffect(MainScreenEffect .WipeStorage )
824832 }
825833 }
826834 return false
@@ -882,6 +890,7 @@ sealed class SendEffect {
882890
883891sealed class MainScreenEffect {
884892 data class NavigateActivityDetail (val activityId : String ) : MainScreenEffect()
893+ data object WipeStorage : MainScreenEffect ()
885894}
886895
887896sealed class SendEvent {
0 commit comments