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

Show multiline balance in coin page. #5216

Merged
merged 1 commit into from
Sep 11, 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 @@ -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,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
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