Skip to content

Commit

Permalink
- Added demo mode in Mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandardimov committed Mar 2, 2023
1 parent f8829a3 commit 3a226fd
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 32 deletions.
12 changes: 6 additions & 6 deletions ConcordiumWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8238,7 +8238,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -8275,7 +8275,7 @@
CODE_SIGN_ENTITLEMENTS = "ConcordiumWallet/Resources/Entitlements/Concordium ID.entitlements";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -8312,7 +8312,7 @@
CODE_SIGN_ENTITLEMENTS = ConcordiumWallet/Resources/Entitlements/ProdMainNet.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 45;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -8348,7 +8348,7 @@
CODE_SIGN_ENTITLEMENTS = ConcordiumWallet/Resources/Entitlements/ProdMainNet.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 45;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -8503,7 +8503,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -8541,7 +8541,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 30;
CURRENT_PROJECT_VERSION = 31;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = K762RM4LQ3;
ENABLE_BITCODE = NO;
Expand Down
3 changes: 3 additions & 0 deletions ConcordiumWallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var version: String {
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
return AppSettings.appVersion + " " + AppSettings.buildNumber + " " + debug
}
return AppSettings.appVersion
#else
return AppSettings.appVersion + " " + AppSettings.buildNumber + " " + debug
Expand Down
21 changes: 7 additions & 14 deletions ConcordiumWallet/Extensions/UserDefaults+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,37 @@ import UIKit

extension UserDefaults {
// Any Object
class func setObject(_ object: Any, forKey key: String)
{
class func setObject(_ object: Any, forKey key: String) {
UserDefaults.standard.set(object, forKey: key)
UserDefaults.standard.synchronize()
}

class func object(forKey key: String) -> Any?
{
class func object(forKey key: String) -> Any? {
return UserDefaults.standard.object(forKey: key)
}

class func removeObject(forKey key: String)
{
class func removeObject(forKey key: String) {
UserDefaults.standard.removeObject(forKey: key)
UserDefaults.standard.synchronize()
}

// Bool
class func setBool(_ value: Bool, forKey key: String)
{
class func setBool(_ value: Bool, forKey key: String) {
UserDefaults.standard.set(value, forKey: key)
UserDefaults.standard.synchronize()
}

class func bool(forKey key: String) -> Bool
{
class func bool(forKey key: String) -> Bool {
return UserDefaults.standard.bool(forKey: key)
}

// Int
class func setInteger(_ value: Int, forKey key: String)
{
class func setInteger(_ value: Int, forKey key: String) {
UserDefaults.standard.set(value, forKey: key)
UserDefaults.standard.synchronize()
}

class func integer(forKey key: String) -> Int
{
class func integer(forKey key: String) -> Int {
return UserDefaults.standard.integer(forKey: key)
}

Expand Down
3 changes: 3 additions & 0 deletions ConcordiumWallet/Model/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ enum Environment: String, Codable {

static var current: Environment {
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
return .test
}
return .main
#elseif TESTNET
return .test
Expand Down
3 changes: 3 additions & 0 deletions ConcordiumWallet/Model/Export/ExportVersionContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct ExportVersionContainer: Codable {

private func currentEnvironemt() -> String {
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
return "testnet"
}
return "mainnet"
#elseif TESTNET
return "testnet"
Expand Down
4 changes: 4 additions & 0 deletions ConcordiumWallet/Model/Net.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
// Copyright © 2022 concordium. All rights reserved.
//

import Foundation

enum Net: String, Codable {
case main = "Mainnet"
case test = "Testnet"

static var current: Net {
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
return .test
}
return .main
#else
return .test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,10 @@ Remember to restart your node with the baker keys.";

"recover.identityKey" = "identity";
"recover.isNewlyCreatedKey" = "isNewlyCreated";

"demomode.title" = "Wallet Demo Mode";
"demomode.message" = "You now have the option to activate the wallet demo mode. This means that the wallet will use the Concordium Testnet backend and blockchain, where you can make demo identities and accounts to try out the wallet.\n\nThe demo mode activation is permanent, and you will have to reinstall the wallet to get out of it again. We therefore recommend activating it, if you are here to review the wallet.";
"demomode.activate" = "Activate Wallet Demo Mode";
"demomode.cancel" = "Cancel";

"demomode.userdefaultskey" = "Demo Mode";
8 changes: 6 additions & 2 deletions ConcordiumWallet/Service/Network/ApiConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ struct ApiConstants {
#if TESTNET
static let proxyUrl = URL(string: overriddenProxyUrl ?? "https://wallet-proxy.testnet.concordium.com")!
#elseif MAINNET
static let proxyUrl = URL(string: overriddenProxyUrl ?? "https://wallet-proxy.mainnet.concordium.software")!
static var proxyUrl: URL {
return URL(string: overriddenProxyUrl ?? (UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true ? "https://wallet-proxy.testnet.concordium.com" : "https://wallet-proxy.mainnet.concordium.software"))!
}
#else // Staging
static let proxyUrl = URL(string: overriddenProxyUrl ?? "https://wallet-proxy.stagenet.concordium.com")!
#endif

#if TESTNET
static let scheme = "concordiumwallettest"
#elseif MAINNET
static let scheme = "concordiumwallet"
static var scheme: String {
return UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true ? "concordiumwallettest" : "concordiumwallet"
}
#else // Staging
static let scheme = "concordiumwalletstaging"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct ExportTransactionLogView: Page {
#if TESTNET
return "[testnet.CCDScan.io](https://testnet.ccdscan.io)"
#elseif MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
return "[testnet.CCDScan.io](https://testnet.ccdscan.io)"
}
return "[CCDScan.io](https://ccdscan.io)"
#else
return "[stagenet.CCDScan.io](https://stagenet.ccdscan.io)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class ExportTransactionLogViewModel: PageViewModel<ExportTransactionLogEvent> {
#if TESTNET
urlString = "https://api-ccdscan.testnet.concordium.com/rest/export/statement?accountAddress="
#elseif MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
urlString = "https://api-ccdscan.testnet.concordium.com/rest/export/statement?accountAddress="
} else {
urlString = "https://api-ccdscan.mainnet.concordium.software/rest/export/statement?accountAddress="
}
#else
urlString = "https://api-ccdscan.stagenet.io/rest/export/statement?accountAddress="
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ class AboutViewController: BaseViewController, AboutViewProtocol, Storyboarded,
let version = AppSettings.appVersion
let buildNo = AppSettings.buildNumber
#if MAINNET
versionLabel.text = "\(version)"
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == true {
versionLabel.text = "\(version) (\(buildNo))"
} else {
versionLabel.text = "\(version)"
}
#else
versionLabel.text = "\(version) (\(buildNo))"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@ protocol RecoveryPhraseGettingStartedPresenterDelegate: AnyObject {
}

class RecoveryPhraseGettingStartedPresenter: SwiftUIPresenter<RecoveryPhraseGettingStartedViewModel> {
private let longPressesTimeTresholdDifference = 1.0

private weak var delegate: RecoveryPhraseGettingStartedPresenterDelegate?
private let recoveryPhraseService: RecoveryPhraseServiceProtocol

var createNewWalletDemoMode: Bool {
didSet {
viewModel.demoMode = createNewWalletDemoMode && recoverWalletDemoMode
}
}

var recoverWalletDemoMode: Bool {
didSet {
viewModel.demoMode = createNewWalletDemoMode && recoverWalletDemoMode
}
}

init(
recoveryPhraseService: RecoveryPhraseServiceProtocol,
delegate: RecoveryPhraseGettingStartedPresenterDelegate
) {
self.recoveryPhraseService = recoveryPhraseService
self.delegate = delegate
self.createNewWalletDemoMode = false
self.recoverWalletDemoMode = false

super.init(
viewModel: .init(
Expand Down Expand Up @@ -58,6 +74,37 @@ class RecoveryPhraseGettingStartedPresenter: SwiftUIPresenter<RecoveryPhraseGett
}
case .recoverWallet:
delegate?.recoverWallet()
case .createNewWalletDemoMode:
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == false {
createNewWalletDemoMode = true
DispatchQueue.main.asyncAfter(deadline: .now() + longPressesTimeTresholdDifference) {
if self.recoverWalletDemoMode == false {
self.createNewWalletDemoMode = false
}
}
}
#endif
case .recoverWalletDemoMode:
#if MAINNET
if UserDefaults.bool(forKey: "demomode.userdefaultskey".localized) == false {
recoverWalletDemoMode = true
DispatchQueue.main.asyncAfter(deadline: .now() + longPressesTimeTresholdDifference) {
if self.createNewWalletDemoMode == false {
self.recoverWalletDemoMode = false
}
}
}
#endif
case .enterDemoMode:
// Enter demo mode
UserDefaults.setBool(true, forKey: "demomode.userdefaultskey".localized)

createNewWalletDemoMode = false
recoverWalletDemoMode = false
case .cancelDemoMode:
createNewWalletDemoMode = false
recoverWalletDemoMode = false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,47 @@ struct RecoveryPhraseGettingStartedView: Page {
VStack {
StyledLabel(text: viewModel.title, style: .title)
.padding([.top, .bottom], 60)
GettingStartedSection(section: viewModel.createNewWalletSection, bottomPadding: 70) {
GettingStartedSection(section: viewModel.createNewWalletSection, bottomPadding: 70, tapAction: {
viewModel.send(.createNewWallet)
}
GettingStartedSection(section: viewModel.recoverWalletSection, bottomPadding: 30) {
}, longPressAction: {
viewModel.send(.createNewWalletDemoMode)
})
GettingStartedSection(section: viewModel.recoverWalletSection, bottomPadding: 30, tapAction: {
viewModel.send(.recoverWallet)
}
}, longPressAction: {
viewModel.send(.recoverWalletDemoMode)
})
}.frame(maxWidth: .infinity)
.padding([.leading, .trailing], 36)
.alert(isPresented: $viewModel.demoMode) {
Alert(title: Text("demomode.title".localized), message: Text("demomode.message".localized), primaryButton: .default(Text("demomode.activate".localized), action: {
viewModel.send(.enterDemoMode)
}), secondaryButton: .cancel(Text("demomode.cancel".localized), action: {
viewModel.send(.cancelDemoMode)
}))
}
}
}
}

private struct GettingStartedSection: View {
let longPressDuration = 30.0

let section: RecoveryPhraseGettingStartedViewModel.Section
let bottomPadding: CGFloat?
let action: () -> Void
let tapAction: () -> Void
let longPressAction: () -> Void

init(
section: RecoveryPhraseGettingStartedViewModel.Section,
bottomPadding: CGFloat? = nil,
action: @escaping () -> Void
tapAction: @escaping () -> Void,
longPressAction: @escaping () -> Void
) {
self.section = section
self.bottomPadding = bottomPadding
self.action = action
self.tapAction = tapAction
self.longPressAction = longPressAction
}

@ViewBuilder
Expand All @@ -55,12 +71,32 @@ private struct GettingStartedSection: View {
Spacer()
}
if let bottomPadding = bottomPadding {
Button(section.buttonTitle, action: action)
Button(section.buttonTitle, action: {})
.applyStandardButtonStyle()
.padding([.bottom], bottomPadding)
.simultaneousGesture(
LongPressGesture(minimumDuration: longPressDuration)
.onEnded { _ in
longPressAction()
}
)
.highPriorityGesture(TapGesture()
.onEnded { _ in
tapAction()
})
} else {
Button(section.buttonTitle, action: action)
Button(section.buttonTitle, action: {})
.applyStandardButtonStyle()
.simultaneousGesture(
LongPressGesture(minimumDuration: longPressDuration)
.onEnded { _ in
longPressAction()
}
)
.highPriorityGesture(TapGesture()
.onEnded { _ in
tapAction()
})
}
}
}
Expand Down
Loading

0 comments on commit 3a226fd

Please sign in to comment.