@@ -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
@@ -70,11 +76,11 @@ class AppViewModel @Inject constructor(
7076 private val _sendUiState = MutableStateFlow (SendUiState ())
7177 val sendUiState = _sendUiState .asStateFlow()
7278
73- private val _sendEffect = MutableSharedFlow <SendEffect >(replay = 0 , extraBufferCapacity = 1 )
79+ private val _sendEffect = MutableSharedFlow <SendEffect >(extraBufferCapacity = 1 )
7480 val sendEffect = _sendEffect .asSharedFlow()
7581 private fun setSendEffect (effect : SendEffect ) = viewModelScope.launch { _sendEffect .emit(effect) }
7682
77- private val _mainScreenEffect = MutableSharedFlow <MainScreenEffect >(replay = 0 , extraBufferCapacity = 1 )
83+ private val _mainScreenEffect = MutableSharedFlow <MainScreenEffect >(extraBufferCapacity = 1 )
7884 val mainScreenEffect = _mainScreenEffect .asSharedFlow()
7985 private fun mainScreenEffect (effect : MainScreenEffect ) = viewModelScope.launch { _mainScreenEffect .emit(effect) }
8086
@@ -820,16 +826,18 @@ class AppViewModel @Inject constructor(
820826 return true
821827 }
822828
823- viewModelScope.launch {
829+ viewModelScope.launch(bgDispatcher) {
824830 val newAttempts = pinAttemptsRemaining.value - 1
825831 keychain.upsertString(Keychain .Key .PIN_ATTEMPTS_REMAINING .name, newAttempts.toString())
826832
827833 if (newAttempts <= 0 ) {
828- // TODO: wipeStorage() & return to onboarding
829834 toast(
830- type = Toast .ToastType .WARNING ,
831- title = " TODO: Wipe App data" ,
835+ type = Toast .ToastType .SUCCESS ,
836+ title = resourceProvider.getString(R .string.security__wiped_title),
837+ description = resourceProvider.getString(R .string.security__wiped_message),
832838 )
839+ delay(250 ) // small delay for UI feedback
840+ mainScreenEffect(MainScreenEffect .WipeStorage )
833841 }
834842 }
835843 return false
@@ -892,6 +900,7 @@ sealed class SendEffect {
892900
893901sealed class MainScreenEffect {
894902 data class NavigateActivityDetail (val activityId : String ) : MainScreenEffect()
903+ data object WipeStorage : MainScreenEffect ()
895904}
896905
897906sealed class SendEvent {
0 commit comments