|
|
@@ -0,0 +1,466 @@
|
|
|
+//
|
|
|
+// LNWalletViewController.swift
|
|
|
+// Lanu
|
|
|
+//
|
|
|
+// Created by OneeChan on 2025/12/24.
|
|
|
+//
|
|
|
+
|
|
|
+import Foundation
|
|
|
+import UIKit
|
|
|
+import SnapKit
|
|
|
+
|
|
|
+
|
|
|
+extension UIView {
|
|
|
+ func pushToWallet() {
|
|
|
+ let vc = LNWalletViewController()
|
|
|
+ navigationController?.pushViewController(vc, animated: true)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+class LNWalletViewController: LNViewController {
|
|
|
+ private let coinLabel = UILabel()
|
|
|
+ private let diamondLabel = UILabel()
|
|
|
+ private let beanLabel = UILabel()
|
|
|
+
|
|
|
+ override func viewDidLoad() {
|
|
|
+ super.viewDidLoad()
|
|
|
+
|
|
|
+ showNavigationBar = false
|
|
|
+ setupViews()
|
|
|
+
|
|
|
+ updateWalletInfo()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension LNWalletViewController {
|
|
|
+ private func updateWalletInfo() {
|
|
|
+ diamondLabel.text = "\(myWalletInfo.diamond)"
|
|
|
+ coinLabel.text = "\(myWalletInfo.coin)"
|
|
|
+ }
|
|
|
+
|
|
|
+ private func setupViews() {
|
|
|
+ view.backgroundColor = .primary_1
|
|
|
+
|
|
|
+ let topCover = UIImageView()
|
|
|
+ topCover.image = .init(named: "ic_home_top_bg")
|
|
|
+ view.addSubview(topCover)
|
|
|
+ topCover.snp.makeConstraints { make in
|
|
|
+ make.top.leading.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let naviBar = buildFakeNavBar()
|
|
|
+ view.addSubview(naviBar)
|
|
|
+ naviBar.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview()
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let stackView = UIStackView()
|
|
|
+ stackView.axis = .vertical
|
|
|
+ stackView.spacing = 16
|
|
|
+ view.addSubview(stackView)
|
|
|
+ stackView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalTo(naviBar.snp.bottom).offset(16)
|
|
|
+ }
|
|
|
+
|
|
|
+ stackView.addArrangedSubview(buildWallet())
|
|
|
+
|
|
|
+ if myUserInfo.playmate {
|
|
|
+ stackView.addArrangedSubview(buildIncome())
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildFakeNavBar() -> UIView {
|
|
|
+ let fakeBar = UIView()
|
|
|
+ fakeBar.snp.makeConstraints { make in
|
|
|
+ make.height.equalTo((navigationController?.navigationBar.bounds.height ?? 44) + UIView.statusBarHeight)
|
|
|
+ }
|
|
|
+
|
|
|
+ let barView = UIView()
|
|
|
+ fakeBar.addSubview(barView)
|
|
|
+ barView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
+ make.height.equalTo(navigationController?.navigationBar.bounds.height ?? 44)
|
|
|
+ }
|
|
|
+
|
|
|
+ let closeButton = UIButton(type: .system)
|
|
|
+ closeButton.setImage(UIImage(systemName: "chevron.backward"), for: .normal)
|
|
|
+ closeButton.tintColor = .text_5
|
|
|
+ closeButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ navigationController?.popViewController(animated: true)
|
|
|
+ }), for: .touchUpInside)
|
|
|
+ closeButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ barView.addSubview(closeButton)
|
|
|
+ closeButton.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = .init(key: "My Wallet")
|
|
|
+ titleLabel.font = .heading_h2
|
|
|
+ titleLabel.textColor = .text_5
|
|
|
+ barView.addSubview(titleLabel)
|
|
|
+ titleLabel.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let history = UIButton()
|
|
|
+ history.setImage(.init(named: "ic_wallet_history"), for: .normal)
|
|
|
+ history.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ }), for: .touchUpInside)
|
|
|
+ barView.addSubview(history)
|
|
|
+ history.snp.makeConstraints { make in
|
|
|
+ make.trailing.equalToSuperview().offset(-16)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(30)
|
|
|
+ }
|
|
|
+
|
|
|
+ return fakeBar
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildWallet() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+ container.backgroundColor = .fill
|
|
|
+
|
|
|
+ let titleView = UIView()
|
|
|
+ container.addSubview(titleView)
|
|
|
+ titleView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview()
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.height.equalTo(40)
|
|
|
+ }
|
|
|
+
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = .init(key: "My Balance")
|
|
|
+ titleLabel.font = .heading_h3
|
|
|
+ titleLabel.textColor = .text_5
|
|
|
+ titleView.addSubview(titleLabel)
|
|
|
+ titleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let coinView = buildCoinView()
|
|
|
+ container.addSubview(coinView)
|
|
|
+ coinView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalTo(titleLabel.snp.bottom)
|
|
|
+ make.height.equalTo(64)
|
|
|
+ }
|
|
|
+
|
|
|
+ let diamondView = buildDiamondView()
|
|
|
+ container.addSubview(diamondView)
|
|
|
+ diamondView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalTo(coinView.snp.bottom).offset(10)
|
|
|
+ make.height.equalTo(64)
|
|
|
+ make.bottom.equalToSuperview().offset(-12)
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildCoinView() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.backgroundColor = .init(hex: "#FFC4000D")
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+
|
|
|
+ let coin = UIImageView.coinImageView()
|
|
|
+ container.addSubview(coin)
|
|
|
+ coin.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(14)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(42)
|
|
|
+ }
|
|
|
+
|
|
|
+ let textView = UIView()
|
|
|
+ container.addSubview(textView)
|
|
|
+ textView.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(coin.snp.trailing).offset(8)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ coinLabel.text = "0"
|
|
|
+ coinLabel.font = .heading_h1_5
|
|
|
+ coinLabel.textColor = .text_5
|
|
|
+ textView.addSubview(coinLabel)
|
|
|
+ coinLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let descLabel = UILabel()
|
|
|
+ descLabel.text = .init(key: "Coin")
|
|
|
+ descLabel.font = .heading_h5
|
|
|
+ descLabel.textColor = .text_5
|
|
|
+ textView.addSubview(descLabel)
|
|
|
+ descLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.trailing.bottom.equalToSuperview()
|
|
|
+ make.top.equalTo(coinLabel.snp.bottom).offset(-5)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpButton = UIButton()
|
|
|
+ jumpButton.setBackgroundImage(.primary_8, for: .normal)
|
|
|
+ jumpButton.layer.cornerRadius = 12
|
|
|
+ jumpButton.clipsToBounds = true
|
|
|
+ jumpButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ view.pushToCoinView()
|
|
|
+ }), for: .touchUpInside)
|
|
|
+ container.addSubview(jumpButton)
|
|
|
+ jumpButton.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview().offset(-14)
|
|
|
+ make.height.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ let contentView = UIView()
|
|
|
+ contentView.isUserInteractionEnabled = false
|
|
|
+ jumpButton.addSubview(contentView)
|
|
|
+ contentView.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ make.leading.greaterThanOrEqualToSuperview().offset(8)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpTitleLabel = UILabel()
|
|
|
+ jumpTitleLabel.text = .init(key: "Top-up")
|
|
|
+ jumpTitleLabel.font = .heading_h5
|
|
|
+ jumpTitleLabel.textColor = .text_1
|
|
|
+ contentView.addSubview(jumpTitleLabel)
|
|
|
+ jumpTitleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let arrow = UIImageView.arrowImageView(size: 10)
|
|
|
+ arrow.tintColor = .white
|
|
|
+ contentView.addSubview(arrow)
|
|
|
+ arrow.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildDiamondView() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.backgroundColor = .init(hex: "#008FFF0D")
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+
|
|
|
+ let diamond = UIImageView.diamondImageView()
|
|
|
+ container.addSubview(diamond)
|
|
|
+ diamond.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(14)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(42)
|
|
|
+ }
|
|
|
+
|
|
|
+ let textView = UIView()
|
|
|
+ container.addSubview(textView)
|
|
|
+ textView.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(diamond.snp.trailing).offset(8)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ diamondLabel.text = "0"
|
|
|
+ diamondLabel.font = .heading_h1_5
|
|
|
+ diamondLabel.textColor = .text_5
|
|
|
+ textView.addSubview(diamondLabel)
|
|
|
+ diamondLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.top.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let descLabel = UILabel()
|
|
|
+ descLabel.text = .init(key: "Diamond")
|
|
|
+ descLabel.font = .heading_h5
|
|
|
+ descLabel.textColor = .text_5
|
|
|
+ textView.addSubview(descLabel)
|
|
|
+ descLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.trailing.bottom.equalToSuperview()
|
|
|
+ make.top.equalTo(diamondLabel.snp.bottom).offset(-5)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpButton = UIButton()
|
|
|
+ jumpButton.setBackgroundImage(.primary_8, for: .normal)
|
|
|
+ jumpButton.layer.cornerRadius = 12
|
|
|
+ jumpButton.clipsToBounds = true
|
|
|
+ jumpButton.addAction(UIAction(handler: { [weak self] _ in
|
|
|
+ guard let self else { return }
|
|
|
+ view.pushToDiamondView()
|
|
|
+ }), for: .touchUpInside)
|
|
|
+ container.addSubview(jumpButton)
|
|
|
+ jumpButton.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview().offset(-14)
|
|
|
+ make.height.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ let contentView = UIView()
|
|
|
+ contentView.isUserInteractionEnabled = false
|
|
|
+ jumpButton.addSubview(contentView)
|
|
|
+ contentView.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ make.leading.greaterThanOrEqualToSuperview().offset(8)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpTitleLabel = UILabel()
|
|
|
+ jumpTitleLabel.text = .init(key: "Top-up")
|
|
|
+ jumpTitleLabel.font = .heading_h5
|
|
|
+ jumpTitleLabel.textColor = .text_1
|
|
|
+ contentView.addSubview(jumpTitleLabel)
|
|
|
+ jumpTitleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let arrow = UIImageView.arrowImageView(size: 10)
|
|
|
+ arrow.tintColor = .white
|
|
|
+ contentView.addSubview(arrow)
|
|
|
+ arrow.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildIncome() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+ container.backgroundColor = .fill
|
|
|
+
|
|
|
+ let titleView = UIView()
|
|
|
+ container.addSubview(titleView)
|
|
|
+ titleView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview()
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.height.equalTo(40)
|
|
|
+ }
|
|
|
+
|
|
|
+ let titleLabel = UILabel()
|
|
|
+ titleLabel.text = .init(key: "My Income")
|
|
|
+ titleLabel.font = .heading_h3
|
|
|
+ titleLabel.textColor = .text_5
|
|
|
+ titleView.addSubview(titleLabel)
|
|
|
+ titleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(16)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let beanView = buildBeanView()
|
|
|
+ container.addSubview(beanView)
|
|
|
+ beanView.snp.makeConstraints { make in
|
|
|
+ make.directionalHorizontalEdges.equalToSuperview().inset(16)
|
|
|
+ make.top.equalTo(titleLabel.snp.bottom)
|
|
|
+ make.height.equalTo(64)
|
|
|
+ make.bottom.equalToSuperview().offset(-10)
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+
|
|
|
+ private func buildBeanView() -> UIView {
|
|
|
+ let container = UIView()
|
|
|
+ container.backgroundColor = .init(hex: "#FF73000D")
|
|
|
+ container.layer.cornerRadius = 12
|
|
|
+
|
|
|
+ let bean = UIImageView.beanImageView()
|
|
|
+ container.addSubview(bean)
|
|
|
+ bean.snp.makeConstraints { make in
|
|
|
+ make.leading.equalToSuperview().offset(14)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.width.height.equalTo(42)
|
|
|
+ }
|
|
|
+
|
|
|
+ let textView = UIView()
|
|
|
+ container.addSubview(textView)
|
|
|
+ textView.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(bean.snp.trailing).offset(8)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ beanLabel.text = "0"
|
|
|
+ beanLabel.font = .heading_h1_5
|
|
|
+ beanLabel.textColor = .text_5
|
|
|
+ textView.addSubview(beanLabel)
|
|
|
+ beanLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.bottom.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let descLabel = UILabel()
|
|
|
+ descLabel.text = .init(key: "Beans")
|
|
|
+ descLabel.font = .heading_h5
|
|
|
+ descLabel.textColor = .text_5
|
|
|
+ textView.addSubview(descLabel)
|
|
|
+ descLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.trailing.top.equalToSuperview()
|
|
|
+ make.bottom.equalTo(beanLabel.snp.top)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpButton = UIButton()
|
|
|
+ jumpButton.setBackgroundImage(.primary_8, for: .normal)
|
|
|
+ jumpButton.layer.cornerRadius = 12
|
|
|
+ jumpButton.clipsToBounds = true
|
|
|
+ container.addSubview(jumpButton)
|
|
|
+ jumpButton.snp.makeConstraints { make in
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview().offset(-14)
|
|
|
+ make.height.equalTo(24)
|
|
|
+ }
|
|
|
+
|
|
|
+ let contentView = UIView()
|
|
|
+ jumpButton.addSubview(contentView)
|
|
|
+ contentView.snp.makeConstraints { make in
|
|
|
+ make.center.equalToSuperview()
|
|
|
+ make.leading.greaterThanOrEqualToSuperview().offset(8)
|
|
|
+ }
|
|
|
+
|
|
|
+ let jumpTitleLabel = UILabel()
|
|
|
+ jumpTitleLabel.text = .init(key: "Details")
|
|
|
+ jumpTitleLabel.font = .heading_h5
|
|
|
+ jumpTitleLabel.textColor = .text_1
|
|
|
+ contentView.addSubview(jumpTitleLabel)
|
|
|
+ jumpTitleLabel.snp.makeConstraints { make in
|
|
|
+ make.leading.verticalEdges.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ let arrow = UIImageView.arrowImageView(size: 10)
|
|
|
+ arrow.tintColor = .white
|
|
|
+ contentView.addSubview(arrow)
|
|
|
+ arrow.snp.makeConstraints { make in
|
|
|
+ make.leading.equalTo(jumpTitleLabel.snp.trailing).offset(2)
|
|
|
+ make.centerY.equalToSuperview()
|
|
|
+ make.trailing.equalToSuperview()
|
|
|
+ }
|
|
|
+
|
|
|
+ return container
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+
|
|
|
+import SwiftUI
|
|
|
+
|
|
|
+struct LNWalletViewControllerPreview: UIViewControllerRepresentable {
|
|
|
+ func makeUIViewController(context: Context) -> some UIViewController {
|
|
|
+ LNWalletViewController()
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
|
|
|
+}
|
|
|
+
|
|
|
+#Preview(body: {
|
|
|
+ LNWalletViewControllerPreview()
|
|
|
+})
|
|
|
+#endif
|