Move properties into TransactionViewModel

pull/2/head
Michael Scoff 7 years ago
parent 7ed600ef93
commit 6f2e2ab35d
  1. 19
      Trust/Transactions/ViewControllers/TransactionViewController.swift
  2. 30
      Trust/Transactions/ViewModels/TransactionViewModel.swift

@ -31,15 +31,6 @@ class TransactionViewController: UIViewController {
title = viewModel.title
view.backgroundColor = viewModel.backgroundColor
let gasUsed = BInt(String(transaction.gasUsed))
let gasPrice = BInt(String(transaction.gasPrice))
let gasFee = EthereumConverter.from(
value: gasPrice * gasUsed,
to: .ether,
minimumFractionDigits: 5,
maximumFractionDigits: 5
)
let confirmation = session.chainState.latestBlock - Int(transaction.blockNumber)
let items: [UIView] = [
@ -51,14 +42,14 @@ class TransactionViewController: UIViewController {
)
),
TransactionAppearance.divider(color: Colors.lightGray, alpha: 0.3),
TransactionAppearance.item(title: "From", subTitle: transaction.from),
TransactionAppearance.item(title: "To", subTitle: transaction.to),
TransactionAppearance.item(title: "Gas Fee", subTitle: gasFee),
TransactionAppearance.item(title: "From", subTitle: viewModel.from),
TransactionAppearance.item(title: "To", subTitle: viewModel.to),
TransactionAppearance.item(title: "Gas Fee", subTitle: viewModel.gasFee),
TransactionAppearance.item(title: "Confirmation", subTitle: String(confirmation)),
TransactionAppearance.divider(color: Colors.lightGray, alpha: 0.3),
TransactionAppearance.item(title: "Transaction #", subTitle: transaction.to),
TransactionAppearance.item(title: "Transaction #", subTitle: viewModel.transactionID),
TransactionAppearance.item(title: "Transaction time", subTitle: viewModel.createdAt),
TransactionAppearance.item(title: "Block #", subTitle: String(transaction.blockNumber)),
TransactionAppearance.item(title: "Block #", subTitle: viewModel.blockNumber),
moreDetails(),
]

@ -54,4 +54,34 @@ struct TransactionViewModel {
var detailsURL: URL {
return ConfigExplorer(server: config.server).transactionURL(for: transaction.id)
}
var transactionID: String {
return transaction.id
}
var to: String {
guard let to = transaction.operation?.to else {
return transaction.to
}
return to
}
var from: String {
return transaction.from
}
var gasFee: String {
let gasUsed = BInt(String(transaction.gasUsed))
let gasPrice = BInt(String(transaction.gasPrice))
return EthereumConverter.from(
value: gasPrice * gasUsed,
to: .ether,
minimumFractionDigits: 5,
maximumFractionDigits: 5
)
}
var blockNumber: String {
return String(transaction.blockNumber)
}
}

Loading…
Cancel
Save