From de1f77bf802a1fb8a56de5e75b5b4802aa0726de Mon Sep 17 00:00:00 2001 From: binarybaron Date: Tue, 27 Aug 2024 15:23:43 +0200 Subject: [PATCH] fix(tauri_bindings): Emit swap id with WaitingForBtcDeposit event --- src-gui/src/store/features/swapSlice.ts | 7 ++++++ swap/src/bin/swap.rs | 9 ++++++++ swap/src/cli/api/request.rs | 29 ++++++++++++++----------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src-gui/src/store/features/swapSlice.ts b/src-gui/src/store/features/swapSlice.ts index 7d093219..14e66617 100644 --- a/src-gui/src/store/features/swapSlice.ts +++ b/src-gui/src/store/features/swapSlice.ts @@ -18,13 +18,20 @@ export const swapSlice = createSlice({ swap, action: PayloadAction, ) { + // 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; } diff --git a/swap/src/bin/swap.rs b/swap/src/bin/swap.rs index 3479b676..941bf18d 100644 --- a/swap/src/bin/swap.rs +++ b/swap/src/bin/swap.rs @@ -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() diff --git a/swap/src/cli/api/request.rs b/swap/src/cli/api/request.rs index a565934b..f15f1f39 100644 --- a/swap/src/cli/api/request.rs +++ b/swap/src/cli/api/request.rs @@ -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( sync: FS, estimate_fee: FFE, event_emitter: Option, + swap_id: Option, ) -> Result<(bitcoin::Amount, bitcoin::Amount)> where TB: Future>, @@ -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?;