Skip to content

Commit

Permalink
Fix: brave/brave-ios#8404: Invalid presentation over panel while load…
Browse files Browse the repository at this point in the history
…ing keyring (brave/brave-ios#8405)

Fix invalid presentation over panel while loading.
  • Loading branch information
StephenHeaps authored Nov 14, 2023
1 parent 300c9a0 commit c8f90c0
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions Sources/BraveWallet/Panels/WalletPanelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,20 @@ public struct WalletPanelContainerView: View {
}
}
.frame(idealWidth: 320, maxWidth: .infinity)
.onChange(of: keyringStore.isWalletCreated) { newValue in
if visibleScreen != .panel, !keyringStore.lockedManually {
presentWalletWithContext?(.panelUnlockOrSetup)
}
}
.onChange(of: keyringStore.isWalletLocked) { newValue in
if visibleScreen != .panel, !keyringStore.lockedManually {
presentWalletWithContext?(.panelUnlockOrSetup)
guard keyringStore.isLoaded, newValue, !keyringStore.lockedManually else { return }
// Wallet was auto-locked with panel open
presentWalletWithContext?(.panelUnlockOrSetup)
}
.onChange(of: keyringStore.isLoaded) { newValue in
guard newValue else { return } // KeyringStore loaded
handleKeyringStoreLoaded()
}
.onAppear {
if keyringStore.isLoaded {
// If KeyringStore is loaded prior to view appearing on
// screen onChange won't be executed
handleKeyringStoreLoaded()
}
}
.environment(
Expand All @@ -163,6 +169,23 @@ public struct WalletPanelContainerView: View {
return .handled
}))
}

/// Flag to help prevent race condition between panel appearing on screen and KeyringStore `isLoaded`.
@State private var didHandleKeyringLoaded: Bool = false
/// Present unlock if displayed locked state (unless manually locked), or onboarding if displaying
/// onboarding state
private func handleKeyringStoreLoaded() {
guard !didHandleKeyringLoaded else { return }
didHandleKeyringLoaded = true
if visibleScreen == .onboarding {
// automatically open full wallet when displaying onboarding
presentWalletWithContext?(.panelUnlockOrSetup)
} else if visibleScreen == .unlock, !keyringStore.lockedManually {
// automatically open full unlock wallet view when displaying
// locked panel unless user locked manually
presentWalletWithContext?(.panelUnlockOrSetup)
}
}
}

struct WalletPanelView: View {
Expand Down

0 comments on commit c8f90c0

Please sign in to comment.