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

Commit

Permalink
Fix Brave Ads state-level targeting crash (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey authored and kylehickinson committed Jul 9, 2020
1 parent 7ec6bac commit cdb7d81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit cdb7d81

Please sign in to comment.