refactor: extract duplicated string literals into constants (sonar)

This commit is contained in:
davotoula
2026-06-12 14:04:47 +02:00
parent 078ceac846
commit 7265a9da36
3 changed files with 14 additions and 9 deletions
@@ -287,6 +287,8 @@ import kotlin.coroutines.cancellation.CancellationException
import com.vitorpamplona.quartz.experimental.nip95.header.thumbhash as nip95thumbhash
import com.vitorpamplona.quartz.experimental.profileGallery.thumbhash as galleryThumbhash
private const val ONCHAIN_BACKEND_NOT_CONFIGURED = "Bitcoin chain backend is not configured"
@OptIn(DelicateCoroutinesApi::class)
@Stable
class Account(
@@ -906,7 +908,7 @@ class Account(
cache.onchainBackend
?: return OnchainZapSendResult.Failure(
OnchainZapSendStage.LOADING_UTXOS,
"Bitcoin chain backend is not configured",
ONCHAIN_BACKEND_NOT_CONFIGURED,
)
return OnchainZapSender.send(
backend = backend,
@@ -934,7 +936,7 @@ class Account(
cache.onchainBackend
?: return OnchainZapSendResult.Failure(
OnchainZapSendStage.LOADING_UTXOS,
"Bitcoin chain backend is not configured",
ONCHAIN_BACKEND_NOT_CONFIGURED,
)
return OnchainZapSender.sendToAddress(
backend = backend,
@@ -961,7 +963,7 @@ class Account(
cache.onchainBackend
?: return OnchainZapSendResult.Failure(
OnchainZapSendStage.LOADING_UTXOS,
"Bitcoin chain backend is not configured",
ONCHAIN_BACKEND_NOT_CONFIGURED,
)
return OnchainZapSender.sendSplit(
backend = backend,
@@ -733,6 +733,8 @@ private fun SectionLabel(text: String) {
// Previews — fake data only; no account or network required.
// ---------------------------------------------------------------------------
private const val PREVIEW_MESSAGE_LABEL = "Add a public message"
private val previewMethods =
persistentListOf(
PaymentMethodUi(ProfilePaymentMethod.LIGHTNING, copyValue = "alice@walletofsatoshi.com"),
@@ -799,7 +801,7 @@ private fun SendPaymentLightningPreview() {
message = "Thank you for all your work!",
onMessageChange = {},
showMessageField = true,
messageLabel = "Add a public message",
messageLabel = PREVIEW_MESSAGE_LABEL,
zapTypes = previewZapTypes,
selectedZapType = LnZapEvent.ZapType.PUBLIC,
onZapTypeChange = {},
@@ -871,7 +873,7 @@ private fun SendPaymentInProgressPreview() {
message = "",
onMessageChange = {},
showMessageField = true,
messageLabel = "Add a public message",
messageLabel = PREVIEW_MESSAGE_LABEL,
zapTypes = null,
selectedZapType = LnZapEvent.ZapType.PUBLIC,
onZapTypeChange = {},
@@ -907,7 +909,7 @@ private fun SendPaymentSuccessPreview() {
message = "",
onMessageChange = {},
showMessageField = true,
messageLabel = "Add a public message",
messageLabel = PREVIEW_MESSAGE_LABEL,
zapTypes = previewZapTypes,
selectedZapType = LnZapEvent.ZapType.PUBLIC,
onZapTypeChange = {},
@@ -51,6 +51,7 @@ import com.vitorpamplona.quartz.nip05DnsIdentifiers.Nip05Id
*/
object OfferCommands {
private const val MAX_FOLLOW_HOPS = 3
private const val ERR_NOT_A_NOFFER = "not a valid noffer pointer"
suspend fun dispatch(
dataDir: DataDir,
@@ -113,7 +114,7 @@ object OfferCommands {
val args = Args(rest)
val offer =
ClinkPointerParser.parse(args.positional(0, "noffer").trim()) as? NOffer
?: return Output.error("bad_args", "not a valid noffer pointer")
?: return Output.error("bad_args", ERR_NOT_A_NOFFER)
Output.emit(
mapOf(
@@ -139,7 +140,7 @@ object OfferCommands {
var offer =
ClinkPointerParser.parse(args.positional(0, "noffer").trim()) as? NOffer
?: return Output.error("bad_args", "not a valid noffer pointer")
?: return Output.error("bad_args", ERR_NOT_A_NOFFER)
val ctx = Context.open(dataDir)
try {
@@ -209,7 +210,7 @@ object OfferCommands {
val offer =
ClinkPointerParser.parse(args.positional(0, "noffer").trim()) as? NOffer
?: return Output.error("bad_args", "not a valid noffer pointer")
?: return Output.error("bad_args", ERR_NOT_A_NOFFER)
val withFlag =
args.flag("with")
?: return Output.error("bad_args", "offer pay needs --with <ndebit> to settle the fetched invoice")