Skip to content

Commit

Permalink
Hide 'Synced Until' date when syncing with blockchair API
Browse files Browse the repository at this point in the history
  • Loading branch information
esen committed Dec 14, 2023
1 parent 6cb87f9 commit 6ff3a95
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BitcoinAdapter: BitcoinBaseAdapter {
throw AdapterError.unsupportedAccount
}

super.init(abstractKit: bitcoinKit, wallet: wallet)
super.init(abstractKit: bitcoinKit, wallet: wallet, syncMode: syncMode)

bitcoinKit.delegate = self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BitcoinBaseAdapter {
private let lastBlockUpdatedSubject = PublishSubject<Void>()
private let balanceStateSubject = PublishSubject<AdapterState>()
private let balanceSubject = PublishSubject<BalanceData>()
private let syncMode: BitcoinCore.SyncMode
let transactionRecordsSubject = PublishSubject<[BitcoinTransactionRecord]>()

private(set) var balanceState: AdapterState {
Expand All @@ -29,10 +30,11 @@ class BitcoinBaseAdapter {
private let token: Token
private let transactionSource: TransactionSource

init(abstractKit: AbstractKit, wallet: Wallet) {
init(abstractKit: AbstractKit, wallet: Wallet, syncMode: BitcoinCore.SyncMode) {
self.abstractKit = abstractKit
token = wallet.token
transactionSource = wallet.transactionSource
self.syncMode = syncMode

balanceState = .notSynced(error: AppError.unknownError)
}
Expand Down Expand Up @@ -154,6 +156,14 @@ class BitcoinBaseAdapter {
open func explorerUrl(transactionHash _: String) -> String? {
fatalError("Must be overridden by subclass")
}

private var showSyncedUntil: Bool {
if case .blockchair = syncMode {
return false
} else {
return true
}
}
}

extension BitcoinBaseAdapter: IAdapter {
Expand Down Expand Up @@ -225,7 +235,9 @@ extension BitcoinBaseAdapter: BitcoinCoreDelegate {
balanceState = .notSynced(error: converted)
case let .syncing(progress):
let newProgress = Int(progress * 100)
let newDate = abstractKit.lastBlockInfo?.timestamp.map { Date(timeIntervalSince1970: Double($0)) }
let newDate = showSyncedUntil
? abstractKit.lastBlockInfo?.timestamp.map { Date(timeIntervalSince1970: Double($0)) }
: nil

if case let .syncing(currentProgress, currentDate) = balanceState, newProgress == currentProgress {
if let currentDate, let newDate, currentDate.isSameDay(as: newDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BitcoinCashAdapter: BitcoinBaseAdapter {
throw AdapterError.unsupportedAccount
}

super.init(abstractKit: bitcoinCashKit, wallet: wallet)
super.init(abstractKit: bitcoinCashKit, wallet: wallet, syncMode: syncMode)

bitcoinCashKit.delegate = self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DashAdapter: BitcoinBaseAdapter {
throw AdapterError.unsupportedAccount
}

super.init(abstractKit: dashKit, wallet: wallet)
super.init(abstractKit: dashKit, wallet: wallet, syncMode: syncMode)

dashKit.delegate = self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ECashAdapter: BitcoinBaseAdapter {
throw AdapterError.unsupportedAccount
}

super.init(abstractKit: eCashKit, wallet: wallet)
super.init(abstractKit: eCashKit, wallet: wallet, syncMode: syncMode)

eCashKit.delegate = self
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LitecoinAdapter: BitcoinBaseAdapter {
throw AdapterError.unsupportedAccount
}

super.init(abstractKit: litecoinKit, wallet: wallet)
super.init(abstractKit: litecoinKit, wallet: wallet, syncMode: syncMode)

litecoinKit.delegate = self
}
Expand Down

0 comments on commit 6ff3a95

Please sign in to comment.