From 2f6fba31e4f4c0388ecd4dd45b099a3d0cc914de Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Thu, 2 Jul 2020 19:02:27 +0100 Subject: [PATCH] Fix Brave Ads state-level targeting crash --- BraveRewardsUI/Localized Strings/Strings.swift | 3 +++ .../Ads/Details/AdsDetailsViewController.swift | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/BraveRewardsUI/Localized Strings/Strings.swift b/BraveRewardsUI/Localized Strings/Strings.swift index 89c0e295a89..f52d86ca0d6 100644 --- a/BraveRewardsUI/Localized Strings/Strings.swift +++ b/BraveRewardsUI/Localized Strings/Strings.swift @@ -222,6 +222,9 @@ internal extension Strings { static let adsMaxPerHour = NSLocalizedString("BraveRewardsAdsMaxPerDay", bundle: .rewardsUI, value: "Maximum number of ads displayed", comment: "") static let numberOfAdsPerHourOptionsTitle = NSLocalizedString("BraveRewardsNumberOfAdsPerHourOptionsTitle", bundle: .rewardsUI, value: "Ads per hour", comment: "") static let adsSubdivisionTargeting = NSLocalizedString("BraveRewardsAdsSubdivisionTargeting", bundle: .rewardsUI, value: "State level ad targeting", comment: "") + static let adsSubdivisionTargetingAutoDetect = NSLocalizedString("BraveRewardsAdsSubdivisionTargetingAutoDetect", bundle: .rewardsUI, value: "Auto-detect", comment: "") + static let adsSubdivisionTargetingDisabled = NSLocalizedString("BraveRewardsAdsSubdivisionTargetingDisabled", bundle: .rewardsUI, value: "Disabled", comment: "") + static let adsSubdivisionTargetingDisable = NSLocalizedString("BraveRewardsAdsSubdivisionTargetingDisable", bundle: .rewardsUI, value: "Disable", comment: "") static let adsEstimatedEarnings = NSLocalizedString("BraveRewardsAdsEstimatedEarnings", bundle: .rewardsUI, value: "Estimated pending rewards", comment: "") static let nextPaymentDate = NSLocalizedString("BraveRewardsPaymentDate", bundle: .rewardsUI, value: "Next payment date", comment: "") static let adNotificationsReceived = NSLocalizedString("BraveRewardsAdNotificationsReceived", bundle: .rewardsUI, value: "Ad notifications received this month", comment: "") diff --git a/BraveRewardsUI/Settings/Ads/Details/AdsDetailsViewController.swift b/BraveRewardsUI/Settings/Ads/Details/AdsDetailsViewController.swift index 4318b0fec5b..1eb48e08570 100644 --- a/BraveRewardsUI/Settings/Ads/Details/AdsDetailsViewController.swift +++ b/BraveRewardsUI/Settings/Ads/Details/AdsDetailsViewController.swift @@ -99,8 +99,8 @@ class AdsDetailsViewController: UIViewController { // TODO(https://github.com/brave/brave-browser/issues/10316) return subdivisions from ads lib private let subdivisionTargetingOptions: KeyValuePairs = [ - "AUTO": "Auto-detect", - "DISABLED": "Disable", + "AUTO": Strings.adsSubdivisionTargetingAutoDetect, + "DISABLED": Strings.adsSubdivisionTargetingDisable, "US-AL": "Alabama", "US-AK": "Alaska", "US-AZ": "Arizona", @@ -228,16 +228,18 @@ extension AdsDetailsViewController: UITableViewDelegate, UITableViewDataSource { cell.label.text = Strings.adsSubdivisionTargeting var adsSubdivisionTargetingCode: String - if state.ads.subdivisionTargetingCode == "DISABLED" { - adsSubdivisionTargetingCode = "Disabled" - } else if state.ads.subdivisionTargetingCode == "AUTO" { + if state.ads.subdivisionTargetingCode == "AUTO" { adsSubdivisionTargetingCode = state.ads.automaticallyDetectedSubdivisionTargetingCode } else { adsSubdivisionTargetingCode = state.ads.subdivisionTargetingCode } - guard let selectedIndex = subdivisionTargetingOptions.firstIndex(where: { $0.0 == adsSubdivisionTargetingCode }) else { fatalError() } - cell.accessoryLabel?.text = subdivisionTargetingOptions[selectedIndex].1 + if adsSubdivisionTargetingCode == "DISABLED" { + cell.accessoryLabel?.text = Strings.adsSubdivisionTargetingDisabled + } else { + guard let selectedIndex = subdivisionTargetingOptions.firstIndex(where: { $0.0 == adsSubdivisionTargetingCode }) else { fatalError() } + cell.accessoryLabel?.text = subdivisionTargetingOptions[selectedIndex].1 + } case .currentEarnings: cell.label.text = Strings.adsEstimatedEarnings cell.selectionStyle = .none