diff --git a/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift b/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift index 2ecad54c61..0fac02b45c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/AccountType.swift @@ -146,13 +146,6 @@ enum AccountType { } } - var hideZeroBalances: Bool { - switch self { - case .evmAddress: return true - default: return false - } - } - var description: String { switch self { case let .mnemonic(words, salt, _): diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListService.swift index 499a623f8d..5759aef000 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListService.swift @@ -24,15 +24,7 @@ class WalletTokenListService: IWalletTokenListService { didSet { switch internalState { case .loaded(let items): - let hideZeroBalances = account.type.hideZeroBalances - - if hideZeroBalances { - state = .loaded(items: items.filter { - $0.balanceData.balanceTotal != 0 || ($0.element.wallet?.token.type.isNative ?? false) - }) - } else { - state = .loaded(items: items) - } + state = .loaded(items: items) default: state = internalState } @@ -84,14 +76,12 @@ class WalletTokenListService: IWalletTokenListService { let priceItemMap = coinPriceService.itemMap(coinUids: elements.compactMap { $0.priceCoinUid }) - let watchAccount = account.watchAccount let items: [Item] = elements.filter { elementFilter?($0) ?? true } .map { element in let item = Item( element: element, isMainNet: elementService.isMainNet(element: element) ?? fallbackIsMainNet, - watchAccount: watchAccount, balanceData: elementService.balanceData(element: element) ?? _cachedBalanceData(element: element, cacheContainer: cacheContainer) ?? fallbackBalanceData, state: elementService.state(element: element) ?? fallbackAdapterState ) @@ -341,15 +331,13 @@ extension WalletTokenListService { class Item { let element: WalletModule.Element var isMainNet: Bool - var watchAccount: Bool var balanceData: BalanceData var state: AdapterState var priceItem: WalletCoinPriceService.Item? - init(element: WalletModule.Element, isMainNet: Bool, watchAccount: Bool, balanceData: BalanceData, state: AdapterState) { + init(element: WalletModule.Element, isMainNet: Bool, balanceData: BalanceData, state: AdapterState) { self.element = element self.isMainNet = isMainNet - self.watchAccount = watchAccount self.balanceData = balanceData self.state = state } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderView.swift index 9c14b94dea..5066369a33 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Views/WalletHeaderView.swift @@ -1,17 +1,19 @@ -import UIKit -import ThemeKit -import SnapKit import ComponentKit -import HUD +import SnapKit +import ThemeKit +import UIKit class WalletHeaderView: UITableViewHeaderFooterView { - static var height: CGFloat = TextDropDownAndSettingsView.height + static var height: CGFloat = .heightSingleLineCell + + private let sortByButton = SecondaryButton() - private let sortAddCoinView = TextDropDownAndSettingsView() + private let stackView = UIStackView() + private let settingsButton = SecondaryCircleButton() private let watchAccountImage = ImageComponent(size: .iconSize24) - var onTapSortBy: (() -> ())? - var onTapAddCoin: (() -> ())? + var onTapSortBy: (() -> Void)? + var onTapSettings: (() -> Void)? override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) @@ -19,35 +21,50 @@ class WalletHeaderView: UITableViewHeaderFooterView { backgroundView = UIView() backgroundView?.backgroundColor = .themeNavigationBarBackground - contentView.addSubview(sortAddCoinView) - sortAddCoinView.snp.makeConstraints { maker in - maker.leading.top.trailing.equalToSuperview() - maker.height.equalTo(TextDropDownAndSettingsView.height) + addSubview(sortByButton) + sortByButton.snp.makeConstraints { maker in + maker.leading.centerY.equalToSuperview() } - sortAddCoinView.onTapDropDown = { [weak self] in self?.onTapSortBy?() } - sortAddCoinView.onTapSettings = { [weak self] in self?.onTapAddCoin?() } + sortByButton.set(style: .transparent, image: UIImage(named: "arrow_small_down_20")) + sortByButton.addTarget(self, action: #selector(onTapSortByButton), for: .touchUpInside) - contentView.addSubview(watchAccountImage) - watchAccountImage.snp.makeConstraints { maker in + addSubview(stackView) + stackView.snp.makeConstraints { maker in maker.trailing.equalToSuperview().inset(CGFloat.margin16) - maker.centerY.equalTo(sortAddCoinView) + maker.centerY.equalToSuperview() } + stackView.axis = .horizontal + stackView.spacing = .margin16 + + stackView.addArrangedSubview(watchAccountImage) watchAccountImage.imageView.image = UIImage(named: "binocule_24")?.withTintColor(.themeGray) + + stackView.addArrangedSubview(settingsButton) + settingsButton.set(image: UIImage(named: "manage_2_20")) + settingsButton.addTarget(self, action: #selector(onTapSettingsButton), for: .touchUpInside) } - required init?(coder aDecoder: NSCoder) { + @available(*, unavailable) + required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } - func bind(sortBy: String?) { - sortAddCoinView.set(dropdownTitle: sortBy) + @objc private func onTapSortByButton() { + onTapSortBy?() } - func bind(controlViewItem: WalletViewModel.ControlViewItem) { - sortAddCoinView.set(settingsHidden: !controlViewItem.coinManagerVisible) - watchAccountImage.isHidden = !controlViewItem.watchVisible + @objc private func onTapSettingsButton() { + onTapSettings?() } + func set(sortByTitle: String?) { + sortByButton.setTitle(sortByTitle, for: .normal) + } + + func set(controlViewItem: WalletViewModel.ControlViewItem) { + watchAccountImage.isHidden = !controlViewItem.watchVisible + settingsButton.isHidden = !controlViewItem.coinManagerVisible + } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift index f8a1e46af0..0701523748 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletService.swift @@ -46,13 +46,7 @@ class WalletService { didSet { switch internalState { case .loaded(let items): - let hideZeroBalances = activeAccount?.type.hideZeroBalances ?? false - - if hideZeroBalances { - state = .loaded(items: items.filter { $0.balanceData.balanceTotal != 0 || ($0.element.wallet?.token.type.isNative ?? false) }) - } else { - state = .loaded(items: items) - } + state = .loaded(items: items) default: state = internalState } @@ -158,13 +152,11 @@ class WalletService { case .loaded(let elements): let cacheContainer = activeAccount.map { cacheManager.cacheContainer(accountId: $0.id) } let priceItemMap = coinPriceService.itemMap(coinUids: elements.compactMap { $0.priceCoinUid }) - let watchAccount = watchAccount let items: [Item] = elements.map { element in let item = Item( element: element, isMainNet: elementService.isMainNet(element: element) ?? fallbackIsMainNet, - watchAccount: watchAccount, balanceData: elementService.balanceData(element: element) ?? _cachedBalanceData(element: element, cacheContainer: cacheContainer) ?? fallbackBalanceData, state: elementService.state(element: element) ?? fallbackAdapterState ) @@ -554,15 +546,13 @@ extension WalletService { class Item { let element: WalletModule.Element var isMainNet: Bool - var watchAccount: Bool var balanceData: BalanceData var state: AdapterState var priceItem: WalletCoinPriceService.Item? - init(element: WalletModule.Element, isMainNet: Bool, watchAccount: Bool, balanceData: BalanceData, state: AdapterState) { + init(element: WalletModule.Element, isMainNet: Bool, balanceData: BalanceData, state: AdapterState) { self.element = element self.isMainNet = isMainNet - self.watchAccount = watchAccount self.balanceData = balanceData self.state = state } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewController.swift index ac54a8b87c..e73eca0203 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewController.swift @@ -25,7 +25,6 @@ class WalletViewController: ThemeViewController { private let spinner = HUDActivityView.create(with: .medium24) private let emptyView = PlaceholderView() - private let watchEmptyView = PlaceholderView() private let failedView = PlaceholderView() private let invalidApiKeyView = PlaceholderView() @@ -133,14 +132,6 @@ class WalletViewController: ThemeViewController { action: #selector(onTapAddCoin) ) - view.addSubview(watchEmptyView) - watchEmptyView.snp.makeConstraints { maker in - maker.edges.equalTo(view.safeAreaLayoutGuide) - } - - watchEmptyView.image = UIImage(named: "empty_wallet_48") - watchEmptyView.text = "balance.watch_empty.description".localized - view.addSubview(failedView) failedView.snp.makeConstraints { maker in maker.edges.equalTo(view.safeAreaLayoutGuide) @@ -319,11 +310,6 @@ class WalletViewController: ThemeViewController { default: emptyView.isHidden = true } - switch state { - case .watchEmpty: watchEmptyView.isHidden = false - default: watchEmptyView.isHidden = true - } - switch state { case .syncFailed: failedView.isHidden = false default: failedView.isHidden = true @@ -354,7 +340,7 @@ class WalletViewController: ThemeViewController { self.sortBy = sortBy if isLoaded, let headerView = tableView.headerView(forSection: 1) as? WalletHeaderView { - headerView.bind(sortBy: sortBy) + headerView.set(sortByTitle: sortBy) } } @@ -362,7 +348,7 @@ class WalletViewController: ThemeViewController { self.controlViewItem = controlViewItem if isLoaded, let controlViewItem, let headerView = tableView.headerView(forSection: 1) as? WalletHeaderView { - headerView.bind(controlViewItem: controlViewItem) + headerView.set(controlViewItem: controlViewItem) } } @@ -643,13 +629,14 @@ extension WalletViewController: UITableViewDelegate { func tableView(_: UITableView, willDisplayHeaderView view: UIView, forSection _: Int) { if let headerView = view as? WalletHeaderView { - headerView.bind(sortBy: sortBy) + headerView.set(sortByTitle: sortBy) + if let controlViewItem { - headerView.bind(controlViewItem: controlViewItem) + headerView.set(controlViewItem: controlViewItem) } headerView.onTapSortBy = { [weak self] in self?.openSortType() } - headerView.onTapAddCoin = { [weak self] in self?.openManageWallets() } + headerView.onTapSettings = { [weak self] in self?.openManageWallets() } } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift index 363475cf3f..27af594e17 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/WalletViewModel.swift @@ -72,7 +72,7 @@ class WalletViewModel { case .loading: state = .loading case let .loaded(items): if items.isEmpty, !service.cexAccount { - state = service.watchAccount ? .watchEmpty : .empty + state = .empty } else { state = .list(viewItems: items.map { _viewItem(item: $0) }) } @@ -94,7 +94,7 @@ class WalletViewModel { nftVisible = activeAccount?.type.supportsNft ?? false controlViewItem = activeAccount.map { - ControlViewItem(watchVisible: $0.watchAccount, coinManagerVisible: !$0.cexAccount && !$0.watchAccount) + ControlViewItem(watchVisible: $0.watchAccount, coinManagerVisible: !$0.cexAccount) } if let account = activeAccount { @@ -202,7 +202,7 @@ extension WalletViewModel { } var swipeActionsEnabled: Bool { - !service.watchAccount && !service.cexAccount + !service.cexAccount } var lastCreatedAccount: Account? { diff --git a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings index b5b24ba7a2..8dfc1a4771 100644 --- a/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings +++ b/UnstoppableWallet/UnstoppableWallet/en.lproj/Localizable.strings @@ -316,7 +316,6 @@ "balance.invalid_api_key" = "Invalid API Key"; "balance.empty.add_coins" = "Add Coins"; "balance.empty.description" = "You haven't added any coins to this wallet."; -"balance.watch_empty.description" = "This wallet address does not have any balance"; "balance.sort_by" = "Sort By"; "balance.sort.header" = "Sort by"; "balance.sort.valueHighToLow" = "Balance";