From 5ee8eb33bebc356129afe3e2b48148b4f92ed867 Mon Sep 17 00:00:00 2001 From: StephenHeaps <5314553+StephenHeaps@users.noreply.github.com> Date: Wed, 5 Apr 2023 11:28:10 -0400 Subject: [PATCH] Fix #7200: Tx Confirmation auto-dismisses after creating tx via asset details (#7203) * Fix `WalletPromptView` dismissing views unintentionally. This was causing Transaction Confirmation to dismiss automatically after creating a Send/Swap transaction via Asset Details. * Remove `buySendSwapDestination` check from `WalletPromptView` now that we only dismiss the presented view controller if we know we presented it. --- Sources/BraveWallet/WalletPromptView.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/BraveWallet/WalletPromptView.swift b/Sources/BraveWallet/WalletPromptView.swift index 38df4cdc036..f283f04072f 100644 --- a/Sources/BraveWallet/WalletPromptView.swift +++ b/Sources/BraveWallet/WalletPromptView.swift @@ -6,6 +6,7 @@ import SwiftUI import BraveUI import DesignSystem +import Shared struct WalletPromptContentView: View where Content: View, Footer: View { let content: () -> Content @@ -56,8 +57,6 @@ struct WalletPromptView: UIViewControllerRepresentable where Co var action: (Bool, UINavigationController?) -> Bool var content: () -> Content var footer: () -> Footer - @Environment(\.buySendSwapDestination) - private var buySendSwapDestination: Binding func makeUIViewController(context: Context) -> UIViewController { .init() @@ -82,13 +81,23 @@ struct WalletPromptView: UIViewControllerRepresentable where Co footer: footer ) ) + context.coordinator.presentedViewController = .init(controller) uiViewController.present(controller, animated: true) } else { - if buySendSwapDestination.wrappedValue == nil { + if let presentedViewController = context.coordinator.presentedViewController?.value, + presentedViewController == uiViewController.presentedViewController { uiViewController.presentedViewController?.dismiss(animated: true) } } } + + class Coordinator { + var presentedViewController: WeakRef? + } + + func makeCoordinator() -> Coordinator { + Coordinator() + } } extension WalletPromptView where Content: View, Footer == EmptyView {