From 120981f8c4ecad4c17ec33da39741d5b054d8a89 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 14 Mar 2026 10:18:16 -0400 Subject: [PATCH] spotless apply --- .../ui/navigation/drawer/DrawerContent.kt | 2 +- .../screen/loggedIn/wallet/WalletViewModel.kt | 31 +++++--- .../quartz/nip47WalletConnect/Nip47Client.kt | 15 ++-- .../quartz/nip47WalletConnect/Nip47Server.kt | 17 +++-- .../nip47WalletConnect/AlbyInteropTest.kt | 16 ++++- .../quartz/nip47WalletConnect/RequestTest.kt | 16 ++++- .../quartz/nip47WalletConnect/ResponseTest.kt | 32 +++++++-- .../jackson/ResponseDeserializer.kt | 70 +++++++++++++++---- 8 files changed, 152 insertions(+), 47 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/drawer/DrawerContent.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/drawer/DrawerContent.kt index a3682c723..139ad10c3 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/drawer/DrawerContent.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/drawer/DrawerContent.kt @@ -46,10 +46,10 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material.icons.filled.AccountCircle import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.outlined.AccountBalanceWallet import androidx.compose.material.icons.outlined.CollectionsBookmark import androidx.compose.material.icons.outlined.Drafts import androidx.compose.material.icons.outlined.GroupAdd -import androidx.compose.material.icons.outlined.AccountBalanceWallet import androidx.compose.material.icons.outlined.Settings import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt index 817c296e2..69a584025 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/wallet/WalletViewModel.kt @@ -112,9 +112,11 @@ class WalletViewModel : ViewModel() { // NWC balance is in millisats, convert to sats _balanceSats.value = (response.result?.balance ?: 0L) / 1000L } + is NwcErrorResponse -> { _error.value = response.error?.message ?: "Balance request failed" } + else -> {} } _isLoading.value = false @@ -135,6 +137,7 @@ class WalletViewModel : ViewModel() { is GetInfoSuccessResponse -> { _walletAlias.value = response.result?.alias } + else -> {} } } @@ -163,9 +166,11 @@ class WalletViewModel : ViewModel() { is ListTransactionsSuccessResponse -> { _transactions.value = response.result?.transactions ?: emptyList() } + is NwcErrorResponse -> { _error.value = response.error?.message ?: "Failed to load transactions" } + else -> {} } _isLoading.value = false @@ -189,16 +194,21 @@ class WalletViewModel : ViewModel() { // Refresh balance after payment fetchBalance() } + is PayInvoiceErrorResponse -> { - _sendState.value = SendState.Error( - response.error?.message ?: "Payment failed", - ) + _sendState.value = + SendState.Error( + response.error?.message ?: "Payment failed", + ) } + is NwcErrorResponse -> { - _sendState.value = SendState.Error( - response.error?.message ?: "Payment failed", - ) + _sendState.value = + SendState.Error( + response.error?.message ?: "Payment failed", + ) } + else -> { _sendState.value = SendState.Error("Unexpected response") } @@ -234,11 +244,14 @@ class WalletViewModel : ViewModel() { _receiveState.value = ReceiveState.Error("No invoice returned") } } + is NwcErrorResponse -> { - _receiveState.value = ReceiveState.Error( - response.error?.message ?: "Invoice creation failed", - ) + _receiveState.value = + ReceiveState.Error( + response.error?.message ?: "Invoice creation failed", + ) } + else -> { _receiveState.value = ReceiveState.Error("Unexpected response") } diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Client.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Client.kt index 5686fc1d5..05cb6e21f 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Client.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Client.kt @@ -137,14 +137,12 @@ class Nip47Client( /** * Builds a lookup_invoice request event by payment hash. */ - suspend fun lookupInvoiceByHash(paymentHash: String): LnZapPaymentRequestEvent = - buildRequest(LookupInvoiceMethod.createByHash(paymentHash)) + suspend fun lookupInvoiceByHash(paymentHash: String): LnZapPaymentRequestEvent = buildRequest(LookupInvoiceMethod.createByHash(paymentHash)) /** * Builds a lookup_invoice request event by BOLT11 invoice. */ - suspend fun lookupInvoiceByInvoice(invoice: String): LnZapPaymentRequestEvent = - buildRequest(LookupInvoiceMethod.createByInvoice(invoice)) + suspend fun lookupInvoiceByInvoice(invoice: String): LnZapPaymentRequestEvent = buildRequest(LookupInvoiceMethod.createByInvoice(invoice)) /** * Builds a list_transactions request event. @@ -178,20 +176,17 @@ class Nip47Client( descriptionHash: String? = null, expiry: Long? = null, minCltvExpiryDelta: Int? = null, - ): LnZapPaymentRequestEvent = - buildRequest(MakeHoldInvoiceMethod.create(amount, paymentHash, description, descriptionHash, expiry, minCltvExpiryDelta)) + ): LnZapPaymentRequestEvent = buildRequest(MakeHoldInvoiceMethod.create(amount, paymentHash, description, descriptionHash, expiry, minCltvExpiryDelta)) /** * Builds a cancel_hold_invoice request event. */ - suspend fun cancelHoldInvoice(paymentHash: String): LnZapPaymentRequestEvent = - buildRequest(CancelHoldInvoiceMethod.create(paymentHash)) + suspend fun cancelHoldInvoice(paymentHash: String): LnZapPaymentRequestEvent = buildRequest(CancelHoldInvoiceMethod.create(paymentHash)) /** * Builds a settle_hold_invoice request event. */ - suspend fun settleHoldInvoice(preimage: String): LnZapPaymentRequestEvent = - buildRequest(SettleHoldInvoiceMethod.create(preimage)) + suspend fun settleHoldInvoice(preimage: String): LnZapPaymentRequestEvent = buildRequest(SettleHoldInvoiceMethod.create(preimage)) /** * Builds a request event from any [Request] object. diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Server.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Server.kt index 6b032f3ae..947bbecf8 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Server.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/Nip47Server.kt @@ -169,7 +169,16 @@ class Nip47Server( buildResponse( GetInfoSuccessResponse( GetInfoSuccessResponse.GetInfoResult( - alias, color, pubkey, network, blockHeight, blockHash, methods, notifications, null, lud16, + alias, + color, + pubkey, + network, + blockHeight, + blockHash, + methods, + notifications, + null, + lud16, ), ), requestEvent, @@ -181,8 +190,7 @@ class Nip47Server( suspend fun respondMakeInvoice( requestEvent: LnZapPaymentRequestEvent, transaction: NwcTransaction, - ): LnZapPaymentResponseEvent = - buildResponse(MakeInvoiceSuccessResponse(transaction), requestEvent) + ): LnZapPaymentResponseEvent = buildResponse(MakeInvoiceSuccessResponse(transaction), requestEvent) /** * Builds a lookup_invoice success response. @@ -190,8 +198,7 @@ class Nip47Server( suspend fun respondLookupInvoice( requestEvent: LnZapPaymentRequestEvent, transaction: NwcTransaction, - ): LnZapPaymentResponseEvent = - buildResponse(LookupInvoiceSuccessResponse(transaction), requestEvent) + ): LnZapPaymentResponseEvent = buildResponse(LookupInvoiceSuccessResponse(transaction), requestEvent) /** * Builds a list_transactions success response. diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/AlbyInteropTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/AlbyInteropTest.kt index c201ab285..6d1d0adb7 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/AlbyInteropTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/AlbyInteropTest.kt @@ -334,8 +334,20 @@ class AlbyInteropTest { assertEquals("018465013e2337234a7e5530a21c4a8cf70d84231f4a8ff0b1e2cce3cb2bd03b", request.params?.preimage) assertNotNull(request.params?.tlv_records) assertEquals(1, request.params?.tlv_records?.size) - assertEquals(5482373484L, request.params?.tlv_records?.first()?.type) - assertEquals("fajsn341414fq", request.params?.tlv_records?.first()?.value) + assertEquals( + 5482373484L, + request.params + ?.tlv_records + ?.first() + ?.type, + ) + assertEquals( + "fajsn341414fq", + request.params + ?.tlv_records + ?.first() + ?.value, + ) } @Test diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt index 3299b0927..21816b647 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/RequestTest.kt @@ -93,8 +93,20 @@ class RequestTest { assertEquals("preimage123", request.params?.preimage) assertNotNull(request.params?.tlv_records) assertEquals(1, request.params?.tlv_records?.size) - assertEquals(7629169L, request.params?.tlv_records?.first()?.type) - assertEquals("hex_value", request.params?.tlv_records?.first()?.value) + assertEquals( + 7629169L, + request.params + ?.tlv_records + ?.first() + ?.type, + ) + assertEquals( + "hex_value", + request.params + ?.tlv_records + ?.first() + ?.value, + ) } @Test diff --git a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/ResponseTest.kt b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/ResponseTest.kt index 148483360..c26e05bf0 100644 --- a/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/ResponseTest.kt +++ b/quartz/src/commonTest/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/ResponseTest.kt @@ -128,10 +128,34 @@ class ResponseTest { assertIs(response) assertNotNull(response.result?.transactions) assertEquals(2, response.result?.transactions?.size) - assertEquals("incoming", response.result?.transactions?.get(0)?.type) - assertEquals(100L, response.result?.transactions?.get(0)?.amount) - assertEquals("outgoing", response.result?.transactions?.get(1)?.type) - assertEquals(200L, response.result?.transactions?.get(1)?.amount) + assertEquals( + "incoming", + response.result + ?.transactions + ?.get(0) + ?.type, + ) + assertEquals( + 100L, + response.result + ?.transactions + ?.get(0) + ?.amount, + ) + assertEquals( + "outgoing", + response.result + ?.transactions + ?.get(1) + ?.type, + ) + assertEquals( + 200L, + response.result + ?.transactions + ?.get(1) + ?.amount, + ) } @Test diff --git a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/jackson/ResponseDeserializer.kt b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/jackson/ResponseDeserializer.kt index c9b210ad9..ccb98c8b7 100644 --- a/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/jackson/ResponseDeserializer.kt +++ b/quartz/src/jvmAndroid/kotlin/com/vitorpamplona/quartz/nip47WalletConnect/jackson/ResponseDeserializer.kt @@ -56,7 +56,10 @@ class ResponseDeserializer : StdDeserializer(Response::class.java) { if (hasError) { return when (resultType) { - NwcMethod.PAY_INVOICE -> jp.codec.treeToValue(jsonObject, PayInvoiceErrorResponse::class.java) + NwcMethod.PAY_INVOICE -> { + jp.codec.treeToValue(jsonObject, PayInvoiceErrorResponse::class.java) + } + else -> { val error = jp.codec.treeToValue(jsonObject.get("error"), NwcError::class.java) NwcErrorResponse(resultType ?: "", error) @@ -66,19 +69,58 @@ class ResponseDeserializer : StdDeserializer(Response::class.java) { if (hasResult || resultType != null) { return when (resultType) { - NwcMethod.PAY_INVOICE -> jp.codec.treeToValue(jsonObject, PayInvoiceSuccessResponse::class.java) - NwcMethod.PAY_KEYSEND -> jp.codec.treeToValue(jsonObject, PayKeysendSuccessResponse::class.java) - NwcMethod.MAKE_INVOICE -> jp.codec.treeToValue(jsonObject, MakeInvoiceSuccessResponse::class.java) - NwcMethod.LOOKUP_INVOICE -> jp.codec.treeToValue(jsonObject, LookupInvoiceSuccessResponse::class.java) - NwcMethod.LIST_TRANSACTIONS -> jp.codec.treeToValue(jsonObject, ListTransactionsSuccessResponse::class.java) - NwcMethod.GET_BALANCE -> jp.codec.treeToValue(jsonObject, GetBalanceSuccessResponse::class.java) - NwcMethod.GET_INFO -> jp.codec.treeToValue(jsonObject, GetInfoSuccessResponse::class.java) - NwcMethod.GET_BUDGET -> jp.codec.treeToValue(jsonObject, GetBudgetSuccessResponse::class.java) - NwcMethod.SIGN_MESSAGE -> jp.codec.treeToValue(jsonObject, SignMessageSuccessResponse::class.java) - NwcMethod.CREATE_CONNECTION -> jp.codec.treeToValue(jsonObject, CreateConnectionSuccessResponse::class.java) - NwcMethod.MAKE_HOLD_INVOICE -> jp.codec.treeToValue(jsonObject, MakeHoldInvoiceSuccessResponse::class.java) - NwcMethod.CANCEL_HOLD_INVOICE -> jp.codec.treeToValue(jsonObject, CancelHoldInvoiceSuccessResponse::class.java) - NwcMethod.SETTLE_HOLD_INVOICE -> jp.codec.treeToValue(jsonObject, SettleHoldInvoiceSuccessResponse::class.java) + NwcMethod.PAY_INVOICE -> { + jp.codec.treeToValue(jsonObject, PayInvoiceSuccessResponse::class.java) + } + + NwcMethod.PAY_KEYSEND -> { + jp.codec.treeToValue(jsonObject, PayKeysendSuccessResponse::class.java) + } + + NwcMethod.MAKE_INVOICE -> { + jp.codec.treeToValue(jsonObject, MakeInvoiceSuccessResponse::class.java) + } + + NwcMethod.LOOKUP_INVOICE -> { + jp.codec.treeToValue(jsonObject, LookupInvoiceSuccessResponse::class.java) + } + + NwcMethod.LIST_TRANSACTIONS -> { + jp.codec.treeToValue(jsonObject, ListTransactionsSuccessResponse::class.java) + } + + NwcMethod.GET_BALANCE -> { + jp.codec.treeToValue(jsonObject, GetBalanceSuccessResponse::class.java) + } + + NwcMethod.GET_INFO -> { + jp.codec.treeToValue(jsonObject, GetInfoSuccessResponse::class.java) + } + + NwcMethod.GET_BUDGET -> { + jp.codec.treeToValue(jsonObject, GetBudgetSuccessResponse::class.java) + } + + NwcMethod.SIGN_MESSAGE -> { + jp.codec.treeToValue(jsonObject, SignMessageSuccessResponse::class.java) + } + + NwcMethod.CREATE_CONNECTION -> { + jp.codec.treeToValue(jsonObject, CreateConnectionSuccessResponse::class.java) + } + + NwcMethod.MAKE_HOLD_INVOICE -> { + jp.codec.treeToValue(jsonObject, MakeHoldInvoiceSuccessResponse::class.java) + } + + NwcMethod.CANCEL_HOLD_INVOICE -> { + jp.codec.treeToValue(jsonObject, CancelHoldInvoiceSuccessResponse::class.java) + } + + NwcMethod.SETTLE_HOLD_INVOICE -> { + jp.codec.treeToValue(jsonObject, SettleHoldInvoiceSuccessResponse::class.java) + } + else -> { // tries to guess for backward compatibility if (jsonObject.get("result")?.get("preimage") != null) {