From 4906843e43f6be00cce1e6a5cd5e4d2c6aac15ce Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 28 Sep 2026 14:39:15 +0000 Subject: [PATCH] refactor: clear two name clashes ahead of the AccountViewModel move - The app's ui/dal DefaultFeedOrder repeated commons' feeds DefaultFeedOrder verbatim; the copy is gone, callers use commons', and the file keeps the app-only orders as FeedOrders.kt. - The app's LNURL-pay resolver becomes LightningInvoiceResolver, so it no longer shares a simple name with commons' plain LightningAddressResolver (the Desktop/CLI one) once both sit in the same package. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01S7FuNBSKiyVecARSoE4B9P --- .../amethyst/service/V4VPaymentHandler.kt | 6 +++--- .../amethyst/service/ZapPaymentHandler.kt | 6 +++--- .../amethyst/service/cashu/melt/MeltProcessor.kt | 14 +++++++------- ...ressResolver.kt => LightningInvoiceResolver.kt} | 4 ++-- .../ui/dal/{DefaultFeedOrder.kt => FeedOrders.kt} | 3 --- .../ui/screen/loggedIn/AccountViewModel.kt | 8 ++++---- ...lverTest.kt => LightningInvoiceResolverTest.kt} | 8 ++++---- .../nip57Zaps/validate/LnurlEndpointCache.kt | 2 +- 8 files changed, 24 insertions(+), 27 deletions(-) rename amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/{LightningAddressResolver.kt => LightningInvoiceResolver.kt} (99%) rename amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/{DefaultFeedOrder.kt => FeedOrders.kt} (96%) rename amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/{LightningAddressResolverTest.kt => LightningInvoiceResolverTest.kt} (95%) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/V4VPaymentHandler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/V4VPaymentHandler.kt index d9582f8014..e5e28bd489 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/V4VPaymentHandler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/V4VPaymentHandler.kt @@ -36,7 +36,7 @@ import com.vitorpamplona.amethyst.commons.resources.podcast_value_no_recipients import com.vitorpamplona.amethyst.commons.service.lnurl.LnurlHttpTransport import com.vitorpamplona.amethyst.commons.tor.MoneyOpRelayRouting import com.vitorpamplona.amethyst.commons.ui.loadStringRes -import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver +import com.vitorpamplona.amethyst.service.lnurl.LightningInvoiceResolver import com.vitorpamplona.amethyst.ui.nwc.nwcFailureDetail import com.vitorpamplona.amethyst.ui.nwc.nwcTimeoutMessage import com.vitorpamplona.quartz.nip01Core.core.toHexKey @@ -245,7 +245,7 @@ class V4VPaymentHandler( } val invoice = - LightningAddressResolver(lnurl).lnAddressInvoice( + LightningInvoiceResolver(lnurl).lnAddressInvoice( lnAddress = lnAddress, milliSats = share.amountMilliSats, message = message, @@ -255,7 +255,7 @@ class V4VPaymentHandler( progress += 1f / shares.size onProgress(progress) InvoicePayable(share, invoice) - } catch (e: LightningAddressResolver.LightningAddressError) { + } catch (e: LightningInvoiceResolver.LightningAddressError) { onError(e.title, e.msg) null } catch (e: Exception) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ZapPaymentHandler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ZapPaymentHandler.kt index 4ee3cb2d77..db908c0643 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ZapPaymentHandler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ZapPaymentHandler.kt @@ -44,7 +44,7 @@ import com.vitorpamplona.amethyst.commons.resources.wallet_connect_pay_invoice_e import com.vitorpamplona.amethyst.commons.service.lnurl.LnurlHttpTransport import com.vitorpamplona.amethyst.commons.tor.MoneyOpRelayRouting import com.vitorpamplona.amethyst.commons.ui.loadStringRes -import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver +import com.vitorpamplona.amethyst.service.lnurl.LightningInvoiceResolver import com.vitorpamplona.amethyst.ui.nwc.nwcFailureDetail import com.vitorpamplona.amethyst.ui.nwc.nwcTimeoutMessage import com.vitorpamplona.quartz.experimental.clink.pointers.NDebit @@ -434,7 +434,7 @@ class ZapPaymentHandler( onProgress(progressAllPayments) }, ) - } catch (e: LightningAddressResolver.LightningAddressError) { + } catch (e: LightningInvoiceResolver.LightningAddressError) { onError(e.title, e.msg, splitZapRequestPair.inputSetup.user) null } catch (e: Exception) { @@ -681,7 +681,7 @@ class ZapPaymentHandler( var sentZapRequest: ZapRequestEvent? = null val invoice = - LightningAddressResolver(lnurl).lnAddressInvoice( + LightningInvoiceResolver(lnurl).lnAddressInvoice( lnAddress = lud16, milliSats = zapValue, message = message, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/cashu/melt/MeltProcessor.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/cashu/melt/MeltProcessor.kt index ce99ae9105..9d0ddc6f06 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/cashu/melt/MeltProcessor.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/cashu/melt/MeltProcessor.kt @@ -28,7 +28,7 @@ import com.vitorpamplona.amethyst.commons.resources.cashu_unsafe_mint_url import com.vitorpamplona.amethyst.commons.resources.cashu_unsafe_mint_url_explainer import com.vitorpamplona.amethyst.commons.service.lnurl.LnurlHttpTransport import com.vitorpamplona.amethyst.commons.ui.loadStringRes -import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver +import com.vitorpamplona.amethyst.service.lnurl.LightningInvoiceResolver import com.vitorpamplona.quartz.nip60Cashu.mintApi.CashuMintOperations import com.vitorpamplona.quartz.nip60Cashu.mintApi.MintHttpClient import com.vitorpamplona.quartz.nip60Cashu.mintApi.MintHttpTransport @@ -75,7 +75,7 @@ class MeltProcessor { // the LN fee_reserve, then add the NUT-02 input fee the mint // charges on these proofs. val probeInvoice = - LightningAddressResolver(lnurl).lnAddressInvoice( + LightningInvoiceResolver(lnurl).lnAddressInvoice( lnAddress = lud16, milliSats = token.totalAmount * 1000, message = "Calculate Fees for Cashu", @@ -86,7 +86,7 @@ class MeltProcessor { val sendable = token.totalAmount - fees if (sendable <= 0) { - throw LightningAddressResolver.LightningAddressError( + throw LightningInvoiceResolver.LightningAddressError( loadStringRes(Res.string.cashu_failed_redemption), loadStringRes( Res.string.cashu_failed_redemption_explainer_error_msg, @@ -99,7 +99,7 @@ class MeltProcessor { // requesting change — there is no wallet to hold leftover proofs, // so the unused fee_reserve stays with the mint. val invoice = - LightningAddressResolver(lnurl).lnAddressInvoice( + LightningInvoiceResolver(lnurl).lnAddressInvoice( lnAddress = lud16, milliSats = sendable * 1000, message = "Redeem Cashu", @@ -115,16 +115,16 @@ class MeltProcessor { ) } catch (e: Exception) { if (e is CancellationException) throw e - if (e is LightningAddressResolver.LightningAddressError) throw e + if (e is LightningInvoiceResolver.LightningAddressError) throw e // The mint URL was refused before any request went out: this is OUR // message, not the mint's, so don't dress it up as "the mint said". if (e is MintUrlException) { - throw LightningAddressResolver.LightningAddressError( + throw LightningInvoiceResolver.LightningAddressError( loadStringRes(Res.string.cashu_unsafe_mint_url), loadStringRes(Res.string.cashu_unsafe_mint_url_explainer, e.message), ) } - throw LightningAddressResolver.LightningAddressError( + throw LightningInvoiceResolver.LightningAddressError( loadStringRes(Res.string.cashu_failed_redemption), loadStringRes(Res.string.cashu_failed_redemption_explainer_error_msg, e.message), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolver.kt similarity index 99% rename from amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt rename to amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolver.kt index 971bf050a2..05dc0610ac 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolver.kt @@ -53,7 +53,7 @@ import kotlinx.serialization.json.longOrNull import kotlin.coroutines.cancellation.CancellationException /** LNURL-pay (LUD-06/16) for zaps and payments, over whatever [transport] the platform supplies. */ -class LightningAddressResolver( +class LightningInvoiceResolver( private val transport: LnurlHttpTransport, ) { fun assembleUrl(lnAddress: String): String? { @@ -166,7 +166,7 @@ class LightningAddressResolver( } if (errorMessage == null) { - Log.d("LightningAddressResolver") { "Error parsing LNResponse: $body" } + Log.d("LightningInvoiceResolver") { "Error parsing LNResponse: $body" } } return errorMessage diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FeedOrders.kt similarity index 96% rename from amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt rename to amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FeedOrders.kt index c4d5d05292..f4182fba95 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DefaultFeedOrder.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FeedOrders.kt @@ -25,9 +25,6 @@ import com.vitorpamplona.amethyst.commons.model.Note import com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.ChannelInviteCard import com.vitorpamplona.quartz.nip01Core.core.Event -val DefaultFeedOrder: Comparator = - compareByDescending { it.createdAt() }.thenBy { it.idHex } - val DefaultFeedOrderEvent: Comparator = compareByDescending { it.createdAt }.thenBy { it.id } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 0abdee6d3d..c4a5ab8e36 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -107,7 +107,7 @@ import com.vitorpamplona.amethyst.service.ClinkDebitPayer import com.vitorpamplona.amethyst.service.V4VPaymentHandler import com.vitorpamplona.amethyst.service.ZapPaymentHandler import com.vitorpamplona.amethyst.service.cashu.melt.MeltProcessor -import com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver +import com.vitorpamplona.amethyst.service.lnurl.LightningInvoiceResolver import com.vitorpamplona.amethyst.service.relayClient.reqCommand.RelaySubscriptionsCoordinator import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.markRoomNoteAsRead import com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.rowHasUnread @@ -2683,7 +2683,7 @@ class AccountViewModel( meltResult.fees.toString(), ), ) - } catch (e: LightningAddressResolver.LightningAddressError) { + } catch (e: LightningInvoiceResolver.LightningAddressError) { onDone(e.title, e.msg) } catch (e: Exception) { if (e is kotlin.coroutines.cancellation.CancellationException) throw e @@ -2915,7 +2915,7 @@ class AccountViewModel( } val invoice = - LightningAddressResolver(host.lnurlTransport).lnAddressInvoice( + LightningInvoiceResolver(host.lnurlTransport).lnAddressInvoice( lnAddress = lnAddress, milliSats = milliSats, message = message, @@ -2927,7 +2927,7 @@ class AccountViewModel( // its message TextFieldState, which is UI-thread confined (see the KDoc on // commons' `onUiThread`). This whole block runs on Dispatchers.IO. withContext(Dispatchers.Main) { onNewInvoice(invoice) } - } catch (e: LightningAddressResolver.LightningAddressError) { + } catch (e: LightningInvoiceResolver.LightningAddressError) { onError(e.title, e.msg) } catch (e: Exception) { if (e is CancellationException) throw e diff --git a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolverTest.kt b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolverTest.kt similarity index 95% rename from amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolverTest.kt rename to amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolverTest.kt index 78ff6a263c..09bd72777b 100644 --- a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolverTest.kt +++ b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/lnurl/LightningInvoiceResolverTest.kt @@ -28,11 +28,11 @@ import org.junit.Assert.assertEquals import org.junit.Test /** - * [LightningAddressResolver] over a scripted transport. The replies use the loose typing real + * [LightningInvoiceResolver] over a scripted transport. The replies use the loose typing real * LNURL servers send (a boolean as text, a number for a flag), which the resolver was written to * read through Jackson's lenient readers. */ -class LightningAddressResolverTest { +class LightningInvoiceResolverTest { // A 1 mBTC (100,000 sat) BOLT-11. private val invoice100kSats = "lnbc1m1pjt9u0qsp553q90pj5mafzv20w45eqavned9tgwhl4q99n9s5ppcw24nzw3zeqpp5002kd3ktym67du86kj665fgaev7ka8ys7j5yz5fg686lr5e2gfkshp5dkk27nnuax05az3pk2r6ytxtvwn5j4xzsq9ajprhc7crjkmgvr3qxqyjw5qcqpjrzjqtzxvfsuxe4l92pf97tt4rcgpy2xalkmlwexh899wqxf83l8nwv4xzh0gvqq89qqqqqqqqlgqqqqq0gqvs9qxpqysgqx5mz04wd7kqu5zhhel9enr036hjrp4gga0nz084p2asjl36a0zmrk6mhqa249zsgqref2rlvhffm73u7rxgr47gden6rugup4ksvpzsqvds4pz" @@ -51,7 +51,7 @@ class LightningAddressResolverTest { private fun resolverFor( lnurlp: String, invoiceReply: String = """{"pr":"$invoice100kSats","routes":[]}""", - ): Pair { + ): Pair { val transport = ScriptedTransport( mapOf( @@ -59,7 +59,7 @@ class LightningAddressResolverTest { "https://example.com/callback" to invoiceReply, ), ) - return LightningAddressResolver(transport) to transport + return LightningInvoiceResolver(transport) to transport } @Test diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip57Zaps/validate/LnurlEndpointCache.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip57Zaps/validate/LnurlEndpointCache.kt index 085f0ce8db..2fcb8d229f 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip57Zaps/validate/LnurlEndpointCache.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip57Zaps/validate/LnurlEndpointCache.kt @@ -32,7 +32,7 @@ import kotlinx.coroutines.CompletableDeferred * recipient's LNURL provider's `nostrPubkey` to validate the signer (NIP-57 * Appendix F). Without a cache, we'd re-fetch the same lnurlp endpoint for * every zap from every popular author. Outbound zaps populate the cache as a - * side effect when [com.vitorpamplona.amethyst.service.lnurl.LightningAddressResolver] + * side effect when Amethyst's `LightningInvoiceResolver` * fetches the recipient's metadata. * * Keys are URLs (not lud16 forms) so callers can convert lud16 / bech32 LNURL