Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix: #8404: Invalid presentation over panel while loading keyring (#8405
Browse files Browse the repository at this point in the history
)

Fix invalid presentation over panel while loading.
  • Loading branch information
StephenHeaps authored Nov 14, 2023
1 parent c04b390 commit a4fe356
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 a4fe356

Please sign in to comment.