Skip to content

Commit

Permalink
Fix optional param ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeross committed Aug 28, 2024
1 parent bbb8981 commit 23daeef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-language-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: bindings-golang
path: lib/bindings/ffi/golang/breez/breez_sdk_liquid/breez_sdk_liquid.*
path: lib/bindings/ffi/golang/breez_sdk_liquid/breez_sdk_liquid.*
6 changes: 3 additions & 3 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,14 @@ interface PaymentDetails {
};

dictionary Payment {
string? destination;
string? tx_id = null;
u32 timestamp;
u64 amount_sat;
u64 fees_sat;
PaymentType payment_type;
PaymentState status;
PaymentDetails? details;
string? destination = null;
string? tx_id = null;
PaymentDetails? details = null;
};

enum PaymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,26 +1156,26 @@ fun asPayment(payment: ReadableMap): Payment? {
) {
return null
}
val destination = if (hasNonNullKey(payment, "destination")) payment.getString("destination") else null
val txId = if (hasNonNullKey(payment, "txId")) payment.getString("txId") else null
val timestamp = payment.getInt("timestamp").toUInt()
val amountSat = payment.getDouble("amountSat").toULong()
val feesSat = payment.getDouble("feesSat").toULong()
val paymentType = payment.getString("paymentType")?.let { asPaymentType(it) }!!
val status = payment.getString("status")?.let { asPaymentState(it) }!!
val destination = if (hasNonNullKey(payment, "destination")) payment.getString("destination") else null
val txId = if (hasNonNullKey(payment, "txId")) payment.getString("txId") else null
val details = if (hasNonNullKey(payment, "details")) payment.getMap("details")?.let { asPaymentDetails(it) } else null
return Payment(destination, txId, timestamp, amountSat, feesSat, paymentType, status, details)
return Payment(timestamp, amountSat, feesSat, paymentType, status, destination, txId, details)
}

fun readableMapOf(payment: Payment): ReadableMap =
readableMapOf(
"destination" to payment.destination,
"txId" to payment.txId,
"timestamp" to payment.timestamp,
"amountSat" to payment.amountSat,
"feesSat" to payment.feesSat,
"paymentType" to payment.paymentType.name.lowercase(),
"status" to payment.status.name.lowercase(),
"destination" to payment.destination,
"txId" to payment.txId,
"details" to payment.details?.let { readableMapOf(it) },
)

Expand Down
34 changes: 17 additions & 17 deletions packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1350,20 +1350,6 @@ enum BreezSDKLiquidMapper {
}

static func asPayment(payment: [String: Any?]) throws -> Payment {
var destination: String?
if hasNonNilKey(data: payment, key: "destination") {
guard let destinationTmp = payment["destination"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "destination"))
}
destination = destinationTmp
}
var txId: String?
if hasNonNilKey(data: payment, key: "txId") {
guard let txIdTmp = payment["txId"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "txId"))
}
txId = txIdTmp
}
guard let timestamp = payment["timestamp"] as? UInt32 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "timestamp", typeName: "Payment"))
}
Expand All @@ -1383,23 +1369,37 @@ enum BreezSDKLiquidMapper {
}
let status = try asPaymentState(paymentState: statusTmp)

var destination: String?
if hasNonNilKey(data: payment, key: "destination") {
guard let destinationTmp = payment["destination"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "destination"))
}
destination = destinationTmp
}
var txId: String?
if hasNonNilKey(data: payment, key: "txId") {
guard let txIdTmp = payment["txId"] as? String else {
throw SdkError.Generic(message: errUnexpectedValue(fieldName: "txId"))
}
txId = txIdTmp
}
var details: PaymentDetails?
if let detailsTmp = payment["details"] as? [String: Any?] {
details = try asPaymentDetails(paymentDetails: detailsTmp)
}

return Payment(destination: destination, txId: txId, timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, details: details)
return Payment(timestamp: timestamp, amountSat: amountSat, feesSat: feesSat, paymentType: paymentType, status: status, destination: destination, txId: txId, details: details)
}

static func dictionaryOf(payment: Payment) -> [String: Any?] {
return [
"destination": payment.destination == nil ? nil : payment.destination,
"txId": payment.txId == nil ? nil : payment.txId,
"timestamp": payment.timestamp,
"amountSat": payment.amountSat,
"feesSat": payment.feesSat,
"paymentType": valueOf(paymentType: payment.paymentType),
"status": valueOf(paymentState: payment.status),
"destination": payment.destination == nil ? nil : payment.destination,
"txId": payment.txId == nil ? nil : payment.txId,
"details": payment.details == nil ? nil : dictionaryOf(paymentDetails: payment.details!),
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ export interface PayOnchainRequest {
}

export interface Payment {
destination?: string
txId?: string
timestamp: number
amountSat: number
feesSat: number
paymentType: PaymentType
status: PaymentState
destination?: string
txId?: string
details?: PaymentDetails
}

Expand Down

0 comments on commit 23daeef

Please sign in to comment.