Skip to content

Commit 3029e0c

Browse files
committed
fix(security): #162 #163 fix PIN issues
1 parent 8c588d3 commit 3029e0c

File tree

4 files changed

+22
-82
lines changed

4 files changed

+22
-82
lines changed

Bitkit/AppScene.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct AppScene: View {
8080
.environmentObject(suggestionsManager)
8181
.environmentObject(tagManager)
8282
.onAppear {
83-
if !settings.requirePinOnLaunch {
83+
if !settings.pinEnabled {
8484
isPinVerified = true
8585
}
8686

@@ -132,7 +132,7 @@ struct AppScene: View {
132132
// Wallet exists and has been restored from backup. isRestoringWallet is set to false inside below component
133133
WalletRestoreSuccess()
134134
} else {
135-
if !isPinVerified && settings.pinEnabled && (settings.requirePinOnLaunch || settings.requirePinWhenIdle) {
135+
if !isPinVerified && settings.pinEnabled {
136136
AuthCheck {
137137
isPinVerified = true
138138
}
@@ -256,8 +256,8 @@ struct AppScene: View {
256256
}
257257

258258
private func handleScenePhaseChange(_: ScenePhase) {
259-
// If 'pinOnIdle' is enabled, lock the app when the app goes to the background
260-
if scenePhase == .background && settings.pinEnabled && settings.requirePinWhenIdle {
259+
// If PIN is enabled, lock the app when the app goes to the background
260+
if scenePhase == .background && settings.pinEnabled {
261261
isPinVerified = false
262262
}
263263
}

Bitkit/ViewModels/Extensions/SettingsViewModel+PIN.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ extension SettingsViewModel {
6464
func resetPinSettings() {
6565
pinEnabled = false
6666
pinFailedAttempts = 0
67-
requirePinOnLaunch = true
68-
requirePinWhenIdle = false
6967
requirePinForPayments = false
7068
useBiometrics = false
7169
Logger.debug("PIN settings reset after app wipe", context: "SettingsViewModel")
@@ -80,8 +78,6 @@ extension SettingsViewModel {
8078

8179
if resetSettings {
8280
// Reset all PIN-related settings when PIN is disabled
83-
requirePinOnLaunch = true
84-
requirePinWhenIdle = false
8581
requirePinForPayments = false
8682
useBiometrics = false
8783
}

Bitkit/ViewModels/SettingsViewModel.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,14 @@ class SettingsViewModel: ObservableObject {
5858
@AppStorage("hideBalanceOnOpen") var hideBalanceOnOpen: Bool = false
5959
@AppStorage("readClipboard") var readClipboard: Bool = false
6060
@AppStorage("warnWhenSendingOver100") var warnWhenSendingOver100: Bool = false
61-
@AppStorage("requirePinOnLaunch") var requirePinOnLaunch: Bool = true
62-
@AppStorage("requirePinWhenIdle") var requirePinWhenIdle: Bool = false
63-
@AppStorage("requirePinForPayments") var requirePinForPayments: Bool = false
64-
@AppStorage("useBiometrics") var useBiometrics: Bool = false
6561
@AppStorage("enableQuickpay") var enableQuickpay: Bool = false
6662
@AppStorage("quickpayAmount") var quickpayAmount: Double = 5
6763

6864
// PIN Management
6965
@Published internal(set) var pinEnabled: Bool = false
7066
@AppStorage("pinFailedAttempts") var pinFailedAttempts: Int = 0
67+
@AppStorage("requirePinForPayments") var requirePinForPayments: Bool = false
68+
@AppStorage("useBiometrics") var useBiometrics: Bool = false
7169

7270
// Electrum Server Settings
7371
@Published var electrumHost: String = ""

Bitkit/Views/Settings/SecurityPrivacySettingsView.swift

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ struct SecurityPrivacySettingsView: View {
66
@EnvironmentObject var sheets: SheetViewModel
77
@EnvironmentObject var settings: SettingsViewModel
88

9-
@State private var showPinCheckForLaunch = false
10-
@State private var showPinCheckForIdle = false
119
@State private var showPinCheckForPayments = false
1210
@State private var showingBiometricError = false
1311
@State private var biometricErrorMessage = ""
@@ -33,6 +31,7 @@ struct SecurityPrivacySettingsView: View {
3331
VStack(alignment: .leading, spacing: 0) {
3432
NavigationBar(title: t("settings__security__title"))
3533
.padding(.bottom, 16)
34+
.padding(.horizontal, 16)
3635

3736
ScrollView(showsIndicators: false) {
3837
VStack(alignment: .leading, spacing: 0) {
@@ -83,32 +82,6 @@ struct SecurityPrivacySettingsView: View {
8382
)
8483
}
8584

86-
Button {
87-
showPinCheckForLaunch = true
88-
} label: {
89-
SettingsListLabel(
90-
title: t("settings__security__pin_launch"),
91-
rightIcon: nil,
92-
toggle: Binding(
93-
get: { settings.requirePinOnLaunch },
94-
set: { _ in showPinCheckForLaunch = true }
95-
)
96-
)
97-
}
98-
99-
Button {
100-
showPinCheckForIdle = true
101-
} label: {
102-
SettingsListLabel(
103-
title: t("settings__security__pin_idle"),
104-
rightIcon: nil,
105-
toggle: Binding(
106-
get: { settings.requirePinWhenIdle },
107-
set: { _ in showPinCheckForIdle = true }
108-
)
109-
)
110-
}
111-
11285
Button {
11386
showPinCheckForPayments = true
11487
} label: {
@@ -122,50 +95,29 @@ struct SecurityPrivacySettingsView: View {
12295
)
12396
}
12497

125-
// Biometrics toggle with custom handling
126-
SettingsListLabel(
127-
title: t(
128-
"settings__security__use_bio",
129-
variables: ["biometryTypeName": biometryTypeName]
130-
),
131-
toggle: Binding(
132-
get: { settings.useBiometrics },
133-
set: { newValue in
134-
handleBiometricToggle(newValue)
135-
}
98+
if isBiometricAvailable {
99+
// Biometrics toggle with custom handling
100+
SettingsListLabel(
101+
title: t("settings__security__use_bio", variables: ["biometryTypeName": biometryTypeName]),
102+
toggle: Binding(
103+
get: { settings.useBiometrics },
104+
set: { newValue in
105+
handleBiometricToggle(newValue)
106+
}
107+
)
136108
)
137-
)
138109

139-
// Footer text for Biometrics
140-
BodySText(t("settings__security__footer", variables: ["biometryTypeName": biometryTypeName]))
141-
.padding(.top, 16)
110+
// Footer text for Biometrics
111+
BodySText(t("settings__security__footer", variables: ["biometryTypeName": biometryTypeName]))
112+
.padding(.top, 16)
113+
}
142114
}
143115
}
116+
.padding(.horizontal, 16)
144117
.bottomSafeAreaPadding()
145118
}
146119
}
147120
.navigationBarHidden(true)
148-
.padding(.horizontal, 16)
149-
.navigationDestination(isPresented: $showPinCheckForLaunch) {
150-
PinCheckView(
151-
title: t("security__pin_enter"),
152-
explanation: "",
153-
onCancel: {},
154-
onPinVerified: { _ in
155-
settings.requirePinOnLaunch.toggle()
156-
}
157-
)
158-
}
159-
.navigationDestination(isPresented: $showPinCheckForIdle) {
160-
PinCheckView(
161-
title: t("security__pin_enter"),
162-
explanation: "",
163-
onCancel: {},
164-
onPinVerified: { _ in
165-
settings.requirePinWhenIdle.toggle()
166-
}
167-
)
168-
}
169121
.navigationDestination(isPresented: $showPinCheckForPayments) {
170122
PinCheckView(
171123
title: t("security__pin_enter"),
@@ -189,12 +141,6 @@ struct SecurityPrivacySettingsView: View {
189141
}
190142

191143
private func handleBiometricToggle(_ newValue: Bool) {
192-
if !isBiometricAvailable {
193-
// Biometrics not available - show setup sheet
194-
sheets.showSheet(.security, data: SecurityConfig(showLaterButton: false))
195-
return
196-
}
197-
198144
if newValue {
199145
// User wants to enable biometrics - request authentication
200146
requestBiometricPermission { success in

0 commit comments

Comments
 (0)