mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-11-26 18:56:23 -05:00
fix(tauri_bindings): Emit swap id with WaitingForBtcDeposit event
This commit is contained in:
parent
88cfd6bc3e
commit
de1f77bf80
3 changed files with 32 additions and 13 deletions
|
|
@ -18,13 +18,20 @@ export const swapSlice = createSlice({
|
|||
swap,
|
||||
action: PayloadAction<TauriSwapProgressEventWrapper>,
|
||||
) {
|
||||
// If either:
|
||||
// 1. No swap is currently running
|
||||
// 2. The swap ID of the event does not match the current swap ID
|
||||
//
|
||||
// Then we create a new swap state object that stores the current and previous events
|
||||
if (swap.state === null || action.payload.swap_id !== swap.state.swapId) {
|
||||
console.log("Creating new swap state object");
|
||||
swap.state = {
|
||||
curr: action.payload.event,
|
||||
prev: null,
|
||||
swapId: action.payload.swap_id,
|
||||
};
|
||||
} else {
|
||||
console.log("Updating existing swap state object");
|
||||
swap.state.prev = swap.state.curr;
|
||||
swap.state.curr = action.payload.event;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -104,6 +105,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -142,6 +144,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -176,6 +179,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -210,6 +214,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -248,6 +253,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
|
@ -291,6 +297,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)
|
||||
.await
|
||||
|
|
@ -341,6 +348,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
),
|
||||
)
|
||||
.await
|
||||
|
|
@ -376,6 +384,7 @@ mod tests {
|
|||
|| async { Ok(()) },
|
||||
|_| async { Ok(Amount::from_sat(1000)) },
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.err()
|
||||
|
|
|
|||
|
|
@ -622,7 +622,8 @@ pub async fn buy_xmr(
|
|||
max_givable,
|
||||
|| bitcoin_wallet.sync(),
|
||||
estimate_fee,
|
||||
context.tauri_handle.clone()
|
||||
context.tauri_handle.clone(),
|
||||
Some(swap_id)
|
||||
);
|
||||
|
||||
let (amount, fees) = match determine_amount.await {
|
||||
|
|
@ -1086,6 +1087,7 @@ pub async fn determine_btc_to_swap<FB, TB, FMG, TMG, FS, TS, FFE, TFE>(
|
|||
sync: FS,
|
||||
estimate_fee: FFE,
|
||||
event_emitter: Option<TauriHandle>,
|
||||
swap_id: Option<Uuid>,
|
||||
) -> Result<(bitcoin::Amount, bitcoin::Amount)>
|
||||
where
|
||||
TB: Future<Output = Result<bitcoin::Amount>>,
|
||||
|
|
@ -1143,18 +1145,19 @@ where
|
|||
"Waiting for Bitcoin deposit",
|
||||
);
|
||||
|
||||
// TODO: Use the real swap id here
|
||||
event_emitter.emit_swap_progress_event(
|
||||
Uuid::new_v4(),
|
||||
TauriSwapProgressEvent::WaitingForBtcDeposit {
|
||||
deposit_address: deposit_address.clone(),
|
||||
max_giveable,
|
||||
min_deposit_until_swap_will_start,
|
||||
max_deposit_until_maximum_amount_is_reached,
|
||||
min_bitcoin_lock_tx_fee,
|
||||
quote: bid_quote,
|
||||
},
|
||||
);
|
||||
if let Some(swap_id) = swap_id {
|
||||
event_emitter.emit_swap_progress_event(
|
||||
swap_id,
|
||||
TauriSwapProgressEvent::WaitingForBtcDeposit {
|
||||
deposit_address: deposit_address.clone(),
|
||||
max_giveable,
|
||||
min_deposit_until_swap_will_start,
|
||||
max_deposit_until_maximum_amount_is_reached,
|
||||
min_bitcoin_lock_tx_fee,
|
||||
quote: bid_quote.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
max_giveable = loop {
|
||||
sync().await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue