From 74e08fbb3047ea7da5fd4c34fe89f3960692f258 Mon Sep 17 00:00:00 2001 From: Dmitrij Meidus Date: Wed, 21 May 2025 16:53:41 +0300 Subject: [PATCH] [trello.com/c/SL4zLZnb] Improve coin tx sending algorithm --- Adamant/Models/BTCRawTransaction.swift | 11 +++++------ ...ervice+RichMessageProviderWithStatusCheck.swift | 2 ++ .../Bitcoin/DTO/BtcTransactionResponse.swift | 2 +- .../DogeTransactionDetailsViewController.swift | 5 ++--- ...ervice+RichMessageProviderWithStatusCheck.swift | 14 ++++++++------ .../TransactionDetailsViewControllerBase.swift | 5 ++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Adamant/Models/BTCRawTransaction.swift b/Adamant/Models/BTCRawTransaction.swift index c6afaf70a..01f1c0d32 100644 --- a/Adamant/Models/BTCRawTransaction.swift +++ b/Adamant/Models/BTCRawTransaction.swift @@ -27,15 +27,14 @@ struct BTCRawTransaction { func asBtcTransaction(_ as: T.Type, for address: String, blockId: String? = nil) -> T { // MARK: Known values - let confirmationsValue: String? - let transactionStatus: TransactionStatus + var confirmationsValue: String? = nil + var transactionStatus: TransactionStatus = .registered if let confirmations = confirmations { confirmationsValue = String(confirmations) - transactionStatus = confirmations > 0 ? .success : .pending - } else { - confirmationsValue = nil - transactionStatus = .registered + if confirmations > 0 { + transactionStatus = .success + } } // Transfers diff --git a/Adamant/Modules/Wallets/Bitcoin/BtcWalletService+RichMessageProviderWithStatusCheck.swift b/Adamant/Modules/Wallets/Bitcoin/BtcWalletService+RichMessageProviderWithStatusCheck.swift index ff73b6b0f..850a7759c 100644 --- a/Adamant/Modules/Wallets/Bitcoin/BtcWalletService+RichMessageProviderWithStatusCheck.swift +++ b/Adamant/Modules/Wallets/Bitcoin/BtcWalletService+RichMessageProviderWithStatusCheck.swift @@ -44,6 +44,8 @@ extension BtcWalletService { transaction: CoinTransaction, btcTransaction: BtcTransaction ) async -> TransactionStatus { + // Before we already stored another status in RawBtcTransactionResponse.asBtcTransaction(_:for:height:). + // So we don't need to double check anything here because it is already at least "registered". guard let status = btcTransaction.transactionStatus else { return .inconsistent(.unknown) } diff --git a/Adamant/Modules/Wallets/Bitcoin/DTO/BtcTransactionResponse.swift b/Adamant/Modules/Wallets/Bitcoin/DTO/BtcTransactionResponse.swift index 911ca8fb5..909768875 100644 --- a/Adamant/Modules/Wallets/Bitcoin/DTO/BtcTransactionResponse.swift +++ b/Adamant/Modules/Wallets/Bitcoin/DTO/BtcTransactionResponse.swift @@ -69,7 +69,7 @@ struct RawBtcStatus: Decodable { extension RawBtcTransactionResponse { func asBtcTransaction(_ as: T.Type, for address: String, height: Decimal? = nil) -> T { - let transactionStatus: TransactionStatus = status.confirmed ? .success : .pending + let transactionStatus: TransactionStatus = status.confirmed ? .success : .registered var date: Date? if let time = status.time { diff --git a/Adamant/Modules/Wallets/Doge/DogeTransactionDetailsViewController.swift b/Adamant/Modules/Wallets/Doge/DogeTransactionDetailsViewController.swift index 15c2564fd..e9146c046 100644 --- a/Adamant/Modules/Wallets/Doge/DogeTransactionDetailsViewController.swift +++ b/Adamant/Modules/Wallets/Doge/DogeTransactionDetailsViewController.swift @@ -97,10 +97,9 @@ final class DogeTransactionDetailsViewController: TransactionDetailsViewControll } let trs = try await service.getTransaction(by: id, waitsForConnectivity: false) + - if let blockInfo = cachedBlockInfo, - blockInfo.hash == trs.blockHash - { + if let blockInfo = cachedBlockInfo, blockInfo.hash == trs.blockHash { transaction = trs.asBtcTransaction( DogeTransaction.self, for: address, diff --git a/Adamant/Modules/Wallets/Doge/DogeWalletService+RichMessageProviderWithStatusCheck.swift b/Adamant/Modules/Wallets/Doge/DogeWalletService+RichMessageProviderWithStatusCheck.swift index 87f92df4f..6d4d263b7 100644 --- a/Adamant/Modules/Wallets/Doge/DogeWalletService+RichMessageProviderWithStatusCheck.swift +++ b/Adamant/Modules/Wallets/Doge/DogeWalletService+RichMessageProviderWithStatusCheck.swift @@ -30,13 +30,15 @@ extension DogeWalletService { } catch { return .init(error: error) } + + let status = await getStatus( + dogeTransaction: dogeTransaction, + transaction: transaction + ) - return await .init( + return .init( sentDate: dogeTransaction.date, - status: getStatus( - dogeTransaction: dogeTransaction, - transaction: transaction - ) + status: status ) } } @@ -51,7 +53,7 @@ extension DogeWalletService { let dogeDate = dogeTransaction.date, confirmations > 0 || dogeDate.timeIntervalSinceNow > -60 * 15 else { - return .pending + return .registered } // MARK: Check amount & address diff --git a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift index 63ffccf0f..4b6255f24 100644 --- a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift +++ b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift @@ -185,6 +185,7 @@ class TransactionDetailsViewControllerBase: FormViewController { ) } } + private lazy var dateFormatter: DateFormatter = { let dateFormatter = DateFormatter() dateFormatter.dateStyle = .medium @@ -597,9 +598,7 @@ class TransactionDetailsViewControllerBase: FormViewController { cell.textLabel?.textColor = UIColor.adamant.textColor cell.detailTextLabel?.textColor = self?.transactionStatus?.color ?? UIColor.adamant.textColor - if let value = self?.transactionStatus?.localized, - !value.isEmpty - { + if let value = self?.transactionStatus?.localized, !value.isEmpty { row.value = value } else { row.value = TransactionStatus.registered.localized