An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/Trust/Transactions/ViewModels/TransactionViewModel.swift

67 lines
1.7 KiB

// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
struct TransactionViewModel {
static let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .medium
formatter.timeZone = TimeZone.current
return formatter
}()
let transaction: Transaction
init(transaction: Transaction) {
self.transaction = transaction
}
var title: String {
return "Transaction"
}
var backgroundColor: UIColor {
return .white
}
var amount: String {
let value = EthereumConverter.from(value: BInt(transaction.value), to: .ether, minimumFractionDigits: 5)
switch transaction.direction {
case .incoming: return "+\(value)"
case .outgoing: return "-\(value)"
}
}
var amountTextColor: UIColor {
switch transaction.direction {
case .incoming: return Colors.green
case .outgoing: return Colors.red
}
}
var amountAttributedString: NSAttributedString {
let amount = NSAttributedString(
string: self.amount,
attributes: [
NSFontAttributeName: UIFont.systemFont(ofSize: 20),
NSForegroundColorAttributeName: amountTextColor,
]
)
let currency = NSAttributedString(
string: " ether",
attributes: [
NSFontAttributeName: UIFont.systemFont(ofSize: 14),
]
)
return amount + currency
}
var createdAt: String {
return TransactionViewModel.formatter.string(from: transaction.date)
}
}