diff --git a/Example/CryptoOnramp Example/CryptoOnramp Example/KYCInfoView.swift b/Example/CryptoOnramp Example/CryptoOnramp Example/KYCInfoView.swift index 08bdd363f8eb..556ad98e0a17 100644 --- a/Example/CryptoOnramp Example/CryptoOnramp Example/KYCInfoView.swift +++ b/Example/CryptoOnramp Example/CryptoOnramp Example/KYCInfoView.swift @@ -17,7 +17,7 @@ import StripePaymentSheet struct KYCInfoView: View { /// Controls which KYC information set this form collects. - enum CollectionMode { + enum CollectionMode: Equatable { /// Original behavior where all fields are shown and date of birth + id number are required. case original @@ -116,21 +116,12 @@ struct KYCInfoView: View { ) } - private var isDateOfBirthIncluded: Binding { - Binding( - get: { dateOfBirth != nil }, - set: { shouldIncludeDateOfBirth in - dateOfBirth = shouldIncludeDateOfBirth ? (dateOfBirth ?? Self.today) : nil - } - ) - } - private var collectedKYCLevel: KYCLevel { switch collectionMode { case .original, .kycLevel1StepUp: return .level1 case .kycLevel0: - return (dateOfBirth != nil && !idNumber.isEmpty) ? .level1 : .level0 + return .level0 } } @@ -183,32 +174,21 @@ struct KYCInfoView: View { } } - FormField(title("Social Security Number", required: collectionMode.requiresDateOfBirthAndIdNumber)) { - makeTextField( - "Enter your SSN", - text: $idNumber, - field: .idNumber, - keyboardType: .numberPad - ) - } + if collectionMode != .kycLevel0 { + FormField(title("Social Security Number", required: collectionMode.requiresDateOfBirthAndIdNumber)) { + makeTextField( + "Enter your SSN", + text: $idNumber, + field: .idNumber, + keyboardType: .numberPad + ) + } - FormField(title("Date of Birth", required: collectionMode.requiresDateOfBirthAndIdNumber)) { - VStack(alignment: .leading, spacing: 12) { - if collectionMode.requiresDateOfBirthAndIdNumber { - DatePicker("", selection: dateOfBirthBinding, in: ...Self.today, displayedComponents: .date) - .datePickerStyle(WheelDatePickerStyle()) - .labelsHidden() - .frame(maxWidth: .infinity) - } else { - Toggle("Add date of birth now", isOn: isDateOfBirthIncluded) - - if dateOfBirth != nil { - DatePicker("", selection: dateOfBirthBinding, in: ...Self.today, displayedComponents: .date) - .datePickerStyle(WheelDatePickerStyle()) - .labelsHidden() - .frame(maxWidth: .infinity) - } - } + FormField(title("Date of Birth", required: collectionMode.requiresDateOfBirthAndIdNumber)) { + DatePicker("", selection: dateOfBirthBinding, in: ...Self.today, displayedComponents: .date) + .datePickerStyle(WheelDatePickerStyle()) + .labelsHidden() + .frame(maxWidth: .infinity) } } diff --git a/Example/CryptoOnramp Example/CryptoOnramp Example/LogInSignUpView.swift b/Example/CryptoOnramp Example/CryptoOnramp Example/LogInSignUpView.swift index 0929e16c3491..febe5f6fb0ff 100644 --- a/Example/CryptoOnramp Example/CryptoOnramp Example/LogInSignUpView.swift +++ b/Example/CryptoOnramp Example/CryptoOnramp Example/LogInSignUpView.swift @@ -114,15 +114,13 @@ struct LogInSignUpView: View { .safeAreaInset(edge: .bottom) { VStack(spacing: 8) { Button("Log In") { - isEmailFieldFocused = false - isPasswordFieldFocused = false + dismissKeyboard() logIn() } .buttonStyle(PrimaryButtonStyle()) Button("Sign Up") { - isEmailFieldFocused = false - isPasswordFieldFocused = false + dismissKeyboard() signUp() } .buttonStyle(PrimaryButtonStyle()) @@ -147,6 +145,11 @@ struct LogInSignUpView: View { // MARK: - Actions + private func dismissKeyboard() { + isEmailFieldFocused = false + isPasswordFieldFocused = false + } + private func logIn() { isLoading.wrappedValue = true Task { diff --git a/Example/CryptoOnramp Example/CryptoOnramp Example/RegistrationView.swift b/Example/CryptoOnramp Example/CryptoOnramp Example/RegistrationView.swift index 350ff7326fd7..7b115dd575bf 100644 --- a/Example/CryptoOnramp Example/CryptoOnramp Example/RegistrationView.swift +++ b/Example/CryptoOnramp Example/CryptoOnramp Example/RegistrationView.swift @@ -29,7 +29,6 @@ struct RegistrationView: View { /// Called when registration and authentication succeed. let onCompleted: () -> Void - @State private var fullName: String = "" @State private var phoneNumber: String = "" @State private var country: String = "US" @State private var errorMessage: String? @@ -39,7 +38,6 @@ struct RegistrationView: View { @Environment(\.isLoading) private var isLoading - @FocusState private var isFullNameFieldFocused: Bool @FocusState private var isPhoneNumberFieldFocused: Bool @FocusState private var isCountryFieldFocused: Bool @@ -76,13 +74,6 @@ struct RegistrationView: View { .foregroundColor(.secondary) } - FormField("Full Name (optional)") { - TextField("Enter your full name", text: $fullName) - .textFieldStyle(RoundedBorderTextFieldStyle()) - .autocapitalization(.words) - .focused($isFullNameFieldFocused) - } - FormField("Phone Number") { TextField("Enter phone number (e.g., +12125551234)", text: $phoneNumber) .textFieldStyle(RoundedBorderTextFieldStyle()) @@ -156,7 +147,7 @@ struct RegistrationView: View { do { try await coordinator.registerLinkUser( email: email, - fullName: fullName.isEmpty ? nil : fullName, + fullName: nil, phone: phoneNumber, country: country ) @@ -253,7 +244,6 @@ struct RegistrationView: View { } private func resetFocusState() { - isFullNameFieldFocused = false isPhoneNumberFieldFocused = false isCountryFieldFocused = false }