Skip to content

Commit db68175

Browse files
committed
Fix comments
1 parent 8c82b68 commit db68175

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

app/src/main/java/to/bitkit/services/MigrationService.kt

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ class MigrationService @Inject constructor(
8383
_isShowingMigrationLoading.value = value
8484
}
8585

86-
var pendingChannelMigration: PendingChannelMigration? = null
86+
@Volatile
87+
private var pendingChannelMigration: PendingChannelMigration? = null
88+
89+
fun consumePendingChannelMigration(): PendingChannelMigration? {
90+
return pendingChannelMigration.also { pendingChannelMigration = null }
91+
}
8792

8893
private val rnNetworkString: String
8994
get() = when (Env.network) {
@@ -97,7 +102,14 @@ class MigrationService @Inject constructor(
97102
get() = File(context.filesDir, "ldk")
98103

99104
private val rnLdkAccountPath: File
100-
get() = File(rnLdkBasePath, "${Companion.RN_WALLET_NAME}${rnNetworkString}ldkaccountv3")
105+
get() {
106+
val accountName = buildString {
107+
append(RN_WALLET_NAME)
108+
append(rnNetworkString)
109+
append("ldkaccountv3")
110+
}
111+
return File(rnLdkBasePath, accountName)
112+
}
101113

102114
private val rnMmkvPath: File
103115
get() = File(context.filesDir, "mmkv/mmkv.default")
@@ -281,7 +293,9 @@ class MigrationService @Inject constructor(
281293
} else {
282294
markMigrationChecked()
283295
setShowingMigrationLoading(false)
284-
throw to.bitkit.utils.AppError("RN keychain data not found")
296+
throw to.bitkit.utils.AppError(
297+
"Migration data unavailable. Please restore your wallet using your recovery phrase."
298+
)
285299
}
286300
} catch (e: Exception) {
287301
Logger.error("RN migration failed: $e", e, context = TAG)
@@ -295,28 +309,21 @@ class MigrationService @Inject constructor(
295309
val mnemonic = loadStringFromRNKeychain(RNKeychainKey.MNEMONIC)
296310

297311
if (mnemonic.isNullOrEmpty()) {
298-
throw to.bitkit.utils.AppError(buildMnemonicNotFoundErrorMessage())
312+
throw to.bitkit.utils.AppError(
313+
"Migration data unavailable. Please restore your wallet using your recovery phrase."
314+
)
299315
}
300316

301317
val words = mnemonic.split(" ").filter { it.isNotBlank() }
302318
if (words.size != MNEMONIC_WORD_COUNT_12 && words.size != MNEMONIC_WORD_COUNT_24) {
303-
throw to.bitkit.utils.AppError("Invalid mnemonic: ${words.size} words")
319+
throw to.bitkit.utils.AppError(
320+
"Recovery phrase format is invalid. Please use your 12 or 24 word recovery phrase to restore manually."
321+
)
304322
}
305323

306324
keychain.saveString(Keychain.Key.BIP39_MNEMONIC.name, mnemonic)
307325
}
308326

309-
private fun buildMnemonicNotFoundErrorMessage(): String {
310-
val keystore = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
311-
val hasWallet0Alias = keystore.containsAlias("wallet0")
312-
313-
return if (hasWallet0Alias) {
314-
"RN keychain data not found"
315-
} else {
316-
"No RN mnemonic found"
317-
}
318-
}
319-
320327
private suspend fun migratePassphrase() {
321328
val passphrase = loadStringFromRNKeychain(RNKeychainKey.PASSPHRASE)
322329
if (passphrase.isNullOrEmpty()) {

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class AppViewModel @Inject constructor(
248248
} catch (e: TimeoutCancellationException) {
249249
if (!isCompletingMigration) {
250250
Logger.warn(
251-
"Migration loading screen timeout after 2 minutes, completing migration anyway",
251+
"Migration loading screen timeout after 2.5 minutes, completing migration anyway",
252252
context = TAG
253253
)
254254
completeMigration()

app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,11 @@ class WalletViewModel @Inject constructor(
189189
if (!walletExists) return
190190

191191
viewModelScope.launch(bgDispatcher) {
192-
var channelMigration: org.lightningdevkit.ldknode.ChannelDataMigration? = null
193-
migrationService.pendingChannelMigration?.let { migration ->
194-
channelMigration = org.lightningdevkit.ldknode.ChannelDataMigration(
192+
val channelMigration = migrationService.consumePendingChannelMigration()?.let { migration ->
193+
org.lightningdevkit.ldknode.ChannelDataMigration(
195194
channelManager = migration.channelManager.map { it.toUByte() },
196195
channelMonitors = migration.channelMonitors.map { monitor -> monitor.map { it.toUByte() } },
197196
)
198-
migrationService.pendingChannelMigration = null
199197
}
200198

201199
lightningRepo.start(walletIndex, channelMigration = channelMigration)

0 commit comments

Comments
 (0)