Skip to content

Commit c39c5b0

Browse files
authored
Merge pull request #867 from Adamant-im/trello.com/c/aIVBEdjR
[trello.com/c/aIVBEdjR] Improve coin tx sending algorithm
2 parents e28c8c5 + 0be6051 commit c39c5b0

6 files changed

+20
-19
lines changed

Adamant/Models/BTCRawTransaction.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ struct BTCRawTransaction {
2727

2828
func asBtcTransaction<T: BaseBtcTransaction>(_ as: T.Type, for address: String, blockId: String? = nil) -> T {
2929
// MARK: Known values
30-
let confirmationsValue: String?
31-
let transactionStatus: TransactionStatus
30+
var confirmationsValue: String? = nil
31+
var transactionStatus: TransactionStatus = .registered
3232

3333
if let confirmations = confirmations {
3434
confirmationsValue = String(confirmations)
35-
transactionStatus = confirmations > 0 ? .success : .pending
36-
} else {
37-
confirmationsValue = nil
38-
transactionStatus = .registered
35+
if confirmations > 0 {
36+
transactionStatus = .success
37+
}
3938
}
4039

4140
// Transfers

Adamant/Modules/Wallets/Bitcoin/BtcWalletService+RichMessageProviderWithStatusCheck.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ extension BtcWalletService {
4444
transaction: CoinTransaction,
4545
btcTransaction: BtcTransaction
4646
) async -> TransactionStatus {
47+
// Before we already stored another status in RawBtcTransactionResponse.asBtcTransaction(_:for:height:).
48+
// So we don't need to double check anything here because it is already at least "registered".
4749
guard let status = btcTransaction.transactionStatus else {
4850
return .inconsistent(.unknown)
4951
}

Adamant/Modules/Wallets/Bitcoin/DTO/BtcTransactionResponse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct RawBtcStatus: Decodable {
6969

7070
extension RawBtcTransactionResponse {
7171
func asBtcTransaction<T: BaseBtcTransaction>(_ as: T.Type, for address: String, height: Decimal? = nil) -> T {
72-
let transactionStatus: TransactionStatus = status.confirmed ? .success : .pending
72+
let transactionStatus: TransactionStatus = status.confirmed ? .success : .registered
7373

7474
var date: Date?
7575
if let time = status.time {

Adamant/Modules/Wallets/Doge/DogeTransactionDetailsViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ final class DogeTransactionDetailsViewController: TransactionDetailsViewControll
9797
}
9898

9999
let trs = try await service.getTransaction(by: id, waitsForConnectivity: false)
100+
100101

101-
if let blockInfo = cachedBlockInfo,
102-
blockInfo.hash == trs.blockHash
103-
{
102+
if let blockInfo = cachedBlockInfo, blockInfo.hash == trs.blockHash {
104103
transaction = trs.asBtcTransaction(
105104
DogeTransaction.self,
106105
for: address,

Adamant/Modules/Wallets/Doge/DogeWalletService+RichMessageProviderWithStatusCheck.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ extension DogeWalletService {
3030
} catch {
3131
return .init(error: error)
3232
}
33+
34+
let status = await getStatus(
35+
dogeTransaction: dogeTransaction,
36+
transaction: transaction
37+
)
3338

34-
return await .init(
39+
return .init(
3540
sentDate: dogeTransaction.date,
36-
status: getStatus(
37-
dogeTransaction: dogeTransaction,
38-
transaction: transaction
39-
)
41+
status: status
4042
)
4143
}
4244
}
@@ -51,7 +53,7 @@ extension DogeWalletService {
5153
let dogeDate = dogeTransaction.date,
5254
confirmations > 0 || dogeDate.timeIntervalSinceNow > -60 * 15
5355
else {
54-
return .pending
56+
return .registered
5557
}
5658

5759
// MARK: Check amount & address

Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
185185
)
186186
}
187187
}
188+
188189
private lazy var dateFormatter: DateFormatter = {
189190
let dateFormatter = DateFormatter()
190191
dateFormatter.dateStyle = .medium
@@ -597,9 +598,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
597598
cell.textLabel?.textColor = UIColor.adamant.textColor
598599
cell.detailTextLabel?.textColor = self?.transactionStatus?.color ?? UIColor.adamant.textColor
599600

600-
if let value = self?.transactionStatus?.localized,
601-
!value.isEmpty
602-
{
601+
if let value = self?.transactionStatus?.localized, !value.isEmpty {
603602
row.value = value
604603
} else {
605604
row.value = TransactionStatus.registered.localized

0 commit comments

Comments
 (0)