Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/e2e_migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ jobs:
- { name: migration_1-restore, grep: "@migration_1" }
- { name: migration_2-migration, grep: "@migration_2" }
- { name: migration_3-with-passphrase, grep: "@migration_3" }
- { name: migration_4-with-sweep, grep: "@migration_4" }

name: e2e-tests - ${{ matrix.rn_version }} - ${{ matrix.scenario.name }}

Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/to/bitkit/data/SettingsStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ class SettingsStore @Inject constructor(

val data: Flow<SettingsData> = store.data

@Volatile
var restoredMonitoredTypesFromBackup: Boolean = false
private set

suspend fun restoreFromBackup(payload: SettingsBackupV1) =
runCatching {
val data = payload.settings.resetPin()
store.updateData { data }

val monitored = data.addressTypesToMonitor
val selected = data.selectedAddressType
restoredMonitoredTypesFromBackup = monitored.size > 1 ||
(monitored.size == 1 && monitored.first() != selected)
}.onSuccess {
Logger.debug("Restored settings", TAG)
Logger.debug("Restored settings, monitoredFromBackup=$restoredMonitoredTypesFromBackup", context = TAG)
}

suspend fun update(transform: (SettingsData) -> SettingsData) {
Expand Down Expand Up @@ -66,6 +75,7 @@ class SettingsStore @Inject constructor(

suspend fun reset() {
store.updateData { SettingsData() }
restoredMonitoredTypesFromBackup = false
Logger.info("Deleted all user settings data.")
}

Expand Down Expand Up @@ -117,6 +127,9 @@ data class SettingsData(
val coinSelectPreference: CoinSelectionPreference = CoinSelectionPreference.BranchAndBound,
val electrumServer: String = Env.electrumServerUrl,
val rgsServerUrl: String? = Env.ldkRgsServerUrl,
val selectedAddressType: String = "nativeSegwit",
val addressTypesToMonitor: List<String> = listOf("nativeSegwit"),
val pendingRestoreAddressTypePrune: Boolean = false,
)

fun SettingsData.resetPin() = this.copy(
Expand Down
48 changes: 42 additions & 6 deletions app/src/main/java/to/bitkit/models/AddressType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class AddressTypeInfo(
val shortName: String,
val description: String,
val example: String,
val shortExample: String,
)

@Suppress("unused")
Expand All @@ -20,32 +21,36 @@ fun AddressType.addressTypeInfo(): AddressTypeInfo = when (this) {
path = "m/86'/0'/0'/0/0",
name = "Taproot",
shortName = "Taproot",
description = "Taproot Address",
description = "Pay-to-Taproot (bc1px...)",
example = "(bc1px...)",
shortExample = "bc1p...",
)

AddressType.P2WPKH -> AddressTypeInfo(
path = "m/84'/0'/0'/0/0",
name = "Native Segwit Bech32",
shortName = "Native Segwit",
description = "Pay-to-witness-public-key-hash",
example = "(bc1x...)",
description = "Pay-to-witness-public-key-hash (bc1q...)",
example = "(bc1q...)",
shortExample = "bc1q...",
)

AddressType.P2SH -> AddressTypeInfo(
path = "m/49'/0'/0'/0/0",
name = "Nested Segwit",
shortName = "Segwit",
description = "Pay-to-Script-Hash",
shortName = "Nested Segwit",
description = "Pay-to-Script-Hash (3x...)",
example = "(3x...)",
shortExample = "3x...",
)

AddressType.P2PKH -> AddressTypeInfo(
path = "m/44'/0'/0'/0/0",
name = "Legacy",
shortName = "Legacy",
description = "Pay-to-public-key-hash",
description = "Pay-to-public-key-hash (1x...)",
example = "(1x...)",
shortExample = "1x...",
)

else -> AddressTypeInfo(
Expand All @@ -54,6 +59,7 @@ fun AddressType.addressTypeInfo(): AddressTypeInfo = when (this) {
shortName = "Unknown",
description = "Unknown",
example = "",
shortExample = "",
)
}

Expand All @@ -80,3 +86,33 @@ fun AddressType.toDerivationPath(
else -> ""
}
}

fun AddressType.toSettingsString(): String = when (this) {
AddressType.P2TR -> "taproot"
AddressType.P2WPKH -> "nativeSegwit"
AddressType.P2SH -> "nestedSegwit"
AddressType.P2PKH -> "legacy"
else -> "nativeSegwit"
}

fun String.toAddressType(): AddressType? = when (this) {
"taproot" -> AddressType.P2TR
"nativeSegwit" -> AddressType.P2WPKH
"nestedSegwit" -> AddressType.P2SH
"legacy" -> AddressType.P2PKH
else -> null
}

val ALL_ADDRESS_TYPES = listOf(AddressType.P2PKH, AddressType.P2SH, AddressType.P2WPKH, AddressType.P2TR)

val ALL_ADDRESS_TYPE_STRINGS = ALL_ADDRESS_TYPES.map { it.toSettingsString() }

val NATIVE_WITNESS_TYPES = setOf(AddressType.P2WPKH, AddressType.P2TR)

fun String.addressTypeFromAddress(): String? = when {
startsWith("bc1p") || startsWith("tb1p") || startsWith("bcrt1p") -> "taproot"
startsWith("bc1") || startsWith("tb1") || startsWith("bcrt1") -> "nativeSegwit"
startsWith("3") || startsWith("2") -> "nestedSegwit"
startsWith("1") || startsWith("m") || startsWith("n") -> "legacy"
else -> null
}
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/models/BalanceState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class BalanceState(
val totalOnchainSats: ULong = 0uL,
val channelFundableBalance: ULong = 0uL,
val totalLightningSats: ULong = 0uL,
val maxSendLightningSats: ULong = 0uL, // Without account routing fees
val maxSendOnchainSats: ULong = 0uL,
Expand Down
Loading
Loading