Skip to content

Commit

Permalink
Finished layout of Acceptance for notifications
Browse files Browse the repository at this point in the history
propgated language to Accepted notification
auto format

Signed-off-by: kcw-grunt <[email protected]>
  • Loading branch information
kcw-grunt committed Jan 7, 2024
1 parent 5d52fab commit f6ca735
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 44 deletions.
15 changes: 13 additions & 2 deletions litewallet/AddressFieldView.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import Foundation
import SwiftUI

enum LWTextFieldType {
case genericType
case email
}

struct AddressFieldView: UIViewRepresentable {
@Binding var text: String

private var placeholder: String

@Binding var text: String
var fieldType: LWTextFieldType

init(_ placeholder: String, text: Binding<String>) {
init(placeholder: String,
text: Binding<String>,
fieldType: LWTextFieldType = .genericType)
{
self.placeholder = placeholder
self.fieldType = fieldType
_text = text
}

Expand Down
3 changes: 3 additions & 0 deletions litewallet/Constant+Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,7 @@ enum CustomEvent: String {

/// User accepted pushes
case _20231225_UAP = "user_accepted_push"

/// User signup
case _20240101_US = "user_signup"
}
2 changes: 1 addition & 1 deletion litewallet/SendAddressCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct SendAddressCellView: View {
Spacer()
HStack {
VStack {
AddressFieldView(S.Send.enterLTCAddressLabel.localize(), text: $viewModel.addressString)
AddressFieldView(placeholder: S.Send.enterLTCAddressLabel.localize(), text: $viewModel.addressString)
.onTapGesture {
didStartEditing = true
}
Expand Down
7 changes: 7 additions & 0 deletions litewallet/StartViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class StartViewModel: ObservableObject {
didTapRecover = completion
}

func didAddToMailingList(email: String, preference: LanguageSelection) {
let signupDict: [String: String] = ["user_email": email,
"date_accepted": Date().ISO8601Format(),
"language_pref": preference.code]
LWAnalytics.logEventWithParameters(itemName: ._20240101_US, properties: signupDict)
}

private func checkForWalletAndSync() {
/// Test seed count
guard seedWords.count == 12 else { return }
Expand Down
2 changes: 1 addition & 1 deletion litewallet/UnstoppableDomainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct UnstoppableDomainView: View {
} else {
VStack {
ZStack {
AddressFieldView(viewModel.placeholderString,
AddressFieldView(placeholder: viewModel.placeholderString,
text: $viewModel.searchString)
.onTapGesture {
didStartEditing = true
Expand Down
131 changes: 104 additions & 27 deletions litewallet/src/AnnounceUpdatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ struct AnnounceUpdatesView: View {
var viewModel: StartViewModel

@State
private var scroll = false
private var emailAddress = ""

@State
private var shouldEnableButton = false
private var isEmailValid = false

@State
private var languagePref: LanguageSelection = .English

@FocusState private var isEmailFieldFocused: Bool

@Binding
var didTapContinue: Bool
Expand All @@ -25,15 +30,18 @@ struct AnnounceUpdatesView: View {
let paragraphFont: Font = .barlowSemiBold(size: 22.0)
let calloutFont: Font = .barlowLight(size: 12.0)

let genericPad = 5.0
let genericPad = 20.0
let smallLabelPad = 15.0
let buttonHeight = 44.0
let hugeFont = Font.barlowBold(size: 30.0)
let smallerFont = Font.barlowLight(size: 15.0)
let buttonLightFont: Font = .barlowLight(size: 20.0)
let buttonFont: Font = .barlowSemiBold(size: 20.0)
let appDelegate = UIApplication.shared.delegate as! AppDelegate

init(navigateStart: NavigateStart, didTapContinue: Binding<Bool>) {
init(navigateStart: NavigateStart, language: LanguageSelection, didTapContinue: Binding<Bool>) {
self.navigateStart = navigateStart
languagePref = language
_didTapContinue = didTapContinue
}

Expand All @@ -46,36 +54,73 @@ struct AnnounceUpdatesView: View {
ZStack {
Color.liteWalletDarkBlue.edgesIgnoringSafeArea(.all)
VStack {
Text("Make sure not to miss anything!")
Text("Don't a miss a thing!")
.font(hugeFont)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.padding([.leading, .trailing, .bottom], 10.0)
.frame(height: buttonHeight)
.foregroundColor(.white)
.padding(.all, 10.0)

WebView(url: URL(string: C.signupURL)!,
scrollToSignup: $scroll)
.frame(width: width * 0.9)
.frame(height: 100)
.edgesIgnoringSafeArea(.all)
.onAppear {
delay(2.0) {
scroll = true
}
}
.padding(.all, genericPad)

Text("Entering your email is a great idea because you will hear about updates and contests. Please consider signing up to also for push notifications.")
.font(smallerFont)
Text(S.Notifications.pitchMessage.localize())
.font(buttonLightFont)
.kerning(0.3)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.padding([.leading, .trailing, .bottom], 10.0)
.foregroundColor(.white)
.padding(.all, 10.0)
.padding(.all, genericPad)
.onTapGesture {
isEmailFieldFocused.toggle()
}

HStack {
VStack(alignment: .leading) {
Text(S.Notifications.emailLabel.localize())
.frame(height: smallLabelPad)
.font(smallerFont)
.multilineTextAlignment(.leading)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.white)

TextField(S.Notifications.emailPlaceholder.localize(), text: $emailAddress)
.focused($isEmailFieldFocused)
.frame(height: buttonHeight)
.frame(maxWidth: .infinity, alignment: .leading)
.textFieldStyle(.roundedBorder)
.foregroundColor(isEmailValid ? .litewalletDarkBlue : .litewalletOrange)
.font(smallerFont)
}
VStack(alignment: .leading) {
Text(S.Notifications.languagePreference.localize())
.frame(height: smallLabelPad)
.font(smallerFont)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.white)
.offset(x: 10.0)

Picker("", selection: $languagePref) {
ForEach(LanguageSelection.allCases) { pref in
Text(pref.nativeName)
.frame(width: height * 0.3)
.font(smallerFont)
.foregroundColor(.white)
.tag(pref.rawValue)
}
}
.pickerStyle(.wheel)
.frame(width: height * 0.3)
.frame(height: buttonHeight)
.clipped()
}
}
.frame(height: 80.0)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.all, genericPad)
Spacer()

Button {
viewModel.didAddToMailingList(email: emailAddress, preference: languagePref)
/// Reuse this struct for Create or Recover
switch navigateStart {
case .create:
Expand All @@ -91,30 +136,62 @@ struct AnnounceUpdatesView: View {
.foregroundColor(.white)
.shadow(radius: 3, x: 3.0, y: 3.0)

Text(S.StartViewController.continueButton.localize())
Text(S.Button.submit.localize())
.frame(width: width * 0.9, height: 45, alignment: .center)
.font(buttonFont)
.foregroundColor(shouldEnableButton ? .litewalletBlue :
.foregroundColor(isEmailValid ? .litewalletBlue :
.litewalletBlue.opacity(0.4))
.overlay(
RoundedRectangle(cornerRadius: bigButtonCornerRadius)
.stroke(.white, lineWidth: 2.0)
)
}
}
.disabled(shouldEnableButton)
.padding(.all, 10.0)
.disabled(!isEmailValid)
.padding(.bottom, smallLabelPad)
.onAppear {
delay(4.0) {
appDelegate.pushNotifications.registerForRemoteNotifications()
}
}
.onChange(of: $emailAddress.wrappedValue) { _ in
isEmailValid = EmailValidation.isEmailValid(emailString: emailAddress)
}

Button {
/// Reuse this struct for Create or Recover
switch navigateStart {
case .create:
viewModel.didTapCreate!()
case .recover:
viewModel.didTapRecover!()
}

} label: {
ZStack {
RoundedRectangle(cornerRadius: bigButtonCornerRadius)
.frame(width: width * 0.9, height: 45, alignment: .center)
.foregroundColor(.litewalletDarkBlue)

Text(S.Button.cancel.localize())
.frame(width: width * 0.9, height: 45, alignment: .center)
.font(buttonLightFont)
.foregroundColor(.white)
.overlay(
RoundedRectangle(cornerRadius: bigButtonCornerRadius)
.stroke(.white, lineWidth: 0.5)
)
}
}
.padding(.bottom, genericPad)
}
}
}
}
}

/// Crashes when env Obj is added
// #Preview {
// /// AnnounceUpdatesView()
// AnnounceUpdatesView(navigateStart: .create,
// didTapContinue: .constant(false))
// }
11 changes: 5 additions & 6 deletions litewallet/src/Constants/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,11 @@ enum S {
static let footer = Localization(key: "About.footer", value: "Made by the LiteWallet Team\nof the\nLitecoin Foundation\n%1$@", comment: "About screen footer")
}

enum PushNotifications {
static let title = Localization(key: "PushNotifications.title", value: "Notifications", comment: "Push notifications settings view title label")
static let body = Localization(key: "PushNotifications.body", value: "Turn on notifications to receive special messages from Litewallet in the future.", comment: "Push notifications settings view body")
static let label = Localization(key: "PushNotifications.label", value: "Push Notifications", comment: "Push notifications toggle switch label")
static let on = Localization(key: "PushNotifications.on", value: "On", comment: "Push notifications are on label")
static let off = Localization(key: "PushNotifications.off", value: "Off", comment: "Push notifications are off label")
enum Notifications {
static let pitchMessage = Localization(key: "Notifications.pitchMessage", value: "Sign up to hear about updates & contests from the Litewallet team!\nAccept notifications to get live news, price & market information!", comment: "Pitch to get user to sign up")
static let emailLabel = Localization(key: "Notifications.emailLabel", value: "Email address", comment: "Email address label")
static let emailPlaceholder = Localization(key: "Notifications.emailPlaceholder", value: "Enter here", comment: "Email address placeholder")
static let languagePreference = Localization(key: "Notifications.languagePreference", value: "Preferred language:", comment: "Language preference label")
}

enum DefaultCurrency {
Expand Down
3 changes: 2 additions & 1 deletion litewallet/src/Environment.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit

/// 14 Languages
enum LanguageSelection: Int, CaseIterable, Equatable {
enum LanguageSelection: Int, CaseIterable, Equatable, Identifiable {
case English = 0
case ChineseTraditional
case ChineseSimplified
Expand All @@ -16,6 +16,7 @@ enum LanguageSelection: Int, CaseIterable, Equatable {
case Spanish
case Turkish
case Ukrainian
var id: LanguageSelection { self }

var code: String {
switch self {
Expand Down
2 changes: 2 additions & 0 deletions litewallet/src/Extensions/SafariServices+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SignupWebView: WKWebView, WKNavigationDelegate {
// webview.scrollView.setZoomScale(0.3, animated: true)

let result = value as? String

print(value)
})
}
}
15 changes: 9 additions & 6 deletions litewallet/src/StartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ struct StartView: View {
@State
private var animationAmount = 0.0

@State
private var currentLanguage: LanguageSelection = .English

@State
private var pickedLanguage: LanguageSelection = .English

Expand All @@ -35,6 +32,9 @@ struct StartView: View {

init(viewModel: StartViewModel) {
startViewModel = viewModel

// print("::: \(UserDefaults.selectedLanguage)")
// pickedLanguage = LanguageSelection(rawValue: <#T##Int#>)
}

var body: some View {
Expand Down Expand Up @@ -136,7 +136,9 @@ struct StartView: View {
Spacer()
NavigationLink(destination:

AnnounceUpdatesView(navigateStart: .create, didTapContinue: $didContinue)
AnnounceUpdatesView(navigateStart: .create,
language: startViewModel.currentLanguage,
didTapContinue: $didContinue)
.environmentObject(startViewModel)
.navigationBarBackButtonHidden(true)
) {
Expand All @@ -160,10 +162,11 @@ struct StartView: View {

NavigationLink(destination:

AnnounceUpdatesView(navigateStart: .recover, didTapContinue: $didContinue)
AnnounceUpdatesView(navigateStart: .recover,
language: startViewModel.currentLanguage,
didTapContinue: $didContinue)
.environmentObject(startViewModel)
.navigationBarBackButtonHidden(true)
// RecoverWalletView().environmentObject(startViewModel)
) {
ZStack {
RoundedRectangle(cornerRadius: bigButtonCornerRadius)
Expand Down

0 comments on commit f6ca735

Please sign in to comment.