mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-23 07:54:22 +01:00
List payments filtering and paging (#369)
* List payments in reverse chonological order * Add payment filtering and paging * Fix examples * Apply suggestions from code review Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com> * Set timestamp for pseudo payments * Filter by the first non-null timestamp from the join query --------- Co-authored-by: Erdem Yerebasmaz <erdem@yerebasmaz.com>
This commit is contained in:
@@ -496,6 +496,64 @@ fun asLimitsList(arr: ReadableArray): List<Limits> {
|
||||
return list
|
||||
}
|
||||
|
||||
fun asListPaymentsRequest(listPaymentsRequest: ReadableMap): ListPaymentsRequest? {
|
||||
if (!validateMandatoryFields(
|
||||
listPaymentsRequest,
|
||||
arrayOf(),
|
||||
)
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val filters =
|
||||
if (hasNonNullKey(listPaymentsRequest, "filters")) {
|
||||
listPaymentsRequest.getArray("filters")?.let {
|
||||
asPaymentTypeList(it)
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val fromTimestamp =
|
||||
if (hasNonNullKey(
|
||||
listPaymentsRequest,
|
||||
"fromTimestamp",
|
||||
)
|
||||
) {
|
||||
listPaymentsRequest.getDouble("fromTimestamp").toLong()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val toTimestamp = if (hasNonNullKey(listPaymentsRequest, "toTimestamp")) listPaymentsRequest.getDouble("toTimestamp").toLong() else null
|
||||
val offset = if (hasNonNullKey(listPaymentsRequest, "offset")) listPaymentsRequest.getInt("offset").toUInt() else null
|
||||
val limit = if (hasNonNullKey(listPaymentsRequest, "limit")) listPaymentsRequest.getInt("limit").toUInt() else null
|
||||
return ListPaymentsRequest(
|
||||
filters,
|
||||
fromTimestamp,
|
||||
toTimestamp,
|
||||
offset,
|
||||
limit,
|
||||
)
|
||||
}
|
||||
|
||||
fun readableMapOf(listPaymentsRequest: ListPaymentsRequest): ReadableMap =
|
||||
readableMapOf(
|
||||
"filters" to listPaymentsRequest.filters?.let { readableArrayOf(it) },
|
||||
"fromTimestamp" to listPaymentsRequest.fromTimestamp,
|
||||
"toTimestamp" to listPaymentsRequest.toTimestamp,
|
||||
"offset" to listPaymentsRequest.offset,
|
||||
"limit" to listPaymentsRequest.limit,
|
||||
)
|
||||
|
||||
fun asListPaymentsRequestList(arr: ReadableArray): List<ListPaymentsRequest> {
|
||||
val list = ArrayList<ListPaymentsRequest>()
|
||||
for (value in arr.toArrayList()) {
|
||||
when (value) {
|
||||
is ReadableMap -> list.add(asListPaymentsRequest(value)!!)
|
||||
else -> throw SdkException.Generic(errUnexpectedType("${value::class.java.name}"))
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
fun asLnUrlAuthRequestData(lnUrlAuthRequestData: ReadableMap): LnUrlAuthRequestData? {
|
||||
if (!validateMandatoryFields(
|
||||
lnUrlAuthRequestData,
|
||||
@@ -2397,6 +2455,7 @@ fun pushToArray(
|
||||
is LocaleOverrides -> array.pushMap(readableMapOf(value))
|
||||
is LocalizedName -> array.pushMap(readableMapOf(value))
|
||||
is Payment -> array.pushMap(readableMapOf(value))
|
||||
is PaymentType -> array.pushString(value.name.lowercase())
|
||||
is Rate -> array.pushMap(readableMapOf(value))
|
||||
is RefundableSwap -> array.pushMap(readableMapOf(value))
|
||||
is RouteHint -> array.pushMap(readableMapOf(value))
|
||||
|
||||
@@ -352,10 +352,15 @@ class BreezSDKLiquidModule(
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun listPayments(promise: Promise) {
|
||||
fun listPayments(
|
||||
req: ReadableMap,
|
||||
promise: Promise,
|
||||
) {
|
||||
executor.execute {
|
||||
try {
|
||||
val res = getBindingLiquidSdk().listPayments()
|
||||
val listPaymentsRequest =
|
||||
asListPaymentsRequest(req) ?: run { throw SdkException.Generic(errMissingMandatoryField("req", "ListPaymentsRequest")) }
|
||||
val res = getBindingLiquidSdk().listPayments(listPaymentsRequest)
|
||||
promise.resolve(readableArrayOf(res))
|
||||
} catch (e: Exception) {
|
||||
promise.reject(e.javaClass.simpleName.replace("Exception", "Error"), e.message, e)
|
||||
|
||||
Reference in New Issue
Block a user