Skip to content

Commit

Permalink
feat: join dashpay bottom sheet dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Oct 21, 2024
1 parent d291542 commit a9bae3c
Show file tree
Hide file tree
Showing 26 changed files with 512 additions and 171 deletions.
94 changes: 66 additions & 28 deletions DashWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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.
10 changes: 0 additions & 10 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 @@ -115,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
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ extension UsernameRequestsDAOImpl {
guard let self = self else { return continuation.resume(returning: []) }

do {
let results = try self.db.prepare(query, bindings).prepareRowIterator().map { Item(row: $0) }
let results = try self.db.prepareRowIterator(query, bindings: bindings).map { Item(row: $0) }
continuation.resume(returning: results)
} catch {
continuation.resume(throwing: error)
Expand Down
15 changes: 8 additions & 7 deletions DashWallet/Sources/Models/Voting/UsernameRequest.swift
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: - GroupedUsernames

Expand Down Expand Up @@ -60,11 +61,11 @@ struct UsernameRequest: RowDecodable, Hashable {
extension UsernameRequest {
static var table: Table { Table("username_requests") }

static var requestId: Expression<String> { Expression<String>("requestId") }
static var username: Expression<String> { Expression<String>("username") }
static var createdAt: Expression<Int64> { Expression<Int64>("createdAt") }
static var identity: Expression<String> { Expression<String>("identity") }
static var votes: Expression<Int> { Expression<Int>("votes") }
static var isApproved: Expression<Bool> { Expression<Bool>("isApproved") }
static var link: Expression<String?> { .init("link") }
static var requestId: SQLite.Expression<String> { Expression<String>("requestId") }
static var username: SQLite.Expression<String> { Expression<String>("username") }
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 isApproved: SQLite.Expression<Bool> { Expression<Bool>("isApproved") }
static var link: SQLite.Expression<String?> { .init("link") }
}
4 changes: 2 additions & 2 deletions DashWallet/Sources/UI/DashPay/DWDashPayConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#import <DashSync/DashSync.h>

uint64_t DWDP_MIN_BALANCE_TO_CREATE_USERNAME = (DUFFS / 100); // 0.01 Dash
uint64_t DWDP_MIN_BALANCE_TO_CREATE_INVITE = (DUFFS / 100); // 0.01 Dash
uint64_t DWDP_MIN_BALANCE_TO_CREATE_USERNAME = (DUFFS / 100) * 3; // 0.03 Dash
uint64_t DWDP_MIN_BALANCE_TO_CREATE_INVITE = (DUFFS / 100); // 0.01 Dash

NSInteger DW_MIN_USERNAME_LENGTH = 3;
NSInteger DW_MAX_USERNAME_LENGTH = 24;
Expand Down
4 changes: 2 additions & 2 deletions DashWallet/Sources/UI/DashPay/Items/Objects/DWDPTxObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ - (instancetype)initWithTransaction:(DSTransaction *)tx
_dataProvider = dataProvider;
_blockchainIdentity = blockchainIdentity;
_username = blockchainIdentity.currentDashpayUsername;

BOOL hasDisplayName = blockchainIdentity.displayName.length > 0;
_displayName = hasDisplayName ? blockchainIdentity.displayName : nil;

_subtitle = [dataProvider shortDateStringForTransaction:tx];
_dataItem = [dataProvider transactionDataForTransaction:tx];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// 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

public struct JoinDashPayInfoDialog: View {
@Environment(\.presentationMode) private var presentationMode

public var body: some View {
BottomSheet(showBackButton: Binding<Bool>.constant(false)) {
JoinDashPayScreen()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// 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

public struct JoinDashPayScreen: View {
@StateObject private var viewModel = RequestUsernameViewModel.shared

public var body: some View {
TextIntro(
buttonLabel: NSLocalizedString("Continue", comment: ""),
action: { }, // TODO: navlink
isActionEnabled: viewModel.hasMinimumRequiredBalance,
inProgress: .constant(false),
topText: {
FeatureTopText(
title: NSLocalizedString("Join DashPay", comment: ""),
text: NSLocalizedString("Forget about long crypto addresses, create the username, find friends and add them to your contacts", comment: "")
)
},
features: {[
FeatureSingleItem(iconName: .custom("username.letter"), title: NSLocalizedString("Create a username", comment: ""), description: NSLocalizedString("Pay to usernames. No more alphanumeric addresses.", comment: "")),
FeatureSingleItem(iconName: .custom("friends.add"), title: NSLocalizedString("Add your friends & family", comment: ""), description: NSLocalizedString("Invite your family, find your friends by searching their usernames.", comment: "")),
FeatureSingleItem(iconName: .custom("profile.personalized"), title: NSLocalizedString("Personalise profile", comment: ""), description: NSLocalizedString("Upload your picture, personalize your identity.", comment: ""))
]},
info: getInfo()
)
}

private func getInfo() -> String? {
if viewModel.hasRecommendedBalance {
return nil
}

if viewModel.hasMinimumRequiredBalance {
return String.localizedStringWithFormat(NSLocalizedString("You have %@ Dash.\nSome usernames cost up to %@ Dash.", comment: "Usernames"), viewModel.balance, viewModel.recommendedBalance)
}

return String.localizedStringWithFormat(NSLocalizedString("You need to have more than %@ Dash to create a username", comment: "Usernames"), viewModel.minimumRequiredBalance)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// 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

public struct MixDashDialog: View {
@Environment(\.presentationMode) private var presentationMode
var positiveAction: () -> Void
var negativeAction: () -> Void

public var body: some View {
BottomSheet(showBackButton: Binding<Bool>.constant(false)) {
VStack(spacing: 0) {
FeatureTopText(
title: NSLocalizedString("Mix your Dash Coins", comment: "CoinJoin"),
text: NSLocalizedString("To help prevent other people from seeing who you make payments to, it is recommended to mix your balance before you create your username.", comment: "CoinJoin"),
alignment: .leading
)

Spacer()

ButtonsGroup(
orientation: .horizontal,
style: .regular,
size: .large,
positiveButtonText: NSLocalizedString("Mix coins", comment: "CoinJoin"),
positiveButtonAction: {
presentationMode.wrappedValue.dismiss()
positiveAction()
},
negativeButtonText: NSLocalizedString("Skip", comment: ""),
negativeButtonAction: {
presentationMode.wrappedValue.dismiss()
negativeAction()
}
)
.padding(.top, 20)
.padding(.bottom, 10)
}
.padding(.horizontal, 20)
.frame(maxHeight: .infinity)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ extension RequestUsernameViewController {
}

func configureObservers() {
viewModel.$hasEnoughBalance
viewModel.$hasMinimumRequiredBalance
.removeDuplicates()
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] hasEnough in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,26 @@ public class RequestUsernameVMObjcWrapper: NSObject {
}
}

class RequestUsernameViewModel {
private let kRecommendedBalance = DUFFS / 4

class RequestUsernameViewModel: ObservableObject {
private var cancellableBag = Set<AnyCancellable>()
private let dao: UsernameRequestsDAO = UsernameRequestsDAOImpl.shared
private let prefs = VotingPrefs.shared

var completionHandler: ((Bool) -> ())?
var enteredUsername: String = ""
@Published private(set) var hasEnoughBalance = false
@Published private(set) var hasMinimumRequiredBalance = false
@Published private(set) var hasRecommendedBalance = false
@Published private(set) var currentUsernameRequest: UsernameRequest? = nil
@Published private(set) var balance: String = ""

var minimumRequiredBalance: String {
return DWDP_MIN_BALANCE_TO_CREATE_USERNAME.formattedDashAmount
return DWDP_MIN_BALANCE_TO_CREATE_USERNAME.dashAmount.formattedDashAmountWithoutCurrencySymbol
}

var recommendedBalance: String {
return kRecommendedBalance.dashAmount.formattedDashAmountWithoutCurrencySymbol
}

var minimumRequiredBalanceFiat: String {
Expand Down Expand Up @@ -151,6 +159,8 @@ class RequestUsernameViewModel {

private func checkBalance() {
let balance = DWEnvironment.sharedInstance().currentAccount.balance
hasEnoughBalance = balance >= DWDP_MIN_BALANCE_TO_CREATE_USERNAME
self.balance = balance.dashAmount.formattedDashAmountWithoutCurrencySymbol
hasMinimumRequiredBalance = balance >= DWDP_MIN_BALANCE_TO_CREATE_USERNAME
hasRecommendedBalance = balance >= kRecommendedBalance
}
}
Loading

0 comments on commit a9bae3c

Please sign in to comment.