Skip to content

Commit

Permalink
Merge pull request #1041 from novasamatech/develop
Browse files Browse the repository at this point in the history
v7.11.2
  • Loading branch information
ERussel committed Apr 17, 2024
2 parents e030da6 + 2c1a402 commit 6954ff2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion novawallet/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension ApplicationConfig: ApplicationConfigProtocol {
#if F_RELEASE
URL(string: "https://api.subquery.network/sq/nova-wallet/subquery-staking")!
#else
URL(string: "https://api.subquery.network/sq/nova-wallet/subquery-staking")!
URL(string: "https://subquery-multi-staking-prod.k8s-1.novasama.co")!
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion novawallet/Common/DataProvider/PriceProviderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ extension PriceProviderFactory: PriceProviderFactoryProtocol {
let source = CoingeckoPriceHistoryProviderSource(
priceId: priceId,
currency: currency,
operationFactory: CoingeckoOperationFactory()
operationFactory: CoingeckoOperationFactory(),
logger: logger
)

let singleValueProvider = SingleValueProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,54 @@ import Foundation
import RobinHood

final class CoingeckoPriceHistoryProviderSource {
static let maxAllowedRange = 365.secondsFromDays

let operationFactory: CoingeckoOperationFactoryProtocol
let currency: Currency
let priceId: AssetModel.PriceId
let logger: LoggerProtocol

init(
priceId: AssetModel.PriceId,
currency: Currency,
operationFactory: CoingeckoOperationFactoryProtocol
operationFactory: CoingeckoOperationFactoryProtocol,
logger: LoggerProtocol
) {
self.priceId = priceId
self.currency = currency
self.operationFactory = operationFactory
self.logger = logger
}

private func logFetchResult(for result: Result<Model, Error>?) {
switch result {
case .success:
logger.debug("Price history fetched for \(priceId)")
case let .failure(error):
logger.error("Price history fetch failed \(error)")
case nil:
logger.error("No result")
}
}
}

extension CoingeckoPriceHistoryProviderSource: SingleValueProviderSourceProtocol {
typealias Model = PriceHistory

func fetchOperation() -> CompoundOperationWrapper<Model?> {
let toTimeInterval = Date().timeIntervalSince1970
let fromTimeInterval = max(toTimeInterval - Self.maxAllowedRange, 0)

let historyOperation = operationFactory.fetchPriceHistory(
for: priceId,
currency: currency,
startDate: Date(timeIntervalSince1970: 0),
endDate: Date(timeIntervalSince1970: TimeInterval(UInt32.max))
startDate: Date(timeIntervalSince1970: fromTimeInterval),
endDate: Date(timeIntervalSince1970: toTimeInterval)
)

let mapOperation = ClosureOperation<Model?> {
try historyOperation.extractNoCancellableResultData()
let mapOperation = ClosureOperation<Model?> { [weak self] in
self?.logFetchResult(for: historyOperation.result)
return try historyOperation.extractNoCancellableResultData()
}

mapOperation.addDependency(historyOperation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BaseSubsquareOperationFactory {
let timeout: TimeInterval
let pageSize: Int

init(baseUrl: URL, chainId: String, pageSize: Int = 1000, timeout: TimeInterval = 10) {
init(baseUrl: URL, chainId: String, pageSize: Int = 100, timeout: TimeInterval = 10) {
self.baseUrl = baseUrl
self.chainId = chainId
self.pageSize = pageSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ extension ReferendumsInteractor: ReferendumsInteractorInputProtocol {
if let chain = governanceState.settings.value?.chain {
subscribeToBlockNumber(for: chain)
}

if governanceState.settings.value != nil {
metadataProvider?.refresh()
}
}

func putOffline() {
clearBlockNumberSubscription()
}

func refresh() {
func refreshReferendums() {
if governanceState.settings.value != nil {
provideReferendumsIfNeeded()
provideBlockTime()

metadataProvider?.refresh()

provideOffchainVotingIfNeeded()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ extension ReferendumsPresenter: ReferendumsInteractorOutputProtocol {
func didReceiveBlockNumber(_ blockNumber: BlockNumber) {
self.blockNumber = blockNumber

interactor.refresh()
interactor.refreshReferendums()
}

func didReceiveBlockTime(_ blockTime: BlockTime) {
Expand Down Expand Up @@ -479,7 +479,7 @@ extension ReferendumsPresenter: ReferendumsInteractorOutputProtocol {
}
case .referendumsFetchFailed:
wireframe.presentRequestStatus(on: view, locale: selectedLocale) { [weak self] in
self?.interactor.refresh()
self?.interactor.refreshReferendums()
}
case .blockNumberSubscriptionFailed, .priceSubscriptionFailed, .balanceSubscriptionFailed,
.metadataSubscriptionFailed, .blockTimeServiceFailed, .votingSubscriptionFailed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protocol ReferendumsInteractorInputProtocol: AnyObject {
func saveSelected(option: GovernanceSelectedOption)
func becomeOnline()
func putOffline()
func refresh()
func refreshReferendums()
func refreshUnlockSchedule(for tracksVoting: ReferendumTracksVotingDistribution, blockHash: Data?)
func remakeSubscriptions()
func retryBlockTime()
Expand Down

0 comments on commit 6954ff2

Please sign in to comment.