Skip to content

Commit

Permalink
[trello.com/c/1tMg5Cbp] Feat: Added tx data record
Browse files Browse the repository at this point in the history
  • Loading branch information
IanaSilosiev committed Jul 26, 2024
1 parent 3bfaa58 commit 0b4a307
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final class KlyTransactionDetailsViewController: TransactionDetailsViewControlle
return control
}()

override var showTxRecordData: Bool {
true
}
// MARK: - Lifecycle

override func viewDidLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ extension Transactions.TransactionModel: TransactionDetails {
var sentDate: Date? {
timestamp.map { Date(timeIntervalSince1970: TimeInterval($0)) }
}

var txRecordData: String? {
txData
}
}

extension LocalTransaction: TransactionDetails {
Expand Down
4 changes: 4 additions & 0 deletions Adamant/Modules/Wallets/Models/TransactionDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ protocol TransactionDetails {

var nonceRaw: String? { get }

var txRecordData: String? { get }

func summary(
with url: String?,
currentValue: String?,
Expand All @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions Adamant/Modules/Wallets/TransactionDetailsViewControllerBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
case historyFiat
case currentFiat
case inconsistentReason
case txRecordData

var tag: String {
switch self {
Expand All @@ -89,6 +90,7 @@ class TransactionDetailsViewControllerBase: FormViewController {
case .historyFiat: return "hfiat"
case .currentFiat: return "cfiat"
case .inconsistentReason: return "incReason"
case .txRecordData: return "data"
}
}

Expand All @@ -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")
}
}

Expand Down Expand Up @@ -160,6 +165,10 @@ class TransactionDetailsViewControllerBase: FormViewController {

// MARK: - Properties

var showTxRecordData: Bool {
false
}

var transaction: TransactionDetails? {
didSet {
if !isFiatSet {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "Подробности";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "详细信息";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 2 additions & 71 deletions LiskKit/Sources/API/Service/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand All @@ -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<Transactions.TransactionsResponse>) -> 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<ServiceTransactionsResponse>) -> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ extension Transactions {

public var executionStatus: ExecutionStatus

public var txData: String?

// MARK: - Hashable

public static func == (lhs: TransactionModel, rhs: TransactionModel) -> Bool {
Expand Down

0 comments on commit 0b4a307

Please sign in to comment.