@@ -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()) {
0 commit comments