spotless apply
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+22
-9
@@ -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")
|
||||
}
|
||||
|
||||
+5
-10
@@ -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.
|
||||
|
||||
+12
-5
@@ -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.
|
||||
|
||||
+14
-2
@@ -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
|
||||
|
||||
+14
-2
@@ -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
|
||||
|
||||
+28
-4
@@ -128,10 +128,34 @@ class ResponseTest {
|
||||
assertIs<ListTransactionsSuccessResponse>(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
|
||||
|
||||
+56
-14
@@ -56,7 +56,10 @@ class ResponseDeserializer : StdDeserializer<Response>(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>(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) {
|
||||
|
||||
Reference in New Issue
Block a user