Kill OWSPaymentsLock.shared

This commit is contained in:
Harry 2024-09-27 08:48:51 -07:00 committed by GitHub
parent 8ae34efe37
commit 8a6fce53bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 39 additions and 18 deletions

View File

@ -180,7 +180,7 @@ public class PaymentsBiometryLockPromptViewController: OWSViewController {
@objc
private func didTapEnableButton() {
databaseStorage.write { transaction in
OWSPaymentsLock.shared.setIsPaymentsLockEnabled(true, transaction: transaction)
Self.owsPaymentsLock.setIsPaymentsLockEnabled(true, transaction: transaction)
}
dismiss(animated: true, completion: nil)
}

View File

@ -202,8 +202,8 @@ public class PaymentsViewPassphraseSplashViewController: OWSViewController {
return
}
if OWSPaymentsLock.shared.isPaymentsLockEnabled() {
OWSPaymentsLock.shared.tryToUnlock { [weak self] outcome in
if Self.owsPaymentsLock.isPaymentsLockEnabled() {
Self.owsPaymentsLock.tryToUnlock { [weak self] outcome in
guard let self = self else { return }
guard outcome == OWSPaymentsLock.LocalAuthOutcome.success else {
PaymentActionSheets.showBiometryAuthFailedActionSheet { _ in

View File

@ -194,7 +194,7 @@ class PrivacySettingsViewController: OWSTableViewController2 {
"SETTINGS_PAYMENTS_LOCK_SWITCH_LABEL",
comment: "Label for UISwitch based payments-lock setting that when enabled requires biometric-authentication (or passcode) to transfer funds or view the recovery phrase."
),
isOn: { OWSPaymentsLock.shared.isPaymentsLockEnabled() },
isOn: { Self.owsPaymentsLock.isPaymentsLockEnabled() },
target: self,
selector: #selector(didTogglePaymentsLockSwitch)
))
@ -266,8 +266,8 @@ class PrivacySettingsViewController: OWSTableViewController2 {
@objc
private func didTogglePaymentsLockSwitch(_ sender: UISwitch) {
// Require unlock to disable payments lock
if OWSPaymentsLock.shared.isPaymentsLockEnabled() {
OWSPaymentsLock.shared.tryToUnlock { [weak self] outcome in
if Self.owsPaymentsLock.isPaymentsLockEnabled() {
Self.owsPaymentsLock.tryToUnlock { [weak self] outcome in
guard let self = self else { return }
guard case .success = outcome else {
self.updateTableContents()
@ -275,13 +275,13 @@ class PrivacySettingsViewController: OWSTableViewController2 {
return
}
self.databaseStorage.write { transaction in
OWSPaymentsLock.shared.setIsPaymentsLockEnabled(false, transaction: transaction)
Self.owsPaymentsLock.setIsPaymentsLockEnabled(false, transaction: transaction)
}
self.updateTableContents()
}
} else {
databaseStorage.write { transaction in
OWSPaymentsLock.shared.setIsPaymentsLockEnabled(true, transaction: transaction)
Self.owsPaymentsLock.setIsPaymentsLockEnabled(true, transaction: transaction)
}
self.updateTableContents()
}

View File

@ -603,7 +603,7 @@ public class SendPaymentCompletionActionSheet: ActionSheetController {
ModalActivityIndicatorViewController.presentAsInvisible(fromViewController: self) { [weak self] modalActivityIndicator in
guard let self = self else { return }
OWSPaymentsLock.shared.tryToUnlockPromise().then(on: DispatchQueue.main) { (authOutcome: OWSPaymentsLock.LocalAuthOutcome) -> Promise<PreparedPayment> in
Self.owsPaymentsLock.tryToUnlockPromise().then(on: DispatchQueue.main) { (authOutcome: OWSPaymentsLock.LocalAuthOutcome) -> Promise<PreparedPayment> in
switch authOutcome {
case .failure(let error):
throw PaymentsUIError.paymentsLockFailed(reason: "local authentication failed with error: \(error)")

View File

@ -314,6 +314,14 @@ public extension NSObject {
SSKEnvironment.shared.paymentsEventsRef
}
final var owsPaymentsLock: OWSPaymentsLock {
SSKEnvironment.shared.owsPaymentsLockRef
}
static var owsPaymentsLock: OWSPaymentsLock {
SSKEnvironment.shared.owsPaymentsLockRef
}
final var spamChallengeResolver: SpamChallengeResolver {
SSKEnvironment.shared.spamChallengeResolverRef
}
@ -690,6 +698,14 @@ public extension Dependencies {
SSKEnvironment.shared.paymentsEventsRef
}
var owsPaymentsLock: OWSPaymentsLock {
SSKEnvironment.shared.owsPaymentsLockRef
}
static var owsPaymentsLock: OWSPaymentsLock {
SSKEnvironment.shared.owsPaymentsLockRef
}
var mobileCoinHelper: MobileCoinHelper {
SSKEnvironment.shared.mobileCoinHelperRef
}

View File

@ -1286,6 +1286,8 @@ public class AppSetup {
groupCallPeekClient: groupCallPeekClient
)
let paymentsLock = OWSPaymentsLock()
let sskEnvironment = SSKEnvironment(
contactManager: contactManager,
messageSender: messageSender,
@ -1326,6 +1328,7 @@ public class AppSetup {
paymentsHelper: paymentsHelper,
paymentsCurrencies: paymentsCurrencies,
paymentsEvents: paymentsEvents,
paymentsLock: paymentsLock,
mobileCoinHelper: mobileCoinHelper,
spamChallengeResolver: spamChallengeResolver,
senderKeyStore: senderKeyStore,

View File

@ -65,6 +65,7 @@ public class SSKEnvironment: NSObject {
public let messageProcessorRef: MessageProcessor
public let paymentsCurrenciesRef: PaymentsCurrenciesSwift
public let paymentsEventsRef: PaymentsEvents
public let owsPaymentsLockRef: OWSPaymentsLock
public let mobileCoinHelperRef: MobileCoinHelper
public let spamChallengeResolverRef: SpamChallengeResolver
public let senderKeyStoreRef: SenderKeyStore
@ -131,6 +132,7 @@ public class SSKEnvironment: NSObject {
paymentsHelper: PaymentsHelperSwift,
paymentsCurrencies: PaymentsCurrenciesSwift,
paymentsEvents: PaymentsEvents,
paymentsLock: OWSPaymentsLock,
mobileCoinHelper: MobileCoinHelper,
spamChallengeResolver: SpamChallengeResolver,
senderKeyStore: SenderKeyStore,
@ -192,6 +194,7 @@ public class SSKEnvironment: NSObject {
self.paymentsHelperRef = paymentsHelper
self.paymentsCurrenciesRef = paymentsCurrencies
self.paymentsEventsRef = paymentsEvents
self.owsPaymentsLockRef = paymentsLock
self.mobileCoinHelperRef = mobileCoinHelper
self.spamChallengeResolverRef = spamChallengeResolver
self.senderKeyStoreRef = senderKeyStore

View File

@ -6,7 +6,7 @@
import Foundation
import LocalAuthentication
public class OWSPaymentsLock: Dependencies {
public class OWSPaymentsLock: NSObject, Dependencies {
public enum LocalAuthOutcome: Equatable {
case success
@ -18,9 +18,8 @@ public class OWSPaymentsLock: Dependencies {
// MARK: - Singleton class
public static let shared = OWSPaymentsLock()
init() {
override init() {
super.init()
SwiftSingletons.register(self)
}
@ -167,7 +166,7 @@ public class OWSPaymentsLock: Dependencies {
public func tryToUnlockPromise() -> Promise<OWSPaymentsLock.LocalAuthOutcome> {
Promise<OWSPaymentsLock.LocalAuthOutcome>(on: DispatchQueue.main) { future in
OWSPaymentsLock.shared.tryToUnlock { outcome in
self.tryToUnlock { outcome in
future.resolve(outcome)
}
}

View File

@ -58,8 +58,8 @@ public class PaymentOnboarding {
}
public class func presentBiometricLockPromptIfNeeded(completion: @escaping () -> Void) {
guard OWSPaymentsLock.shared.isTimeToShowSuggestion()
&& OWSPaymentsLock.shared.isPaymentsLockEnabled() == false
guard NSObject.owsPaymentsLock.isTimeToShowSuggestion()
&& NSObject.owsPaymentsLock.isPaymentsLockEnabled() == false
else {
completion()
return
@ -72,7 +72,7 @@ public class PaymentOnboarding {
actionSheet.addAction(ActionSheetAction(title: ftPaymentsLockAffirmativeActionTitle(),
accessibilityIdentifier: "payments.lock.first_time.affirmative_action",
style: .default) { _ in
OWSPaymentsLock.shared.setIsPaymentsLockEnabledAndSnooze(true)
NSObject.owsPaymentsLock.setIsPaymentsLockEnabledAndSnooze(true)
completion()
})
@ -82,7 +82,7 @@ public class PaymentOnboarding {
style: .cancel
) { _ in
Logger.debug("Not Now")
OWSPaymentsLock.shared.setIsPaymentsLockEnabledAndSnooze(false)
NSObject.owsPaymentsLock.setIsPaymentsLockEnabledAndSnooze(false)
completion()
})