Skip to content

Commit

Permalink
feat: mixed balance and errors on the send screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Sep 22, 2024
1 parent b7c25c1 commit 56f47de
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 232 deletions.
2 changes: 1 addition & 1 deletion DashSyncCurrentCommit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315879b4d157a026fc760d3742f6a55a8883fde5
49b001b3a003a443fd3fc6d2cd1a470e2cb7638a
33 changes: 21 additions & 12 deletions DashWallet/Sources/Models/CoinJoin/CoinJoinService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CoinJoinService: NSObject {
private var networkStatus: NetworkStatus = .online

private var _savedMode: Int? = nil
var savedMode: Int {
private var savedMode: Int {
get { _savedMode ?? UserDefaults.standard.integer(forKey: kCoinJoinMode) }
set(value) {
_savedMode = value
Expand Down Expand Up @@ -161,11 +161,20 @@ class CoinJoinService: NSObject {
}

private func updateProgress() {
guard let coinJoinManager = self.coinJoinManager else { return }
self.progress = coinJoinManager.getMixingProgress()
let coinJoinBalance = coinJoinManager.getBalance()
self.totalBalance = coinJoinBalance.myTrusted
self.coinJoinBalance = coinJoinBalance.anonymized
DispatchQueue.global(qos: .background).async { [weak self] in
guard let self = self, let coinJoinManager = self.coinJoinManager else { return }

let progress = coinJoinManager.getMixingProgress()
let coinJoinBalance = coinJoinManager.getBalance()
let totalBalance = coinJoinBalance.myTrusted
let anonymizedBalance = coinJoinBalance.anonymized

DispatchQueue.main.async {
self.progress = progress
self.totalBalance = totalBalance
self.coinJoinBalance = anonymizedBalance
}
}
}

private func createCoinJoinManager() -> DSCoinJoinManager? {
Expand All @@ -174,12 +183,6 @@ class CoinJoinService: NSObject {
return self.coinJoinManager
}

private func synchronized(_ lock: NSLock, closure: () -> Void) {
lock.lock()
defer { lock.unlock() }
closure()
}

private func updateBalance(balance: UInt64) {
guard let coinJoinManager = self.coinJoinManager else { return }

Expand Down Expand Up @@ -315,5 +318,11 @@ extension CoinJoinService: DSCoinJoinManagerDelegate {

DSLogger.log("[SW] CoinJoin: Active sessions: \(activeSessions)")
}

private func synchronized(_ lock: NSLock, closure: () -> Void) {
lock.lock()
defer { lock.unlock() }
closure()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -88,27 +88,23 @@ extension CoinJoinLevelsViewController {

@objc
private func selectIntermediate() {
if viewModel.selectedMode == .intermediate {
return
}

if viewModel.mixingState == .mixing {
confirmFor(.intermediate)
} else {
viewModel.selectedMode = .intermediate
}
selectMode(.intermediate)
}

@objc
private func selectAdvanced() {
if viewModel.selectedMode == .advanced {
selectMode(.advanced)
}

private func selectMode(_ mode: CoinJoinMode) {
if viewModel.selectedMode == mode {
return
}

if viewModel.mixingState == .mixing {
confirmFor(.advanced)
if viewModel.selectedMode == .none {
viewModel.selectedMode = mode
} else {
viewModel.selectedMode = .advanced
confirmFor(mode)
}
}

Expand Down Expand Up @@ -176,6 +172,7 @@ extension CoinJoinLevelsViewController {
let alert = UIAlertController(title: "", message: NSLocalizedString("Are you sure you want to change the privacy level?", comment: "CoinJoin"), preferredStyle: .alert)
alert.addAction(UIAlertAction(title: title, style: .default, handler: { [weak self] _ in
self?.viewModel.selectedMode = mode
self?.viewModel.startMixing()
}))
let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel)
alert.addAction(cancelAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ final class BuyCreditsViewController: SendAmountViewController, ObservableObject

let intro = SendIntro(
title: NSLocalizedString("Buy credits", comment: "Credits"),
dashBalance: Int64(model.walletBalance),
balanceLabel: NSLocalizedString("Dash balance", comment: "") + ":"
dashBalance: model.walletBalance,
balanceLabel: NSLocalizedString("Dash balance", comment: "") + ":",
avatarView: { }
)
let swiftUIController = UIHostingController(rootView: intro)
swiftUIController.view.backgroundColor = UIColor.dw_secondaryBackground()
Expand Down Expand Up @@ -131,7 +132,9 @@ final class BuyCreditsViewController: SendAmountViewController, ObservableObject
rateLabel.topAnchor.constraint(equalTo: rateContainer.topAnchor, constant: 4),
rateLabel.leadingAnchor.constraint(equalTo: rateContainer.leadingAnchor, constant: 8),
rateLabel.trailingAnchor.constraint(equalTo: rateContainer.trailingAnchor, constant: -8),
rateLabel.bottomAnchor.constraint(equalTo: rateContainer.bottomAnchor, constant: -4)
rateLabel.bottomAnchor.constraint(equalTo: rateContainer.bottomAnchor, constant: -4),

swiftUIController.view.heightAnchor.constraint(equalToConstant: 100)
])
}

Expand Down
22 changes: 11 additions & 11 deletions DashWallet/Sources/UI/Home/Views/Cells/CoinJoinProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ struct CoinJoinProgressInfo: View {
.foregroundColor(textColor)
.font(font)
.padding(.leading, 4)

Spacer()
Text("\(mixed, format: .number.precision(.fractionLength(0...3))) of \(total, format: .number.precision(.fractionLength(0...3)))") // TODO
.foregroundColor(textColor)
.font(font)
Image("icon_dash_currency")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: font.pointSize, height: font.pointSize)
.padding(.leading, 2)
.foregroundColor(textColor)
}

Spacer()
Text("\(mixed, format: .number.precision(.fractionLength(0...3))) of \(total, format: .number.precision(.fractionLength(0...3)))") // TODO
.foregroundColor(textColor)
.font(font)
Image("icon_dash_currency")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: font.pointSize, height: font.pointSize)
.padding(.leading, 2)
.foregroundColor(textColor)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions DashWallet/Sources/UI/Home/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ struct TransactionList<Content: View>: View {
.sheet(item: $selectedTxDataItem) { item in
TransactionDetailsSheet(item: item)
}
.onChange(of: viewModel.coinJoinItem) { new in
DSLogger.log("[SW] CoinJoin: on change of coinJoinItem: \(viewModel.coinJoinItem.description)")
}
}

@ViewBuilder
Expand Down
Loading

0 comments on commit 56f47de

Please sign in to comment.