blockchainethereumblockchain-walleterc20erc721walletxdaidappdecentralizederc1155erc875iosswifttokens
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.4 KiB
115 lines
3.4 KiB
7 years ago
|
// Copyright SIX DAY LLC. All rights reserved.
|
||
7 years ago
|
|
||
|
import UIKit
|
||
|
|
||
7 years ago
|
enum BalanceMode {
|
||
|
case short
|
||
|
case full
|
||
|
}
|
||
|
|
||
7 years ago
|
class BalanceTitleView: UIView {
|
||
|
|
||
7 years ago
|
@objc dynamic var titleTextColor: UIColor? {
|
||
|
get { return self.titleLabel.textColor }
|
||
|
set { self.titleLabel.textColor = newValue }
|
||
|
}
|
||
|
|
||
|
@objc dynamic var subTitleTextColor: UIColor? {
|
||
|
get { return self.subTitleLabel.textColor }
|
||
|
set { self.subTitleLabel.textColor = newValue }
|
||
|
}
|
||
|
|
||
7 years ago
|
let titleLabel = UILabel()
|
||
|
let subTitleLabel = UILabel()
|
||
7 years ago
|
var viewModel: BalanceBaseViewModel? {
|
||
|
didSet {
|
||
|
guard let viewModel = viewModel else { return }
|
||
|
configure(viewModel: viewModel)
|
||
|
}
|
||
|
}
|
||
|
private var mode = BalanceMode.short
|
||
7 years ago
|
|
||
7 years ago
|
override init(frame: CGRect) {
|
||
|
super.init(frame: .zero)
|
||
7 years ago
|
|
||
7 years ago
|
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
||
|
titleLabel.textAlignment = .center
|
||
7 years ago
|
titleLabel.adjustsFontSizeToFitWidth = true
|
||
7 years ago
|
|
||
|
subTitleLabel.translatesAutoresizingMaskIntoConstraints = false
|
||
|
subTitleLabel.textAlignment = .center
|
||
7 years ago
|
subTitleLabel.adjustsFontSizeToFitWidth = true
|
||
7 years ago
|
|
||
7 years ago
|
let stackView = [
|
||
7 years ago
|
titleLabel,
|
||
|
subTitleLabel,
|
||
7 years ago
|
].asStackView(axis: .vertical, spacing: 2)
|
||
7 years ago
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||
|
addSubview(stackView)
|
||
7 years ago
|
|
||
7 years ago
|
NSLayoutConstraint.activate([
|
||
7 years ago
|
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
||
|
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||
|
stackView.topAnchor.constraint(equalTo: topAnchor),
|
||
|
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
||
7 years ago
|
])
|
||
7 years ago
|
|
||
|
stackView.addGestureRecognizer(
|
||
|
UITapGestureRecognizer(target: self, action: #selector(self.switchModel))
|
||
|
)
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
private func configure(viewModel: BalanceBaseViewModel) {
|
||
7 years ago
|
titleLabel.font = Fonts.semibold(size: 18)
|
||
|
subTitleLabel.font = Fonts.regular(size: 14)
|
||
7 years ago
|
|
||
|
let amount: String
|
||
|
switch mode {
|
||
|
case .full:
|
||
|
amount = viewModel.amountFull
|
||
|
case .short:
|
||
|
amount = viewModel.amountShort
|
||
|
}
|
||
|
|
||
|
titleLabel.text = "\(amount) \(viewModel.symbol)"
|
||
|
subTitleLabel.text = viewModel.currencyAmount
|
||
|
}
|
||
|
|
||
|
@objc func switchModel() {
|
||
|
switch mode {
|
||
|
case .full:
|
||
|
mode = .short
|
||
|
case .short:
|
||
|
mode = .full
|
||
|
}
|
||
|
|
||
|
guard let viewModel = viewModel else { return }
|
||
|
configure(viewModel: viewModel)
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
required init?(coder aDecoder: NSCoder) {
|
||
|
fatalError("init(coder:) has not been implemented")
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
extension BalanceTitleView {
|
||
7 years ago
|
static func make(from session: WalletSession, _ transferType: TransferType) -> BalanceTitleView {
|
||
7 years ago
|
let view = BalanceTitleView(frame: .zero)
|
||
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||
7 years ago
|
switch transferType {
|
||
|
case .ether:
|
||
7 years ago
|
session.balanceViewModel.subscribe { [weak view] viewModel in
|
||
7 years ago
|
guard let viewModel = viewModel else { return }
|
||
7 years ago
|
view?.viewModel = viewModel
|
||
7 years ago
|
}
|
||
|
case .token(let token):
|
||
7 years ago
|
view.viewModel = BalanceTokenViewModel(token: token)
|
||
7 years ago
|
case .stormBird(let token):
|
||
7 years ago
|
view.viewModel = BalanceTokenViewModel(token: token)
|
||
7 years ago
|
case .stormBirdOrder: break
|
||
7 years ago
|
}
|
||
7 years ago
|
session.refresh(.ethBalance)
|
||
7 years ago
|
return view
|
||
|
}
|
||
|
}
|