diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertModule.swift index 5940a5e854..9a84258c05 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertModule.swift @@ -13,11 +13,13 @@ protocol IAlertRouter { struct AlertViewItem { let text: String + let description: String? let selected: Bool let disabled: Bool - init(text: String, selected: Bool, disabled: Bool = false) { + init(text: String, description: String? = nil, selected: Bool, disabled: Bool = false) { self.text = text + self.description = description self.selected = selected self.disabled = disabled } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertViewController.swift index 613a50fc43..aabc65cfee 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Alert/AlertViewController.swift @@ -1,7 +1,8 @@ -import UIKit import ActionSheet -import ThemeKit +import ComponentKit import SectionsTableView +import ThemeKit +import UIKit class AlertViewController: ThemeActionSheetController { private let alertTitle: String @@ -17,7 +18,8 @@ class AlertViewController: ThemeActionSheetController { super.init() } - required init?(coder aDecoder: NSCoder) { + @available(*, unavailable) + required init?(coder _: NSCoder) { fatalError("init(coder:) has not been implemented") } @@ -29,8 +31,6 @@ class AlertViewController: ThemeActionSheetController { maker.edges.equalToSuperview() } - tableView.allowsSelection = false - tableView.registerCell(forClass: AlertTitleCell.self) tableView.registerCell(forClass: AlertItemCell.self) tableView.sectionDataSource = self @@ -42,35 +42,53 @@ class AlertViewController: ThemeActionSheetController { private var titleRow: RowProtocol { Row( - id: "title", - height: AlertTitleCell.height, - bind: { [weak self] cell, _ in - cell.bind(text: self?.alertTitle) - } + id: "title", + height: AlertTitleCell.height, + bind: { [weak self] cell, _ in + cell.bind(text: self?.alertTitle) + } ) } private func itemRow(viewItem: AlertViewItem, index: Int) -> RowProtocol { - Row( - id: "item_\(index)", - hash: "\(viewItem.selected)", - height: .heightCell48, - bind: { [weak self] cell, _ in - cell.set(backgroundStyle: .transparent) - cell.title = viewItem.text - cell.isSelected = viewItem.selected - cell.isEnabled = !viewItem.disabled - cell.onSelect = { - self?.delegate?.onTapViewItem(index: index) - } - } + let defaultColor: UIColor = viewItem.disabled ? .themeGray50 : .themeLeah + + var elements = [CellBuilderNew.CellElement]() + var verticalTexts = [CellBuilderNew.CellElement]() + verticalTexts.append( + .textElement( + text: .body(viewItem.text, color: viewItem.selected ? .themeJacob : defaultColor), + parameters: .centerAlignment + ) + ) + if let description = viewItem.description { + verticalTexts.append(.margin(1)) + verticalTexts.append( + .textElement( + text: .subhead2(description), + parameters: .centerAlignment + ) + ) + } + elements.append(.vStackCentered(verticalTexts)) + + return CellBuilderNew.row( + rootElement: .hStack(elements), + tableView: tableView, + id: "item_\(index)", + height: viewItem.description == nil ? .heightCell48 : .heightDoubleLineCell, + autoDeselect: true, + bind: { cell in + cell.set(backgroundStyle: .transparent) + }, + action: { [weak self] in + self?.delegate?.onTapViewItem(index: index) + } ) } - } extension AlertViewController: SectionsDataSource { - func buildSections() -> [SectionProtocol] { var rows = [RowProtocol]() @@ -79,13 +97,10 @@ extension AlertViewController: SectionsDataSource { return [Section(id: "main", rows: rows)] } - } extension AlertViewController: IAlertView { - func set(viewItems: [AlertViewItem]) { self.viewItems = viewItems } - } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchModule.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchModule.swift index a3828ff967..f52e1a18e4 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchModule.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchModule.swift @@ -1,17 +1,16 @@ -import UIKit -import ThemeKit import MarketKit +import ThemeKit +import UIKit struct WatchModule { - static func viewController(sourceViewController: UIViewController? = nil) -> UIViewController { let ethereumToken = try? App.shared.marketKit.token(query: TokenQuery(blockchainType: .ethereum, tokenType: .native)) let evmAddressParserItem = EvmAddressParser() let udnAddressParserItem = UdnAddressParserItem.item(rawAddressParserItem: evmAddressParserItem, coinCode: "ETH", token: ethereumToken) let addressParserChain = AddressParserChain() - .append(handler: evmAddressParserItem) - .append(handler: udnAddressParserItem) + .append(handler: evmAddressParserItem) + .append(handler: udnAddressParserItem) if let httpSyncSource = App.shared.evmSyncSourceManager.httpSyncSource(blockchainType: .ethereum), let ensAddressParserItem = EnsAddressParserItem(rpcSource: httpSyncSource.rpcSource, rawAddressParserItem: evmAddressParserItem) { @@ -39,22 +38,22 @@ struct WatchModule { let tronService = WatchTronService(accountFactory: App.shared.accountFactory, accountManager: App.shared.accountManager, walletManager: App.shared.walletManager, marketKit: App.shared.marketKit) let viewModel = WatchViewModel( - service: service, - tronService: tronService, - evmAddressViewModel: evmAddressViewModel, - tronAddressViewModel: tronAddressViewModel, - publicKeyViewModel: publicKeyViewModel + service: service, + tronService: tronService, + evmAddressViewModel: evmAddressViewModel, + tronAddressViewModel: tronAddressViewModel, + publicKeyViewModel: publicKeyViewModel ) let evmRecipientAddressViewModel = RecipientAddressViewModel(service: addressService, handlerDelegate: nil) let tronRecipientAddressViewModel = RecipientAddressViewModel(service: tronAddressService, handlerDelegate: nil) let viewController = WatchViewController( - viewModel: viewModel, - evmAddressViewModel: evmRecipientAddressViewModel, - tronAddressViewModel: tronRecipientAddressViewModel, - publicKeyViewModel: publicKeyViewModel, - sourceViewController: sourceViewController + viewModel: viewModel, + evmAddressViewModel: evmRecipientAddressViewModel, + tronAddressViewModel: tronRecipientAddressViewModel, + publicKeyViewModel: publicKeyViewModel, + sourceViewController: sourceViewController ) return ThemeNavigationController(rootViewController: viewController) @@ -64,40 +63,38 @@ struct WatchModule { let service: IChooseWatchService switch watchType { - case .evmAddress: - service = ChooseBlockchainService( - accountType: accountType, - accountName: name, - accountFactory: App.shared.accountFactory, - accountManager: App.shared.accountManager, - walletManager: App.shared.walletManager, - evmBlockchainManager: App.shared.evmBlockchainManager, - marketKit: App.shared.marketKit - ) - - case .tronAddress: - return nil - - case .publicKey: - service = ChooseCoinService( - accountType: accountType, - accountName: name, - accountFactory: App.shared.accountFactory, - accountManager: App.shared.accountManager, - walletManager: App.shared.walletManager, - marketKit: App.shared.marketKit - ) + case .evmAddress: + service = ChooseBlockchainService( + accountType: accountType, + accountName: name, + accountFactory: App.shared.accountFactory, + accountManager: App.shared.accountManager, + walletManager: App.shared.walletManager, + evmBlockchainManager: App.shared.evmBlockchainManager, + marketKit: App.shared.marketKit + ) + + case .tronAddress: + return nil + + case .publicKey: + service = ChooseCoinService( + accountType: accountType, + accountName: name, + accountFactory: App.shared.accountFactory, + accountManager: App.shared.accountManager, + walletManager: App.shared.walletManager, + marketKit: App.shared.marketKit + ) } let viewModel = ChooseWatchViewModel(service: service, watchType: watchType) return ChooseWatchViewController(viewModel: viewModel, sourceViewController: sourceViewController) } - } extension WatchModule { - enum WatchType: CaseIterable { case evmAddress case tronAddress @@ -105,9 +102,17 @@ extension WatchModule { var title: String { switch self { - case .evmAddress: return "watch_address.evm_address".localized - case .tronAddress: return "watch_address.tron_address".localized - case .publicKey: return "watch_address.public_key".localized + case .evmAddress: return "watch_address.evm_address".localized + case .tronAddress: return "watch_address.tron_address".localized + case .publicKey: return "watch_address.public_key".localized + } + } + + var subtitle: String { + switch self { + case .evmAddress: return "(Ethereum, Binance, …)" + case .tronAddress: return "(TRX, Tron tokens, …)" + case .publicKey: return "(Bitcoin, Litecoin, …)" } } } @@ -116,5 +121,4 @@ extension WatchModule { case coin(token: Token) case blockchain(blockchain: Blockchain) } - } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchViewController.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchViewController.swift index 6627a2f62d..6f276d51f1 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchViewController.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchViewController.swift @@ -137,6 +137,7 @@ class WatchViewController: KeyboardAwareViewController { viewItems: WatchModule.WatchType.allCases.enumerated().map { index, watchType in AlertViewItem( text: watchType.title, + description: watchType.subtitle, selected: self.watchType == watchType ) }