Skip to content

Commit

Permalink
- wire up real code for delegation/staking onboarding
Browse files Browse the repository at this point in the history
- bug fix some loading
- remove unnecessary extra loading
- remove all hacks to speed up testing
  • Loading branch information
simonmcl committed Dec 2, 2024
1 parent 2b62c42 commit d34b976
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public class EnterAddressComponent: UIView {
private var currentSelectedType: AddressType = .tezosAddress

public weak var delegate: EnterAddressComponentDelegate? = nil
public var allowEmpty: Bool = false {
didSet {
if (self.textField.text == nil || self.textField.text == "") && allowEmpty {
self.sendButton.isEnabled = true
}
}
}


required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -71,7 +78,7 @@ public class EnterAddressComponent: UIView {
textField.validatorTextFieldDelegate = self

self.hideError(animate: false)
self.sendButton.isEnabled = false
self.sendButton.isEnabled = allowEmpty
}

public func updateAvilableAddressTypes(_ types: [AddressType]) {
Expand Down Expand Up @@ -275,7 +282,7 @@ extension EnterAddressComponent: ValidatorTextFieldDelegate {
self.sendButton.isEnabled = true

} else if text == "" {
self.sendButton.isEnabled = false
self.sendButton.isEnabled = allowEmpty

} else {
self.sendButton.isEnabled = false
Expand Down
2 changes: 1 addition & 1 deletion Kukai Mobile/Extensions/UIViewController+extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension UIViewController {
activityViewStatusLabel.font = UIFont.custom(ofType: .medium, andSize: 16)
activityViewStatusLabel.textColor = UIColor.white
activityViewStatusLabel.textAlignment = .center
activityViewStatusLabel.frame = CGRect(x: view.center.x, y: view.center.y, width: view.frame.width - 64, height: 50)
activityViewStatusLabel.frame = CGRect(x: view.center.x, y: view.center.y, width: view.frame.width - 64, height: 200)

UIViewController.activityViewActivityIndicator.color = UIColor.white

Expand Down
18 changes: 18 additions & 0 deletions Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit
import KukaiCoreSwift
import Combine
import OSLog

struct AllChartData: Hashable {
Expand Down Expand Up @@ -122,6 +123,7 @@ public class TokenDetailsViewModel: ViewModel, TokenDetailsChartCellDelegate {
private let chartDateFormatter = DateFormatter(withFormat: "MMM dd HH:mm a")
private var initialChartLoad = true
private var onlineXTZFetchGroup = DispatchGroup()
private var bag = [AnyCancellable]()

// Set by VC
weak var delegate: (TokenDetailsViewModelDelegate & TokenDetailsBakerDelegate & TokenDetailsStakeBalanceDelegate)? = nil
Expand Down Expand Up @@ -155,6 +157,22 @@ public class TokenDetailsViewModel: ViewModel, TokenDetailsChartCellDelegate {
var finaliseableAmount: TokenAmount = .zero()


override init() {
super.init()

DependencyManager.shared.$addressRefreshed
.dropFirst()
.sink { [weak self] address in
let selectedAddress = DependencyManager.shared.selectedWalletAddress ?? ""
if self?.dataSource != nil && selectedAddress == address {
self?.refresh(animate: true)
}
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
}



Expand Down
5 changes: 1 addition & 4 deletions Kukai Mobile/Modules/Login/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LoginViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
/* // TODO: uncomment

// Hide biometric button if its not enabled, or we are in the middle of the edit passcode flow
if isEditPasscodeMode() || CurrentDevice.biometricTypeAuthorized() == .none || StorageService.isBiometricEnabled() == false {
useBiometricsButton.isHidden = true
Expand All @@ -83,9 +83,6 @@ class LoginViewController: UIViewController {
// Edit passcode popup
self.hiddenTextfield.becomeFirstResponder()
}
*/

self.next()
}

override func viewDidDisappear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SendAbstractConfirmViewController: UIViewController {
if collapseOnly == false {
if isDuringStakeOnboardingFlow {
topMostNavigationController?.dismiss(animated: true)

} else {
(self?.presentingViewController as? UINavigationController)?.popToHome()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,7 @@ class ChooseBakerConfirmViewController: SendAbstractConfirmViewController, Slide

func didCompleteSlide() {
self.blockInteraction(exceptFor: [closeButton])

// TODO: swap back
//self.performAuth()
self.handleApproval(opHash: "", slideButton: self.slideButton)
self.performAuth()
}

override func authSuccessful() {
Expand Down
21 changes: 17 additions & 4 deletions Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ChooseBakerViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!

private let viewModel = ChooseBakerViewModel()
private var viewModel = ChooseBakerViewModel()
private var cancellable: AnyCancellable?
private let footerView = UIView(frame: CGRect(x: 0, y: 0, width: 1, height: 2))
private let blankView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0.1))
Expand Down Expand Up @@ -49,7 +49,10 @@ class ChooseBakerViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.refresh(animate: false)

if viewModel.bakers.count == 0 {
viewModel.refresh(animate: false)
}
}

public func enteredCustomBaker(address: String) {
Expand All @@ -58,21 +61,24 @@ class ChooseBakerViewController: UIViewController {
if address == "" {
let currentDelegate = DependencyManager.shared.balanceService.account.delegate
let name = currentDelegate?.alias ?? currentDelegate?.address.truncateTezosAddress() ?? ""
let baker = TzKTBaker(address: "", name: name)
let baker = TzKTBaker(address: currentDelegate?.address ?? "", name: name)

TransactionService.shared.delegateData.chosenBaker = baker
TransactionService.shared.stakeData.chosenBaker = baker
TransactionService.shared.delegateData.isAdd = false

} else {
self.showLoadingView()

if let foundBaker = viewModel.bakerFor(address: address) {
TransactionService.shared.delegateData.chosenBaker = foundBaker
TransactionService.shared.stakeData.chosenBaker = foundBaker
TransactionService.shared.delegateData.isAdd = true

} else {
let baker = TzKTBaker(address: address, name: address.truncateTezosAddress())
TransactionService.shared.delegateData.chosenBaker = baker
TransactionService.shared.stakeData.chosenBaker = baker
TransactionService.shared.delegateData.isAdd = true
}
}
Expand All @@ -97,7 +103,13 @@ class ChooseBakerViewController: UIViewController {
return
}

let operations = OperationFactory.delegateOperation(to: toAddress, from: selectedWallet.address)
var operations: [KukaiCoreSwift.Operation] = []
if TransactionService.shared.delegateData.isAdd == true {
operations = OperationFactory.delegateOperation(to: toAddress, from: selectedWallet.address)
} else {
operations = OperationFactory.undelegateOperation(address: selectedWallet.address)
}

DependencyManager.shared.tezosNodeClient.estimate(operations: operations, walletAddress: selectedWallet.address, base58EncodedPublicKey: selectedWallet.publicKeyBase58encoded()) { [weak self] estimationResult in
self?.hideLoadingView()

Expand Down Expand Up @@ -132,6 +144,7 @@ extension ChooseBakerViewController: UITableViewDelegate {
if let baker = viewModel.bakerFor(indexPath: indexPath) {

TransactionService.shared.delegateData.chosenBaker = baker
TransactionService.shared.stakeData.chosenBaker = baker
TransactionService.shared.delegateData.isAdd = true
self.performSegue(withIdentifier: "details", sender: nil)

Expand Down
9 changes: 0 additions & 9 deletions Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ class ChooseBakerViewModel: ViewModel, UITableViewDiffableDataSourceHandler {

override init() {
super.init()

DependencyManager.shared.$addressRefreshed
.dropFirst()
.sink { [weak self] address in
let selectedAddress = DependencyManager.shared.selectedWalletAddress ?? ""
if self?.dataSource != nil && selectedAddress == address {
self?.refresh(animate: true)
}
}.store(in: &bag)
}

deinit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EnterCustomBakerViewController: UIViewController, EnterAddressComponentDel
enterAddressComponent.headerLabel.text = "Baker:"
enterAddressComponent.updateAvilableAddressTypes([.tezosAddress, .tezosDomain])
enterAddressComponent.delegate = self
enterAddressComponent.allowEmpty = true // undelegate by entering blank into field
}

func validatedInput(entered: String, validAddress: Bool, ofType: AddressType) {
Expand Down
Loading

0 comments on commit d34b976

Please sign in to comment.