diff --git a/ZWallet/Infrastructure/de.lproj/InfoPlist.strings b/ZWallet/Infrastructure/de.lproj/InfoPlist.strings index 5d94481..aaa96b1 100644 --- a/ZWallet/Infrastructure/de.lproj/InfoPlist.strings +++ b/ZWallet/Infrastructure/de.lproj/InfoPlist.strings @@ -22,3 +22,7 @@ "global.Ok" = "Ok"; +"trxDetailCell.received" = "Empfangen"; + +"trxDetailCell.sent" = "Gesendet"; + diff --git a/ZWallet/Infrastructure/en.lproj/InfoPlist.strings b/ZWallet/Infrastructure/en.lproj/InfoPlist.strings index 11b6819..8801ce7 100644 --- a/ZWallet/Infrastructure/en.lproj/InfoPlist.strings +++ b/ZWallet/Infrastructure/en.lproj/InfoPlist.strings @@ -36,3 +36,7 @@ "global.Ok" = "Ok"; +"trxDetailCell.received" = "Received"; + +"trxDetailCell.sent" = "Sent"; + diff --git a/ZWallet/Services/TrxHistoryProvider.swift b/ZWallet/Services/TrxHistoryProvider.swift index c48b9fb..677c1ac 100644 --- a/ZWallet/Services/TrxHistoryProvider.swift +++ b/ZWallet/Services/TrxHistoryProvider.swift @@ -9,9 +9,10 @@ import Foundation -public protocol TrxHistoryProviderProtocol { +public protocol TrxHistoryProviderProtocol: class { func add(trxDetail: TrxDetail) func all() -> [TrxDetail] + func count() -> Int func register(observer: TrxHistoryObserver) func deregister(observer: TrxHistoryObserver) } @@ -36,6 +37,10 @@ public class TrxHistoryProvider: TrxHistoryProviderProtocol { return self.trxHistory } + public func count() -> Int { + return self.trxHistory.count + } + public func register(observer: TrxHistoryObserver) { self.observers.append(observer) } diff --git a/ZWallet/Storyboards/Home.storyboard b/ZWallet/Storyboards/Home.storyboard index 41553b8..2da1a64 100644 --- a/ZWallet/Storyboards/Home.storyboard +++ b/ZWallet/Storyboards/Home.storyboard @@ -29,107 +29,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -215,12 +116,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/ZWallet/ViewCoordinators/HomeCoordinator.swift b/ZWallet/ViewCoordinators/HomeCoordinator.swift index 2c15e44..0e68c10 100644 --- a/ZWallet/ViewCoordinators/HomeCoordinator.swift +++ b/ZWallet/ViewCoordinators/HomeCoordinator.swift @@ -52,8 +52,39 @@ extension HomeCoordinator: HomeVCDelegate { } private func showHomeView() { + + #warning("remove") + self.test_addDummyData() + let vc = self.viewFactory.getHomeView() + vc.delegate = self vc.localizer = self.localizer + vc.trxHistoryProvider = self.iocContainer.trxHistoryProvider self.navigationController.pushViewController(vc, animated: true) } + + private func test_addDummyData() { + let trxHistoryProvider = self.iocContainer.trxHistoryProvider + + let detailSent = TrxDetail(direction: .send, + date: Date.init(), + amountInAtomicUnits: 2208, + address: "address send to", + trxId: "trx id send", + memo: "memo send") + let detailReceived = TrxDetail(direction: .receive, + date: Date.init(), + amountInAtomicUnits: 22, + address: "address received from", + trxId: "trx id receive", + memo: "memo receive") + trxHistoryProvider.add(trxDetail: detailSent) + trxHistoryProvider.add(trxDetail: detailReceived) + trxHistoryProvider.add(trxDetail: detailSent) + trxHistoryProvider.add(trxDetail: detailReceived) + trxHistoryProvider.add(trxDetail: detailSent) + trxHistoryProvider.add(trxDetail: detailReceived) + trxHistoryProvider.add(trxDetail: detailSent) + trxHistoryProvider.add(trxDetail: detailReceived) + } } diff --git a/ZWallet/Views/Home/HomeVC.swift b/ZWallet/Views/Home/HomeVC.swift index 763cf74..a2726de 100644 --- a/ZWallet/Views/Home/HomeVC.swift +++ b/ZWallet/Views/Home/HomeVC.swift @@ -20,6 +20,9 @@ class HomeVC: UIViewController { public weak var delegate: HomeVCDelegate? public weak var localizer: Localizable? + public weak var trxHistoryProvider: TrxHistoryProviderProtocol? + + private var trxHistory = [TrxDetail]() @IBAction func sendButtonTouched() { self.delegate?.homeVCSendButtonTouched(sender: self) @@ -35,20 +38,69 @@ class HomeVC: UIViewController { override func viewDidLoad() { super.viewDidLoad() + + self.setup() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - self.setup() + self.trxHistoryProvider?.register(observer: self) + self.updateView() } - private func setup() { + override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated) + self.trxHistoryProvider?.deregister(observer: self) + } + + private func setup() { + self.trxTableView.dataSource = self } private func updateView() { + #warning("move somewhere else") + self.trxHistory = self.trxHistoryProvider?.all() ?? [TrxDetail]() + self.trxTableView.reloadData() + } +} + + +extension HomeVC: TrxHistoryObserver { + + func changed() { + DispatchQueue.main.async { + self.updateView() + } + } +} + + +extension HomeVC: UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.trxHistory.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = self.trxTableView.dequeueReusableCell(withIdentifier: "TrxCell") as! HomeTrxTableViewCell + + let cellData = self.trxHistory[indexPath.row] + switch cellData.direction { + case .receive: + cell.directionLabel.text = self.localizer?.localized("trxDetailCell.received") + cell.directionImageView.image = UIImage(named: "ArrowDown") + case .send: + cell.directionLabel.text = self.localizer?.localized("trxDetailCell.sent") + cell.directionImageView.image = UIImage(named: "ArrowUp") + } + cell.trxDateLabel.text = "date" + cell.trxAmountLabel.text = "amount ZEC" + cell.trxFiatAmountLabel.text = "fiat CHF" + + return cell } } diff --git a/ZWalletTests/Services/TrxHistoryProviderTests.swift b/ZWalletTests/Services/TrxHistoryProviderTests.swift index 6dc2e24..1884b38 100644 --- a/ZWalletTests/Services/TrxHistoryProviderTests.swift +++ b/ZWalletTests/Services/TrxHistoryProviderTests.swift @@ -50,6 +50,25 @@ class TrxHistoryProviderTests: XCTestCase { XCTAssertTrue(observer.isNotified) } + func test_WhenAddingAnElement_ThenCountIsIncremented() { + let countBefore = self.testee.count() + + self.testee.add(trxDetail: self.getTrxDetail()) + + let countAfter = self.testee.count() + XCTAssertTrue(countAfter == countBefore + 1) + } + + func test_WhenRemovingObserver_ThenThisObserverIsNoLongerNotified() { + let observer = ObserverMock() + self.testee.register(observer: observer) + self.testee.deregister(observer: observer) + + self.testee.add(trxDetail: self.getTrxDetail()) + + XCTAssertFalse(observer.isNotified) + } + private func getTrxDetail() -> TrxDetail { return TrxDetail(direction: .receive, date: Date.init(),