mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-19 15:10:34 -04:00
fix(tauri): Emit 'Initiated' progress event once swap lock is aquired (#112)
* fix(tauri): Emit 'Initiated' progress event once swap lock is aquired
This commit is contained in:
parent
83f831ccac
commit
ec86fa13cd
5 changed files with 39 additions and 38 deletions
|
@ -570,12 +570,14 @@ pub async fn buy_xmr(
|
|||
.as_ref()
|
||||
.context("Could not get Monero wallet")?,
|
||||
);
|
||||
|
||||
let env_config = context.config.env_config;
|
||||
let seed = context.config.seed.clone().context("Could not get seed")?;
|
||||
|
||||
let seller_peer_id = seller
|
||||
.extract_peer_id()
|
||||
.context("Seller address must contain peer ID")?;
|
||||
|
||||
context
|
||||
.db
|
||||
.insert_address(seller_peer_id, seller.clone())
|
||||
|
@ -587,6 +589,7 @@ pub async fn buy_xmr(
|
|||
bitcoin_wallet.clone(),
|
||||
(seed.derive_libp2p_identity(), context.config.namespace),
|
||||
);
|
||||
|
||||
let mut swarm = swarm::cli(
|
||||
seed.derive_libp2p_identity(),
|
||||
context.config.tor_socks5_port,
|
||||
|
@ -605,6 +608,10 @@ pub async fn buy_xmr(
|
|||
|
||||
context.swap_lock.acquire_swap_lock(swap_id).await?;
|
||||
|
||||
context
|
||||
.tauri_handle
|
||||
.emit_swap_progress_event(swap_id, TauriSwapProgressEvent::RequestingQuote);
|
||||
|
||||
let initialize_swap = tokio::select! {
|
||||
biased;
|
||||
_ = context.swap_lock.listen_for_swap_force_suspension() => {
|
||||
|
@ -632,6 +639,7 @@ pub async fn buy_xmr(
|
|||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
tracing::error!(%swap_id, "Swap initialization failed: {:#}", error);
|
||||
|
||||
context
|
||||
.swap_lock
|
||||
.release_swap_lock()
|
||||
|
@ -750,7 +758,6 @@ pub async fn resume_swap(
|
|||
context: Arc<Context>,
|
||||
) -> Result<ResumeSwapResponse> {
|
||||
let ResumeSwapArgs { swap_id } = resume;
|
||||
context.swap_lock.acquire_swap_lock(swap_id).await?;
|
||||
|
||||
let seller_peer_id = context.db.get_peer_id(swap_id).await?;
|
||||
let seller_addresses = context.db.get_addresses(seller_peer_id).await?;
|
||||
|
@ -778,6 +785,7 @@ pub async fn resume_swap(
|
|||
|
||||
tracing::debug!(peer_id = %our_peer_id, "Network layer initialized");
|
||||
|
||||
// Fetch the seller's addresses from the database and add them to the swarm
|
||||
for seller_address in seller_addresses {
|
||||
swarm
|
||||
.behaviour_mut()
|
||||
|
@ -786,7 +794,9 @@ pub async fn resume_swap(
|
|||
|
||||
let (event_loop, event_loop_handle) =
|
||||
EventLoop::new(swap_id, swarm, seller_peer_id, context.db.clone())?;
|
||||
|
||||
let monero_receive_address = context.db.get_monero_address(swap_id).await?;
|
||||
|
||||
let swap = Swap::from_db(
|
||||
Arc::clone(&context.db),
|
||||
swap_id,
|
||||
|
@ -809,6 +819,12 @@ pub async fn resume_swap(
|
|||
.await?
|
||||
.with_event_emitter(context.tauri_handle.clone());
|
||||
|
||||
context.swap_lock.acquire_swap_lock(swap_id).await?;
|
||||
|
||||
context
|
||||
.tauri_handle
|
||||
.emit_swap_progress_event(swap_id, TauriSwapProgressEvent::Resuming);
|
||||
|
||||
context.tasks.clone().spawn(
|
||||
async move {
|
||||
let handle = tokio::spawn(event_loop.run().in_current_span());
|
||||
|
|
|
@ -118,7 +118,8 @@ pub struct TauriSwapProgressEventWrapper {
|
|||
#[serde(tag = "type", content = "content")]
|
||||
#[typeshare]
|
||||
pub enum TauriSwapProgressEvent {
|
||||
Initiated,
|
||||
RequestingQuote,
|
||||
Resuming,
|
||||
ReceivedQuote(BidQuote),
|
||||
WaitingForBtcDeposit {
|
||||
#[typeshare(serialized_as = "string")]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue