diff --git a/Adamant/Modules/Wallets/Klayr/KlyTransactionDetailsViewController.swift b/Adamant/Modules/Wallets/Klayr/KlyTransactionDetailsViewController.swift index 872d8a640..e6f49f1fa 100644 --- a/Adamant/Modules/Wallets/Klayr/KlyTransactionDetailsViewController.swift +++ b/Adamant/Modules/Wallets/Klayr/KlyTransactionDetailsViewController.swift @@ -28,6 +28,9 @@ final class KlyTransactionDetailsViewController: TransactionDetailsViewControlle return control }() + override var showTxRecordData: Bool { + true + } // MARK: - Lifecycle override func viewDidLoad() { diff --git a/Adamant/Modules/Wallets/Klayr/KlyTransactionsViewController.swift b/Adamant/Modules/Wallets/Klayr/KlyTransactionsViewController.swift index 5106ab376..4b549e50f 100644 --- a/Adamant/Modules/Wallets/Klayr/KlyTransactionsViewController.swift +++ b/Adamant/Modules/Wallets/Klayr/KlyTransactionsViewController.swift @@ -121,6 +121,10 @@ extension Transactions.TransactionModel: TransactionDetails { var sentDate: Date? { timestamp.map { Date(timeIntervalSince1970: TimeInterval($0)) } } + + var txRecordData: String? { + txData + } } extension LocalTransaction: TransactionDetails { diff --git a/Adamant/Modules/Wallets/Models/TransactionDetails.swift b/Adamant/Modules/Wallets/Models/TransactionDetails.swift index 3384f61bb..d25191f8c 100644 --- a/Adamant/Modules/Wallets/Models/TransactionDetails.swift +++ b/Adamant/Modules/Wallets/Models/TransactionDetails.swift @@ -47,6 +47,8 @@ protocol TransactionDetails { var nonceRaw: String? { get } + var txRecordData: String? { get } + func summary( with url: String?, currentValue: String?, @@ -57,6 +59,8 @@ protocol TransactionDetails { extension TransactionDetails { var feeCurrencySymbol: String? { defaultCurrencySymbol } + var txRecordData: String? { nil } + func summary( with url: String? = nil, currentValue: String? = nil, diff --git a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift index 0bda84cb3..050a390f4 100644 --- a/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift +++ b/Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift @@ -71,6 +71,7 @@ class TransactionDetailsViewControllerBase: FormViewController { case historyFiat case currentFiat case inconsistentReason + case txRecordData var tag: String { switch self { @@ -89,6 +90,7 @@ class TransactionDetailsViewControllerBase: FormViewController { case .historyFiat: return "hfiat" case .currentFiat: return "cfiat" case .inconsistentReason: return "incReason" + case .txRecordData: return "data" } } @@ -110,6 +112,9 @@ class TransactionDetailsViewControllerBase: FormViewController { case .currentFiat: return .localized("TransactionDetailsScene.Row.CurrentFiat", comment: "Transaction details: current fiat value") case .inconsistentReason: return .localized("TransactionStatus.Inconsistent.Reason.Title", comment: "Transaction status: inconsistent reason title") + case .txRecordData: + return + .localized("TransactionStatus.Inconsistent.RecordData.Title", comment: "Transaction details: Tx data record") } } @@ -160,6 +165,10 @@ class TransactionDetailsViewControllerBase: FormViewController { // MARK: - Properties + var showTxRecordData: Bool { + false + } + var transaction: TransactionDetails? { didSet { if !isFiatSet { @@ -592,6 +601,40 @@ class TransactionDetailsViewControllerBase: FormViewController { detailsSection.append(statusRow) + // MARK: Tx data record + let txRecordData = LabelRow { + $0.disabled = true + $0.tag = Rows.txRecordData.tag + $0.title = Rows.txRecordData.localized + + if let value = transaction?.txRecordData { + $0.value = value + } else { + $0.value = TransactionDetailsViewControllerBase.awaitingValueString + } + + $0.cell.detailTextLabel?.textAlignment = .right + $0.cell.detailTextLabel?.lineBreakMode = .byTruncatingMiddle + }.cellSetup { (cell, _) in + cell.selectionStyle = .gray + cell.textLabel?.textColor = UIColor.adamant.textColor + }.onCellSelection { [weak self] (cell, row) in + if let text = row.value { + self?.shareValue(text, from: cell) + } + }.cellUpdate { [weak self] (cell, row) in + cell.textLabel?.textColor = UIColor.adamant.textColor + if let value = self?.transaction?.txRecordData { + row.value = value + } else { + row.value = TransactionDetailsViewControllerBase.awaitingValueString + } + } + + if showTxRecordData { + detailsSection.append(txRecordData) + } + // MARK: Current Fiat let currentFiatRow = LabelRow { $0.disabled = true diff --git a/CommonKit/Sources/CommonKit/Assets/Localization/de.lproj/Localizable.strings b/CommonKit/Sources/CommonKit/Assets/Localization/de.lproj/Localizable.strings index 4088c7870..83c1fa116 100644 --- a/CommonKit/Sources/CommonKit/Assets/Localization/de.lproj/Localizable.strings +++ b/CommonKit/Sources/CommonKit/Assets/Localization/de.lproj/Localizable.strings @@ -982,6 +982,9 @@ /* Transaction status: inconsistent reason title */ "TransactionStatus.Inconsistent.Reason.Title" = "Inkonsistenter Grund"; +/* Transaction status: inconsistent data title */ +"TransactionStatus.Inconsistent.RecordData.Title" = "Tx-Datensatz"; + /* Transaction details: scene title */ "TransactionDetailsScene.Title" = "Details"; diff --git a/CommonKit/Sources/CommonKit/Assets/Localization/en.lproj/Localizable.strings b/CommonKit/Sources/CommonKit/Assets/Localization/en.lproj/Localizable.strings index 37bca7fef..e5b51ddb7 100644 --- a/CommonKit/Sources/CommonKit/Assets/Localization/en.lproj/Localizable.strings +++ b/CommonKit/Sources/CommonKit/Assets/Localization/en.lproj/Localizable.strings @@ -967,6 +967,9 @@ /* Transaction status: inconsistent reason title */ "TransactionStatus.Inconsistent.Reason.Title" = "Inconsistent reason"; +/* Transaction status: inconsistent data title */ +"TransactionStatus.Inconsistent.RecordData.Title" = "Tx data record"; + /* Transaction details: scene title */ "TransactionDetailsScene.Title" = "Details"; diff --git a/CommonKit/Sources/CommonKit/Assets/Localization/ru.lproj/Localizable.strings b/CommonKit/Sources/CommonKit/Assets/Localization/ru.lproj/Localizable.strings index 066703b31..3a2478eaf 100644 --- a/CommonKit/Sources/CommonKit/Assets/Localization/ru.lproj/Localizable.strings +++ b/CommonKit/Sources/CommonKit/Assets/Localization/ru.lproj/Localizable.strings @@ -961,6 +961,9 @@ /* Transaction status: inconsistent reason title */ "TransactionStatus.Inconsistent.Reason.Title" = "Противоречивая причина"; +/* Transaction status: inconsistent data title */ +"TransactionStatus.Inconsistent.RecordData.Title" = "Данные транзакции"; + /* Transaction details: scene title */ "TransactionDetailsScene.Title" = "Подробности"; diff --git a/CommonKit/Sources/CommonKit/Assets/Localization/zh.lproj/Localizable.strings b/CommonKit/Sources/CommonKit/Assets/Localization/zh.lproj/Localizable.strings index 63fafa539..2863ea7a6 100644 --- a/CommonKit/Sources/CommonKit/Assets/Localization/zh.lproj/Localizable.strings +++ b/CommonKit/Sources/CommonKit/Assets/Localization/zh.lproj/Localizable.strings @@ -964,6 +964,9 @@ /* Transaction status: inconsistent reason title */ "TransactionStatus.Inconsistent.Reason.Title" = "不一致的原因"; +/* Transaction status: inconsistent data title */ +"TransactionStatus.Inconsistent.RecordData.Title" = "Tx数据记录"; + /* Transaction details: scene title */ "TransactionDetailsScene.Title" = "详细信息"; diff --git a/LiskKit/Sources/API/Service/Models/ServiceTransactionModel.swift b/LiskKit/Sources/API/Service/Models/ServiceTransactionModel.swift index a8fa3a812..a06b98862 100644 --- a/LiskKit/Sources/API/Service/Models/ServiceTransactionModel.swift +++ b/LiskKit/Sources/API/Service/Models/ServiceTransactionModel.swift @@ -84,6 +84,7 @@ public struct ServiceTransactionModel: APIModel { public struct Params: APIModel { public let amount: String public let recipientAddress: String + public let data: String? } public let id: String diff --git a/LiskKit/Sources/API/Service/Service.swift b/LiskKit/Sources/API/Service/Service.swift index 8624f755b..27f2d835d 100644 --- a/LiskKit/Sources/API/Service/Service.swift +++ b/LiskKit/Sources/API/Service/Service.swift @@ -75,48 +75,6 @@ extension Service { sort: APIRequest.Sort? = nil, completionHandler: @escaping (Result<[Transactions.TransactionModel]>) -> Void ) { - if version == .v1 { - transactionsV1(id: id, block: block, sender: sender, recipient: recipient, senderIdOrRecipientId: senderIdOrRecipientId, limit: limit, offset: offset, sort: sort) { result in - switch result { - case .success(response: let value): - completionHandler(.success(response: value.data)) - case .error(response: let error): - completionHandler(.error(response: error)) - } - } - return - } - if version == .v2 { - transactionsV2(id: id, block: block, sender: sender, recipient: recipient, senderIdOrRecipientId: senderIdOrRecipientId, limit: limit, offset: offset, sort: sort) { result in - switch result { - case .success(response: let value): - let transaction = value.data.map { - Transactions.TransactionModel( - id: $0.id, - height: $0.height, - blockId: $0.blockId, - type: $0.type, - timestamp: $0.timestamp, - senderPublicKey: $0.senderPublicKey, - senderId: $0.senderId, - recipientId: $0.recipientId, - recipientPublicKey: $0.recipientPublicKey, - amount: $0.amount, - fee: $0.fee, - signature: $0.signature, - confirmations: $0.confirmations, - isOutgoing: $0.senderId.lowercased() == ownerAddress?.lowercased(), - nonce: $0.nonce, - executionStatus: $0.executionStatus - ) - } - completionHandler(.success(response: transaction)) - case .error(response: let error): - completionHandler(.error(response: error)) - } - } - } - if version == .v3 { transactionsV3( id: id, @@ -147,7 +105,8 @@ extension Service { confirmations: $0.confirmations, isOutgoing: $0.senderId.lowercased() == ownerAddress?.lowercased(), nonce: $0.nonce, - executionStatus: $0.executionStatus + executionStatus: $0.executionStatus, + txData: $0.params.data ) } completionHandler(.success(response: transaction)) @@ -158,34 +117,6 @@ extension Service { } } - private func transactionsV1(id: String? = nil, block: String? = nil, sender: String? = nil, recipient: String? = nil, senderIdOrRecipientId: String? = nil, limit: UInt? = nil, offset: UInt? = nil, sort: APIRequest.Sort? = nil, completionHandler: @escaping (Response) -> Void) { - var options: RequestOptions = [:] - if let value = id { options["id"] = value } - if let value = block { options["blockId"] = value } - if let value = limit { options["limit"] = value } - if let value = offset { options["offset"] = value } - if let value = sort?.value { options["sort"] = value } - if let value = sender { options["senderId"] = value } - if let value = recipient { options["recipientId"] = value } - if let value = senderIdOrRecipientId { options["senderIdOrRecipientId"] = value } - - client.get(path: "\(Version.v1.rawValue)/transactions", options: options, completionHandler: completionHandler) - } - - private func transactionsV2(id: String? = nil, block: String? = nil, sender: String? = nil, recipient: String? = nil, senderIdOrRecipientId: String? = nil, limit: UInt? = nil, offset: UInt? = nil, sort: APIRequest.Sort? = nil, completionHandler: @escaping (Response) -> Void) { - var options: RequestOptions = [:] - if let value = id { options["transactionId"] = value } - if let value = block { options["blockId"] = value } - if let value = limit { options["limit"] = value } - if let value = offset { options["offset"] = value } - if let value = sort?.value { options["sort"] = value } - if let value = sender { options["senderAddress"] = value } - if let value = recipient { options["recipientAddress"] = value } - if let value = senderIdOrRecipientId { options["address"] = value } - - client.get(path: "\(Version.v2.rawValue)/transactions", options: options, completionHandler: completionHandler) - } - private func transactionsV3( id: String? = nil, block: String? = nil, diff --git a/LiskKit/Sources/API/Transactions/Models/TransactionModel.swift b/LiskKit/Sources/API/Transactions/Models/TransactionModel.swift index 4a2d5d4fd..01708120a 100644 --- a/LiskKit/Sources/API/Transactions/Models/TransactionModel.swift +++ b/LiskKit/Sources/API/Transactions/Models/TransactionModel.swift @@ -57,6 +57,8 @@ extension Transactions { public var executionStatus: ExecutionStatus + public var txData: String? + // MARK: - Hashable public static func == (lhs: TransactionModel, rhs: TransactionModel) -> Bool {