From 778baac188fff802bf245537d17c0e8c9d81a51d Mon Sep 17 00:00:00 2001
From: Brandon T <JustBrandonT@gmail.com>
Date: Tue, 8 Aug 2023 11:13:44 -0400
Subject: [PATCH] Fix bug where backgroundView on stats don't show or it shows
 multiple times causing UI issues.

---
 .../New Tab Page/Sections/StatsSectionProvider.swift     | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/Sources/Brave/Frontend/Browser/New Tab Page/Sections/StatsSectionProvider.swift b/Sources/Brave/Frontend/Browser/New Tab Page/Sections/StatsSectionProvider.swift
index fe41ddb8b59..86a4b47eb43 100644
--- a/Sources/Brave/Frontend/Browser/New Tab Page/Sections/StatsSectionProvider.swift	
+++ b/Sources/Brave/Frontend/Browser/New Tab Page/Sections/StatsSectionProvider.swift	
@@ -175,16 +175,11 @@ class BraveShieldStatsView: SpringButton {
   
   var isPrivateBrowsing: Bool = false {
     didSet {
-      if oldValue == isPrivateBrowsing {
+      if backgroundView.superview != nil {
         return
       }
 
-      if isPrivateBrowsing {
-        backgroundView.removeFromSuperview()
-        topStackView.arrangedSubviews.forEach {
-          $0.removeFromSuperview()
-        }
-      } else if Preferences.NewTabPage.showNewTabPrivacyHub.value {
+      if !isPrivateBrowsing && Preferences.NewTabPage.showNewTabPrivacyHub.value {
         backgroundView.backgroundColor = .init(white: 0, alpha: 0.25)
         backgroundView.layer.cornerRadius = 12
         backgroundView.layer.cornerCurve = .continuous