Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix Brave Ads state-level targeting crash #2693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BraveRewardsUI/Localized Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down