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

Fix: #8404: Invalid presentation over panel while loading keyring #8405

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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