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

implement account filter operation on privacy setup #765

Merged
merged 7 commits into from May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4,188 changes: 2,094 additions & 2,094 deletions Decred Wallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1240"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Expand Up @@ -35,6 +35,7 @@ import Dcrlibwallet
var showWatchOnlyWallet = true
var showMixedAccount = true
var showUnMixedAccount = true
var showMixedOnly = true

var onAccountSelectionChanged: ((_ selectedWallet: DcrlibwalletWallet, _ selectedAccount: DcrlibwalletAccount) -> Void)?

Expand Down Expand Up @@ -81,7 +82,7 @@ import Dcrlibwallet
selectedWallet: self.selectedWallet,
selectedAccount: self.selectedAccount, showWatchOnlyWallet: showWatchOnlyWallet,
showUnMixedAccount: showUnMixedAccount,
showMixedAccount: showMixedAccount,
showMixedAccount: showMixedAccount, showMixedOnly: showMixedOnly,
callback: self.updateSelectedAccount)
}

Expand All @@ -104,4 +105,37 @@ import Dcrlibwallet

self.onAccountSelectionChanged?(firstWallet, firstWalletAccount)
}

func selectFirstFilterWalletAccount() {
guard let firstWallet = WalletLoader.shared.wallets.first,
let firstWalletAccount = firstWallet.accounts.filter({ $0.totalBalance > 0 || $0.name != "imported" }).first,
let firstWalletUnMixedAccount = firstWallet.accounts.filter({ $0.totalBalance > 0 || $0.name != "imported" && $0.number != firstWallet.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerUnmixedAccount, defaultValue: -1)}).first,
let firstWalletMixedOnlyAccount = firstWallet.accounts.filter({$0.number == firstWallet.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerMixedAccount, defaultValue: -1)}).first,
let firstWalletMixedAccount = firstWallet.accounts.filter({ $0.totalBalance > 0 || $0.name != "imported" && $0.number != firstWallet.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerMixedAccount, defaultValue: -1)}).first
else { return }
self.selectedWallet = firstWallet
if !showUnMixedAccount {
self.selectedAccount = firstWalletUnMixedAccount
self.onAccountSelectionChanged?(firstWallet, firstWalletUnMixedAccount)
return
}

if !showMixedOnly {
self.selectedAccount = firstWalletMixedOnlyAccount
self.onAccountSelectionChanged?(firstWallet, firstWalletMixedOnlyAccount)
return
}

if !showMixedAccount {
self.selectedAccount = firstWalletMixedAccount
self.onAccountSelectionChanged?(firstWallet, firstWalletMixedAccount)
return
}

self.selectedAccount = firstWalletAccount


self.onAccountSelectionChanged?(firstWallet, firstWalletAccount)

}
}
Expand Up @@ -25,6 +25,7 @@ class AccountSelectorDialog: UIViewController {
var showWatchOnly = true
var showUnMixedAccount = true
var showMixedAccount = true
var showMixedOnly = true

let accountCellRowHeight: CGFloat = 74
let walletHeaderSectionHeight: CGFloat = 36
Expand All @@ -36,6 +37,7 @@ class AccountSelectorDialog: UIViewController {
showWatchOnlyWallet: Bool,
showUnMixedAccount: Bool,
showMixedAccount: Bool,
showMixedOnly: Bool,
callback: @escaping AccountSelectorDialogCallback) {

let dialog = AccountSelectorDialog.instantiate(from: .CustomDialogs)
Expand All @@ -45,6 +47,7 @@ class AccountSelectorDialog: UIViewController {
dialog.selectedAccount = selectedAccount
dialog.showWatchOnly = showWatchOnlyWallet
dialog.showUnMixedAccount = showUnMixedAccount
dialog.showMixedOnly = showMixedOnly
dialog.showMixedAccount = showMixedAccount
dialog.modalPresentationStyle = .pageSheet
vc.present(dialog, animated: true, completion: nil)
Expand Down Expand Up @@ -75,8 +78,12 @@ class AccountSelectorDialog: UIViewController {
accountsFilterFn = { $0.totalBalance > 0 || $0.name != "imported" && $0.number != self.selectedWallet?.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerUnmixedAccount, defaultValue: -1)}
}

if !showMixedOnly {
accountsFilterFn = {$0.number == self.selectedWallet?.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerMixedAccount, defaultValue: -1)}
}

if !showMixedAccount {
accountsFilterFn = { $0.totalBalance > 0 || $0.name != "imported" && $0.number != self.selectedWallet?.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerMixedAccount, defaultValue: -1)}
accountsFilterFn = { $0.name != "imported" && $0.number != self.selectedWallet?.readInt32ConfigValue(forKey: DcrlibwalletAccountMixerMixedAccount, defaultValue: -1)}
}

let fullCoinWallet = WalletLoader.shared.wallets.filter { !$0.isWatchingOnlyWallet()}
Expand Down
52 changes: 39 additions & 13 deletions Decred Wallet/Features/Send/SendViewController.swift
Expand Up @@ -105,16 +105,20 @@ class SendViewController: UIViewController {

func setupViews() {
self.sourceAccountView.showWatchOnlyWallet = false
self.sourceAccountView.showMixedAccount = false
self.sourceAccountView.onAccountSelectionChanged = { _, newSourceAccount in
let spendableAmount = (Decimal(newSourceAccount.balance!.dcrSpendable) as NSDecimalNumber).round(8).formattedWithSeparator
self.sourceAccountSpendableBalanceLabel.text = "\(LocalizedStrings.spendable): \(spendableAmount) DCR"

self.sourceAccountView.selectFirstFilterWalletAccount()

if let setup = self.sourceAccountView?.selectedWallet?.readBoolConfigValue(forKey: DcrlibwalletAccountMixerConfigSet, defaultValue: false) {

if self.sendMax {
self.calculateAndSetMaxSendableAmount()
if setup {
self.sourceAccountView.showMixedOnly = false
} else {
self.sourceAccountView.showUnMixedAccount = false
}
}

self.sourceAccountView.onAccountSelectionChanged = self.updateSelectedAccount

self.destinationAddressTextField.placeholder = LocalizedStrings.destinationAddress

self.destinationAddressTextField.add(button: self.scanQRCodeForAddressButton)
Expand All @@ -123,8 +127,7 @@ class SendViewController: UIViewController {

self.toSelfAccountSection.isHidden = true
self.destinationAccountView.showWatchOnlyWallet = true
self.sourceAccountView.showUnMixedAccount = false
self.destinationAccountView.showUnMixedAccount = false
self.destinationAccountView.showMixedAccount = false
self.destinationAccountView.onAccountSelectionChanged = { _, _ in
self.displayFeeDetailsAndTransactionSummary() // re-calculate fee with updated destination info
}
Expand All @@ -139,6 +142,18 @@ class SendViewController: UIViewController {
)
self.transactionFeeDetailsSection.isHidden = true
}

func updateSelectedAccount(_ selectedWallet: DcrlibwalletWallet, _ selectedAccount: DcrlibwalletAccount) {
self.sourceAccountView.selectedWallet = selectedWallet
self.sourceAccountView.selectedAccount = selectedAccount

let spendableAmount = (Decimal(selectedAccount.balance!.dcrSpendable) as NSDecimalNumber).round(8).formattedWithSeparator
self.sourceAccountSpendableBalanceLabel.text = "\(LocalizedStrings.spendable): \(spendableAmount) DCR"

if self.sendMax {
self.calculateAndSetMaxSendableAmount()
}
}

@objc func toggleTransactionFeeDetailsVisibility() {
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseInOut, animations: {
Expand All @@ -150,7 +165,7 @@ class SendViewController: UIViewController {
}

@objc func resetFields() {
self.sourceAccountView.selectFirstWalletAccount()
self.sourceAccountView.selectFirstFilterWalletAccount()

// Clearing the destination address textfield will trigger the set textview delegate
// which will hide the error label and show the paste button if a valid address is in clipboard.
Expand All @@ -160,7 +175,7 @@ class SendViewController: UIViewController {
self.amountValue = nil
self.exchangeValue = nil

self.destinationAccountView.selectFirstWalletAccount()
self.destinationAccountView.selectFirstFilterWalletAccount()

// Clearing the primary amount textfield should set the usd amount to 0,
// hide the address error label, update the transaction fee details and sending summary fields.
Expand All @@ -169,10 +184,10 @@ class SendViewController: UIViewController {
}

func refreshFields() {
self.sourceAccountView.selectFirstWalletAccount()
self.sourceAccountView.selectFirstFilterWalletAccount()
self.amountTextFieldEditingBegan()
self.amountTextFieldChanged()
self.destinationAccountView.selectFirstWalletAccount()
self.destinationAccountView.selectFirstFilterWalletAccount()
self.amountTextFieldEditingEnded()
}

Expand Down Expand Up @@ -255,7 +270,11 @@ class SendViewController: UIViewController {
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseIn, animations: {
self.toAddressSection.isHidden = true
self.toSelfAccountSection.isHidden = false

self.sourceAccountView.showMixedAccount = self.toAddressSection.isHidden
self.sourceAccountView.showUnMixedAccount = self.toAddressSection.isHidden
self.sourceAccountView.showMixedOnly = true
self.destinationAccountView.showMixedAccount = false
self.sourceAccountView.selectFirstFilterWalletAccount()
self.displayFeeDetailsAndTransactionSummary() // re-calculate fee with updated destination info
})
}
Expand All @@ -265,6 +284,13 @@ class SendViewController: UIViewController {
self.toSelfAccountSection.isHidden = true
self.toAddressSection.isHidden = false

if ((self.sourceAccountView?.selectedWallet?.readBoolConfigValue(forKey: DcrlibwalletAccountMixerConfigSet, defaultValue: false)) != nil) {
self.sourceAccountView.showMixedOnly = false
self.sourceAccountView.selectFirstFilterWalletAccount()
} else {
self.sourceAccountView.showUnMixedAccount = false
}

self.displayFeeDetailsAndTransactionSummary() // re-calculate fee with updated destination info
})
}
Expand Down
Expand Up @@ -71,12 +71,16 @@ class TransactionDetailsViewController: UIViewController {

private func displayTitle() {
if self.transaction.type == DcrlibwalletTxTypeRegular {
if self.transaction.direction == DcrlibwalletTxDirectionSent {
self.txTypeLabel.text = LocalizedStrings.sent
} else if self.transaction.direction == DcrlibwalletTxDirectionReceived {
self.txTypeLabel.text = LocalizedStrings.received
} else if self.transaction.direction == DcrlibwalletTxDirectionTransferred {
self.txTypeLabel.text = LocalizedStrings.transferred
if transaction.isMixed {
self.txTypeLabel.text = LocalizedStrings.mixed
} else {
if self.transaction.direction == DcrlibwalletTxDirectionSent {
self.txTypeLabel.text = LocalizedStrings.sent
} else if self.transaction.direction == DcrlibwalletTxDirectionReceived {
self.txTypeLabel.text = LocalizedStrings.received
} else if self.transaction.direction == DcrlibwalletTxDirectionTransferred {
self.txTypeLabel.text = LocalizedStrings.transferred
}
}
} else if self.transaction.type == DcrlibwalletTxTypeVote {
self.txTypeLabel.text = LocalizedStrings.voted
Expand Down Expand Up @@ -224,7 +228,7 @@ class TransactionDetailsViewController: UIViewController {
} else if transaction.direction == DcrlibwalletTxDirectionReceived {
self.txOverview.txIconImage = UIImage(named: "ic_receive")
} else if transaction.direction == DcrlibwalletTxDirectionTransferred {
self.txOverview.txIconImage = UIImage(named: "ic_fee")
self.txOverview.txIconImage = UIImage(named: "nav_menu/ic_wallet")
}
}

Expand Down