Skip to content

[trello.com/c/SL4zLZnb] Improve coin tx sending algorithm #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/3.11.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Adamant/Models/BTCRawTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ struct BTCRawTransaction {

func asBtcTransaction<T: BaseBtcTransaction>(_ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct RawBtcStatus: Decodable {

extension RawBtcTransactionResponse {
func asBtcTransaction<T: BaseBtcTransaction>(_ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
)
}
}

private lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
Expand Down Expand Up @@ -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
Expand Down