From d745b82314c1bb01cd7339377379b2cce37573b5 Mon Sep 17 00:00:00 2001 From: Stephen Heaps Date: Tue, 21 Nov 2023 15:30:53 -0500 Subject: [PATCH] Fix for Accounts modals resetting if KeyringStore changes. Sheet(s) presented from Lists that are redrawn lose their state. --- .../Crypto/Accounts/AccountsHeaderView.swift | 34 +++---------------- .../Crypto/Accounts/AccountsView.swift | 32 ++++++++++++++++- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Sources/BraveWallet/Crypto/Accounts/AccountsHeaderView.swift b/Sources/BraveWallet/Crypto/Accounts/AccountsHeaderView.swift index a008f540200..5e940bee6f4 100644 --- a/Sources/BraveWallet/Crypto/Accounts/AccountsHeaderView.swift +++ b/Sources/BraveWallet/Crypto/Accounts/AccountsHeaderView.swift @@ -13,8 +13,8 @@ struct AccountsHeaderView: View { var settingsStore: SettingsStore var networkStore: NetworkStore - @State private var isPresentingBackup: Bool = false - @State private var isPresentingAddAccount: Bool = false + @Binding var isPresentingBackup: Bool + @Binding var isPresentingAddAccount: Bool var body: some View { HStack { @@ -27,20 +27,6 @@ struct AccountsHeaderView: View { .foregroundColor(Color(.braveBlurpleTint)) } } - .background( - Color.clear - .sheet(isPresented: $isPresentingBackup) { - NavigationView { - BackupWalletView( - password: nil, - keyringStore: keyringStore - ) - } - .navigationViewStyle(StackNavigationViewStyle()) - .environment(\.modalPresentationMode, $isPresentingBackup) - .accentColor(Color(.braveBlurpleTint)) - } - ) Spacer() HStack(spacing: 16) { Button(action: { @@ -49,18 +35,6 @@ struct AccountsHeaderView: View { Label(Strings.Wallet.addAccountTitle, systemImage: "plus") .labelStyle(.iconOnly) } - .background( - Color.clear - .sheet(isPresented: $isPresentingAddAccount) { - NavigationView { - AddAccountView( - keyringStore: keyringStore, - networkStore: networkStore - ) - } - .navigationViewStyle(StackNavigationViewStyle()) - } - ) NavigationLink( destination: Web3SettingsView( settingsStore: settingsStore, @@ -83,7 +57,9 @@ struct AccountsHeaderView_Previews: PreviewProvider { AccountsHeaderView( keyringStore: .previewStore, settingsStore: .previewStore, - networkStore: .previewStore + networkStore: .previewStore, + isPresentingBackup: .constant(false), + isPresentingAddAccount: .constant(false) ) .previewLayout(.sizeThatFits) .previewColorSchemes() diff --git a/Sources/BraveWallet/Crypto/Accounts/AccountsView.swift b/Sources/BraveWallet/Crypto/Accounts/AccountsView.swift index 4cae507872c..76760e53dc1 100644 --- a/Sources/BraveWallet/Crypto/Accounts/AccountsView.swift +++ b/Sources/BraveWallet/Crypto/Accounts/AccountsView.swift @@ -14,6 +14,8 @@ struct AccountsView: View { var cryptoStore: CryptoStore @ObservedObject var keyringStore: KeyringStore @State private var selectedAccount: BraveWallet.AccountInfo? + @State private var isPresentingBackup: Bool = false + @State private var isPresentingAddAccount: Bool = false private var primaryAccounts: [BraveWallet.AccountInfo] { keyringStore.allAccounts.filter(\.isPrimary) @@ -29,7 +31,9 @@ struct AccountsView: View { header: AccountsHeaderView( keyringStore: keyringStore, settingsStore: cryptoStore.settingsStore, - networkStore: cryptoStore.networkStore + networkStore: cryptoStore.networkStore, + isPresentingBackup: $isPresentingBackup, + isPresentingAddAccount: $isPresentingAddAccount ) .resetListHeaderStyle() ) { @@ -106,6 +110,32 @@ struct AccountsView: View { ) .listStyle(InsetGroupedListStyle()) .listBackgroundColor(Color(UIColor.braveGroupedBackground)) + .background( + Color.clear + .sheet(isPresented: $isPresentingBackup) { + NavigationView { + BackupWalletView( + password: nil, + keyringStore: keyringStore + ) + } + .navigationViewStyle(StackNavigationViewStyle()) + .environment(\.modalPresentationMode, $isPresentingBackup) + .accentColor(Color(.braveBlurpleTint)) + } + ) + .background( + Color.clear + .sheet(isPresented: $isPresentingAddAccount) { + NavigationView { + AddAccountView( + keyringStore: keyringStore, + networkStore: cryptoStore.networkStore + ) + } + .navigationViewStyle(StackNavigationViewStyle()) + } + ) } }