diff --git a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/Constants.kt b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/Constants.kt index a2e7fccb0..8601b35aa 100644 --- a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/Constants.kt +++ b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/Constants.kt @@ -69,8 +69,10 @@ object Constants { "swap_tx_confirmed_notification_channel_description" const val SWAP_TX_CONFIRMED_NOTIFICATION_CHANNEL_NAME = "swap_tx_confirmed_notification_channel_name" - const val SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = + const val SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT = "swap_tx_confirmed_notification_failure_text" + const val SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = + "swap_tx_confirmed_notification_failure_title" const val SWAP_TX_CONFIRMED_NOTIFICATION_TITLE = "swap_tx_confirmed_notification_title" const val SWAP_TX_CONFIRMED_WORKGROUP_ID = "swap_tx" @@ -116,8 +118,10 @@ object Constants { "Notifications for received swaps when the application is in the background" const val DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_CHANNEL_NAME = "Received Swaps" + const val DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT = + "Tap to complete swap" const val DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = - "Redeem Swap Failed" + "Swap Ongoing" const val DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE = "Swap Confirmed" const val DEFAULT_SWAP_TX_CONFIRMED_WORKGROUP_DESCRIPTION = diff --git a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/job/RedeemSwap.kt b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/job/RedeemSwap.kt index e44c1f354..cadd213de 100644 --- a/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/job/RedeemSwap.kt +++ b/libs/sdk-bindings/bindings-android/lib/src/main/kotlin/breez_sdk_notification/job/RedeemSwap.kt @@ -3,9 +3,11 @@ package breez_sdk_notification.job import android.content.Context import breez_sdk.BlockingBreezServices import breez_sdk.BreezEvent +import breez_sdk_notification.Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT import breez_sdk_notification.Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE import breez_sdk_notification.Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE import breez_sdk_notification.Constants.NOTIFICATION_CHANNEL_SWAP_TX_CONFIRMED +import breez_sdk_notification.Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT import breez_sdk_notification.Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE import breez_sdk_notification.Constants.SWAP_TX_CONFIRMED_NOTIFICATION_TITLE import breez_sdk_notification.NotificationHelper.Companion.notifyChannel @@ -39,6 +41,7 @@ class RedeemSwapJob( logger.log(TAG, "Found swap for ${request.address}", "INFO") } catch (e: Exception) { logger.log(TAG, "Failed to manually redeem swap notification: ${e.message}", "WARN") + notifyFailure() } } @@ -60,9 +63,11 @@ class RedeemSwapJob( } } - override fun onShutdown() {} + override fun onShutdown() { + notifyFailure() + } - private fun notifySuccessAndShutdown(address: String) { + private fun notifySuccessAndShutdown(address: String) { logger.log(TAG, "Swap address $address redeemed successfully", "INFO") notifyChannel( context, @@ -75,4 +80,24 @@ class RedeemSwapJob( ) fgService.onFinished(this) } + + private fun notifyFailure() { + this.bitcoinAddress?.let{address -> + logger.log(TAG, "Swap address $address not redeemed", "INFO") + notifyChannel( + context, + NOTIFICATION_CHANNEL_SWAP_TX_CONFIRMED, + getString( + context, + SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE, + DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE + ), + getString( + context, + SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT, + DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT + ), + ) + } + } } diff --git a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Constants.swift b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Constants.swift index 9be2f0af5..5801b6c64 100644 --- a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Constants.swift +++ b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Constants.swift @@ -24,6 +24,7 @@ struct Constants { static let PAYMENT_RECEIVED_NOTIFICATION_TITLE = "payment_received_notification_title" static let PAYMENT_RECEIVED_NOTIFICATION_FAILURE_TITLE = "payment_received_notification_failure_title" static let SWAP_TX_CONFIRMED_NOTIFICATION_TITLE = "swap_tx_confirmed_notification_title" + static let SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT = "swap_tx_confirmed_notification_failure_text" static let SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = "swap_tx_confirmed_notification_failure_title" // Resource Identifier Defaults @@ -35,5 +36,6 @@ struct Constants { static let DEFAULT_PAYMENT_RECEIVED_NOTIFICATION_TITLE = "Received %d sats" static let DEFAULT_PAYMENT_RECEIVED_NOTIFICATION_FAILURE_TITLE = "Receive Payment Failed" static let DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE = "Swap Confirmed" - static let DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = "Redeem Swap Failed" + static let DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT = "Tap to complete swap" + static let DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE = "Swap Ongoing" } diff --git a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Task/RedeemSwap.swift b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Task/RedeemSwap.swift index 74502d400..be8876870 100644 --- a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Task/RedeemSwap.swift +++ b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/Task/RedeemSwap.swift @@ -29,8 +29,8 @@ class RedeemSwapTask : TaskProtocol { if address == swapInfo.bitcoinAddress { if (swapInfo.paidMsat > 0) { self.logger.log(tag: TAG, line: "Swap address \(swapInfo.bitcoinAddress) redeemed succesfully", level: "INFO") - let successRedeemSwap = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE) - self.displayPushNotification(title: successRedeemSwap, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED) + let notificationTitle = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_TITLE) + self.displayPushNotification(title: notificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED) } } break @@ -65,7 +65,8 @@ class RedeemSwapTask : TaskProtocol { } func onShutdown() { - let failRedeemSwap = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE) - self.displayPushNotification(title: failRedeemSwap, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED) + let notificationTitle = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TITLE) + let notificationBody = ResourceHelper.shared.getString(key: Constants.SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT, fallback: Constants.DEFAULT_SWAP_TX_CONFIRMED_NOTIFICATION_FAILURE_TEXT) + self.displayPushNotification(title: notificationTitle, body: notificationBody, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_SWAP_TX_CONFIRMED) } } diff --git a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/TaskProtocol.swift b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/TaskProtocol.swift index e33afd954..6f237bbbe 100644 --- a/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/TaskProtocol.swift +++ b/libs/sdk-bindings/bindings-swift/Sources/BreezSDK/TaskProtocol.swift @@ -10,7 +10,7 @@ public protocol TaskProtocol : EventListener { } extension TaskProtocol { - func displayPushNotification(title: String, logger: ServiceLogger, threadIdentifier: String? = nil) { + func displayPushNotification(title: String, body: String? = nil, logger: ServiceLogger, threadIdentifier: String? = nil) { logger.log(tag: "TaskProtocol", line:"displayPushNotification \(title)", level: "INFO") guard let contentHandler = contentHandler, @@ -19,8 +19,12 @@ extension TaskProtocol { return } - if threadIdentifier != nil { - bestAttemptContent.threadIdentifier = threadIdentifier! + if let body = body { + bestAttemptContent.body = body + } + + if let threadIdentifier = threadIdentifier { + bestAttemptContent.threadIdentifier = threadIdentifier } bestAttemptContent.title = title