Skip to content

Commit

Permalink
Add Wallet info screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vikmeup committed Jun 27, 2018
1 parent c0b1630 commit d3d26b3
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 59 deletions.
12 changes: 12 additions & 0 deletions Trust.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@
77E81D94203687FB00534C99 /* NotificationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E81D93203687FB00534C99 /* NotificationsViewController.swift */; };
77E81D962036883B00534C99 /* NotificationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E81D952036883B00534C99 /* NotificationsViewModel.swift */; };
77EAD88220E156E900D14AA2 /* DynamicCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77EAD88120E156E900D14AA2 /* DynamicCollectionView.swift */; };
77EAD88420E1B82300D14AA2 /* WalletInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77EAD88320E1B82300D14AA2 /* WalletInfoViewController.swift */; };
77EAD88620E1C00C00D14AA2 /* WalletInfoType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77EAD88520E1C00C00D14AA2 /* WalletInfoType.swift */; };
77EAD88820E1C02200D14AA2 /* WalletInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77EAD88720E1C02200D14AA2 /* WalletInfoViewModel.swift */; };
902CAB592051818B00F96FFE /* BookmarkViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 902CAB582051818A00F96FFE /* BookmarkViewCell.xib */; };
902CAB5B2051835E00F96FFE /* BookmarkViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 902CAB5A2051835E00F96FFE /* BookmarkViewCell.swift */; };
903682F1204A6DB800013479 /* BookmarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 903682F0204A6DB800013479 /* BookmarkViewController.swift */; };
Expand Down Expand Up @@ -899,6 +902,9 @@
77E81D93203687FB00534C99 /* NotificationsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsViewController.swift; sourceTree = "<group>"; };
77E81D952036883B00534C99 /* NotificationsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsViewModel.swift; sourceTree = "<group>"; };
77EAD88120E156E900D14AA2 /* DynamicCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicCollectionView.swift; sourceTree = "<group>"; };
77EAD88320E1B82300D14AA2 /* WalletInfoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInfoViewController.swift; sourceTree = "<group>"; };
77EAD88520E1C00C00D14AA2 /* WalletInfoType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInfoType.swift; sourceTree = "<group>"; };
77EAD88720E1C02200D14AA2 /* WalletInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletInfoViewModel.swift; sourceTree = "<group>"; };
87FA1153388F27F599C430B8 /* Pods-TrustTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TrustTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TrustTests/Pods-TrustTests.debug.xcconfig"; sourceTree = "<group>"; };
902CAB582051818A00F96FFE /* BookmarkViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BookmarkViewCell.xib; sourceTree = "<group>"; };
902CAB5A2051835E00F96FFE /* BookmarkViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1266,6 +1272,7 @@
children = (
291A1B641F974E8600ADEC80 /* WalletEntryPoint.swift */,
29F114EF1FA6D53700114A29 /* ImportSelectionType.swift */,
77EAD88520E1C00C00D14AA2 /* WalletInfoType.swift */,
);
path = Types;
sourceTree = "<group>";
Expand Down Expand Up @@ -1457,6 +1464,7 @@
77872D282025116E0032D687 /* EnterPasswordCoordinator.swift */,
BB1CC279203D061B0042E56C /* TrustDocumentPickerViewController.swift */,
7716EDC220DFB86100773010 /* VerifyPassphraseViewController.swift */,
77EAD88320E1B82300D14AA2 /* WalletInfoViewController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand All @@ -1468,6 +1476,7 @@
2996F1421F6C96FF005C33AE /* ImportWalletViewModel.swift */,
771AA961200D5EC700D25403 /* PassphraseViewModel.swift */,
77872D26202505C00032D687 /* EnterPasswordViewModel.swift */,
77EAD88720E1C02200D14AA2 /* WalletInfoViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -3005,6 +3014,7 @@
73ACEEFF20163E08003DD71D /* PasscodeCharacterView.swift in Sources */,
903682F4204A714C00013479 /* BookmarksStore.swift in Sources */,
295B61D41FE7D5B500642E60 /* CurrencyFormatter.swift in Sources */,
77EAD88620E1C00C00D14AA2 /* WalletInfoType.swift in Sources */,
775DF42B203693CD009CD082 /* Preferences.swift in Sources */,
296421991F70C1F900EB363B /* EmptyView.swift in Sources */,
298542E51FBA9B0700CB5081 /* ShapeShift.swift in Sources */,
Expand All @@ -3020,8 +3030,10 @@
29FA00D0201CA66A002F7DC5 /* DAppError.swift in Sources */,
291EC9DF1F7053C50004EDD0 /* NavigationController.swift in Sources */,
2995739F1FA1F294006F17FD /* QRURLParser.swift in Sources */,
77EAD88420E1B82300D14AA2 /* WalletInfoViewController.swift in Sources */,
29C9F5F91F720BD30025C494 /* FloatLabelCell.swift in Sources */,
77B641032097211F00BEF3EB /* TransactionsTableView.swift in Sources */,
77EAD88820E1C02200D14AA2 /* WalletInfoViewModel.swift in Sources */,
77EAD88220E156E900D14AA2 /* DynamicCollectionView.swift in Sources */,
775DF443203E5685009CD082 /* Tabs.swift in Sources */,
771AA960200D5E8800D25403 /* PassphraseView.swift in Sources */,
Expand Down
22 changes: 21 additions & 1 deletion Trust/Accounts/Coordinators/AccountsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class AccountsCoordinator: Coordinator {
navigationController.present(coordinator.navigationController, animated: true, completion: nil)
}

func showWalletInfo(for wallet: Wallet, sender: UIView) {
let controller = WalletInfoViewController(wallet: wallet)
controller.delegate = self
navigationController.pushViewController(controller, animated: true)
}

func showInfoSheet(for account: Wallet, sender: UIView) {
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
controller.popoverPresentationController?.sourceView = sender
Expand Down Expand Up @@ -163,7 +169,8 @@ extension AccountsCoordinator: AccountsViewControllerDelegate {
}

func didSelectInfoForAccount(account: Wallet, sender: UIView, in viewController: AccountsViewController) {
showInfoSheet(for: account, sender: sender)
//showInfoSheet(for: account, sender: sender)
showWalletInfo(for: account, sender: sender)
}
}

Expand Down Expand Up @@ -209,3 +216,16 @@ extension AccountsCoordinator: ExportPrivateKeyCoordinatorDelegate {
removeCoordinator(coordinator)
}
}

extension AccountsCoordinator: WalletInfoViewControllerDelegate {
func didPress(item: WalletInfoType, in controller: WalletInfoViewController) {
switch item {
case .exportKeystore(let account):
exportKeystore(for: account)
case .exportPrivateKey(let account):
exportPrivateKey(for: account)
case .exportRecoveryPhrase(let account):
exportMnemonic(for: account)
}
}
}
2 changes: 1 addition & 1 deletion Trust/Export/Coordinators/ExportPhraseCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExportPhraseCoordinator: Coordinator {
controller.delegate = self
controller.title = viewModel.title
controller.navigationItem.leftBarButtonItem = UIBarButtonItem(
barButtonSystemItem: .cancel,
barButtonSystemItem: .done,
target: self,
action: #selector(dismiss)
)
Expand Down
50 changes: 50 additions & 0 deletions Trust/Wallet/Types/WalletInfoType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright SIX DAY LLC. All rights reserved.

import Foundation
import TrustKeystore
import UIKit

enum WalletInfoType {
case exportRecoveryPhrase(Account)
case exportPrivateKey(Account)
case exportKeystore(Account)

var title: String {
switch self {
case .exportRecoveryPhrase:
return NSLocalizedString("wallet.info.exportRecoveryPhrase", value: "Export Recovery phrase", comment: "")
case .exportKeystore:
return NSLocalizedString("wallets.backup.alertSheet.title", value: "Backup Keystore", comment: "")
case .exportPrivateKey:
return NSLocalizedString("wallets.export.alertSheet.title", value: "Export Private Key", comment: "")
}
}

var image: UIImage? {
switch self {
case .exportRecoveryPhrase:
return R.image.backup_warning()
case .exportKeystore:
return R.image.backup_warning()
case .exportPrivateKey:
return R.image.backup_warning()
}
}
}

extension WalletInfoType: Equatable {
static func == (lhs: WalletInfoType, rhs: WalletInfoType) -> Bool {
switch (lhs, rhs) {
case (let .exportRecoveryPhrase(lhs), let .exportRecoveryPhrase(rhs)):
return lhs == rhs
case (let .exportKeystore(lhs), let .exportKeystore(rhs)):
return lhs == rhs
case (let .exportPrivateKey(lhs), let .exportPrivateKey(rhs)):
return lhs == rhs
case (_, .exportRecoveryPhrase),
(_, .exportKeystore),
(_, .exportPrivateKey):
return false
}
}
}
85 changes: 69 additions & 16 deletions Trust/Wallet/ViewControllers/PassphraseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ enum PassphraseMode {

class PassphraseViewController: UIViewController {

let contentView = PassphraseContentView()
let viewModel = PassphraseViewModel()
let account: Account
let words: [String]
Expand All @@ -27,6 +26,8 @@ class PassphraseViewController: UIViewController {
button.setTitle(NSLocalizedString("Verify", value: "Verify", comment: ""), for: .normal)
return button
}()
let subTitleLabel = UILabel()
let copyButton = Button(size: .small, style: .clear)
weak var delegate: PassphraseViewControllerDelegate?

init(
Expand All @@ -42,30 +43,82 @@ class PassphraseViewController: UIViewController {
navigationItem.title = viewModel.title
view.backgroundColor = viewModel.backgroundColor

contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.copyButton.addTarget(self, action: #selector(copyAction(_:)), for: .touchUpInside)
contentView.passphraseView.words = words
view.addSubview(contentView)
setupViews(for: mode)
}

func setupViews(for mode: PassphraseMode) {
subTitleLabel.translatesAutoresizingMaskIntoConstraints = false
subTitleLabel.textAlignment = .center
subTitleLabel.numberOfLines = 0
subTitleLabel.text = NSLocalizedString(
"passphrase.seed.label.title",
value: "These 12 words are the only way to restore your Trust accounts. Save them somewhere safe and secret.",
comment: ""
)
subTitleLabel.font = AppStyle.heading.font
subTitleLabel.textColor = AppStyle.heading.textColor

copyButton.translatesAutoresizingMaskIntoConstraints = false
copyButton.setTitle(NSLocalizedString("Copy", value: "Copy", comment: ""), for: .normal)
copyButton.translatesAutoresizingMaskIntoConstraints = false

let wordsLabel = UILabel()
wordsLabel.translatesAutoresizingMaskIntoConstraints = false
wordsLabel.numberOfLines = 0
wordsLabel.text = words.joined(separator: ", ")
wordsLabel.backgroundColor = .clear
wordsLabel.font = UIFont.systemFont(ofSize: 22, weight: .regular)
wordsLabel.textColor = Colors.black
wordsLabel.textAlignment = .center

let wordBackgroundView = UIView()
wordBackgroundView.translatesAutoresizingMaskIntoConstraints = false
wordBackgroundView.backgroundColor = Colors.veryVeryLightGray

let stackView = UIStackView(arrangedSubviews: [
.spacer(height: 10),
subTitleLabel,
.spacer(height: 30),
wordsLabel,
.spacer(height: 30),
copyButton,
])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.spacing = 15
stackView.backgroundColor = .clear

view.addSubview(wordBackgroundView)
view.addSubview(stackView)
view.addSubview(button)

NSLayoutConstraint.activate([
stackView.topAnchor.constraint(greaterThanOrEqualTo: view.readableContentGuide.topAnchor),
stackView.centerYAnchor.constraint(equalTo: view.readableContentGuide.centerYAnchor, constant: -80),
stackView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),

button.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
button.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
button.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor, constant: -StyleLayout.sideMargin),

wordBackgroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
wordBackgroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
wordBackgroundView.centerYAnchor.constraint(equalTo: wordsLabel.centerYAnchor),
wordBackgroundView.heightAnchor.constraint(equalToConstant: 110),

stackView.centerXAnchor.constraint(equalTo: stackView.centerXAnchor),
])

copyButton.addTarget(self, action: #selector(copyAction(_:)), for: .touchUpInside)

switch mode {
case .showOnly:
button.isHidden = true
case .showAndVerify:
button.isHidden = false
}
button.addTarget(self, action: #selector(nextAction(_:)), for: .touchUpInside)

NSLayoutConstraint.activate([
contentView.topAnchor.constraint(equalTo: view.readableContentGuide.topAnchor),
contentView.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
contentView.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
contentView.bottomAnchor.constraint(lessThanOrEqualTo: button.topAnchor),

button.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
button.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor),
button.bottomAnchor.constraint(equalTo: view.readableContentGuide.bottomAnchor, constant: -StyleLayout.sideMargin),
])
}

@objc private func copyAction(_ sender: UIButton) {
Expand Down
80 changes: 80 additions & 0 deletions Trust/Wallet/ViewControllers/WalletInfoViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright SIX DAY LLC. All rights reserved.

import UIKit
import Eureka
import TrustKeystore

protocol WalletInfoViewControllerDelegate: class {
func didPress(item: WalletInfoType, in controller: WalletInfoViewController)
}

class WalletInfoViewController: FormViewController {

let wallet: Wallet
weak var delegate: WalletInfoViewControllerDelegate?

init(wallet: Wallet) {
self.wallet = wallet
super.init(nibName: nil, bundle: nil)
}

override func viewDidLoad() {
super.viewDidLoad()

//navigationItem.title = viewModel.title
let types = fieldTypes(for: wallet)

let section = Section()

for type in types {
section.append(link(item: type))
}

form +++ section
}

func fieldTypes(for wallet: Wallet) -> [WalletInfoType] {
switch wallet.type {
case .privateKey(let account):
return [
.exportKeystore(account),
.exportPrivateKey(account),
]
case .hd(let account):
return [
.exportRecoveryPhrase(account),
.exportPrivateKey(account),
.exportKeystore(account),
]
case .address:
return []
}
}

private func link(
item: WalletInfoType
) -> ButtonRowRow {
let button = ButtonRowRow(item.title) {
$0.title = item.title
$0.value = item
}.onCellSelection { [weak self] (_, row) in
guard let `self` = self, let item = row.value else { return }
self.delegate?.didPress(item: item, in: self)
}.cellSetup { cell, _ in
cell.imageView?.image = item.image
cell.imageView?.layer.cornerRadius = 6
cell.imageView?.layer.masksToBounds = true
}.cellUpdate { cell, _ in
cell.textLabel?.textAlignment = .left
cell.textLabel?.textColor = .black
}
return button
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

typealias ButtonRowRow = ButtonRowOf<WalletInfoType>

3 changes: 3 additions & 0 deletions Trust/Wallet/ViewModels/WalletInfoViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright SIX DAY LLC. All rights reserved.

import Foundation
Loading

0 comments on commit d3d26b3

Please sign in to comment.