Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change redeem swap failure notification text #947

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}

Expand All @@ -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,
Expand All @@ -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
),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Loading