Do not show "ENS" label in Actionsheet for transaction confirmation under Recipient if there is no ENS name resolved (yet) #2310

pull/2314/head
Vladyslav shepitko 4 years ago
parent cec7d074a4
commit a68ce7557c
  1. 7
      AlphaWallet/Transfer/Types/RecipientResolver.swift
  2. 44
      AlphaWallet/Transfer/ViewControllers/TransactionConfirmationViewController.swift
  3. 4
      AlphaWallet/Transfer/ViewModels/TransactionConfirmationViewModel.swift
  4. 18
      AlphaWallet/Transfer/Views/TransactionConfirmationHeaderView.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
}

@ -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:

@ -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

@ -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
}
}
}
}

Loading…
Cancel
Save