Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watch Wallet: Add subtitles in the Address Type menu #5206

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
}

Expand All @@ -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
Expand All @@ -42,35 +42,53 @@ class AlertViewController: ThemeActionSheetController {

private var titleRow: RowProtocol {
Row<AlertTitleCell>(
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<AlertItemCell>(
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]()

Expand All @@ -79,13 +97,10 @@ extension AlertViewController: SectionsDataSource {

return [Section(id: "main", rows: rows)]
}

}

extension AlertViewController: IAlertView {

func set(viewItems: [AlertViewItem]) {
self.viewItems = viewItems
}

}
92 changes: 48 additions & 44 deletions UnstoppableWallet/UnstoppableWallet/Modules/Watch/WatchModule.swift
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -64,50 +63,56 @@ 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
case publicKey

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, …)"
}
}
}
Expand All @@ -116,5 +121,4 @@ extension WatchModule {
case coin(token: Token)
case blockchain(blockchain: Blockchain)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down