Skip to content

Commit

Permalink
Balance UI updates.
Browse files Browse the repository at this point in the history
- Remove refresh on send token select
- Set Unstoppable image on receive screen
  • Loading branch information
ant013 committed Aug 29, 2023
1 parent 16443d2 commit 61f4b27
Show file tree
Hide file tree
Showing 20 changed files with 57 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class CexDepositViewItemFactory: IReceiveAddressViewItemFactory {

let qrItem = ReceiveAddressModule.QrItem(
address: item.address,
text: "deposit.qr_code_description".localized(item.coinCode),
imageUrl: item.imageUrl
text: "deposit.qr_code_description".localized(item.coinCode)
)
sections.append([.qrItem(qrItem)])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ class BaseSendViewController: ThemeViewController, SectionsDataSource {

title = "send.title".localized(viewModel.token.coin.code)

navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)
if (navigationController?.viewControllers.count ?? 0) == 1 {
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)
}

if feeSettingsFactory == nil {
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "button.cancel".localized, style: .plain, target: self, action: #selector(didTapCancel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SendModule {
feeCautionViewModel: feeCautionViewModel
)

return ThemeNavigationController(rootViewController: viewController)
return viewController
}

private static func viewController(token: Token, adapter: ISendBinanceAdapter) -> UIViewController? {
Expand Down Expand Up @@ -246,7 +246,7 @@ class SendModule {
feeWarningViewModel: feeWarningViewModel
)

return ThemeNavigationController(rootViewController: viewController)
return viewController
}

private static func viewController(token: Token, adapter: ISendZcashAdapter) -> UIViewController? {
Expand Down Expand Up @@ -335,7 +335,7 @@ class SendModule {
feeViewModel: feeViewModel
)

return ThemeNavigationController(rootViewController: viewController)
return viewController
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class SendEvmModule {
recipientViewModel: recipientViewModel
)

return ThemeNavigationController(rootViewController: viewController)
return viewController
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class SendEvmViewController: ThemeViewController {

title = "send.title".localized(viewModel.token.coin.code)

navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)

if (navigationController?.viewControllers.count ?? 0) == 1 {
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)
}
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "button.cancel".localized, style: .plain, target: self, action: #selector(didTapCancel))
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SendTronModule {
recipientViewModel: recipientViewModel
)

return ThemeNavigationController(rootViewController: viewController)
return viewController
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class SendTronViewController: ThemeViewController {

title = "send.title".localized(viewModel.token.coin.code)

navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)
if (navigationController?.viewControllers.count ?? 0) == 1 {
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: iconImageView)
}
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "button.cancel".localized, style: .plain, target: self, action: #selector(didTapCancel))
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ extension ReceiveAddressModule {
struct QrItem {
let address: String
let text: String
let imageUrl: String?
}

struct DescriptionItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,14 @@ class ReceiveAddressViewController<Service: IReceiveAddressService, Factory: IRe
}

extension ReceiveAddressViewController: SectionsDataSource {
private func qrRow(address: String, imageUrl: String?, text: String) -> RowProtocol {
private func qrRow(address: String, text: String) -> RowProtocol {
Row<QrCodeCell>(
id: "qr-code",
dynamicHeight: { width in
QrCodeCell.height(containerWidth: width, text: text)
},
bind: { [weak self] cell, _ in
cell.set(qrCodeString: address, text: text)
cell.set(tokenUrl: imageUrl)
cell.onTap = {
self?.onTapCopy()
}
Expand Down Expand Up @@ -275,7 +274,7 @@ extension ReceiveAddressViewController: SectionsDataSource {
viewItems.enumerated().forEach { index, viewItem in
switch viewItem {
case let .qrItem(item):
rows.append(qrRow(address: item.address, imageUrl: item.imageUrl, text: item.text))
rows.append(qrRow(address: item.address, text: item.text))
case let .value(title, value, copyable):
let rowInfo = RowInfo(index: index, count: viewItems.count)
rows.append(valueRow(title: title, value: value, copyable: copyable, rowInfo: rowInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class ReceiveAddressViewItemFactory: IReceiveAddressViewItemFactory {
let text = (item.watchAccount ? "deposit.qr_code_description.watch" : "deposit.qr_code_description").localized(item.coinCode)
let qrItem = ReceiveAddressModule.QrItem(
address: item.address.address,
text: text,
imageUrl: item.imageUrl
text: text
)
sections.append([.qrItem(qrItem)])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ extension ReceiveSelectCoinViewController: SectionsDataSource {
image: .url(viewItem.imageUrl, placeholder: "placeholder_circle_32"),
title: .body(viewItem.title),
description: .subhead2(viewItem.description),
accessoryType: .disclosure,
backgroundStyle: .transparent,
autoDeselect: true,
isLast: isLast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class WalletTokenBalanceDataSource: NSObject {
case .wallet(let wallet):
cell.actions[.send] = { [weak self] in
if let viewController = SendModule.controller(wallet: wallet) {
self?.parentViewController?.present(viewController, animated: true)
self?.parentViewController?.present(ThemeNavigationController(rootViewController: viewController), animated: true)
}
}
cell.actions[.swap] = { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SnapKit
import ComponentKit

class WalletTokenCell: UITableViewCell {
private let topSeparatorView = UIView()
private let topView = BalanceTopView()
private let separatorView = UIView()

Expand All @@ -12,6 +13,13 @@ class WalletTokenCell: UITableViewCell {

backgroundColor = .clear

contentView.addSubview(topSeparatorView)
topSeparatorView.snp.makeConstraints { maker in
maker.leading.top.trailing.equalToSuperview()
maker.height.equalTo(CGFloat.heightOneDp)
}

topSeparatorView.backgroundColor = .themeSteel20
contentView.addSubview(topView)
topView.snp.makeConstraints { maker in
maker.leading.top.trailing.equalToSuperview()
Expand All @@ -32,7 +40,8 @@ class WalletTokenCell: UITableViewCell {
fatalError("not implemented")
}

func bind(viewItem: BalanceViewItem, animated: Bool = false, duration: TimeInterval = 0.2, onTapError: (() -> ())?) {
func bind(viewItem: BalanceViewItem, first: Bool = false, animated: Bool = false, duration: TimeInterval = 0.2, onTapError: (() -> ())?) {
topSeparatorView.isHidden = !first
topView.bind(viewItem: viewItem.topViewItem, onTapError: onTapError)
topView.layoutIfNeeded()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,6 @@ extension WalletTokenListService {
}
}

func refresh() {
elementService.refresh()

queue.async {
self.coinPriceService.refresh()
}
}

}

extension WalletTokenListService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class WalletTokenListViewController: ThemeSearchViewController {
private let disposeBag = DisposeBag()

private let tableView = UITableView(frame: .zero, style: .plain)
private let refreshControl = UIRefreshControl()

private let spinner = HUDActivityView.create(with: .medium24)

Expand Down Expand Up @@ -55,10 +54,6 @@ class WalletTokenListViewController: ThemeSearchViewController {
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
navigationItem.searchController?.searchBar.placeholder = "add_token.coin_name".localized

refreshControl.tintColor = .themeLeah
refreshControl.alpha = 0.6
refreshControl.addTarget(self, action: #selector(onRefresh), for: .valueChanged)

view.addSubview(tableView)
tableView.snp.makeConstraints { maker in
maker.edges.equalToSuperview()
Expand All @@ -71,6 +66,7 @@ class WalletTokenListViewController: ThemeSearchViewController {
tableView.dataSource = self
tableView.delegate = self
tableView.registerCell(forClass: WalletTokenCell.self)
tableView.registerCell(forClass: EmptyCell.self)

view.addSubview(spinner)
spinner.snp.makeConstraints { make in
Expand Down Expand Up @@ -129,24 +125,10 @@ class WalletTokenListViewController: ThemeSearchViewController {
tableView.deselectCell(withCoordinator: transitionCoordinator, animated: animated)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

tableView.refreshControl = refreshControl
}

@objc func onTapClose() {
dismiss(animated: true)
}

@objc func onRefresh() {
viewModel.onTriggerRefresh()

DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.refreshControl.endRefreshing()
}
}

@objc private func onTapRetry() {
// todo
}
Expand Down Expand Up @@ -233,14 +215,15 @@ class WalletTokenListViewController: ThemeSearchViewController {

updateIndexes.forEach {
if let cell = tableView.cellForRow(at: IndexPath(row: $0, section: 0)) as? WalletTokenCell {
bind(cell: cell, viewItem: viewItems[$0], animated: true)
bind(cell: cell, viewItem: viewItems[$0], first: $0 == 0, animated: true)
}
}
}

private func bind(cell: WalletTokenCell, viewItem: BalanceViewItem, animated: Bool = false) {
private func bind(cell: WalletTokenCell, viewItem: BalanceViewItem, first: Bool = false, animated: Bool = false) {
cell.bind(
viewItem: viewItem,
first: first,
animated: animated,
duration: animationDuration,
onTapError: { [weak self] in
Expand Down Expand Up @@ -273,15 +256,23 @@ class WalletTokenListViewController: ThemeSearchViewController {
extension WalletTokenListViewController: UITableViewDataSource {

func numberOfSections(in tableView: UITableView) -> Int {
1
2
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
viewItems.count
switch section {
case 0: return viewItems.count
case 1: return 1
default: return 0
}
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
tableView.dequeueReusableCell(withIdentifier: String(describing: WalletTokenCell.self), for: indexPath)
switch indexPath.section {
case 0: return tableView.dequeueReusableCell(withIdentifier: String(describing: WalletTokenCell.self), for: indexPath)
default: return tableView.dequeueReusableCell(withIdentifier: String(describing: EmptyCell.self), for: indexPath)
}

}

}
Expand All @@ -290,12 +281,15 @@ extension WalletTokenListViewController: UITableViewDelegate {

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let cell = cell as? WalletTokenCell {
bind(cell: cell, viewItem: viewItems[indexPath.row])
bind(cell: cell, viewItem: viewItems[indexPath.row], first: indexPath.row == 0)
}
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
WalletTokenCell.height
switch indexPath.section {
case 0: return WalletTokenCell.height
default: return .margin32
}
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ extension WalletTokenListViewModel {
openSyncErrorRelay.accept((wallet, error))
}

func onTriggerRefresh() {
service.refresh()
}

func didSelect(item: BalanceViewItem) {
if item.topViewItem.indefiniteSearchCircle || item.topViewItem.syncSpinnerProgress != nil {
showSyncingRelay.accept(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BalanceButtonsView: UIView {
maker.width.equalTo(sendButton)
}

receiveButton.set(style: .gray)
receiveButton.set(style: .gray, accessoryType: .icon(image: UIImage(named: "arrow_medium_2_down_left_24")))
receiveButton.setTitle("balance.receive".localized, for: .normal)
receiveButton.addTarget(self, action: #selector(onReceive), for: .touchUpInside)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ComponentKit

class BalanceTopView: UIView {
static let height: CGFloat = 62
static let expandedMargin: CGFloat = 6

private let coinIconView = BalanceCoinIconHolder()
private let testnetImageView = UIImageView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ class WalletViewItemFactory {
private let minimumProgress = 10
private let infiniteProgress = 50

init() {
}

private func topViewItem(item: WalletService.Item, balancePrimaryValue: BalancePrimaryValue, balanceHidden: Bool) -> BalanceTopViewItem {
let state = item.state

Expand Down Expand Up @@ -147,7 +144,7 @@ class WalletViewItemFactory {
return [
.send: .enabled,
.receive: .enabled,
// .swap: .enabled
.swap: .enabled
]
case .evmAddress, .tronAddress: return [:]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ class QrCodeCell: UITableViewCell {
tokenWrapperView.isUserInteractionEnabled = false
tokenWrapperView.cornerRadius = .cornerRadius8
tokenWrapperView.backgroundColor = .themeWhite
tokenWrapperView.clipsToBounds = true

tokenWrapperView.addSubview(tokenImageView)
tokenImageView.snp.makeConstraints { maker in
maker.center.equalToSuperview()
maker.size.equalTo(CGFloat.iconSize32)
}

tokenImageView.contentMode = .scaleAspectFit
tokenImageView.image = UIImage(named: AppIcon.main.imageName)
tokenImageView.cornerRadius = 6

wrapperView.addSubview(label)
label.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview().inset(Self.textHorizontalMargin)
Expand Down Expand Up @@ -107,13 +112,6 @@ class QrCodeCell: UITableViewCell {
label.text = text
}

func set(tokenUrl: String?) {
guard let tokenUrl else {
return
}
tokenImageView.setImage(withUrlString: tokenUrl, placeholder: nil)
}

}

extension QrCodeCell {
Expand Down

0 comments on commit 61f4b27

Please sign in to comment.