Skip to content

Commit

Permalink
- wire up new add account screen
Browse files Browse the repository at this point in the history
- add chevron rotation animation
  • Loading branch information
simonmcl committed May 24, 2024
1 parent f84ed2f commit 07d9ad0
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 101 deletions.
22 changes: 11 additions & 11 deletions Kukai Mobile/Modules/Account/Account.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -758,23 +758,23 @@
<rect key="frame" x="0.0" y="0.0" width="393" height="91"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="dIV-vR-veM">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dIV-vR-veM">
<rect key="frame" x="16" y="16" width="361" height="59"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Getting Started" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OaX-dE-p7M">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Getting Started" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OaX-dE-p7M">
<rect key="frame" x="12" y="20.333333333333336" width="159" height="26.666666666666664"/>
<accessibility key="accessibilityConfiguration" identifier="account-getting-started-header"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="22"/>
<color key="textColor" name="Txt2"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Copy here about needing some XTZ to get started etc and how to get XTZ." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WUd-ec-WyL">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Copy here about needing some XTZ to get started etc and how to get XTZ." textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WUd-ec-WyL">
<rect key="frame" x="16" y="59" width="329" height="0.0"/>
<fontDescription key="fontDescription" name="Figtree-Medium" family="Figtree" pointSize="14"/>
<color key="textColor" name="Txt6"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" image="Social_TZ_Ovalcolor" translatesAutoresizingMaskIntoConstraints="NO" id="0XZ-Q7-XG3">
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Social_TZ_Ovalcolor" translatesAutoresizingMaskIntoConstraints="NO" id="0XZ-Q7-XG3">
<rect key="frame" x="311" y="16" width="38" height="35"/>
<constraints>
<constraint firstAttribute="height" constant="38" id="VwN-8M-Lxz"/>
Expand Down Expand Up @@ -811,7 +811,7 @@
<rect key="frame" x="0.0" y="0.0" width="393" height="63"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1Ao-zL-OIA" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1Ao-zL-OIA" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="28" y="8" width="337" height="47"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="NL4-wV-VUW"/>
Expand Down Expand Up @@ -843,30 +843,30 @@
<rect key="frame" x="0.0" y="0.0" width="393" height="212"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="p5E-1m-530">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="p5E-1m-530">
<rect key="frame" x="16" y="16" width="361" height="180"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Receive Assets" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2ij-BE-VqB">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Receive Assets" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2ij-BE-VqB">
<rect key="frame" x="12" y="21.666666666666664" width="153.33333333333334" height="26.666666666666664"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="22"/>
<color key="textColor" name="Txt2"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="You can also copy your address by tapping the top left button and choose copy in the side menu" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Juv-Ge-4u3">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="You can also copy your address by tapping the top left button and choose copy in the side menu" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Juv-Ge-4u3">
<rect key="frame" x="12" y="62" width="337" height="38"/>
<fontDescription key="fontDescription" name="Figtree-Medium" family="Figtree" pointSize="14"/>
<color key="textColor" name="Txt6"/>
<nil key="highlightedColor"/>
</label>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" image="btnQR_Outline_Dark" translatesAutoresizingMaskIntoConstraints="NO" id="BGW-ha-UIr">
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="btnQR_Outline_Dark" translatesAutoresizingMaskIntoConstraints="NO" id="BGW-ha-UIr">
<rect key="frame" x="311" y="16" width="38" height="38"/>
<color key="tintColor" name="BGB4"/>
<constraints>
<constraint firstAttribute="height" constant="38" id="Ndq-gW-8Lh"/>
<constraint firstAttribute="width" constant="38" id="NlK-3x-MQg"/>
</constraints>
</imageView>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EKG-xY-HYO" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EKG-xY-HYO" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="12" y="116" width="164.66666666666666" height="48"/>
<fontDescription key="fontDescription" name="Figtree-Bold" family="Figtree" pointSize="18"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
Expand All @@ -875,7 +875,7 @@
<action selector="qrButtonTapped:" destination="I2q-rN-gX7" eventType="touchUpInside" id="plX-QU-ZkK"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rdt-d8-lSF" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rdt-d8-lSF" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="184.66666666666663" y="116" width="164.33333333333337" height="48"/>
<constraints>
<constraint firstAttribute="height" constant="48" id="7e9-HA-La6"/>
Expand Down
4 changes: 2 additions & 2 deletions Kukai Mobile/Modules/Home/AccountsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ extension AccountsViewController: UITableViewDelegate {
cell.setSelected(false, animated: true)
}

if let c = cell as? AccountItemCell, c.newIndicatorView.isHidden == false {
if let c = cell as? AccountItemCell, c.newIndicatorView?.isHidden == false {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
c.newIndicatorView.shake()
c.newIndicatorView?.shake()
}
}
}
Expand Down
52 changes: 11 additions & 41 deletions Kukai Mobile/Modules/Home/AccountsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
cell.subtitleLabel.text = walletMedia.subtitle

if let newAddress = self?.newlyAddedAddress, obj.address == newAddress {
cell.newIndicatorView.isHidden = false
cell.newIndicatorView?.isHidden = false
} else {
cell.newIndicatorView.isHidden = true
cell.newIndicatorView?.isHidden = true
}

return cell
Expand Down Expand Up @@ -339,32 +339,16 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
let addAccount = UIAction(title: "Add Account", image: UIImage(named: "AddNewAccount")) { [weak self] action in

vc.showLoadingView()
self?.isPreviousAccountUsed(forAddress: walletMetadata.address, completion: { isUsed in
guard isUsed else {
vc.hideLoadingView()
vc.windowError(withTitle: "error-previous-account-title".localized(), description: "error-previous-account-empty".localized())
return
}

guard let wallet = WalletCacheService().fetchWallet(forAddress: walletMetadata.address) as? HDWallet,
let newChild = wallet.createChild(accountIndex: walletMetadata.children.count+1) else {
vc.hideLoadingView()
vc.windowError(withTitle: "error".localized(), description: "error-cant-add-account".localized())
return
}

WalletManagementService.cacheNew(wallet: newChild, forChildOfIndex: hdWalletIndex, backedUp: false, markSelected: false) { [weak self] errorString in
if let eString = errorString {
vc.hideLoadingView()
vc.windowError(withTitle: "error".localized(), description: eString)
} else {
self?.shouldScrollToSelected = false
self?.expandedSection = DependencyManager.shared.walletList.socialWallets.count > 0 ? hdWalletIndex+1 : hdWalletIndex
self?.refresh(animate: true)
vc.hideLoadingView()
}
AddAccountViewModel.addAccount(forMetadata: walletMetadata, hdWalletIndex: hdWalletIndex) { [weak self] errorTitle, errorMessage in
vc.hideLoadingView()
if let title = errorTitle, let message = errorMessage {
vc.windowError(withTitle: title, description: message)
} else {
self?.shouldScrollToSelected = false
self?.expandedSection = DependencyManager.shared.walletList.socialWallets.count > 0 ? hdWalletIndex+1 : hdWalletIndex
self?.refresh(animate: true)
}
})
}
}

let remove = UIAction(title: "Remove Wallet", image: UIImage(named: "Delete")) { [weak self] action in
Expand All @@ -378,20 +362,6 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
return MenuViewController(actions: [[edit, addAccount, remove]], header: walletMetadata.hdWalletGroupName, alertStyleIndexes: [IndexPath(row: 2, section: 0)], sourceViewController: vc)
}

private func isPreviousAccountUsed(forAddress address: String, completion: @escaping ((Bool) -> Void)) {
var metadataToCheck = DependencyManager.shared.walletList.metadata(forAddress: address)
if (metadataToCheck?.children.count ?? 0) > 0, let last = metadataToCheck?.children.last {
metadataToCheck = last
}

guard let meta = metadataToCheck else {
completion(false)
return
}

WalletManagementService.isUsedAccount(address: meta.address, completion: completion)
}

func pullToRefresh(animate: Bool) {
if !state.isLoading() {
state = .loading
Expand Down
82 changes: 80 additions & 2 deletions Kukai Mobile/Modules/Home/AddAccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,90 @@
//

import UIKit
import Combine
import KukaiCoreSwift

class AddAccountViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!

private let viewModel = AddAccountViewModel()
private var cancellable: AnyCancellable?

override func viewDidLoad() {
super.viewDidLoad()
}
super.viewDidLoad()
let _ = self.view.addGradientBackgroundFull()

viewModel.makeDataSource(withTableView: tableView)
tableView.dataSource = viewModel.dataSource
tableView.delegate = self
tableView.sectionFooterHeight = 8

cancellable = viewModel.$state.sink { [weak self] state in
switch state {
case .loading:
break

case .failure(_, let errorString):
self?.windowError(withTitle: "error".localized(), description: errorString)

case .success:
break
}
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

viewModel.refresh(animate: false)
}
}

extension AddAccountViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.layoutIfNeeded()

if indexPath.row == 0, let c = cell as? UITableViewCellContainerView {
c.addGradientBackground(withFrame: c.containerView.bounds, toView: c.containerView)
}
}

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let clearView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
clearView.backgroundColor = .clear
return clearView
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row != 0 { return }

guard let metadata = viewModel.metadataFor(indexPath: indexPath) else {
return
}

deselectCurrentSelection()

viewModel.selectedIndex = indexPath
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)

self.showLoadingView()
AddAccountViewModel.addAccount(forMetadata: metadata, hdWalletIndex: indexPath.section) { [weak self] errorTitle, errorMessage in
self?.hideLoadingView()

if let title = errorTitle, let message = errorMessage {
self?.windowError(withTitle: title, description: message)

} else if let previous = self?.navigationController?.viewControllers.first(where: { $0 is AccountsViewController }) {
self?.navigationController?.popToViewController(previous, animated: true)
}
}
}

private func deselectCurrentSelection() {
tableView.deselectRow(at: viewModel.selectedIndex, animated: true)
let previousCell = tableView.cellForRow(at: viewModel.selectedIndex)
previousCell?.setSelected(false, animated: true)
}
}
Loading

0 comments on commit 07d9ad0

Please sign in to comment.