From 6f2e2ab35d7c6d574e15a79580d37d63d1dffe92 Mon Sep 17 00:00:00 2001 From: Michael Scoff Date: Tue, 21 Nov 2017 10:20:53 -0800 Subject: [PATCH] Move properties into TransactionViewModel --- .../TransactionViewController.swift | 19 ++++-------- .../ViewModels/TransactionViewModel.swift | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Trust/Transactions/ViewControllers/TransactionViewController.swift b/Trust/Transactions/ViewControllers/TransactionViewController.swift index 1b46f9ed0..83f1d2f1a 100644 --- a/Trust/Transactions/ViewControllers/TransactionViewController.swift +++ b/Trust/Transactions/ViewControllers/TransactionViewController.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(), ] diff --git a/Trust/Transactions/ViewModels/TransactionViewModel.swift b/Trust/Transactions/ViewModels/TransactionViewModel.swift index f4cc12bc7..2c54e43cc 100644 --- a/Trust/Transactions/ViewModels/TransactionViewModel.swift +++ b/Trust/Transactions/ViewModels/TransactionViewModel.swift @@ -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) + } }