mirror of
https://github.com/lil-org/tokenary.git
synced 2024-12-24 20:41:35 +03:00
Display created accounts
This commit is contained in:
parent
3e0e4f8e68
commit
36f5212382
@ -5,7 +5,10 @@ import UIKit
|
||||
@main
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
private let walletsManager = WalletsManager.shared
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
walletsManager.start()
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -61,9 +61,24 @@
|
||||
<view key="view" contentMode="scaleToFill" id="K92-L8-Bkg">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" estimatedSectionHeaderHeight="-1" sectionFooterHeight="18" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="0xi-7N-lca">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
</tableView>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="ydA-69-gGk"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="0xi-7N-lca" secondAttribute="bottom" id="6f7-U1-uCe"/>
|
||||
<constraint firstAttribute="trailing" secondItem="0xi-7N-lca" secondAttribute="trailing" id="SD0-Nu-rh2"/>
|
||||
<constraint firstItem="0xi-7N-lca" firstAttribute="top" secondItem="K92-L8-Bkg" secondAttribute="top" id="hcU-2B-dS3"/>
|
||||
<constraint firstItem="0xi-7N-lca" firstAttribute="leading" secondItem="K92-L8-Bkg" secondAttribute="leading" id="yMa-WS-nBe"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="tableView" destination="0xi-7N-lca" id="vc7-HM-CEH"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="LIM-xG-p0t" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
|
@ -4,6 +4,19 @@ import UIKit
|
||||
|
||||
class AccountsListViewController: UIViewController {
|
||||
|
||||
private let walletsManager = WalletsManager.shared
|
||||
|
||||
private var wallets: [TokenaryWallet] {
|
||||
return walletsManager.wallets
|
||||
}
|
||||
|
||||
@IBOutlet weak var tableView: UITableView! {
|
||||
didSet {
|
||||
tableView.delegate = self
|
||||
tableView.dataSource = self
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
navigationItem.title = Strings.accounts
|
||||
@ -39,7 +52,29 @@ class AccountsListViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func createNewAccountAndShowSecretWords() {
|
||||
// TODO: implement
|
||||
guard let wallet = try? walletsManager.createWallet() else { return }
|
||||
tableView.reloadData()
|
||||
showKey(wallet: wallet, mnemonic: true)
|
||||
}
|
||||
|
||||
private func showKey(wallet: TokenaryWallet, mnemonic: Bool) {
|
||||
let secret: String
|
||||
if mnemonic, let mnemonicString = try? walletsManager.exportMnemonic(wallet: wallet) {
|
||||
secret = mnemonicString
|
||||
} else if let data = try? walletsManager.exportPrivateKey(wallet: wallet) {
|
||||
secret = data.hexString
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
let alert = UIAlertController(title: mnemonic ? Strings.secretWords : Strings.privateKey, message: secret, preferredStyle: .alert)
|
||||
let okAction = UIAlertAction(title: Strings.ok, style: .default)
|
||||
let cancelAction = UIAlertAction(title: Strings.copy, style: .default) { _ in
|
||||
UIPasteboard.general.string = secret
|
||||
}
|
||||
alert.addAction(cancelAction)
|
||||
alert.addAction(okAction)
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
private func importExistingAccount() {
|
||||
@ -48,3 +83,27 @@ class AccountsListViewController: UIViewController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extension AccountsListViewController: UITableViewDelegate {
|
||||
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension AccountsListViewController: UITableViewDataSource {
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return walletsManager.wallets.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let cell = UITableViewCell()
|
||||
let wallet = wallets[indexPath.row]
|
||||
cell.textLabel?.text = wallet.ethereumAddress
|
||||
return cell
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user