@@ -220,9 +220,9 @@ class AppViewModel @Inject constructor(
220220 }
221221 viewModelScope.launch {
222222 // Delays are required for auth check on launch functionality
223- delay(1000 )
223+ delay(AUTH_CHECK_INITIAL_DELAY_MS )
224224 resetIsAuthenticatedState()
225- delay(500 )
225+ delay(AUTH_CHECK_SPLASH_DELAY_MS )
226226 splashVisible = false
227227 }
228228 viewModelScope.launch {
@@ -249,7 +249,7 @@ class AppViewModel @Inject constructor(
249249 } catch (e: TimeoutCancellationException ) {
250250 if (! isCompletingMigration) {
251251 Logger .warn(
252- " Migration loading screen timeout after 2.5 minutes , completing migration anyway" ,
252+ " Migration loading screen timeout, completing migration anyway" ,
253253 context = TAG
254254 )
255255 completeMigration()
@@ -319,18 +319,14 @@ class AppViewModel @Inject constructor(
319319 }
320320
321321 private suspend fun handleSyncCompleted () {
322- walletRepo.debounceSyncByEvent()
323-
324322 val isShowingLoading = migrationService.isShowingMigrationLoading.value
325323 val isRestoringRemote = migrationService.isRestoringFromRNRemoteBackup.value
326324
327325 when {
328- isShowingLoading && ! isCompletingMigration -> {
329- completeMigration()
330- }
331- isRestoringRemote -> {
332- completeRNRemoteBackupRestore()
333- }
326+ isShowingLoading && ! isCompletingMigration -> completeMigration()
327+ isRestoringRemote -> completeRNRemoteBackupRestore()
328+ ! isShowingLoading && ! isCompletingMigration -> walletRepo.debounceSyncByEvent()
329+ else -> Unit
334330 }
335331 }
336332
@@ -351,9 +347,7 @@ class AppViewModel @Inject constructor(
351347 }
352348
353349 private suspend fun completeMigration () {
354- if (isCompletingMigration) {
355- return
356- }
350+ if (isCompletingMigration) return
357351 isCompletingMigration = true
358352
359353 try {
@@ -368,61 +362,79 @@ class AppViewModel @Inject constructor(
368362 lightningRepo.stop().onFailure {
369363 Logger .error(" Failed to stop node during migration restart" , it, context = TAG )
370364 }
371- delay(500 )
365+ delay(MIGRATION_NODE_RESTART_DELAY_MS )
372366 lightningRepo.start(channelMigration = channelMigration, shouldRetry = false )
373367 .onSuccess {
374368 migrationService.consumePendingChannelMigration()
375369 walletRepo.syncNodeAndWallet()
376370 .onSuccess {
377- lightningRepo.getPayments().onSuccess { payments ->
378- activityRepo.syncLdkNodePayments(payments)
379- }
380- transferRepo.syncTransferStates()
381- migrationService.reapplyMetadataAfterSync()
382-
383- migrationService.setShowingMigrationLoading(false )
384-
385- toast(
386- type = Toast .ToastType .SUCCESS ,
387- title = " Migration Complete" ,
388- description = " Your wallet has been successfully migrated"
389- )
371+ finishMigrationSuccessfully()
390372 }
391373 .onFailure { e ->
392374 Logger .warn(" Sync failed after restart during migration: $e " , e, context = TAG )
393- walletRepo.syncBalances()
394- lightningRepo.getPayments().onSuccess { payments ->
395- activityRepo.syncLdkNodePayments(payments)
396- }
397- transferRepo.syncTransferStates()
398- migrationService.reapplyMetadataAfterSync()
399-
400- migrationService.setShowingMigrationLoading(false )
401-
402- toast(
403- type = Toast .ToastType .SUCCESS ,
404- title = " Migration Complete" ,
405- description = " Your wallet has been successfully migrated"
406- )
375+ finishMigrationWithFallbackSync()
407376 }
408377 }
409378 .onFailure { e ->
410379 Logger .error(" Failed to restart node after migration: $e " , e, context = TAG )
411- migrationService.setShowingMigrationLoading(false )
412- toast(
413- type = Toast .ToastType .ERROR ,
414- title = " Migration Warning" ,
415- description = " Migration completed but node restart failed. Please restart the app."
416- )
380+ finishMigrationWithError()
417381 }
418382 } catch (e: Exception ) {
419383 Logger .error(" Migration completion error: $e " , e, context = TAG )
420- migrationService.setShowingMigrationLoading( false )
384+ finishMigrationWithError( )
421385 } finally {
422386 isCompletingMigration = false
423387 }
424388 }
425389
390+ private suspend fun finishMigrationSuccessfully () {
391+ lightningRepo.getPayments().onSuccess { payments ->
392+ activityRepo.syncLdkNodePayments(payments)
393+ }
394+ transferRepo.syncTransferStates()
395+ migrationService.reapplyMetadataAfterSync()
396+
397+ migrationService.setShowingMigrationLoading(false )
398+ delay(MIGRATION_AUTH_RESET_DELAY_MS )
399+ resetIsAuthenticatedStateInternal()
400+
401+ toast(
402+ type = Toast .ToastType .SUCCESS ,
403+ title = " Migration Complete" ,
404+ description = " Your wallet has been successfully migrated"
405+ )
406+ }
407+
408+ private suspend fun finishMigrationWithFallbackSync () {
409+ walletRepo.syncBalances()
410+ lightningRepo.getPayments().onSuccess { payments ->
411+ activityRepo.syncLdkNodePayments(payments)
412+ }
413+ transferRepo.syncTransferStates()
414+ migrationService.reapplyMetadataAfterSync()
415+
416+ migrationService.setShowingMigrationLoading(false )
417+ delay(MIGRATION_AUTH_RESET_DELAY_MS )
418+ resetIsAuthenticatedStateInternal()
419+
420+ toast(
421+ type = Toast .ToastType .SUCCESS ,
422+ title = " Migration Complete" ,
423+ description = " Your wallet has been successfully migrated"
424+ )
425+ }
426+
427+ private suspend fun finishMigrationWithError () {
428+ migrationService.setShowingMigrationLoading(false )
429+ delay(MIGRATION_AUTH_RESET_DELAY_MS )
430+ resetIsAuthenticatedStateInternal()
431+ toast(
432+ type = Toast .ToastType .ERROR ,
433+ title = " Migration Warning" ,
434+ description = " Migration completed but node restart failed. Please restart the app."
435+ )
436+ }
437+
426438 private suspend fun handleOnchainTransactionConfirmed (event : Event .OnchainTransactionConfirmed ) {
427439 activityRepo.handleOnchainTransactionConfirmed(event.txid, event.details)
428440 }
@@ -1767,13 +1779,15 @@ class AppViewModel @Inject constructor(
17671779 // endregion
17681780
17691781 // region security
1782+ private suspend fun resetIsAuthenticatedStateInternal () {
1783+ val settings = settingsStore.data.first()
1784+ val needsAuth = settings.isPinEnabled && settings.isPinOnLaunchEnabled
1785+ _isAuthenticated .value = ! needsAuth
1786+ }
1787+
17701788 fun resetIsAuthenticatedState () {
17711789 viewModelScope.launch {
1772- val settings = settingsStore.data.first()
1773- val needsAuth = settings.isPinEnabled && settings.isPinOnLaunchEnabled
1774- if (! needsAuth) {
1775- _isAuthenticated .value = true
1776- }
1790+ resetIsAuthenticatedStateInternal()
17771791 }
17781792 }
17791793
@@ -2130,7 +2144,11 @@ class AppViewModel @Inject constructor(
21302144 private const val MAX_BALANCE_FRACTION = 0.5
21312145 private const val MAX_FEE_AMOUNT_RATIO = 0.5
21322146 private const val SCREEN_TRANSITION_DELAY_MS = 300L
2133- private const val MIGRATION_LOADING_TIMEOUT_MS = 150_000L
2147+ private const val MIGRATION_LOADING_TIMEOUT_MS = 300_000L
2148+ private const val MIGRATION_NODE_RESTART_DELAY_MS = 500L
2149+ private const val MIGRATION_AUTH_RESET_DELAY_MS = 500L
2150+ private const val AUTH_CHECK_INITIAL_DELAY_MS = 1000L
2151+ private const val AUTH_CHECK_SPLASH_DELAY_MS = 500L
21342152
21352153 /* *How high the balance must be to show this warning to the user (in USD)*/
21362154 private const val BALANCE_THRESHOLD_USD = 500L
0 commit comments