Skip to content

Commit

Permalink
Add receiver amount to FetchPaymentProposedFeesResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Jan 3, 2025
1 parent b18ad6d commit fa70c0b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ pub(crate) async fn handle_command(
.await?;

let confirmation_msg = format!(
"Payer amount: {} sat. Fees: {} sat. Are the fees acceptable? (y/N) ",
fetch_response.payer_amount_sat, fetch_response.fees_sat
"Payer amount: {} sat. Fees: {} sat. Resulting received amount: {} sat. Are the fees acceptable? (y/N) ",
fetch_response.payer_amount_sat, fetch_response.fees_sat, fetch_response.receiver_amount_sat
);

wait_confirmation!(confirmation_msg, "Payment proposed fees review halted");
Expand Down
1 change: 1 addition & 0 deletions lib/bindings/src/breez_sdk_liquid.udl
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ dictionary FetchPaymentProposedFeesResponse {
string swap_id;
u64 fees_sat;
u64 payer_amount_sat;
u64 receiver_amount_sat;
};

dictionary AcceptPaymentProposedFeesRequest {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,8 @@ pub struct FetchPaymentProposedFeesResponse {
pub fees_sat: u64,
/// Amount sent by the swap payer
pub payer_amount_sat: u64,
/// Amount that will be received if these fees are accepted
pub receiver_amount_sat: u64,
}

/// An argument when calling [crate::sdk::LiquidSdk::accept_payment_proposed_fees].
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2614,6 +2614,7 @@ impl LiquidSdk {
swap_id: req.swap_id.clone(),
fees_sat,
payer_amount_sat: actual_payer_amount_sat,
receiver_amount_sat: actual_payer_amount_sat - fees_sat,
})
}

Expand All @@ -2628,6 +2629,7 @@ impl LiquidSdk {
swap_id,
fees_sat,
payer_amount_sat,
..
} = req.clone().response;

let chain_swap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ fun asFetchPaymentProposedFeesResponse(fetchPaymentProposedFeesResponse: Readabl
"swapId",
"feesSat",
"payerAmountSat",
"receiverAmountSat",
),
)
) {
Expand All @@ -560,14 +561,16 @@ fun asFetchPaymentProposedFeesResponse(fetchPaymentProposedFeesResponse: Readabl
val swapId = fetchPaymentProposedFeesResponse.getString("swapId")!!
val feesSat = fetchPaymentProposedFeesResponse.getDouble("feesSat").toULong()
val payerAmountSat = fetchPaymentProposedFeesResponse.getDouble("payerAmountSat").toULong()
return FetchPaymentProposedFeesResponse(swapId, feesSat, payerAmountSat)
val receiverAmountSat = fetchPaymentProposedFeesResponse.getDouble("receiverAmountSat").toULong()
return FetchPaymentProposedFeesResponse(swapId, feesSat, payerAmountSat, receiverAmountSat)
}

fun readableMapOf(fetchPaymentProposedFeesResponse: FetchPaymentProposedFeesResponse): ReadableMap =
readableMapOf(
"swapId" to fetchPaymentProposedFeesResponse.swapId,
"feesSat" to fetchPaymentProposedFeesResponse.feesSat,
"payerAmountSat" to fetchPaymentProposedFeesResponse.payerAmountSat,
"receiverAmountSat" to fetchPaymentProposedFeesResponse.receiverAmountSat,
)

fun asFetchPaymentProposedFeesResponseList(arr: ReadableArray): List<FetchPaymentProposedFeesResponse> {
Expand Down
6 changes: 5 additions & 1 deletion packages/react-native/ios/BreezSDKLiquidMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -633,15 +633,19 @@ enum BreezSDKLiquidMapper {
guard let payerAmountSat = fetchPaymentProposedFeesResponse["payerAmountSat"] as? UInt64 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "payerAmountSat", typeName: "FetchPaymentProposedFeesResponse"))
}
guard let receiverAmountSat = fetchPaymentProposedFeesResponse["receiverAmountSat"] as? UInt64 else {
throw SdkError.Generic(message: errMissingMandatoryField(fieldName: "receiverAmountSat", typeName: "FetchPaymentProposedFeesResponse"))
}

return FetchPaymentProposedFeesResponse(swapId: swapId, feesSat: feesSat, payerAmountSat: payerAmountSat)
return FetchPaymentProposedFeesResponse(swapId: swapId, feesSat: feesSat, payerAmountSat: payerAmountSat, receiverAmountSat: receiverAmountSat)
}

static func dictionaryOf(fetchPaymentProposedFeesResponse: FetchPaymentProposedFeesResponse) -> [String: Any?] {
return [
"swapId": fetchPaymentProposedFeesResponse.swapId,
"feesSat": fetchPaymentProposedFeesResponse.feesSat,
"payerAmountSat": fetchPaymentProposedFeesResponse.payerAmountSat,
"receiverAmountSat": fetchPaymentProposedFeesResponse.receiverAmountSat,
]
}

Expand Down
1 change: 1 addition & 0 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface FetchPaymentProposedFeesResponse {
swapId: string
feesSat: number
payerAmountSat: number
receiverAmountSat: number
}

export interface FiatCurrency {
Expand Down

0 comments on commit fa70c0b

Please sign in to comment.