diff --git a/SignalMessaging/Payments/PaymentsImpl.swift b/SignalMessaging/Payments/PaymentsImpl.swift index 8dad485f42..0de1eaf90a 100644 --- a/SignalMessaging/Payments/PaymentsImpl.swift +++ b/SignalMessaging/Payments/PaymentsImpl.swift @@ -64,10 +64,6 @@ public class PaymentsImpl: NSObject, PaymentsSwift { } private func getOrBuildCurrentApi(paymentsEntropy: Data) -> Promise { - guard !isKillSwitchActive else { - return Promise(error: PaymentsError.killSwitch) - } - func getCurrentApi() -> MobileCoinAPI? { return Self.unfairLock.withLock { () -> MobileCoinAPI? in if let handle = self.currentApiHandle, @@ -115,6 +111,9 @@ public class PaymentsImpl: NSObject, PaymentsSwift { guard FeatureFlags.paymentsEnabled else { return false } + guard !isKillSwitchActive else { + return false + } return hasValidPhoneNumberForPayments } @@ -246,7 +245,7 @@ public class PaymentsImpl: NSObject, PaymentsSwift { transaction: SDSAnyWriteTransaction) { let oldPaymentsState = self.paymentsState - guard oldPaymentsState.isEnabled || canEnablePayments else { + guard !newPaymentsState.isEnabled || canEnablePayments else { owsFailDebug("Payments cannot be enabled.") return } @@ -550,7 +549,10 @@ public extension PaymentsImpl { receipt: MobileCoin.Receipt, paymentRequestModel: TSPaymentRequestModel?, isOutgoingTransfer: Bool) -> Promise { - firstly(on: .global()) { + guard !isKillSwitchActive else { + return Promise(error: PaymentsError.killSwitch) + } + return firstly(on: .global()) { var addressUuidString: String? if let recipientAddress = recipientAddress { guard recipientAddress.isValid else { @@ -720,6 +722,9 @@ public extension PaymentsImpl { isOutgoingTransfer: Bool, canDefragment: Bool) -> Promise { + guard !isKillSwitchActive else { + return Promise(error: PaymentsError.killSwitch) + } guard let recipient = recipient as? SendPaymentRecipientImpl else { return Promise(error: OWSAssertionError("Invalid recipient.")) } @@ -761,6 +766,9 @@ public extension PaymentsImpl { isOutgoingTransfer: Bool, canDefragment: Bool) -> Promise { + guard !isKillSwitchActive else { + return Promise(error: PaymentsError.killSwitch) + } guard paymentAmount.currency == .mobileCoin else { return Promise(error: OWSAssertionError("Invalid currency.")) } @@ -880,7 +888,10 @@ public extension PaymentsImpl { } func initiateOutgoingPayment(preparedPayment: PreparedPayment) -> Promise { - firstly(on: .global()) { () -> Promise in + guard !isKillSwitchActive else { + return Promise(error: PaymentsError.killSwitch) + } + return firstly(on: .global()) { () -> Promise in guard let preparedPayment = preparedPayment as? PreparedPaymentImpl else { throw OWSAssertionError("Invalid preparedPayment.") } diff --git a/SignalMessaging/Payments/PaymentsProcessor.swift b/SignalMessaging/Payments/PaymentsProcessor.swift index 12626fbb3b..3dcccbc77c 100644 --- a/SignalMessaging/Payments/PaymentsProcessor.swift +++ b/SignalMessaging/Payments/PaymentsProcessor.swift @@ -674,6 +674,19 @@ private class PaymentProcessingOperation: OWSOperation { Logger.verbose("") + guard !payments.isKillSwitchActive else { + do { + try Self.databaseStorage.write { transaction in + try paymentModel.updatePaymentModelState(fromState: .outgoingUnsubmitted, + toState: .outgoingUnverified, + transaction: transaction) + } + } catch { + owsFailDebug("Error: \(error)") + } + return Promise(error: PaymentsError.killSwitch) + } + if DebugFlags.paymentsSkipSubmissionAndOutgoingVerification.get() { return Self.updatePaymentStatePromise(paymentModel: paymentModel, fromState: .outgoingUnsubmitted,