Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/java/to/bitkit/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ data class SettingsData(
val electrumServer: ElectrumServer = Env.defaultElectrumServer,
val rgsServerUrl: String? = Env.ldkRgsServerUrl,
)

fun SettingsData.resetPin() = this.copy(
isPinEnabled = false,
isPinOnLaunchEnabled = true,
isPinOnIdleEnabled = false,
isPinForPaymentsEnabled = false,
isBiometricEnabled = false,
)
5 changes: 3 additions & 2 deletions app/src/main/java/to/bitkit/repositories/BackupsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import to.bitkit.data.WidgetsData
import to.bitkit.data.WidgetsStore
import to.bitkit.data.backup.VssBackupsClient
import to.bitkit.data.backup.VssObjectInfo
import to.bitkit.data.resetPin
import to.bitkit.di.BgDispatcher
import to.bitkit.di.json
import to.bitkit.ext.formatPlural
Expand Down Expand Up @@ -243,7 +244,7 @@ class BackupsRepo @Inject constructor(

private suspend fun getBackupDataBytes(category: BackupCategory): ByteArray = when (category) {
BackupCategory.SETTINGS -> {
val data = settingsStore.data.first()
val data = settingsStore.data.first().resetPin()
json.encodeToString(data).toByteArray()
}

Expand Down Expand Up @@ -295,7 +296,7 @@ class BackupsRepo @Inject constructor(

return@withContext try {
performRestore(BackupCategory.SETTINGS) { dataBytes ->
val parsed = json.decodeFromString<SettingsData>(String(dataBytes))
val parsed = json.decodeFromString<SettingsData>(String(dataBytes)).resetPin()
settingsStore.update { parsed }
}
performRestore(BackupCategory.WIDGETS) { dataBytes ->
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.lightningdevkit.ldknode.Txid
import to.bitkit.R
import to.bitkit.data.SettingsStore
import to.bitkit.data.keychain.Keychain
import to.bitkit.data.resetPin
import to.bitkit.di.BgDispatcher
import to.bitkit.env.Env
import to.bitkit.ext.WatchResult
Expand Down Expand Up @@ -1132,13 +1133,7 @@ class AppViewModel @Inject constructor(
fun removePin() {
viewModelScope.launch(bgDispatcher) {
settingsStore.update {
it.copy(
isPinEnabled = false,
isPinOnLaunchEnabled = true,
isPinOnIdleEnabled = false,
isPinForPaymentsEnabled = false,
isBiometricEnabled = false,
)
it.resetPin()
}
keychain.delete(Keychain.Key.PIN.name)
keychain.upsertString(Keychain.Key.PIN_ATTEMPTS_REMAINING.name, Env.PIN_ATTEMPTS.toString())
Expand Down
Loading