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

fix: Update balance on Home Screen during sync #555

Merged
merged 1 commit into from
Jun 22, 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 @@ -44,12 +44,7 @@ final class BalanceModel {
}
}

@objc
func applicationWillEnterForeground(_ notification: NSNotification) {
hideBalanceIfNeeded()
}

private func reloadBalance() {
func reloadBalance() {
let balanceValue = DWEnvironment.sharedInstance().currentWallet.balance

if balanceValue > value &&
Expand All @@ -73,6 +68,11 @@ final class BalanceModel {
balanceDidChange?()
}

@objc
func applicationWillEnterForeground(_ notification: NSNotification) {
hideBalanceIfNeeded()
}

deinit {
NotificationCenter.default.removeObserver(self)
SyncingActivityMonitor.shared.remove(observer: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,9 @@ final class HomeBalanceView: UIView {
hideBalance(model.isBalanceHidden)
}

func reloadView() {
var titleString = ""

let isBalanceHidden = model.isBalanceHidden

if !isBalanceHidden && state == .syncing {
titleString = NSLocalizedString("Syncing Balance", comment: "")

titleLabel.alpha = 0.8
titleLabel.layer.removeAllAnimations()

UIView.animate(withDuration: 0.8,
delay:0.0,
options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat],
animations: { self.titleLabel.alpha = 0.3 },
completion: nil)

} else {
titleLabel.layer.removeAllAnimations()
}

titleLabel.text = titleString
hideBalance(isBalanceHidden)
}

public func reloadData() {
balanceView.reloadData()
model.reloadBalance()
reloadView()
}

private func commonInit() {
Expand Down Expand Up @@ -147,14 +123,37 @@ final class HomeBalanceView: UIView {
object: nil)

reloadView()
reloadData()

model.balanceDidChange = { [weak self] in
self?.reloadView()
self?.reloadData()
self?.balanceView.reloadData()
}
}

private func reloadView() {
var titleString = ""

let isBalanceHidden = model.isBalanceHidden

if !isBalanceHidden && state == .syncing {
titleString = NSLocalizedString("Syncing Balance", comment: "")

titleLabel.alpha = 0.8
titleLabel.layer.removeAllAnimations()

UIView.animate(withDuration: 0.8,
delay:0.0,
options:[.allowUserInteraction, .curveEaseInOut, .autoreverse, .repeat],
animations: { self.titleLabel.alpha = 0.3 },
completion: nil)

} else {
titleLabel.layer.removeAllAnimations()
}

titleLabel.text = titleString
hideBalance(isBalanceHidden)
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

Expand Down Expand Up @@ -188,7 +187,6 @@ final class HomeBalanceView: UIView {
self.amountsView.alpha = hidden ? 0.0 : 1.0

self.tapToUnhideLabel.alpha = hidden ? 0.0 : 1.0
self.reloadData()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ final class HomeHeaderView: UIView {
func reloadBalance() {
let isSyncing = SyncingActivityMonitor.shared.state == .syncing

balanceView.reloadView()
balanceView.reloadData()
balanceView.state = isSyncing ? .syncing : .`default`
}
Expand Down