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.automirrored.filled.Send
|
||||||
import androidx.compose.material.icons.filled.AccountCircle
|
import androidx.compose.material.icons.filled.AccountCircle
|
||||||
import androidx.compose.material.icons.filled.Delete
|
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.CollectionsBookmark
|
||||||
import androidx.compose.material.icons.outlined.Drafts
|
import androidx.compose.material.icons.outlined.Drafts
|
||||||
import androidx.compose.material.icons.outlined.GroupAdd
|
import androidx.compose.material.icons.outlined.GroupAdd
|
||||||
import androidx.compose.material.icons.outlined.AccountBalanceWallet
|
|
||||||
import androidx.compose.material.icons.outlined.Settings
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
|||||||
+16
-3
@@ -112,9 +112,11 @@ class WalletViewModel : ViewModel() {
|
|||||||
// NWC balance is in millisats, convert to sats
|
// NWC balance is in millisats, convert to sats
|
||||||
_balanceSats.value = (response.result?.balance ?: 0L) / 1000L
|
_balanceSats.value = (response.result?.balance ?: 0L) / 1000L
|
||||||
}
|
}
|
||||||
|
|
||||||
is NwcErrorResponse -> {
|
is NwcErrorResponse -> {
|
||||||
_error.value = response.error?.message ?: "Balance request failed"
|
_error.value = response.error?.message ?: "Balance request failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
_isLoading.value = false
|
_isLoading.value = false
|
||||||
@@ -135,6 +137,7 @@ class WalletViewModel : ViewModel() {
|
|||||||
is GetInfoSuccessResponse -> {
|
is GetInfoSuccessResponse -> {
|
||||||
_walletAlias.value = response.result?.alias
|
_walletAlias.value = response.result?.alias
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,9 +166,11 @@ class WalletViewModel : ViewModel() {
|
|||||||
is ListTransactionsSuccessResponse -> {
|
is ListTransactionsSuccessResponse -> {
|
||||||
_transactions.value = response.result?.transactions ?: emptyList()
|
_transactions.value = response.result?.transactions ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
is NwcErrorResponse -> {
|
is NwcErrorResponse -> {
|
||||||
_error.value = response.error?.message ?: "Failed to load transactions"
|
_error.value = response.error?.message ?: "Failed to load transactions"
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
_isLoading.value = false
|
_isLoading.value = false
|
||||||
@@ -189,16 +194,21 @@ class WalletViewModel : ViewModel() {
|
|||||||
// Refresh balance after payment
|
// Refresh balance after payment
|
||||||
fetchBalance()
|
fetchBalance()
|
||||||
}
|
}
|
||||||
|
|
||||||
is PayInvoiceErrorResponse -> {
|
is PayInvoiceErrorResponse -> {
|
||||||
_sendState.value = SendState.Error(
|
_sendState.value =
|
||||||
|
SendState.Error(
|
||||||
response.error?.message ?: "Payment failed",
|
response.error?.message ?: "Payment failed",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
is NwcErrorResponse -> {
|
is NwcErrorResponse -> {
|
||||||
_sendState.value = SendState.Error(
|
_sendState.value =
|
||||||
|
SendState.Error(
|
||||||
response.error?.message ?: "Payment failed",
|
response.error?.message ?: "Payment failed",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
_sendState.value = SendState.Error("Unexpected response")
|
_sendState.value = SendState.Error("Unexpected response")
|
||||||
}
|
}
|
||||||
@@ -234,11 +244,14 @@ class WalletViewModel : ViewModel() {
|
|||||||
_receiveState.value = ReceiveState.Error("No invoice returned")
|
_receiveState.value = ReceiveState.Error("No invoice returned")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is NwcErrorResponse -> {
|
is NwcErrorResponse -> {
|
||||||
_receiveState.value = ReceiveState.Error(
|
_receiveState.value =
|
||||||
|
ReceiveState.Error(
|
||||||
response.error?.message ?: "Invoice creation failed",
|
response.error?.message ?: "Invoice creation failed",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
_receiveState.value = ReceiveState.Error("Unexpected response")
|
_receiveState.value = ReceiveState.Error("Unexpected response")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-10
@@ -137,14 +137,12 @@ class Nip47Client(
|
|||||||
/**
|
/**
|
||||||
* Builds a lookup_invoice request event by payment hash.
|
* Builds a lookup_invoice request event by payment hash.
|
||||||
*/
|
*/
|
||||||
suspend fun lookupInvoiceByHash(paymentHash: String): LnZapPaymentRequestEvent =
|
suspend fun lookupInvoiceByHash(paymentHash: String): LnZapPaymentRequestEvent = buildRequest(LookupInvoiceMethod.createByHash(paymentHash))
|
||||||
buildRequest(LookupInvoiceMethod.createByHash(paymentHash))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a lookup_invoice request event by BOLT11 invoice.
|
* Builds a lookup_invoice request event by BOLT11 invoice.
|
||||||
*/
|
*/
|
||||||
suspend fun lookupInvoiceByInvoice(invoice: String): LnZapPaymentRequestEvent =
|
suspend fun lookupInvoiceByInvoice(invoice: String): LnZapPaymentRequestEvent = buildRequest(LookupInvoiceMethod.createByInvoice(invoice))
|
||||||
buildRequest(LookupInvoiceMethod.createByInvoice(invoice))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a list_transactions request event.
|
* Builds a list_transactions request event.
|
||||||
@@ -178,20 +176,17 @@ class Nip47Client(
|
|||||||
descriptionHash: String? = null,
|
descriptionHash: String? = null,
|
||||||
expiry: Long? = null,
|
expiry: Long? = null,
|
||||||
minCltvExpiryDelta: Int? = null,
|
minCltvExpiryDelta: Int? = null,
|
||||||
): LnZapPaymentRequestEvent =
|
): LnZapPaymentRequestEvent = buildRequest(MakeHoldInvoiceMethod.create(amount, paymentHash, description, descriptionHash, expiry, minCltvExpiryDelta))
|
||||||
buildRequest(MakeHoldInvoiceMethod.create(amount, paymentHash, description, descriptionHash, expiry, minCltvExpiryDelta))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a cancel_hold_invoice request event.
|
* Builds a cancel_hold_invoice request event.
|
||||||
*/
|
*/
|
||||||
suspend fun cancelHoldInvoice(paymentHash: String): LnZapPaymentRequestEvent =
|
suspend fun cancelHoldInvoice(paymentHash: String): LnZapPaymentRequestEvent = buildRequest(CancelHoldInvoiceMethod.create(paymentHash))
|
||||||
buildRequest(CancelHoldInvoiceMethod.create(paymentHash))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a settle_hold_invoice request event.
|
* Builds a settle_hold_invoice request event.
|
||||||
*/
|
*/
|
||||||
suspend fun settleHoldInvoice(preimage: String): LnZapPaymentRequestEvent =
|
suspend fun settleHoldInvoice(preimage: String): LnZapPaymentRequestEvent = buildRequest(SettleHoldInvoiceMethod.create(preimage))
|
||||||
buildRequest(SettleHoldInvoiceMethod.create(preimage))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a request event from any [Request] object.
|
* Builds a request event from any [Request] object.
|
||||||
|
|||||||
+12
-5
@@ -169,7 +169,16 @@ class Nip47Server(
|
|||||||
buildResponse(
|
buildResponse(
|
||||||
GetInfoSuccessResponse(
|
GetInfoSuccessResponse(
|
||||||
GetInfoSuccessResponse.GetInfoResult(
|
GetInfoSuccessResponse.GetInfoResult(
|
||||||
alias, color, pubkey, network, blockHeight, blockHash, methods, notifications, null, lud16,
|
alias,
|
||||||
|
color,
|
||||||
|
pubkey,
|
||||||
|
network,
|
||||||
|
blockHeight,
|
||||||
|
blockHash,
|
||||||
|
methods,
|
||||||
|
notifications,
|
||||||
|
null,
|
||||||
|
lud16,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
requestEvent,
|
requestEvent,
|
||||||
@@ -181,8 +190,7 @@ class Nip47Server(
|
|||||||
suspend fun respondMakeInvoice(
|
suspend fun respondMakeInvoice(
|
||||||
requestEvent: LnZapPaymentRequestEvent,
|
requestEvent: LnZapPaymentRequestEvent,
|
||||||
transaction: NwcTransaction,
|
transaction: NwcTransaction,
|
||||||
): LnZapPaymentResponseEvent =
|
): LnZapPaymentResponseEvent = buildResponse(MakeInvoiceSuccessResponse(transaction), requestEvent)
|
||||||
buildResponse(MakeInvoiceSuccessResponse(transaction), requestEvent)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a lookup_invoice success response.
|
* Builds a lookup_invoice success response.
|
||||||
@@ -190,8 +198,7 @@ class Nip47Server(
|
|||||||
suspend fun respondLookupInvoice(
|
suspend fun respondLookupInvoice(
|
||||||
requestEvent: LnZapPaymentRequestEvent,
|
requestEvent: LnZapPaymentRequestEvent,
|
||||||
transaction: NwcTransaction,
|
transaction: NwcTransaction,
|
||||||
): LnZapPaymentResponseEvent =
|
): LnZapPaymentResponseEvent = buildResponse(LookupInvoiceSuccessResponse(transaction), requestEvent)
|
||||||
buildResponse(LookupInvoiceSuccessResponse(transaction), requestEvent)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a list_transactions success response.
|
* Builds a list_transactions success response.
|
||||||
|
|||||||
+14
-2
@@ -334,8 +334,20 @@ class AlbyInteropTest {
|
|||||||
assertEquals("018465013e2337234a7e5530a21c4a8cf70d84231f4a8ff0b1e2cce3cb2bd03b", request.params?.preimage)
|
assertEquals("018465013e2337234a7e5530a21c4a8cf70d84231f4a8ff0b1e2cce3cb2bd03b", request.params?.preimage)
|
||||||
assertNotNull(request.params?.tlv_records)
|
assertNotNull(request.params?.tlv_records)
|
||||||
assertEquals(1, request.params?.tlv_records?.size)
|
assertEquals(1, request.params?.tlv_records?.size)
|
||||||
assertEquals(5482373484L, request.params?.tlv_records?.first()?.type)
|
assertEquals(
|
||||||
assertEquals("fajsn341414fq", request.params?.tlv_records?.first()?.value)
|
5482373484L,
|
||||||
|
request.params
|
||||||
|
?.tlv_records
|
||||||
|
?.first()
|
||||||
|
?.type,
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"fajsn341414fq",
|
||||||
|
request.params
|
||||||
|
?.tlv_records
|
||||||
|
?.first()
|
||||||
|
?.value,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+14
-2
@@ -93,8 +93,20 @@ class RequestTest {
|
|||||||
assertEquals("preimage123", request.params?.preimage)
|
assertEquals("preimage123", request.params?.preimage)
|
||||||
assertNotNull(request.params?.tlv_records)
|
assertNotNull(request.params?.tlv_records)
|
||||||
assertEquals(1, request.params?.tlv_records?.size)
|
assertEquals(1, request.params?.tlv_records?.size)
|
||||||
assertEquals(7629169L, request.params?.tlv_records?.first()?.type)
|
assertEquals(
|
||||||
assertEquals("hex_value", request.params?.tlv_records?.first()?.value)
|
7629169L,
|
||||||
|
request.params
|
||||||
|
?.tlv_records
|
||||||
|
?.first()
|
||||||
|
?.type,
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
"hex_value",
|
||||||
|
request.params
|
||||||
|
?.tlv_records
|
||||||
|
?.first()
|
||||||
|
?.value,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+28
-4
@@ -128,10 +128,34 @@ class ResponseTest {
|
|||||||
assertIs<ListTransactionsSuccessResponse>(response)
|
assertIs<ListTransactionsSuccessResponse>(response)
|
||||||
assertNotNull(response.result?.transactions)
|
assertNotNull(response.result?.transactions)
|
||||||
assertEquals(2, response.result?.transactions?.size)
|
assertEquals(2, response.result?.transactions?.size)
|
||||||
assertEquals("incoming", response.result?.transactions?.get(0)?.type)
|
assertEquals(
|
||||||
assertEquals(100L, response.result?.transactions?.get(0)?.amount)
|
"incoming",
|
||||||
assertEquals("outgoing", response.result?.transactions?.get(1)?.type)
|
response.result
|
||||||
assertEquals(200L, response.result?.transactions?.get(1)?.amount)
|
?.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
|
@Test
|
||||||
|
|||||||
+56
-14
@@ -56,7 +56,10 @@ class ResponseDeserializer : StdDeserializer<Response>(Response::class.java) {
|
|||||||
|
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
return when (resultType) {
|
return when (resultType) {
|
||||||
NwcMethod.PAY_INVOICE -> jp.codec.treeToValue(jsonObject, PayInvoiceErrorResponse::class.java)
|
NwcMethod.PAY_INVOICE -> {
|
||||||
|
jp.codec.treeToValue(jsonObject, PayInvoiceErrorResponse::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val error = jp.codec.treeToValue(jsonObject.get("error"), NwcError::class.java)
|
val error = jp.codec.treeToValue(jsonObject.get("error"), NwcError::class.java)
|
||||||
NwcErrorResponse(resultType ?: "", error)
|
NwcErrorResponse(resultType ?: "", error)
|
||||||
@@ -66,19 +69,58 @@ class ResponseDeserializer : StdDeserializer<Response>(Response::class.java) {
|
|||||||
|
|
||||||
if (hasResult || resultType != null) {
|
if (hasResult || resultType != null) {
|
||||||
return when (resultType) {
|
return when (resultType) {
|
||||||
NwcMethod.PAY_INVOICE -> jp.codec.treeToValue(jsonObject, PayInvoiceSuccessResponse::class.java)
|
NwcMethod.PAY_INVOICE -> {
|
||||||
NwcMethod.PAY_KEYSEND -> jp.codec.treeToValue(jsonObject, PayKeysendSuccessResponse::class.java)
|
jp.codec.treeToValue(jsonObject, PayInvoiceSuccessResponse::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.PAY_KEYSEND -> {
|
||||||
NwcMethod.GET_BALANCE -> jp.codec.treeToValue(jsonObject, GetBalanceSuccessResponse::class.java)
|
jp.codec.treeToValue(jsonObject, PayKeysendSuccessResponse::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.MAKE_INVOICE -> {
|
||||||
NwcMethod.CREATE_CONNECTION -> jp.codec.treeToValue(jsonObject, CreateConnectionSuccessResponse::class.java)
|
jp.codec.treeToValue(jsonObject, MakeInvoiceSuccessResponse::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.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 -> {
|
else -> {
|
||||||
// tries to guess for backward compatibility
|
// tries to guess for backward compatibility
|
||||||
if (jsonObject.get("result")?.get("preimage") != null) {
|
if (jsonObject.get("result")?.get("preimage") != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user