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

🦺[Tech debt] Add configuration to hide / unhide card tab #47

Merged
merged 9 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
32 changes: 32 additions & 0 deletions loafwallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@
C3270B99259BF7F20073DA7B /* LitecoinCardUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3270B98259BF7F20073DA7B /* LitecoinCardUser.swift */; };
C32DAE0725925B7E003FC978 /* Color+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DAE0625925B7E003FC978 /* Color+Extension.swift */; };
C32DAE9125929492003FC978 /* CardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DAE9025929492003FC978 /* CardViewController.swift */; };
C32DB42D264847FD00017D26 /* CardTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DB42C264847FD00017D26 /* CardTests.swift */; };
C32DB42F26488CAA00017D26 /* NonUSTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DB42E26488CAA00017D26 /* NonUSTabBarViewController.swift */; };
C32DC793259396AB00A7FDB4 /* CardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DC792259396AB00A7FDB4 /* CardViewModel.swift */; };
C32DC79C2593971500A7FDB4 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DC79B2593971500A7FDB4 /* CardView.swift */; };
C32DC7AC2593B5C900A7FDB4 /* AnimatedCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C32DC7AB2593B5C900A7FDB4 /* AnimatedCardView.swift */; };
Expand All @@ -286,6 +288,8 @@
C345D81525A8D52600657E30 /* LoginViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C345D81425A8D52600657E30 /* LoginViewModelTests.swift */; };
C345D82525A8D54200657E30 /* RegistrationViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C345D82425A8D54200657E30 /* RegistrationViewModelTests.swift */; };
C345D83725A8D57E00657E30 /* AnimatedCardViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C345D83625A8D57E00657E30 /* AnimatedCardViewModelTests.swift */; };
C3543A27264AFE490005D17A /* LocaleChangeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3543A26264AFE490005D17A /* LocaleChangeView.swift */; };
C3543A29264AFE720005D17A /* LocaleChangeViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3543A28264AFE720005D17A /* LocaleChangeViewModel.swift */; };
C354C45A258FA9C000675E0E /* MainTabBarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C354C459258FA9C000675E0E /* MainTabBarViewModel.swift */; };
C354C4632590059500675E0E /* TransactionsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C354C4622590059500675E0E /* TransactionsViewModel.swift */; };
C35ABD232574070A002BB9BB /* PartnersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35ABD222574070A002BB9BB /* PartnersView.swift */; };
Expand Down Expand Up @@ -1456,6 +1460,8 @@
C3270B98259BF7F20073DA7B /* LitecoinCardUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LitecoinCardUser.swift; sourceTree = "<group>"; };
C32DAE0625925B7E003FC978 /* Color+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extension.swift"; sourceTree = "<group>"; };
C32DAE9025929492003FC978 /* CardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardViewController.swift; sourceTree = "<group>"; };
C32DB42C264847FD00017D26 /* CardTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardTests.swift; sourceTree = "<group>"; };
C32DB42E26488CAA00017D26 /* NonUSTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonUSTabBarViewController.swift; sourceTree = "<group>"; };
C32DC792259396AB00A7FDB4 /* CardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardViewModel.swift; sourceTree = "<group>"; };
C32DC79B2593971500A7FDB4 /* CardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
C32DC7AB2593B5C900A7FDB4 /* AnimatedCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatedCardView.swift; sourceTree = "<group>"; };
Expand All @@ -1464,6 +1470,8 @@
C345D81425A8D52600657E30 /* LoginViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModelTests.swift; sourceTree = "<group>"; };
C345D82425A8D54200657E30 /* RegistrationViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationViewModelTests.swift; sourceTree = "<group>"; };
C345D83625A8D57E00657E30 /* AnimatedCardViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimatedCardViewModelTests.swift; sourceTree = "<group>"; };
C3543A26264AFE490005D17A /* LocaleChangeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocaleChangeView.swift; sourceTree = "<group>"; };
C3543A28264AFE720005D17A /* LocaleChangeViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocaleChangeViewModel.swift; sourceTree = "<group>"; };
C354C459258FA9C000675E0E /* MainTabBarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewModel.swift; sourceTree = "<group>"; };
C354C4622590059500675E0E /* TransactionsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionsViewModel.swift; sourceTree = "<group>"; };
C35ABD222574070A002BB9BB /* PartnersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartnersView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2135,6 +2143,7 @@
children = (
2427342B2381C21800E2D22F /* MainViewController.swift */,
24313C762381E8F100A83F69 /* TabBarViewController.swift */,
C32DB42E26488CAA00017D26 /* NonUSTabBarViewController.swift */,
);
name = Main;
sourceTree = "<group>";
Expand Down Expand Up @@ -2175,6 +2184,7 @@
2465873723A5AAD100A32E9E /* loafwalletTests */ = {
isa = PBXGroup;
children = (
C32DB42B264847D500017D26 /* Card Tests */,
C3188E3126445E5E0008ADD1 /* File Tests */,
C3B7C3EC255FF56100E98A64 /* Constants Tests */,
24470E3923A5FF5700ADDA27 /* TestHelpers.swift */,
Expand Down Expand Up @@ -3112,6 +3122,14 @@
name = CardModels;
sourceTree = "<group>";
};
C32DB42B264847D500017D26 /* Card Tests */ = {
isa = PBXGroup;
children = (
C32DB42C264847FD00017D26 /* CardTests.swift */,
);
path = "Card Tests";
sourceTree = "<group>";
};
C345D81325A8D50600657E30 /* LitecoinCardTests */ = {
isa = PBXGroup;
children = (
Expand All @@ -3123,9 +3141,19 @@
path = LitecoinCardTests;
sourceTree = "<group>";
};
C3543A25264AFE190005D17A /* Settings */ = {
isa = PBXGroup;
children = (
C3543A26264AFE490005D17A /* LocaleChangeView.swift */,
C3543A28264AFE720005D17A /* LocaleChangeViewModel.swift */,
);
name = Settings;
sourceTree = "<group>";
};
C35ABD07257404C6002BB9BB /* SwiftUI+UIKit */ = {
isa = PBXGroup;
children = (
C3543A25264AFE190005D17A /* Settings */,
C3F7BCD825FEC69B00694C28 /* Alerts */,
C32142E825C97CB900BECCD0 /* Transactions */,
C3B7C3C1255EAF1200E98A64 /* SupportSafariView.swift */,
Expand Down Expand Up @@ -4032,6 +4060,7 @@
C3188E3326445EA20008ADD1 /* FileTests.swift in Sources */,
24470E4223A6007200ADDA27 /* WalletInfoTest.swift in Sources */,
24470E2123A5DA9700ADDA27 /* APIManagerTests.swift in Sources */,
C32DB42D264847FD00017D26 /* CardTests.swift in Sources */,
24470E3423A5F5E600ADDA27 /* PaymentRequestTests.swift in Sources */,
24470E2E23A5F4FF00ADDA27 /* BRCoderTests.swift in Sources */,
2494037623AD35C000369261 /* BuyWKWebVCTests.swift in Sources */,
Expand Down Expand Up @@ -4196,6 +4225,7 @@
C30029E225D0185500F08C2B /* StandardDividerView.swift in Sources */,
223DB2191DF691260076A151 /* BRSocketHelpers.c in Sources */,
CEF3E82D1DE528BF007C0A9E /* AlertView.swift in Sources */,
C3543A29264AFE720005D17A /* LocaleChangeViewModel.swift in Sources */,
CEF3E82B1DE51612007C0A9E /* GradientCircle.swift in Sources */,
CE124CFE1E68F57700DFA146 /* Async.swift in Sources */,
2218BD771E8F55430091D5E8 /* BRAPIClient+Assets.swift in Sources */,
Expand All @@ -4222,6 +4252,7 @@
C32DC793259396AB00A7FDB4 /* CardViewModel.swift in Sources */,
7528D2981ECF655500925DBC /* PaymentProtocol.swift in Sources */,
22A9A9491DF61945000F0016 /* BRBSPatch.swift in Sources */,
C3543A27264AFE490005D17A /* LocaleChangeView.swift in Sources */,
24A6DCFC2230BD9000505F44 /* WipeEmptyWalletViewController.swift in Sources */,
CE92F9F61DEDF6890046B516 /* UIViewControllerContextTransitioning+BRAdditions.swift in Sources */,
CEA362681E00EE320061FC0E /* CameraGuideView.swift in Sources */,
Expand Down Expand Up @@ -4362,6 +4393,7 @@
CEAA9E911DC0FDFE0066731D /* UIViewPropertyAnimator+BRWAdditions.swift in Sources */,
C3BD4A4A2597542700D97079 /* LoginCardAlertView.swift in Sources */,
CEAA9EA01DC2F9F50066731D /* UIFont+BRWAdditions.swift in Sources */,
C32DB42F26488CAA00017D26 /* NonUSTabBarViewController.swift in Sources */,
CEC6AA491DEFD00100EE5AFD /* MenuButton.swift in Sources */,
CEF61B121ECF52C700C7EA6A /* AmountViewController.swift in Sources */,
CECCE5B21E04B00D00D99448 /* SendCell.swift in Sources */,
Expand Down
20 changes: 19 additions & 1 deletion loafwallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

setFirebaseConfiguration()

updateCurrentUserLocale(localeId: Locale.current.identifier)

guard let thisWindow = self.window else { return false }

thisWindow.tintColor = .liteWalletBlue

UIView.swizzleSetFrame()

applicationController.launch(application: application, window: self.window, options: launchOptions)
applicationController.launch(application: application, window: thisWindow, options: launchOptions)

LWAnalytics.logEventWithParameters(itemName:._20191105_AL)

Expand Down Expand Up @@ -97,6 +103,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
FirebaseApp.configure(options: fileOpts)
#endif
}

/// Check Locale
func updateCurrentUserLocale(localeId: String) {

let suffix = String(localeId.suffix(3))

if suffix == "_US" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcw-grunt we can simplify the expression like this:
UserDefaults.userIsInUSA = suffix == "_US"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mosadialiou this is to allow people that are in the US but speak other languages . So, someone that speaks French and has their phone set for french but are in say, New York . This region code would be "fr_US".
So this code truncates the fr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcw-grunt yeah I understand. I am talking about the code. You can simplify it like I said!

UserDefaults.userIsInUSA = true
} else {
UserDefaults.userIsInUSA = false
}
}
}


Expand Down
55 changes: 55 additions & 0 deletions loafwallet/LocaleChangeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// LocaleChangeView.swift
// loafwallet
//
// Created by Kerry Washington on 5/11/21.
// Copyright © 2021 Litecoin Foundation. All rights reserved.
//

import SwiftUI

struct LocaleChangeView: View {

//MARK: - Combine Variables
@ObservedObject
var viewModel: LocaleChangeViewModel

init(viewModel: LocaleChangeViewModel) {
self.viewModel = viewModel
}
var body: some View {
VStack {

Text("Current Locale: \(viewModel.displayName)")
.font(Font(UIFont.barlowSemiBold(size: 18.0)))
.foregroundColor(.black)
.padding(.leading, 20)
.padding(.top, 10)

Spacer()
}
}
}

struct LocaleChangeView_Previews: PreviewProvider {

static let viewModel = LocaleChangeViewModel()

static var previews: some View {

Group {
LocaleChangeView(viewModel: viewModel)
.previewDevice(PreviewDevice(rawValue: DeviceType.Name.iPhoneSE2))
.previewDisplayName(DeviceType.Name.iPhoneSE2)

LocaleChangeView(viewModel: viewModel)
.previewDevice(PreviewDevice(rawValue: DeviceType.Name.iPhone8))
.previewDisplayName(DeviceType.Name.iPhone8)

LocaleChangeView(viewModel: viewModel)
.previewDevice(PreviewDevice(rawValue: DeviceType.Name.iPhone12ProMax))
.previewDisplayName(DeviceType.Name.iPhone12ProMax)
}
}
}

28 changes: 28 additions & 0 deletions loafwallet/LocaleChangeViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// LocaleChangeViewModel.swift
// loafwallet
//
// Created by Kerry Washington on 5/11/21.
// Copyright © 2021 Litecoin Foundation. All rights reserved.
//

import Foundation
class LocaleChangeViewModel: ObservableObject {

var updatedLocale: Locale = Locale.current

//MARK: - Combine Variables
@Published
var displayName: String = ""

init() {
let currentLocale = Locale.current

if let regionCode = currentLocale.regionCode,
let name = currentLocale.localizedString(forRegionCode: regionCode) {
displayName = name
} else {
displayName = "-"
}
}
}
77 changes: 49 additions & 28 deletions loafwallet/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,61 @@ class MainViewController : UIViewController, Subscriber, LoginViewControllerDele
}

func didUnlockLogin() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcw-grunt refactor this method like this:

func didUnlockLogin() {
          

var vc : UIViewController
if UserDefaults.userIsInUSA {
vc = UIStoryboard.init(name: "Main", bundle: nil)
                        .instantiateViewController(withIdentifier: "TabBarViewController")
                        as? TabBarViewController
} else {
vc = UIStoryboard.init(name: "Main", bundle: nil)
                        .instantiateViewController(withIdentifier: "NonUSTabBarViewController")
                        as? NonUSTabBarViewController
}


vc.store = self.store
vc.walletManager = walletManager
            
addChildViewController(vc, layout: {
    vc.view.constrain(toSuperviewEdges: nil)
    vc.view.alpha = 0
    vc.view.layoutIfNeeded()
})
            
UIView.animate(withDuration: 0.3,
               delay: 0.1,
               options: .transitionCrossDissolve,
               animations: {          
    vc.view.alpha = 1             
}) { (finished) in
    NSLog("\(UserDefaults.userIsInUSA ? US : Ex US)  MainView Controller presented")
}

}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that won't work. The classes are custom and inherit so the values can't be passed to the NonUS and Tab ViewControllers

Copy link
Contributor

@mosadialiou mosadialiou May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcw-grunt hmm I see. Can you do this 👇 ?

func didUnlockLogin() {
          

var vc : UIViewController
if UserDefaults.userIsInUSA  {
guard let usaVC = UIStoryboard.init(name: "Main", bundle: nil)
                        .instantiateViewController(withIdentifier: "TabBarViewController")
                        as? TabBarViewController else {
                
                NSLog("TabBarViewController not intialized")
                return
            }
usaVC.store = self.store
usaVC.walletManager = walletManager
vc = usaVC
}  else  {
guard let exUSAVC = UIStoryboard.init(name: "Main", bundle: nil)
                        .instantiateViewController(withIdentifier: "NonUSTabBarViewController")
                        as? NonUSTabBarViewController else {
                
                NSLog("NonUSTabBarViewController not intialized")
                return
            }
exUSAVC.store = self.store
exUSAVC.walletManager = walletManager
vc = exUSAVC
}


addChildViewController(vc, layout: {
    vc.view.constrain(toSuperviewEdges: nil)
    vc.view.alpha = 0
    vc.view.layoutIfNeeded()
})
            
UIView.animate(withDuration: 0.3,
               delay: 0.1,
               options: .transitionCrossDissolve,
               animations: {          
    vc.view.alpha = 1             
}) { (finished) in
    NSLog("\(UserDefaults.userIsInUSA ? US : Ex US)  MainView Controller presented")
}

}


if let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TabBarViewController") as? TabBarViewController {

vc.store = self.store
vc.isLtcSwapped = store.state.isLtcSwapped
vc.walletManager = self.walletManager

if let rate = store.state.currentRate {
vc.exchangeRate = rate
let placeholderAmount = Amount(amount: 0, rate: rate, maxDigits: store.state.maxDigits)
vc.secondaryBalanceLabel = UpdatingLabel(formatter: placeholderAmount.localFormat)
vc.primaryBalanceLabel = UpdatingLabel(formatter: placeholderAmount.ltcFormat)
} else {
vc.secondaryBalanceLabel = UpdatingLabel(formatter: NumberFormatter())
vc.primaryBalanceLabel
= UpdatingLabel(formatter: NumberFormatter())

if UserDefaults.userIsInUSA {
guard let usaVC = UIStoryboard.init(name: "Main", bundle: nil)
.instantiateViewController(withIdentifier: "TabBarViewController")
as? TabBarViewController else {

NSLog("TabBarViewController not intialized")
return
}

addChildViewController(vc, layout:{
vc.view.constrain(toSuperviewEdges: nil)
vc.view.alpha = 0
vc.view.layoutIfNeeded()

usaVC.store = self.store
usaVC.walletManager = walletManager

addChildViewController(usaVC, layout:{
usaVC.view.constrain(toSuperviewEdges: nil)
usaVC.view.alpha = 0
usaVC.view.layoutIfNeeded()
})

UIView.animate(withDuration: 0.3, delay: 0.1, options: .transitionCrossDissolve, animations: {
vc.view.alpha = 1

UIView.animate(withDuration: 0.3,
delay: 0.1,
options: .transitionCrossDissolve,
animations: {

usaVC.view.alpha = 1

}) { (finished) in
NSLog("MainView Controller presented")
NSLog(" Ex US MainView Controller presented")
}

} else {
NSLog("ERROR: MainView Controller Not presented")

guard let exUSAVC = UIStoryboard.init(name: "Main", bundle: nil)
.instantiateViewController(withIdentifier: "NonUSTabBarViewController")
as? NonUSTabBarViewController else {

NSLog("NonUSTabBarViewController not intialized")
return
}

exUSAVC.store = self.store
exUSAVC.walletManager = walletManager

addChildViewController(exUSAVC, layout:{
exUSAVC.view.constrain(toSuperviewEdges: nil)
exUSAVC.view.alpha = 0
exUSAVC.view.layoutIfNeeded()
})

UIView.animate(withDuration: 0.3, delay: 0.1, options: .transitionCrossDissolve, animations: {
exUSAVC.view.alpha = 1
}) { (finished) in
NSLog("US MainView Controller presented")
}
}

}

private func addTemporaryStartupViews() {
Expand Down
Loading