forked from trustwallet/trust-wallet-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
238 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Trust/Wallet/ViewControllers/WalletInfoViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Copyright SIX DAY LLC. All rights reserved. | ||
|
||
import Foundation |
Oops, something went wrong.