Skip to content

Commit

Permalink
Merge pull request #674 from Syn-McJ/feat/usernames-submit-request-ui
Browse files Browse the repository at this point in the history
feat(usernames): submit request UI
  • Loading branch information
Syn-McJ authored Dec 17, 2024
2 parents b461f1b + 2f6a0d5 commit 1218643
Show file tree
Hide file tree
Showing 192 changed files with 4,411 additions and 4,284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,10 @@
//

#import <Foundation/Foundation.h>
#import "dashwallet-Swift.h"

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, DWUsernameValidationRuleResult) {
/// No icon, black text
DWUsernameValidationRuleResultEmpty,
/// activity indicator, black text
DWUsernameValidationRuleResultLoading,
/// Checkmark, black text
DWUsernameValidationRuleResultValid,
/// Red cross and black text
DWUsernameValidationRuleResultInvalid,
/// Red cross and red text
DWUsernameValidationRuleResultInvalidCritical,
/// Red cross and red text
DWUsernameValidationRuleResultError,
/// View is hidden
DWUsernameValidationRuleResultHidden,
};

@interface DWUsernameValidationRule : NSObject

@property (readonly, nonatomic, copy) NSString *title;
Expand Down
2 changes: 1 addition & 1 deletion DashSyncCurrentCommit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
09eee81df1a1a89cdcd77dd8965edb1f78b2eb84
343de629f6e561188db22918b507ea27a0f9be17
110 changes: 63 additions & 47 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions DashWallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SupportEmail</key>
<string>support@dash.org</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.dashcore.dashsync.backgroundblocksync</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "link.png",
"filename" : "link.badge.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "link@2x.png",
"filename" : "link.badge@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "link@3x.png",
"filename" : "link.badge@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" : "checkmark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "checkmark@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "checkmark@3x.png",
"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" : "checkmark.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "checkmark@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "checkmark@3x.png",
"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" : "xmark.circle.fill.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "xmark.circle.fill@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "xmark.circle.fill@3x.png",
"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.
13 changes: 7 additions & 6 deletions DashWallet/Sources/Categories/DSChain+DashWallet.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#import "DSChainsManager.h"
#import "DSCheckpoint.h"
#import "DSMasternodeManager.h"
#import "DSSimplifiedMasternodeEntry.h"
#import "NSDate+Utils.h"
#import <objc/runtime.h>
#import "DSSimplifiedMasternodeEntry.h"


NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -91,17 +91,18 @@ - (NSNumber *_Nullable)calculateMasternodeAPY {
return nil;

DSMasternodeList *masternodeList = self.chainManager.masternodeManager.currentMasternodeList;

if (masternodeList.validMasternodeCount == 0)
return nil;

NSInteger virtualMNCount = 0;

for (DSSimplifiedMasternodeEntry *entry in masternodeList.simplifiedMasternodeEntries) {
if (entry.isValid) {
if (entry.type == 1) { // HPMN
virtualMNCount += 4;
} else {
}
else {
virtualMNCount += 1;
}
}
Expand Down Expand Up @@ -188,14 +189,14 @@ - (uint64_t)calculateMasternodePaymentWithHeight:(uint64_t)height blockReward:(u
// Activated but we have to wait for the next cycle to start realocation, nothing to do
return ret;
}

if ([self isCore20ActiveAtHeight:height]) {
// Once MNRewardReallocated activates, block reward is 80% of block subsidy (+ tx fees) since treasury is 20%
// Since the MN reward needs to be equal to 60% of the block subsidy (according to the proposal), MN reward is set to 75% of the block reward.
// Previous reallocation periods are dropped.
return blockReward * 3 / 4;
}

NSUInteger reallocCycle = superblockCycle * 3;
NSUInteger nCurrentPeriod = MIN((height - reallocStart) / reallocCycle, periodsCount - 1);
return (blockReward * periods[nCurrentPeriod]) / 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE username_requests ADD COLUMN blockVotes INTEGER NOT NULL DEFAULT 0;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SQLite
import SQLiteMigrationManager

struct SeedDB: Migration {
var version: Int64 = 20231023152234
var version: Int64 = 20241130210940

func migrateDatabase(_ db: Connection) throws { }
}
52 changes: 29 additions & 23 deletions DashWallet/Sources/Models/CoinJoin/CoinJoinService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
private var timeSkew: TimeInterval = 0
private var savedBalance: UInt64 = 0
private var workingChain: ChainType
private var currentSyncState: SyncingActivityMonitor.State = .unknown

private var chainModeKey: String {
get {
Expand Down Expand Up @@ -222,16 +223,13 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
coinJoinManager.updateOptions(withAmount: balance)
DSLogger.log("CoinJoin: total balance: \(balance)")
let canDenominate = await coinJoinManager.doAutomaticDenominating(withDryRun: true)

let coinJoinBalance = coinJoinManager.getBalance()
DSLogger.log("CoinJoin: mixed balance: \(coinJoinBalance.anonymized)")

let anonBalance = coinJoinManager.getAnonymizableBalance(withSkipDenominated: false, skipUnconfirmed: false)
DSLogger.log("CoinJoin: anonymizable balance \(anonBalance)")

let smallestDenomination = coinJoinManager.getSmallestDenomination()
DSLogger.log("CoinJoin: mixed balance: \(coinJoinBalance.anonymized), denomTrusted: \(coinJoinBalance.denominatedTrusted)")
let anonBalance = await coinJoinManager.calculateAnonymizableBalance(withSkipDenominated: false, skipUnconfirmed: false)
let minValue = await coinJoinManager.minimumAnonymizableBalance()
DSLogger.log("CoinJoin: anonymizable balance \(anonBalance), minValue: \(minValue)")
let hasPartiallyMixedCoins = (coinJoinBalance.denominatedTrusted - coinJoinBalance.anonymized) > 0
let hasAnonymizableBalance = anonBalance > smallestDenomination
let hasAnonymizableBalance = anonBalance > minValue
let hasBalanceLeftToMix: Bool

if hasPartiallyMixedCoins {
Expand All @@ -242,7 +240,7 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
hasBalanceLeftToMix = false
}

DSLogger.log("CoinJoin: can mix balance: \(hasBalanceLeftToMix) = balance: (\(anonBalance > smallestDenomination) && canDenominate: \(canDenominate)) || partially-mixed: \(hasPartiallyMixedCoins)")
DSLogger.log("CoinJoin: can mix balance: \(hasBalanceLeftToMix) = balance: (\(anonBalance > minValue) && canDenominate: \(canDenominate)) || partially-mixed: \(hasPartiallyMixedCoins)")

updateState(
mode: self.currentMode,
Expand Down Expand Up @@ -415,26 +413,26 @@ class CoinJoinService: NSObject, NetworkReachabilityHandling {
}

extension CoinJoinService: DSCoinJoinManagerDelegate {
func sessionStarted(withId baseId: Int32, clientSessionId clientId: UInt256, denomination denom: UInt32, poolState state: PoolState, poolMessage message: PoolMessage, ipAddress address: UInt128, isJoined joined: Bool) { }
func sessionStarted(withId baseId: Int32, clientSessionId clientId: UInt256, denomination denom: UInt32, poolState state: PoolState, poolMessage message: PoolMessage, poolStatus status: PoolStatus, ipAddress address: UInt128, isJoined joined: Bool) { }

func sessionComplete(withId baseId: Int32, clientSessionId clientId: UInt256, denomination denom: UInt32, poolState state: PoolState, poolMessage message: PoolMessage, ipAddress address: UInt128, isJoined joined: Bool) { }
func sessionComplete(withId baseId: Int32, clientSessionId clientId: UInt256, denomination denom: UInt32, poolState state: PoolState, poolMessage message: PoolMessage, poolStatus status: PoolStatus, ipAddress address: UInt128, isJoined joined: Bool) { }

func mixingStarted() { }

func mixingComplete(_ withError: Bool, isInterrupted: Bool) {
func mixingComplete(_ withError: Bool, errorStatus: PoolStatus, isInterrupted: Bool) {
if isInterrupted {
DSLogger.log("[SW] CoinJoin: Mixing Interrupted. \(progress)")
DSLogger.log("CoinJoin: Mixing Interrupted. \(progress)")
updateMixingState(state: .notStarted)
return
}

if withError {
DSLogger.log("[SW] CoinJoin: Mixing Error. \(progress)")
DSLogger.log("CoinJoin: Mixing Error. status: \(errorStatus), progress: \(progress)")
} else {
DSLogger.log("[SW] CoinJoin: Mixing Complete. \(progress)")
DSLogger.log("CoinJoin: Mixing Complete. status: \(errorStatus), \(progress)")
}

self.updateMixingState(state: withError ? .error : .finished) // TODO: paused?
self.updateMixingState(state: withError && errorStatus != PoolStatus_ErrNotEnoughFunds ? .error : .finished)
}

func transactionProcessed(withId txId: UInt256, type: CoinJoinTransactionType) {
Expand All @@ -446,12 +444,20 @@ extension CoinJoinService: SyncingActivityMonitorObserver {
func syncingActivityMonitorProgressDidChange(_ progress: Double) { }

func syncingActivityMonitorStateDidChange(previousState: SyncingActivityMonitor.State, state: SyncingActivityMonitor.State) {
self.updateState(
mode: self.currentMode,
timeSkew: self.timeSkew,
hasAnonymizableBalance: self.hasAnonymizableBalance,
networkStatus: self.networkStatus,
chain: DWEnvironment.sharedInstance().currentChain
)
if state != currentSyncState {
currentSyncState = state
self.updateState(
mode: self.currentMode,
timeSkew: self.timeSkew,
hasAnonymizableBalance: self.hasAnonymizableBalance,
networkStatus: self.networkStatus,
chain: DWEnvironment.sharedInstance().currentChain
)
} else {
Task {
let balance = DWEnvironment.sharedInstance().currentAccount.balance
await self.updateBalance(balance: balance)
}
}
}
}
2 changes: 1 addition & 1 deletion DashWallet/Sources/Models/DWGlobalOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (void)restoreToDefaults {
self.dateHistoricalRatesActivated = nil;
self.exploreDashMerchantsInfoShown = NO;
self.coinbaseInfoShown = NO;

#ifdef DASHPAY
self.dashpayUsername = nil;
self.dashpayRegistrationCompleted = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class UsernameRequestsDAOImpl: NSObject, UsernameRequestsDAO {
private var cache: [String: UsernameRequest] = [:]

func create(dto: UsernameRequest) async {

do {
let usernameRequest = UsernameRequest.table.insert(or: .replace,
UsernameRequest.requestId <- dto.requestId,
Expand All @@ -48,6 +47,7 @@ class UsernameRequestsDAOImpl: NSObject, UsernameRequestsDAO {
UsernameRequest.identity <- dto.identity,
UsernameRequest.link <- dto.link,
UsernameRequest.votes <- dto.votes,
UsernameRequest.blockVotes <- dto.blockVotes,
UsernameRequest.isApproved <- dto.isApproved)
try await execute(usernameRequest)
self.cache[dto.requestId] = dto
Expand Down
7 changes: 6 additions & 1 deletion DashWallet/Sources/Models/Voting/UsernameRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private typealias Expression = SQLite.Expression
struct GroupedUsernames: Hashable {
var username: String
var requests: [UsernameRequest]
var votesForUsername: Int = 0
}

// MARK: - UsernameRequest
Expand All @@ -35,15 +36,17 @@ struct UsernameRequest: RowDecodable, Hashable {
var identity: String
var link: String?
var votes: Int
var blockVotes: Int
var isApproved: Bool

init(requestId: String, username: String, createdAt: Int64, identity: String, link: String?, votes: Int, isApproved: Bool) {
init(requestId: String, username: String, createdAt: Int64, identity: String, link: String?, votes: Int, blockVotes: Int, isApproved: Bool) {
self.requestId = requestId
self.username = username
self.createdAt = createdAt
self.identity = identity
self.link = link
self.votes = votes
self.blockVotes = blockVotes
self.isApproved = isApproved
}

Expand All @@ -54,6 +57,7 @@ struct UsernameRequest: RowDecodable, Hashable {
self.identity = row[UsernameRequest.identity]
self.link = row[UsernameRequest.link]
self.votes = row[UsernameRequest.votes]
self.blockVotes = row[UsernameRequest.blockVotes]
self.isApproved = row[UsernameRequest.isApproved]
}
}
Expand All @@ -66,6 +70,7 @@ extension UsernameRequest {
static var createdAt: SQLite.Expression<Int64> { Expression<Int64>("createdAt") }
static var identity: SQLite.Expression<String> { Expression<String>("identity") }
static var votes: SQLite.Expression<Int> { Expression<Int>("votes") }
static var blockVotes: SQLite.Expression<Int> { Expression<Int>("blockVotes") }
static var isApproved: SQLite.Expression<Bool> { Expression<Bool>("isApproved") }
static var link: SQLite.Expression<String?> { .init("link") }
}
1 change: 1 addition & 0 deletions DashWallet/Sources/Models/Voting/VotingConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

@objcMembers
class VotingConstants: NSObject {
static let maxVotes = 5 // max allowed by Platform for a masternode
// TODO: replace
static let votingStartTime = TimeInterval(1696091858)
static let votingEndTime = TimeInterval(1702695521)
Expand Down
5 changes: 4 additions & 1 deletion DashWallet/Sources/Models/Voting/VotingPrefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class VotingPrefs {

private var _votingEnabled: Bool? = nil
var votingEnabled: Bool {
get { _votingEnabled ?? UserDefaults.standard.bool(forKey: kVotingEnabled) }
get {
let result = _votingEnabled ?? UserDefaults.standard.bool(forKey: kVotingEnabled)
return result
}
set(value) {
_votingEnabled = value
UserDefaults.standard.set(value, forKey: kVotingEnabled)
Expand Down
Loading

0 comments on commit 1218643

Please sign in to comment.