Show full transaction details for Monero and XRP
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Full detail for one transaction. Monero and XRP fill different fields, so
|
||||
/// rows are included only when the wallet knows the value.
|
||||
struct TransactionDetailView: View {
|
||||
var record: TransactionRecord
|
||||
var symbol: String
|
||||
var chain: Chain
|
||||
var onDone: () -> Void
|
||||
|
||||
private var dateFormatter: DateFormatter {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .medium
|
||||
formatter.timeStyle = .medium
|
||||
return formatter
|
||||
}
|
||||
|
||||
/// A Monero incoming transfer only reveals the wallet's own receiving
|
||||
/// address (the sender is hidden), so it is not labelled "From".
|
||||
private var counterpartyLabel: String {
|
||||
if chain == .xmr, record.direction == .incoming { return "Received at" }
|
||||
return record.direction == .incoming ? "From" : "To"
|
||||
}
|
||||
|
||||
private var statusText: String {
|
||||
if record.direction == .incoming {
|
||||
if let confirmations = record.confirmations, confirmations > 0 {
|
||||
return "Confirmed · \(confirmations) confirmation\(confirmations == 1 ? "" : "s")"
|
||||
}
|
||||
return record.confirmed ? "Confirmed" : "Waiting for confirmation"
|
||||
}
|
||||
if let confirmations = record.confirmations, confirmations > 0 {
|
||||
return "Confirmed · \(confirmations) confirmation\(confirmations == 1 ? "" : "s")"
|
||||
}
|
||||
return record.confirmed ? "Confirmed" : "Pending"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Theme.background.ignoresSafeArea()
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 18) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack(spacing: 8) {
|
||||
Image(systemName: record.direction == .incoming ? "arrow.down.left" : "arrow.up.right")
|
||||
.font(.system(size: 14, weight: .bold))
|
||||
.foregroundStyle(record.direction == .incoming ? Theme.success : Theme.accent)
|
||||
Text(record.direction == .incoming ? "Received" : "Sent")
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundStyle(Theme.text)
|
||||
}
|
||||
Text("\(record.direction == .incoming ? "+" : "-")\(record.amount) \(symbol)")
|
||||
.font(.system(size: 30, weight: .bold, design: .rounded))
|
||||
.foregroundStyle(Theme.text)
|
||||
Text(statusText)
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Theme.muted)
|
||||
}
|
||||
|
||||
Card {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let timestamp = record.timestamp {
|
||||
DetailRow(label: "Date", value: dateFormatter.string(from: timestamp))
|
||||
}
|
||||
if let fee = record.fee, !fee.isEmpty, record.direction == .outgoing {
|
||||
DetailRow(label: "Network fee", value: "\(fee) \(symbol)")
|
||||
}
|
||||
if let counterparty = record.counterparty, !counterparty.isEmpty {
|
||||
DetailRow(label: counterpartyLabel, value: counterparty, monospaced: true, copyable: true)
|
||||
}
|
||||
if let tag = record.tag {
|
||||
DetailRow(label: "Destination tag", value: String(tag))
|
||||
}
|
||||
if let height = record.height ?? record.ledgerIndex {
|
||||
DetailRow(label: chain == .xmr ? "Block height" : "Ledger index", value: String(height))
|
||||
}
|
||||
if let confirmations = record.confirmations {
|
||||
DetailRow(label: "Confirmations", value: String(confirmations))
|
||||
}
|
||||
if let accountIndex = record.accountIndex {
|
||||
DetailRow(label: "Account", value: accountIndex == 0 ? "Primary (0)" : "Account \(accountIndex + 1) (\(accountIndex))")
|
||||
}
|
||||
if let subaddressIndex = record.subaddressIndex {
|
||||
DetailRow(label: "Address index", value: "\(subaddressIndex)")
|
||||
}
|
||||
if let sequence = record.sequence {
|
||||
DetailRow(label: "Sequence", value: String(sequence))
|
||||
}
|
||||
if let paymentId = record.paymentId {
|
||||
DetailRow(label: "Payment ID", value: paymentId, monospaced: true, copyable: true)
|
||||
}
|
||||
if let weight = record.weight {
|
||||
DetailRow(label: "Weight", value: "\(weight) bytes")
|
||||
}
|
||||
if let note = record.note {
|
||||
DetailRow(label: "Note", value: note)
|
||||
}
|
||||
DetailRow(label: chain == .xmr ? "Transaction ID" : "Ledger hash",
|
||||
value: record.id,
|
||||
monospaced: true,
|
||||
copyable: true)
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryButton(title: "Done", action: onDone)
|
||||
}
|
||||
.padding(20)
|
||||
}
|
||||
}
|
||||
.preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
|
||||
struct DetailRow: View {
|
||||
var label: String
|
||||
var value: String
|
||||
var monospaced = false
|
||||
var copyable = false
|
||||
|
||||
@State private var copied = false
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 12) {
|
||||
Text(label)
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Theme.muted)
|
||||
.frame(width: 108, alignment: .leading)
|
||||
Text(value)
|
||||
.font(.system(size: 12, design: monospaced ? .monospaced : .default))
|
||||
.foregroundStyle(Theme.text)
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
if copyable {
|
||||
Button {
|
||||
UIPasteboard.general.string = value
|
||||
copied = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { copied = false }
|
||||
} label: {
|
||||
Image(systemName: copied ? "checkmark" : "doc.on.doc")
|
||||
.font(.system(size: 12, weight: .semibold))
|
||||
.foregroundStyle(Theme.accent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user