@@ -76,8 +76,8 @@ class WakeNodeWorker @AssistedInject constructor(
7676 Logger .warn(" Notification type is null, proceeding with node wake" , context = TAG )
7777 }
7878
79- try {
80- measured(TAG ) {
79+ return runCatching {
80+ measured(label = " doWork " , context = TAG ) {
8181 lightningRepo.start(
8282 walletIndex = 0 ,
8383 timeout = timeout,
@@ -92,31 +92,35 @@ class WakeNodeWorker @AssistedInject constructor(
9292 Logger .error(" Missing orderId" , context = TAG )
9393 } else {
9494 Logger .info(" Open channel request for order $orderId " , context = TAG )
95- blocktankRepo.openChannel(orderId).onFailure { e ->
96- Logger .error(" Failed to open channel" , e , context = TAG )
95+ blocktankRepo.openChannel(orderId).onFailure {
96+ Logger .error(" Failed to open channel" , it , context = TAG )
9797 bestAttemptContent = NotificationDetails (
98- title = appContext.getString(R .string.notification_channel_open_failed_title ),
99- body = e .message ? : appContext.getString(R .string.notification_unknown_error ),
98+ title = appContext.getString(R .string.notification__channel_open_failed_title ),
99+ body = it .message ? : appContext.getString(R .string.common__error_body ),
100100 )
101101 deliver()
102102 }
103103 }
104104 }
105105 }
106- withTimeout(timeout) { deliverSignal.await() } // Stops node on timeout & avoids notification replay by OS
107- return Result .success()
108- } catch (e: Exception ) {
109- val reason = e.message ? : appContext.getString(R .string.notification_unknown_error)
106+ // Stops node on timeout & avoids notification replay by OS
107+ withTimeout(timeout) { deliverSignal.await() }
108+ }
109+ .fold(
110+ onSuccess = { Result .success() },
111+ onFailure = { e ->
112+ val reason = e.message ? : appContext.getString(R .string.common__error_body)
110113
111- bestAttemptContent = NotificationDetails (
112- title = appContext.getString(R .string.notification_lightning_error_title ),
113- body = reason,
114- )
115- Logger .error(" Lightning error" , e, context = TAG )
116- deliver()
114+ bestAttemptContent = NotificationDetails (
115+ title = appContext.getString(R .string.notification__lightning_error_title ),
116+ body = reason,
117+ )
118+ Logger .error(" Lightning error" , e, context = TAG )
119+ deliver()
117120
118- return Result .failure(workDataOf(" Reason" to reason))
119- }
121+ Result .failure(workDataOf(" Reason" to reason))
122+ }
123+ )
120124 }
121125
122126 /* *
@@ -125,14 +129,14 @@ class WakeNodeWorker @AssistedInject constructor(
125129 */
126130 private suspend fun handleLdkEvent (event : Event ) {
127131 val showDetails = settingsStore.data.first().showNotificationDetails
128- val hiddenBody = appContext.getString(R .string.notification_received_body_hidden )
132+ val hiddenBody = appContext.getString(R .string.notification__received__body_hidden )
129133 when (event) {
130134 is Event .PaymentReceived -> onPaymentReceived(event, showDetails, hiddenBody)
131135
132136 is Event .ChannelPending -> {
133137 bestAttemptContent = NotificationDetails (
134- title = appContext.getString(R .string.notification_channel_opened_title ),
135- body = appContext.getString(R .string.notification_channel_pending_body ),
138+ title = appContext.getString(R .string.notification__channel_opened_title ),
139+ body = appContext.getString(R .string.notification__channel_pending_body ),
136140 )
137141 // Don't deliver, give a chance for channelReady event to update the content if it's a turbo channel
138142 }
@@ -142,7 +146,7 @@ class WakeNodeWorker @AssistedInject constructor(
142146
143147 is Event .PaymentFailed -> {
144148 bestAttemptContent = NotificationDetails (
145- title = appContext.getString(R .string.notification_payment_failed_title ),
149+ title = appContext.getString(R .string.notification__payment_failed_title ),
146150 body = " ⚡ ${event.reason} " ,
147151 )
148152
@@ -158,18 +162,18 @@ class WakeNodeWorker @AssistedInject constructor(
158162 private suspend fun onChannelClosed (event : Event .ChannelClosed ) {
159163 bestAttemptContent = when (notificationType) {
160164 mutualClose -> NotificationDetails (
161- title = appContext.getString(R .string.notification_channel_closed_title ),
162- body = appContext.getString(R .string.notification_channel_closed_mutual_body ),
165+ title = appContext.getString(R .string.notification__channel_closed__title ),
166+ body = appContext.getString(R .string.notification__channel_closed__mutual_body ),
163167 )
164168
165169 orderPaymentConfirmed -> NotificationDetails (
166- title = appContext.getString(R .string.notification_channel_open_bg_failed_title ),
167- body = appContext.getString(R .string.notification_please_try_again_body ),
170+ title = appContext.getString(R .string.notification__channel_open_bg_failed_title ),
171+ body = appContext.getString(R .string.notification__please_try_again_body ),
168172 )
169173
170174 else -> NotificationDetails (
171- title = appContext.getString(R .string.notification_channel_closed_title ),
172- body = appContext.getString(R .string.notification_channel_closed_reason_body , event.reason),
175+ title = appContext.getString(R .string.notification__channel_closed__title ),
176+ body = appContext.getString(R .string.notification__channel_closed__reason_body , event.reason),
173177 )
174178 }
175179
@@ -193,7 +197,7 @@ class WakeNodeWorker @AssistedInject constructor(
193197 )
194198 val content = if (showDetails) " $BITCOIN_SYMBOL $sats " else hiddenBody
195199 bestAttemptContent = NotificationDetails (
196- title = appContext.getString(R .string.notification_received_title ),
200+ title = appContext.getString(R .string.notification__received__title ),
197201 body = content,
198202 )
199203 if (notificationType == incomingHtlc) {
@@ -206,10 +210,10 @@ class WakeNodeWorker @AssistedInject constructor(
206210 showDetails : Boolean ,
207211 hiddenBody : String ,
208212 ) {
209- val viaNewChannel = appContext.getString(R .string.notification_via_new_channel_body )
213+ val viaNewChannel = appContext.getString(R .string.notification__received__body_channel )
210214 if (notificationType == cjitPaymentArrived) {
211215 bestAttemptContent = NotificationDetails (
212- title = appContext.getString(R .string.notification_received_title ),
216+ title = appContext.getString(R .string.notification__received__title ),
213217 body = viaNewChannel,
214218 )
215219
@@ -235,8 +239,8 @@ class WakeNodeWorker @AssistedInject constructor(
235239 }
236240 } else if (notificationType == orderPaymentConfirmed) {
237241 bestAttemptContent = NotificationDetails (
238- title = appContext.getString(R .string.notification_channel_opened_title ),
239- body = appContext.getString(R .string.notification_channel_ready_body ),
242+ title = appContext.getString(R .string.notification__channel_opened_title ),
243+ body = appContext.getString(R .string.notification__channel_ready_body ),
240244 )
241245 }
242246 deliver()
0 commit comments