Skip to content

Commit

Permalink
fix: report cached rates on ratesprovider init
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed May 3, 2024
1 parent 818b7d0 commit 5e025d4
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,21 @@ final class BaseRatesProvider: NSObject, RatesProvider {
private let kRefreshTimeInterval: TimeInterval = 60
private let kPriceByCodeKey = "DS_PRICEMANAGER_PRICESBYCODE"

var updateHandler: (([RateObject]) -> Void)?
var updateHandler: (([RateObject]) -> Void)? {
didSet {
let plainPricesByCode = UserDefaults.standard.object(forKey: kPriceByCodeKey) as! [String : NSNumber]
updateHandler?(plainPricesByCode.map { code, rate in
RateObject(code: code, name: currencyName(fromCode: code), price: rate.decimalValue)
})
}
}

private var lastPriceSourceInfo: String!

private let operationQueue: DSOperationQueue

override init() {
operationQueue = DSOperationQueue()

super.init()
}

Expand Down Expand Up @@ -110,4 +116,11 @@ final class BaseRatesProvider: NSObject, RatesProvider {

operationQueue.addOperation(priceOperation)
}

func currencyName(fromCode code: String) -> String {
let locale = Locale.current
let currencyName = locale.localizedString(forCurrencyCode: code)

return currencyName ?? code
}
}

0 comments on commit 5e025d4

Please sign in to comment.