Skip to content

Commit

Permalink
Merge pull request #651 from Syn-McJ/feat/stale-rates
Browse files Browse the repository at this point in the history
feat: stale rates warning
  • Loading branch information
Syn-McJ authored May 21, 2024
2 parents 60e779b + 49528e2 commit 4ed9a80
Show file tree
Hide file tree
Showing 82 changed files with 1,549 additions and 1,122 deletions.
7 changes: 3 additions & 4 deletions DashPay/Presentation/Home/Cells/DWFilterHeaderView.xib
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -30,7 +29,7 @@
<color key="textColor" name="DarkTitleColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4tg-cy-qVc" customClass="DashButton" customModule="dashwallet" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4tg-cy-qVc" customClass="DWDashButton" customModule="dashwallet" customModuleProvider="target">
<rect key="frame" x="319" y="8" width="12" height="53"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption2"/>
<color key="tintColor" name="DashBlueColor"/>
Expand Down
2 changes: 1 addition & 1 deletion DashSyncCurrentCommit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
def9c768c36fcc1436f7e7185693369405977e61
49b6db28808308255a8a6a30d1fe5670d9c9c50e
96 changes: 48 additions & 48 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//

import Foundation
import Combine

// MARK: - RateObject

Expand Down Expand Up @@ -61,60 +62,59 @@ protocol RatesProvider: AnyObject {
// MARK: - RatesProviderFactory

enum RatesProviderFactory {
static var base: RatesProvider { BaseRatesProvider() }
static var base: RatesProvider = BaseRatesProvider.shared
}

// MARK: - BaseRatesProvider

final class BaseRatesProvider: NSObject, RatesProvider {
private let kRefreshTimeInterval: TimeInterval = 60
private let kPriceByCodeKey = "DS_PRICEMANAGER_PRICESBYCODE"
private var cancellableBag = Set<AnyCancellable>()
static var shared: BaseRatesProvider = BaseRatesProvider()

private var lastPriceSourceInfo: String!
private let operationQueue: DSOperationQueue

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)
})
self.emitRates()
}
}

private var lastPriceSourceInfo: String!

private let operationQueue: DSOperationQueue

var lastUpdated: Int {
get { UserDefaults.standard.integer(forKey: LAST_RATES_RETRIEVAL_TIME) }
}

@Published private(set) var hasFetchError: Bool = false
@Published private(set) var isVolatile: Bool = false

override init() {
operationQueue = DSOperationQueue()
super.init()
}

func startExchangeRateFetching() {
updatePrices()
}

@objc
func updatePrices() {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(Int(kRefreshTimeInterval))) { [weak self] in
self?.updatePrices()
}

let priceOperation = DSPriceOperationProvider.fetchPrices { [weak self] prices, priceSource in
guard let self, let prices else { return }

// TODO: save prices in different way
var plainPricesByCode: [String: NSNumber] = [:]

for rate in prices {
plainPricesByCode[rate.code] = rate.price
// TODO: migrate rate fetching from DashSync to here
NotificationCenter.default.publisher(for: NSNotification.Name.DSExchangeRatesReported)
.sink { [weak self] notification in
if let error = notification.userInfo?[DSExchangeRatesErrorKey] as? NSError {
if error.domain == NSURLErrorDomain {
self?.hasFetchError = true
}
} else {
self?.hasFetchError = false
self?.emitRates()
self?.isVolatile = DSPriceManager.sharedInstance().isVolatile
}
}

UserDefaults.standard.set(plainPricesByCode, forKey: self.kPriceByCodeKey)

self.lastPriceSourceInfo = priceSource
self.updateHandler?(prices.map { .init(code: $0.code, name: $0.name, price: $0.price.decimalValue) })
.store(in: &cancellableBag)
}

private func emitRates() {
let plainPricesByCode = UserDefaults.standard.object(forKey: PRICESBYCODE_KEY) as! [String : NSNumber]
let rates = plainPricesByCode.map { code, rate in
RateObject(code: code, name: currencyName(fromCode: code), price: rate.decimalValue)
}

operationQueue.addOperation(priceOperation)
updateHandler?(rates)
}

func currencyName(fromCode code: String) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ extension GettingStartedViewController: BackupInfoViewControllerDelegate {
dismiss(animated: true)
}

internal func secureWalletRoutineDidCanceled(_ controller: UIViewController) { }
internal func secureWalletRoutineDidCancel(_ controller: UIViewController) { }

internal func secureWalletRoutineDidVerify(_ controller: UIViewController) {
refreshCreateAccountButton()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -30,7 +29,7 @@
<color key="textColor" name="DarkTitleColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4tg-cy-qVc" customClass="DashButton" customModule="dashwallet" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" verticalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4tg-cy-qVc" customClass="DWDashButton" customModule="dashwallet" customModuleProvider="target">
<rect key="frame" x="301" y="8" width="30" height="53"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption2"/>
<color key="tintColor" name="DashBlueColor"/>
Expand Down
51 changes: 0 additions & 51 deletions DashWallet/Sources/UI/Home/DWHomeViewController+DWBackupReminder.m

This file was deleted.

This file was deleted.

This file was deleted.

117 changes: 0 additions & 117 deletions DashWallet/Sources/UI/Home/DWHomeViewController+DWJailbreakCheck.m

This file was deleted.

Loading

0 comments on commit 4ed9a80

Please sign in to comment.