From a68ce7557cdd37a5116f596a229ea8a685b944cc Mon Sep 17 00:00:00 2001 From: Vladyslav shepitko Date: Tue, 24 Nov 2020 11:53:46 +0200 Subject: [PATCH] Do not show "ENS" label in Actionsheet for transaction confirmation under Recipient if there is no ENS name resolved (yet) #2310 --- .../Transfer/Types/RecipientResolver.swift | 7 +++ ...ransactionConfirmationViewController.swift | 44 +++++++++++++++---- .../TransactionConfirmationViewModel.swift | 4 +- .../TransactionConfirmationHeaderView.swift | 18 ++++++-- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/AlphaWallet/Transfer/Types/RecipientResolver.swift b/AlphaWallet/Transfer/Types/RecipientResolver.swift index 5c1263fd7..586dc1ba1 100644 --- a/AlphaWallet/Transfer/Types/RecipientResolver.swift +++ b/AlphaWallet/Transfer/Types/RecipientResolver.swift @@ -16,6 +16,13 @@ class RecipientResolver { let address: AlphaWallet.Address? var ensName: String? + var hasResolvedESNName: Bool { + if let value = ensName { + return !value.trimmed.isEmpty + } + return false + } + init(address: AlphaWallet.Address?) { self.address = address } diff --git a/AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift index 79ce46a57..e8449ef4e 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift @@ -98,7 +98,7 @@ class TransactionConfirmationViewController: UIViewController { var canBeDismissed = true weak var delegate: TransactionConfirmationViewControllerDelegate? - + // swiftlint:disable function_body_length init(viewModel: TransactionConfirmationViewModel) { self.viewModel = viewModel super.init(nibName: nil, bundle: nil) @@ -151,7 +151,7 @@ class TransactionConfirmationViewController: UIViewController { ]) headerView.closeButton.addTarget(self, action: #selector(dismissViewController), for: .touchUpInside) - contentSizeObservation = scrollView.observe(\.contentSize, options: [.new, .initial]) { [weak self] scrollView, change in + contentSizeObservation = scrollView.observe(\.contentSize, options: [.new, .initial]) { [weak self] scrollView, _ in guard let strongSelf = self, strongSelf.allowDismissialAnimation else { return } let statusBarHeight = UIApplication.shared.statusBarFrame.height @@ -214,7 +214,7 @@ class TransactionConfirmationViewController: UIViewController { strongSelf.generateSubviews() } sendNftViewModel.ethPrice.subscribe { [weak self] cryptoToDollarRate in - guard let strongSelf = self else {return} + guard let strongSelf = self else { return } sendNftViewModel.cryptoToDollarRate = cryptoToDollarRate strongSelf.generateSubviews() } @@ -228,7 +228,7 @@ class TransactionConfirmationViewController: UIViewController { generateSubviews() } - + // swiftlint:enable function_body_length override func viewDidLoad() { super.viewDidLoad() @@ -445,15 +445,18 @@ fileprivate class HeaderView: UIView { } extension TransactionConfirmationViewController { + // swiftlint:disable function_body_length private func generateSubviews() { stackView.removeAllArrangedSubviews() var views: [UIView] = [] switch viewModel { case .dappTransaction(let viewModel): for (sectionIndex, section) in viewModel.sections.enumerated() { + var children: [UIView] = [] + let header = TransactionConfirmationHeaderView(viewModel: viewModel.headerViewModel(section: sectionIndex)) header.delegate = self - var children: [UIView] = [] + switch section { case .gas: header.setEditButton(section: sectionIndex, self, selector: #selector(editTransactionButtonTapped)) @@ -557,26 +560,51 @@ extension TransactionConfirmationViewController { for (sectionIndex, section) in viewModel.sections.enumerated() { let header = TransactionConfirmationHeaderView(viewModel: viewModel.headerViewModel(section: sectionIndex)) header.delegate = self - var children: [UIView] = [] switch section { case .gas: header.setEditButton(section: sectionIndex, self, selector: #selector(editTransactionButtonTapped)) case .amount, .numberOfTokens: break } - header.childrenStackView.addArrangedSubviews(children) views.append(header) } } stackView.addArrangedSubviews(views) } - + // swiftlint:enable function_body_length @objc private func editTransactionButtonTapped(_ sender: UIButton) { delegate?.controller(self, editTransactionButtonTapped: sender) } } extension TransactionConfirmationViewController: TransactionConfirmationHeaderViewDelegate { + + func headerView(_ header: TransactionConfirmationHeaderView, shouldHideChildren section: Int, index: Int) -> Bool { + return true + } + + func headerView(_ header: TransactionConfirmationHeaderView, shouldShowChildren section: Int, index: Int) -> Bool { + switch viewModel { + case .dappTransaction, .claimPaidErc875MagicLink, .tokenScriptTransaction: + return true + case .sendFungiblesTransaction(let viewModel): + switch viewModel.sections[section] { + case .recipient: + return !viewModel.isSubviewsHidden(section: section, row: index) + case .gas, .amount, .balance: + return true + } + case .sendNftTransaction(let viewModel): + switch viewModel.sections[section] { + case .recipient: + //NOTE: Here we need to make sure that this view is available to display + return !viewModel.isSubviewsHidden(section: section, row: index) + case .gas, .tokenId: + return true + } + } + } + func headerView(_ header: TransactionConfirmationHeaderView, openStateChanged section: Int) { switch viewModel.showHideSection(section) { case .show: diff --git a/AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift b/AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift index 011489271..4bf5e4a90 100644 --- a/AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift @@ -212,7 +212,7 @@ extension TransactionConfirmationViewModel { case .address: return false case .ens: - return recipientResolver.ensName == nil + return !recipientResolver.hasResolvedESNName } } else { return true @@ -457,7 +457,7 @@ extension TransactionConfirmationViewModel { case .address: return false case .ens: - return recipientResolver.ensName == nil + return !recipientResolver.hasResolvedESNName } } else { return true diff --git a/AlphaWallet/Transfer/Views/TransactionConfirmationHeaderView.swift b/AlphaWallet/Transfer/Views/TransactionConfirmationHeaderView.swift index 400978180..127295d51 100644 --- a/AlphaWallet/Transfer/Views/TransactionConfirmationHeaderView.swift +++ b/AlphaWallet/Transfer/Views/TransactionConfirmationHeaderView.swift @@ -8,6 +8,8 @@ import UIKit protocol TransactionConfirmationHeaderViewDelegate: class { + func headerView(_ header: TransactionConfirmationHeaderView, shouldHideChildren section: Int, index: Int) -> Bool + func headerView(_ header: TransactionConfirmationHeaderView, shouldShowChildren section: Int, index: Int) -> Bool func headerView(_ header: TransactionConfirmationHeaderView, openStateChanged section: Int) } @@ -174,14 +176,22 @@ class TransactionConfirmationHeaderView: UIView { } func expand() { - for view in childrenStackView.arrangedSubviews { - view.isHidden = false + guard let delegate = delegate else { return } + + for (index, view) in childrenStackView.arrangedSubviews.enumerated() { + if delegate.headerView(self, shouldShowChildren: viewModel.configuration.section, index: index) { + view.isHidden = false + } } } func collapse() { - for view in childrenStackView.arrangedSubviews { - view.isHidden = true + guard let delegate = delegate else { return } + + for (index, view) in childrenStackView.arrangedSubviews.enumerated() { + if delegate.headerView(self, shouldHideChildren: viewModel.configuration.section, index: index) { + view.isHidden = true + } } } }