Refactor: Improve updating `walletSummaryView` view #3078

pull/3079/head
Vladyslav shepitko 3 years ago
parent f9b574fc56
commit 629f54a415
  1. 14
      AlphaWallet/Tokens/ViewControllers/TokensViewController.swift

@ -261,12 +261,11 @@ class TokensViewController: UIViewController {
} }
blockieImageView.addTarget(self, action: #selector(blockieButtonSelected), for: .touchUpInside) blockieImageView.addTarget(self, action: #selector(blockieButtonSelected), for: .touchUpInside)
subscriptionKey = walletSummarySubscription.subscribe { [weak self] balance in TokensViewController.reloadWalletSummaryView(walletSummaryView, with: walletSummarySubscription.value)
guard let strongSelf = self, let balance = balance else { return } subscriptionKey = walletSummarySubscription.subscribe { [weak walletSummaryView] balance in
DispatchQueue.main.async { DispatchQueue.main.async {
let summary = WalletSummary(balances: [balance]) guard let view = walletSummaryView else { return }
strongSelf.walletSummaryView.configure(viewModel: .init(summary: summary, alignment: .center)) TokensViewController.reloadWalletSummaryView(view, with: balance)
} }
} }
} }
@ -412,6 +411,11 @@ class TokensViewController: UIViewController {
tableViewHeader.bounds.size.height = size.height tableViewHeader.bounds.size.height = size.height
tableView.tableHeaderView = tableViewHeader tableView.tableHeaderView = tableViewHeader
} }
private static func reloadWalletSummaryView(_ walletSummaryView: WalletSummaryView, with balance: WalletBalance?) {
let summary = balance.map { WalletSummary(balances: [$0]) }
walletSummaryView.configure(viewModel: .init(summary: summary, alignment: .center))
}
} }
extension TokensViewController: StatefulViewController { extension TokensViewController: StatefulViewController {

Loading…
Cancel
Save