From bfd3dd639a7780ba64a67d365c847aa4f2f421db Mon Sep 17 00:00:00 2001 From: ant013 Date: Mon, 11 Sep 2023 15:15:40 +0600 Subject: [PATCH] Show multiline balance in coin page. - Use short format for send/swap pages balances --- .../Views/WalletTokenBalanceCell.swift | 32 ++++++++++++------- .../WalletTokenBalanceDataSource.swift | 9 +++++- .../WalletTokenListViewItemFactory.swift | 4 +-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/Views/WalletTokenBalanceCell.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/Views/WalletTokenBalanceCell.swift index 26fa7f8407..ae3961d082 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/Views/WalletTokenBalanceCell.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/Views/WalletTokenBalanceCell.swift @@ -4,11 +4,10 @@ import ThemeKit import ComponentKit class WalletTokenBalanceCell: UITableViewCell { - private static let height: CGFloat = 147 - private let stackView = UIStackView() private let testnetImageView = UIImageView() private let coinIconView = BalanceCoinIconHolder() + private let amountLabel = UILabel() private let amountButton = TextButtonComponent() private let descriptionLabel = UILabel() @@ -21,7 +20,7 @@ class WalletTokenBalanceCell: UITableViewCell { contentView.addSubview(stackView) stackView.snp.makeConstraints { maker in - maker.top.equalToSuperview().inset(CGFloat.margin6) + maker.top.equalToSuperview().inset(18) maker.leading.trailing.equalToSuperview().inset(CGFloat.margin16) } @@ -46,9 +45,17 @@ class WalletTokenBalanceCell: UITableViewCell { make.height.equalTo(44) } - stackView.addArrangedSubview(amountButton) - amountButton.font = .title2R - amountButton.textColor = .themeLeah + stackView.addArrangedSubview(amountLabel) + amountLabel.font = .title2R + amountLabel.textColor = .themeLeah + amountLabel.numberOfLines = 0 + amountLabel.textAlignment = .center + amountLabel.isUserInteractionEnabled = true + + amountLabel.addSubview(amountButton) + amountButton.snp.makeConstraints { maker in + maker.edges.equalToSuperview() + } stackView.addArrangedSubview(descriptionLabel) @@ -71,9 +78,10 @@ class WalletTokenBalanceCell: UITableViewCell { onTapError: onTapError ) - amountButton.text = viewItem.balanceValue?.text - amountButton.textColor = (viewItem.balanceValue?.dimmed ?? true) ? .themeGray : .themeLeah - descriptionLabel.text = viewItem.descriptionValue?.text + amountLabel.text = viewItem.balanceValue?.text ?? "----" + amountLabel.textColor = (viewItem.balanceValue?.dimmed ?? true) ? .themeGray : .themeLeah + + descriptionLabel.text = viewItem.descriptionValue?.text ?? "----" descriptionLabel.textColor = (viewItem.descriptionValue?.dimmed ?? true) ? .themeGray50 : .themeGray } @@ -86,8 +94,10 @@ class WalletTokenBalanceCell: UITableViewCell { extension WalletTokenBalanceCell { - static func height(viewItem: WalletTokenBalanceViewModel.ViewItem?) -> CGFloat { - var height: CGFloat = Self.height + static func height(containerWidth: CGFloat, viewItem: WalletTokenBalanceViewModel.ViewItem?) -> CGFloat { + var height: CGFloat = .margin24 + .iconSize32 + .margin12 + height += (viewItem?.balanceValue?.text ?? "----").height(forContainerWidth: containerWidth - 2 * .margin16, font: .title2R) + .margin6 + height += (viewItem?.descriptionValue?.text ?? "----").height(forContainerWidth: containerWidth - 2 * .margin16, font: .body) + .margin24 if !(viewItem?.isMainNet ?? true) { height += .margin12 diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceDataSource.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceDataSource.swift index 6c2228e37c..4ab8f8ea6e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceDataSource.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/Token/DataSources/WalletTokenBalance/WalletTokenBalanceDataSource.swift @@ -120,6 +120,13 @@ class WalletTokenBalanceDataSource: NSObject { cell.bind(viewItem: headerViewItem) { [weak self] in self?.viewModel.onTapFailedIcon() } + + if let tableView { + UIView.animate(withDuration: 0.3) { + tableView.beginUpdates() + tableView.endUpdates() + } + } } } @@ -300,7 +307,7 @@ extension WalletTokenBalanceDataSource: UITableViewDelegate { switch indexPath.section { case 0: switch indexPath.row { - case 0: return WalletTokenBalanceCell.height(viewItem: headerViewItem) + case 0: return WalletTokenBalanceCell.height(containerWidth: tableView.width, viewItem: headerViewItem) default: return BalanceButtonsCell.height } case 1: return .heightSingleLineCell diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift index 7366fa7a84..13641776e6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Wallet/TokenList/WalletTokenListViewItemFactory.swift @@ -89,7 +89,7 @@ class WalletTokenListViewItemFactory { private func coinValue(value: Decimal, decimalCount: Int, symbol: String? = nil, state: AdapterState) -> (text: String?, dimmed: Bool) { ( - text: ValueFormatter.instance.formatFull(value: value, decimalCount: decimalCount, symbol: symbol), + text: ValueFormatter.instance.formatShort(value: value, decimalCount: decimalCount, symbol: symbol), dimmed: state != .synced ) } @@ -103,7 +103,7 @@ class WalletTokenListViewItemFactory { let currencyValue = CurrencyValue(currency: price.currency, value: value * price.value) return ( - text: ValueFormatter.instance.formatFull(currencyValue: currencyValue), + text: ValueFormatter.instance.formatShort(currencyValue: currencyValue), dimmed: state != .synced || priceItem.expired ) }