-
Notifications
You must be signed in to change notification settings - Fork 37
/
LatestTransactionListViewCell.swift
59 lines (48 loc) · 2.71 KB
/
LatestTransactionListViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// LatestTransactionListViewCell.swift
// Wei
//
// Created by Ryosuke Fukuda on 2018/04/14.
// Copyright © 2018 popshoot All rights reserved.
//
import UIKit
import EthereumKit
final class LatestTransactionListViewCell: UITableViewCell, InputAppliable {
@IBOutlet private weak var timestampLabel: UILabel!
@IBOutlet private weak var transactionStatusImageViewView: UIImageView!
@IBOutlet private weak var transactionStatusLabel: UILabel!
@IBOutlet private weak var etherAmountLabel: UILabel!
typealias Input = TransactionHistory
func apply(input: Input) {
let (kind, address) = (input.kind, input.myAddress)
switch kind {
case .local(let localTransaction):
if let etherAmount = Wei(localTransaction.value).flatMap({ try? Converter.toEther(wei: $0) })?.string {
etherAmountLabel.text = etherAmount
} else {
etherAmountLabel.text = R.string.localizable.errorEtherFailedToConvert()
}
timestampLabel.text = DateFormatter.fullDateString(from: Date(timeIntervalSince1970: TimeInterval(localTransaction.date)))
transactionStatusLabel.text = R.string.localizable.transactionWaitingForSend()
transactionStatusImageViewView.image = #imageLiteral(resourceName: "icon_card_waiting")
case .remote(let transaction):
if let etherAmount = Wei(transaction.value).flatMap({ try? Converter.toEther(wei: $0) })?.string {
etherAmountLabel.text = etherAmount
} else {
etherAmountLabel.text = R.string.localizable.errorEtherFailedToConvert()
}
timestampLabel.text = DateFormatter.fullDateString(from: Date(timeIntervalSince1970: TimeInterval(Int64(transaction.timeStamp)!)))
let isReceiveTransaction = transaction.isReceiveTransaction(myAddress: address)
if transaction.isPending {
let text = isReceiveTransaction ? R.string.localizable.transactionWatingForReceive() : R.string.localizable.transactionWaitingForSend()
transactionStatusLabel.text = text
transactionStatusImageViewView.image = #imageLiteral(resourceName: "icon_card_waiting")
} else {
let text = isReceiveTransaction ? R.string.localizable.transactionReceived() : R.string.localizable.transactionSent()
transactionStatusLabel.text = text
let icon = isReceiveTransaction ? #imageLiteral(resourceName: "icon_card_receive") : #imageLiteral(resourceName: "icon_card_send")
transactionStatusImageViewView.image = icon
}
}
}
}