Skip to content

Commit

Permalink
Don't show PIN as you enter it
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenperera committed Dec 15, 2024
1 parent a858517 commit 0838794
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions ios/Cove/CoveApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ struct CoveApp: App {
LockView(
lockType: app.authType,
isPinCorrect: app.checkPin,
showPin: false,
lockState: $app.lockState,
onUnlock: { _ in showCover = false }
) {
Expand Down
2 changes: 2 additions & 0 deletions ios/Cove/SettingsScreen/ChangePinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct ChangePinView: View {
NumberPadPinView(
title: "Enter new PIN",
isPinCorrect: { _ in true },
showPin: false,
backAction: backAction,
onUnlock: { enteredPin in
withAnimation {
Expand All @@ -51,6 +52,7 @@ struct ChangePinView: View {
NumberPadPinView(
title: "Confirm New PIN",
isPinCorrect: { $0 == pinToConfirm },
showPin: false,
backAction: backAction,
onUnlock: onComplete
)
Expand Down
2 changes: 2 additions & 0 deletions ios/Cove/SettingsScreen/NewPinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct NewPinView: View {
NumberPadPinView(
title: "Enter New PIN",
isPinCorrect: { _ in true },
showPin: false,
backAction: backAction,
onUnlock: { enteredPin in
withAnimation {
Expand All @@ -37,6 +38,7 @@ struct NewPinView: View {
NumberPadPinView(
title: "Confirm New PIN",
isPinCorrect: { $0 == pinToConfirm },
showPin: false,
backAction: backAction,
onUnlock: onComplete
)
Expand Down
10 changes: 7 additions & 3 deletions ios/Cove/Views/LockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct LockView<Content: View>: View {
/// Args: Lock Properties
var lockType: AuthType
var isPinCorrect: (String) -> Bool
var showPin: Bool
var bioMetricUnlockMessage: String

/// default calllbacks on success and failure
Expand Down Expand Up @@ -51,6 +52,7 @@ struct LockView<Content: View>: View {
init(
lockType: AuthType,
isPinCorrect: @escaping (String) -> Bool,
showPin: Bool = true,
lockState: Binding<LockState>? = nil,
bioMetricUnlockMessage: String = "Unlock your wallet",
onUnlock: @escaping (String) -> Void = { _ in },
Expand All @@ -64,6 +66,7 @@ struct LockView<Content: View>: View {
lockStateBinding = lockState

self.isPinCorrect = isPinCorrect
self.showPin = showPin
self.bioMetricUnlockMessage = bioMetricUnlockMessage
self.onUnlock = onUnlock
self.onWrongPin = onWrongPin
Expand Down Expand Up @@ -120,9 +123,9 @@ struct LockView<Content: View>: View {
case (_, .biometric, false):

Check warning on line 123 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
PermissionsNeeded

Check warning on line 124 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
case (_, .biometric, true):

Check warning on line 125 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
PinOrBioMetric
BiometricView

Check warning on line 126 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
case (.biometric, .both, true):

Check warning on line 127 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
PinOrBioMetric
BiometricView

Check warning on line 128 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
case (_, .pin, _):

Check warning on line 129 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
numberPadPinView

Check warning on line 130 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
case (.biometric, .both, false):

Check warning on line 131 in ios/Cove/Views/LockView.swift

View workflow job for this annotation

GitHub Actions / swiftformat

Indent code in accordance with the scope level. (indent)
Expand Down Expand Up @@ -159,6 +162,7 @@ struct LockView<Content: View>: View {
NumberPadPinView(
lockState: lockState,
isPinCorrect: isPinCorrect,
showPin: showPin,
pinLength: pinLength,
backAction: backEnabled ? backAction : nil,
onUnlock: onUnlock,
Expand All @@ -182,7 +186,7 @@ struct LockView<Content: View>: View {
}

@ViewBuilder
var PinOrBioMetric: some View {
var BiometricView: some View {
VStack(spacing: 12) {
VStack(spacing: 6) {
Image(systemName: "faceid")
Expand Down
26 changes: 24 additions & 2 deletions ios/Cove/Views/NumberPadPinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct NumberPadPinView: View {
@Binding var lockState: LockState

let isPinCorrect: (String) -> Bool
var showPin: Bool
var pinLength: Int

// back button
Expand All @@ -31,6 +32,7 @@ struct NumberPadPinView: View {
title: String = "Enter Pin",
lockState: Binding<LockState> = .constant(.unlocked),
isPinCorrect: @escaping (String) -> Bool,
showPin: Bool = true,
pinLength: Int = 6,
backAction: (() -> Void)? = nil,
onUnlock: @escaping (String) -> Void = { _ in },
Expand All @@ -39,6 +41,7 @@ struct NumberPadPinView: View {
self.title = title
_lockState = lockState
self.isPinCorrect = isPinCorrect
self.showPin = showPin
self.pinLength = pinLength
backEnabled = backAction != nil
self.backAction = backAction ?? {}
Expand Down Expand Up @@ -76,10 +79,11 @@ struct NumberPadPinView: View {
/// Safe Check
if pin.count > index {
let index = pin.index(pin.startIndex, offsetBy: index)
let string = String(pin[index])
let string = showPin ? String(pin[index]) : ""

Text(string)
.font(.title.bold())
.font(showPin ? .title : .body)
.fontWeight(.bold)
.foregroundStyle(.black)
}
}
Expand Down Expand Up @@ -210,3 +214,21 @@ struct NumberPadPinView: View {

return Container()
}

#Preview("hidden pin") {
struct Container: View {
@State var pin = ""
@State var lockState: LockState = .locked

var body: some View {
NumberPadPinView(
lockState: $lockState,
isPinCorrect: { $0 == "000000" },
showPin: false,
pinLength: 6
)
}
}

return Container()
}

0 comments on commit 0838794

Please sign in to comment.