Skip to content

Commit

Permalink
Show multiline balance in coin page.
Browse files Browse the repository at this point in the history
- Use short format for send/swap pages balances
  • Loading branch information
ant013 committed Sep 11, 2023
1 parent cc4468f commit ddd8931
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
}

Expand All @@ -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)

Expand All @@ -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
}

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

Expand Down Expand Up @@ -300,7 +307,9 @@ extension WalletTokenBalanceDataSource: UITableViewDelegate {
switch indexPath.section {
case 0:
switch indexPath.row {
case 0: return WalletTokenBalanceCell.height(viewItem: headerViewItem)
case 0:
print(WalletTokenBalanceCell.height(containerWidth: tableView.width, viewItem: headerViewItem))
return WalletTokenBalanceCell.height(containerWidth: tableView.width, viewItem: headerViewItem)
default: return BalanceButtonsCell.height
}
case 1: return .heightSingleLineCell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand All @@ -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
)
}
Expand Down

0 comments on commit ddd8931

Please sign in to comment.