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

feat(usernames): Join DashPay & voting info dialogs #671

Merged
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
2 changes: 1 addition & 1 deletion DashSyncCurrentCommit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5527d76881a78c324e8bb64036ab99e3bf9792a9
09eee81df1a1a89cdcd77dd8965edb1f78b2eb84
66 changes: 59 additions & 7 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "passphrase.png",
"filename" : "icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "passphrase@2x.png",
"filename" : "icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "passphrase@3x.png",
"filename" : "icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "username.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "voting.blocked.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "feature.list.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions DashWallet/Sources/Categories/UIHostingController+DashWallet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Created by Andrei Ashikhmin
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

extension UIHostingController {
func setDetent(_ detent: CGFloat) {
if #available(iOS 16.0, *) {
if let sheet = self.sheetPresentationController {
let fitId = UISheetPresentationController.Detent.Identifier("fit")
let fitDetent = UISheetPresentationController.Detent.custom(identifier: fitId) { _ in
detent
}
sheet.detents = [fitDetent]
}
}
}
}
35 changes: 18 additions & 17 deletions DashWallet/Sources/Models/CoinJoin/CoinJoinService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ private let kDefaultRounds: Int32 = 4
private let kDefaultSessions: Int32 = 6
private let kDefaultDenominationGoal: Int32 = 50
private let kDefaultDenominationHardcap: Int32 = 300
private let kCoinJoinMixDashShown = "coinJoinMixDashShownKey"
private let kCoinJoinMainnetMode = "coinJoinModeMainnetKey"
private let kCoinJoinTestnetMode = "coinJoinModeTestnetKey"
let kMaxAllowedAheadTimeskew: TimeInterval = 5
Expand Down Expand Up @@ -90,6 +89,7 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
private var coinJoinManager: DSCoinJoinManager? = nil
private var hasAnonymizableBalance: Bool = false
private var timeSkew: TimeInterval = 0
private var savedBalance: UInt64 = 0
private var workingChain: ChainType

private var chainModeKey: String {
Expand All @@ -114,15 +114,6 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
}
}

private var _mixDashShown: Bool? = nil
var mixDashShown: Bool {
get { _mixDashShown ?? UserDefaults.standard.bool(forKey: kCoinJoinMixDashShown) }
set(value) {
_mixDashShown = value
UserDefaults.standard.set(value, forKey: kCoinJoinMixDashShown)
}
}

@Published private(set) var mode: CoinJoinMode = .none
@Published var mixingState: MixingStatus = .notStarted
@Published private(set) var progress = CoinJoinProgress(progress: 0.0, totalBalance: 0, coinJoinBalance: 0)
Expand Down Expand Up @@ -158,7 +149,7 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
}

let account = DWEnvironment.sharedInstance().currentAccount
updateBalance(balance: account.balance)
await updateBalance(balance: account.balance)
updateState(mode: mode, timeSkew: self.timeSkew, hasAnonymizableBalance: self.hasAnonymizableBalance, networkStatus: self.networkStatus, chain: DWEnvironment.sharedInstance().currentChain)
}

Expand All @@ -174,15 +165,15 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
coinJoinManager.start()
}

private func startMixing() {
private func startMixing() async {
guard let coinJoinManager = self.coinJoinManager else { return }

if !coinJoinManager.startMixing() {
DSLogger.log("CoinJoin: Mixing has been started already.")
} else {
coinJoinManager.refreshUnusedKeys()
coinJoinManager.initMasternodeGroup()
coinJoinManager.doAutomaticDenominating(withReport: true)
await coinJoinManager.doAutomaticDenominating(withDryRun: false)
}
}

Expand Down Expand Up @@ -224,12 +215,13 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
return self.coinJoinManager
}

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

self.savedBalance = balance
coinJoinManager.updateOptions(withAmount: balance)
DSLogger.log("CoinJoin: total balance: \(balance)")
let canDenominate = coinJoinManager.doAutomaticDenominating(withDryRun: true)
let canDenominate = await coinJoinManager.doAutomaticDenominating(withDryRun: true)

let coinJoinBalance = coinJoinManager.getBalance()
DSLogger.log("CoinJoin: mixed balance: \(coinJoinBalance.anonymized)")
Expand Down Expand Up @@ -318,7 +310,9 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
if state == .mixing && previousMixingStatus != .mixing {
// start mixing
prepareMixing()
startMixing()
Task {
await startMixing()
}
} else if previousMixingStatus == .mixing && state != .mixing {
// finish mixing
stopMixing()
Expand Down Expand Up @@ -378,7 +372,14 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
private func configureObservers() {
NotificationCenter.default.publisher(for: NSNotification.Name.DSWalletBalanceDidChange)
.sink { [weak self] _ in
self?.updateBalance(balance: DWEnvironment.sharedInstance().currentAccount.balance)
guard let self = self else { return }
let balance = DWEnvironment.sharedInstance().currentAccount.balance

if self.savedBalance != balance {
Task {
await self.updateBalance(balance: balance)
}
}
}
.store(in: &cancellableBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protocol RowDecodable {
// MARK: - String + RowDecodable

extension String: RowDecodable {
private static let territory = Expression<String?>("territory")
private static let territory = SQLite.Expression<String?>("territory")

init(row: Row) {
self.init(row[String.territory]!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import CoreLocation
import Foundation
import SQLite
private typealias Expression = SQLite.Expression

class AtmDAO: PointOfUseDAO {
typealias Item = ExplorePointOfUse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import CoreLocation
import Foundation
import SQLite
private typealias Expression = SQLite.Expression

// MARK: - MerchantDAO

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ class ExploreDatabaseConnection {
}

func execute<Item: RowDecodable>(query: String) throws -> [Item] {
try db.prepare(query).prepareRowIterator().map { Item(row: $0) }
try db.prepareRowIterator(query).map { Item(row: $0) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import Foundation
import SQLite
private typealias Expression = SQLite.Expression

// MARK: - ExplorePointOfUse + Hashable

Expand Down
4 changes: 2 additions & 2 deletions DashWallet/Sources/Models/Taxes/Address/AddressUserInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ extension AddressUserInfo {

extension AddressUserInfo {
static var table: Table { Table("address_userinfo") }
static var txCategoryColumn: Expression<Int> { Expression<Int>("taxCategory") }
static var addressColumn: Expression<String> { Expression<String>("address") }
static var txCategoryColumn: SQLite.Expression<Int> { SQLite.Expression<Int>("taxCategory") }
static var addressColumn: SQLite.Expression<String> { SQLite.Expression<String>("address") }
}
11 changes: 6 additions & 5 deletions DashWallet/Sources/Models/Taxes/Tx/TxUserInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import Foundation
import SQLite


extension TxUserInfoTaxCategory {
var stringValue: String {
switch self {
Expand Down Expand Up @@ -109,11 +110,11 @@ extension TxUserInfo {

extension TxUserInfo {
static var table: Table { Table("tx_userinfo") }
static var txCategoryColumn: Expression<Int> { Expression<Int>("taxCategory") }
static var txHashColumn: Expression<Data> { Expression<Data>("txHash") }
static var txRateColumn: Expression<Int?> { .init("rate") }
static var txRateCurrencyCodeColumn: Expression<String?> { .init("rateCurrencyCode") }
static var txRateMaximumFractionDigitsColumn: Expression<Int?> { .init("rateMaximumFractionDigits") }
static var txCategoryColumn: SQLite.Expression<Int> { Expression<Int>("taxCategory") }
static var txHashColumn: SQLite.Expression<Data> { Expression<Data>("txHash") }
static var txRateColumn: SQLite.Expression<Int?> { .init("rate") }
static var txRateCurrencyCodeColumn: SQLite.Expression<String?> { .init("rateCurrencyCode") }
static var txRateMaximumFractionDigitsColumn: SQLite.Expression<Int?> { .init("rateMaximumFractionDigits") }
}

@objc
Expand Down
45 changes: 45 additions & 0 deletions DashWallet/Sources/Models/UsernamePrefs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by Andrei Ashikhmin
// Copyright © 2023 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

private let kCoinJoinMixDashShown = "coinJoinMixDashShownKey"
private let kJoinDashPayInfoShown = "joinDashPayInfoShownKey"

// MARK: - UsernamePrefs

class UsernamePrefs {
public static let shared: UsernamePrefs = .init()

private var _mixDashShown: Bool? = nil
var mixDashShown: Bool {
get { _mixDashShown ?? UserDefaults.standard.bool(forKey: kCoinJoinMixDashShown) }
set(value) {
_mixDashShown = value
UserDefaults.standard.set(value, forKey: kCoinJoinMixDashShown)
}
}

private var _joinDashPayInfoShown: Bool? = nil
var joinDashPayInfoShown: Bool {
get { _joinDashPayInfoShown ?? UserDefaults.standard.bool(forKey: kJoinDashPayInfoShown) }
set(value) {
_joinDashPayInfoShown = value
UserDefaults.standard.set(value, forKey: kJoinDashPayInfoShown)
}
}
}
45 changes: 45 additions & 0 deletions DashWallet/Sources/Models/Usernames/UsernamePrefs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Created by Andrei Ashikhmin
// Copyright © 2023 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

private let kCoinJoinMixDashShown = "coinJoinMixDashShownKey"
private let kJoinDashPayInfoShown = "joinDashPayInfoShownKey"

// MARK: - UsernamePrefs

class UsernamePrefs {
public static let shared: UsernamePrefs = .init()

private var _mixDashShown: Bool? = nil
var mixDashShown: Bool {
get { _mixDashShown ?? UserDefaults.standard.bool(forKey: kCoinJoinMixDashShown) }
set(value) {
_mixDashShown = value
UserDefaults.standard.set(value, forKey: kCoinJoinMixDashShown)
}
}

private var _joinDashPayInfoShown: Bool? = nil
var joinDashPayInfoShown: Bool {
get { _joinDashPayInfoShown ?? UserDefaults.standard.bool(forKey: kJoinDashPayInfoShown) }
set(value) {
_joinDashPayInfoShown = value
UserDefaults.standard.set(value, forKey: kJoinDashPayInfoShown)
}
}
}
Loading
Loading