-
Notifications
You must be signed in to change notification settings - Fork 121
[CIAB] Hide Blaze and Payments from hub menu #16096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b0c1d39
c85ccdf
8f12431
3de52d8
c337898
c5dc307
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -85,11 +85,13 @@ final class HubMenuViewModel: ObservableObject { | |||||
| private let inboxEligibilityChecker: InboxEligibilityChecker | ||||||
| private let blazeEligibilityChecker: BlazeEligibilityCheckerProtocol | ||||||
| private let googleAdsEligibilityChecker: GoogleAdsEligibilityChecker | ||||||
| private let siteCIABEligibilityChecker: CIABEligibilityCheckerProtocol | ||||||
|
|
||||||
| private(set) lazy var inboxViewModel = InboxViewModel(siteID: siteID) | ||||||
|
|
||||||
| @Published private(set) var shouldShowNewFeatureBadgeOnPayments: Bool = false | ||||||
|
|
||||||
| @Published private var isSiteEligibleForPayments = false | ||||||
| @Published private var isSiteEligibleForBlaze = false | ||||||
| @Published private var isSiteEligibleForGoogleAds = false | ||||||
| @Published private var isSiteEligibleForInbox = false | ||||||
|
|
@@ -125,6 +127,7 @@ final class HubMenuViewModel: ObservableObject { | |||||
| inboxEligibilityChecker: InboxEligibilityChecker = InboxEligibilityUseCase(), | ||||||
| blazeEligibilityChecker: BlazeEligibilityCheckerProtocol = BlazeEligibilityChecker(), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we inject
Suggested change
then inside init: self.blazeEligibilityChecker = blazeEligibilityChecker ?? BlazeEligibilityChecker(siteCIABEligibilityChecker: siteCIABEligibilityChecker)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx for the attention here. |
||||||
| googleAdsEligibilityChecker: GoogleAdsEligibilityChecker = DefaultGoogleAdsEligibilityChecker(), | ||||||
| siteCIABEligibilityChecker: CIABEligibilityCheckerProtocol = CIABEligibilityChecker(), | ||||||
| analytics: Analytics = ServiceLocator.analytics) { | ||||||
| self.siteID = siteID | ||||||
| self.credentials = stores.sessionManager.defaultCredentials | ||||||
|
|
@@ -136,6 +139,7 @@ final class HubMenuViewModel: ObservableObject { | |||||
| self.inboxEligibilityChecker = inboxEligibilityChecker | ||||||
| self.blazeEligibilityChecker = blazeEligibilityChecker | ||||||
| self.googleAdsEligibilityChecker = googleAdsEligibilityChecker | ||||||
| self.siteCIABEligibilityChecker = siteCIABEligibilityChecker | ||||||
| self.cardPresentPaymentsOnboarding = CardPresentPaymentsOnboardingUseCase() | ||||||
| self.analytics = analytics | ||||||
| observeSiteForUIUpdates() | ||||||
|
|
@@ -251,30 +255,55 @@ private extension HubMenuViewModel { | |||||
| } | ||||||
|
|
||||||
| func setupGeneralElements() { | ||||||
| $shouldShowNewFeatureBadgeOnPayments | ||||||
| .combineLatest($isSiteEligibleForInbox, | ||||||
| $isSiteEligibleForBlaze, | ||||||
| $isSiteEligibleForGoogleAds) | ||||||
| .map { [weak self] combinedResult -> [HubMenuItem] in | ||||||
| guard let self else { return [] } | ||||||
| let (shouldShowBadgeOnPayments, eligibleForInbox, eligibleForBlaze, eligibleForGoogleAds) = combinedResult | ||||||
| return createGeneralElements( | ||||||
| shouldShowBadgeOnPayments: shouldShowBadgeOnPayments, | ||||||
| eligibleForGoogleAds: eligibleForGoogleAds, | ||||||
| eligibleForBlaze: eligibleForBlaze, | ||||||
| eligibleForInbox: eligibleForInbox | ||||||
| ) | ||||||
| } | ||||||
| .assign(to: &$generalElements) | ||||||
| Publishers.CombineLatest( | ||||||
| $shouldShowNewFeatureBadgeOnPayments, | ||||||
| $isSiteEligibleForPayments | ||||||
| ) | ||||||
| .combineLatest( | ||||||
| Publishers.CombineLatest3( | ||||||
| $isSiteEligibleForInbox, | ||||||
| $isSiteEligibleForBlaze, | ||||||
| $isSiteEligibleForGoogleAds | ||||||
| ) | ||||||
| ) | ||||||
| .map { [weak self] combinedResults -> [HubMenuItem] in | ||||||
| guard let self else { return [] } | ||||||
|
|
||||||
| let ((shouldShowBadgeOnPayments, eligibleForPayments), (eligibleForInbox, eligibleForBlaze, eligibleForGoogleAds)) = combinedResults | ||||||
|
|
||||||
| let paymentsEligibility: PaymentsFeatureEligibility = eligibleForPayments ? | ||||||
| .eligible(shouldShowBadgeOnPayments: shouldShowBadgeOnPayments) : | ||||||
| .ineligible | ||||||
|
|
||||||
| return createGeneralElements( | ||||||
| paymentsEligibility: paymentsEligibility, | ||||||
| eligibleForGoogleAds: eligibleForGoogleAds, | ||||||
| eligibleForBlaze: eligibleForBlaze, | ||||||
| eligibleForInbox: eligibleForInbox | ||||||
| ) | ||||||
| } | ||||||
| .assign(to: &$generalElements) | ||||||
| } | ||||||
|
|
||||||
| enum PaymentsFeatureEligibility { | ||||||
| case ineligible | ||||||
| case eligible(shouldShowBadgeOnPayments: Bool) | ||||||
| } | ||||||
|
|
||||||
| func createGeneralElements(shouldShowBadgeOnPayments: Bool, | ||||||
| func createGeneralElements(paymentsEligibility: PaymentsFeatureEligibility, | ||||||
| eligibleForGoogleAds: Bool, | ||||||
| eligibleForBlaze: Bool, | ||||||
| eligibleForInbox: Bool) -> [HubMenuItem] { | ||||||
| var items: [HubMenuItem] = [ | ||||||
| Payments(iconBadge: shouldShowBadgeOnPayments ? .dot : nil) | ||||||
| ] | ||||||
| var items: [HubMenuItem] = [] | ||||||
|
|
||||||
| switch paymentsEligibility { | ||||||
| case .ineligible: | ||||||
| break | ||||||
| case .eligible(let shouldShowBadgeOnPayments): | ||||||
| items.append( | ||||||
| Payments(iconBadge: shouldShowBadgeOnPayments ? .dot : nil) | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
| if shouldShowAISettings { | ||||||
| items.append(AISettings()) | ||||||
|
|
@@ -354,7 +383,7 @@ private extension HubMenuViewModel { | |||||
| } | ||||||
|
|
||||||
| func updateMenuItemEligibility(with site: Yosemite.Site) { | ||||||
|
|
||||||
| isSiteEligibleForPayments = siteCIABEligibilityChecker.isFeatureSupported(.payments, for: site) | ||||||
| isSiteEligibleForInbox = inboxEligibilityChecker.isEligibleForInbox(siteID: site.siteID) | ||||||
|
|
||||||
| Task { @MainActor in | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please consider adding unit tests to check for this condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c337898