From eac435aba630dab1a2368d440d062e53edddd479 Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:18:13 +0100 Subject: [PATCH] feat(gui): Display state page for inflight swap setup (#158) We now display a "Starting swap with provider to lock ... BTC" page when the Bitcoin have been deposited and the swap setup is inflight. --- .../modal/swap/SwapStateStepper.tsx | 10 +++++----- .../modal/swap/pages/SwapStatePage.tsx | 8 ++++---- ...rtedPage.tsx => SwapSetupInflightPage.tsx} | 7 +++---- .../init/WaitingForBitcoinDepositPage.tsx | 11 +++++----- swap/src/cli/api/tauri_bindings.rs | 2 +- swap/src/protocol/bob/swap.rs | 20 +++++++++---------- 6 files changed, 28 insertions(+), 30 deletions(-) rename src-gui/src/renderer/components/modal/swap/pages/in_progress/{StartedPage.tsx => SwapSetupInflightPage.tsx} (62%) diff --git a/src-gui/src/renderer/components/modal/swap/SwapStateStepper.tsx b/src-gui/src/renderer/components/modal/swap/SwapStateStepper.tsx index 74d5ac19..8b45de64 100644 --- a/src-gui/src/renderer/components/modal/swap/SwapStateStepper.tsx +++ b/src-gui/src/renderer/components/modal/swap/SwapStateStepper.tsx @@ -55,14 +55,14 @@ function getActiveStep(state: SwapState | null): PathStep | null { case "RequestingQuote": case "ReceivedQuote": case "WaitingForBtcDeposit": - case "Started": + case "SwapSetupInflight": return [PathType.HAPPY_PATH, 0, isReleased]; // Step 1: Waiting for Bitcoin lock confirmation // Bitcoin has been locked, waiting for the counterparty to lock their XMR case "BtcLockTxInMempool": // We only display the first step as completed if the Bitcoin lock has been confirmed - if(latestState.content.btc_lock_confirmations > 0) { + if (latestState.content.btc_lock_confirmations > 0) { return [PathType.HAPPY_PATH, 1, isReleased]; } return [PathType.HAPPY_PATH, 0, isReleased]; @@ -86,7 +86,7 @@ function getActiveStep(state: SwapState | null): PathStep | null { // XMR redemption transaction is in mempool, swap is essentially complete case "XmrRedeemInMempool": return [PathType.HAPPY_PATH, 4, false]; - + // Unhappy Path States // Step 1: Cancel timelock has expired. Waiting for cancel transaction to be published @@ -117,8 +117,8 @@ function getActiveStep(state: SwapState | null): PathStep | null { return null; default: return fallbackStep("No step is assigned to the current state"); - // TODO: Make this guard work. It should force the compiler to check if we have covered all possible cases. - // return exhaustiveGuard(latestState.type); + // TODO: Make this guard work. It should force the compiler to check if we have covered all possible cases. + // return exhaustiveGuard(latestState.type); } } diff --git a/src-gui/src/renderer/components/modal/swap/pages/SwapStatePage.tsx b/src-gui/src/renderer/components/modal/swap/pages/SwapStatePage.tsx index c954473c..20e0d4d2 100644 --- a/src-gui/src/renderer/components/modal/swap/pages/SwapStatePage.tsx +++ b/src-gui/src/renderer/components/modal/swap/pages/SwapStatePage.tsx @@ -11,7 +11,7 @@ import BitcoinRedeemedPage from "./in_progress/BitcoinRedeemedPage"; import CancelTimelockExpiredPage from "./in_progress/CancelTimelockExpiredPage"; import EncryptedSignatureSentPage from "./in_progress/EncryptedSignatureSentPage"; import ReceivedQuotePage from "./in_progress/ReceivedQuotePage"; -import StartedPage from "./in_progress/StartedPage"; +import SwapSetupInflightPage from "./in_progress/SwapSetupInflightPage"; import XmrLockedPage from "./in_progress/XmrLockedPage"; import XmrLockTxInMempoolPage from "./in_progress/XmrLockInMempoolPage"; import InitPage from "./init/InitPage"; @@ -21,7 +21,7 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) { if (state === null) { return ; } - + switch (state.curr.type) { case "RequestingQuote": return ; @@ -31,8 +31,8 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) { return ; case "WaitingForBtcDeposit": return ; - case "Started": - return ; + case "SwapSetupInflight": + return ; case "BtcLockTxInMempool": return ; case "XmrLockTxInMempool": diff --git a/src-gui/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx b/src-gui/src/renderer/components/modal/swap/pages/in_progress/SwapSetupInflightPage.tsx similarity index 62% rename from src-gui/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx rename to src-gui/src/renderer/components/modal/swap/pages/in_progress/SwapSetupInflightPage.tsx index a338365d..b99abba9 100644 --- a/src-gui/src/renderer/components/modal/swap/pages/in_progress/StartedPage.tsx +++ b/src-gui/src/renderer/components/modal/swap/pages/in_progress/SwapSetupInflightPage.tsx @@ -2,16 +2,15 @@ import { TauriSwapProgressEventContent } from "models/tauriModelExt"; import { SatsAmount } from "renderer/components/other/Units"; import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle"; -export default function StartedPage({ +export default function SwapSetupInflightPage({ btc_lock_amount, btc_tx_lock_fee, -}: TauriSwapProgressEventContent<"Started">) { +}: TauriSwapProgressEventContent<"SwapSetupInflight">) { return ( - Locking with a network fee of{" "} - + Starting swap with provider to lock } /> diff --git a/src-gui/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx b/src-gui/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx index 17cdc5fb..1ec8c218 100644 --- a/src-gui/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx +++ b/src-gui/src/renderer/components/modal/swap/pages/init/WaitingForBitcoinDepositPage.tsx @@ -24,12 +24,11 @@ export default function WaitingForBtcDepositPage({ min_deposit_until_swap_will_start, max_deposit_until_maximum_amount_is_reached, min_bitcoin_lock_tx_fee, + max_giveable, quote, }: TauriSwapProgressEventContent<"WaitingForBtcDeposit">) { const classes = useStyles(); - const bitcoinBalance = useAppSelector((s) => s.rpc.state.balance) || 0; - // TODO: Account for BTC lock tx fees return (
    - {bitcoinBalance > 0 ? ( + {max_giveable > 0 ? (
  • - You have already deposited{" "} - + You have already deposited enough funds to swap + . However, that is below the minimum amount required to start the swap.
  • ) : null}
  • @@ -52,7 +51,7 @@ export default function WaitingForBtcDepositPage({ amount={max_deposit_until_maximum_amount_is_reached} />{" "} to the address above - {bitcoinBalance > 0 && ( + {max_giveable > 0 && ( <> (on top of the already deposited funds) )}
  • diff --git a/swap/src/cli/api/tauri_bindings.rs b/swap/src/cli/api/tauri_bindings.rs index 9335f446..2463a722 100644 --- a/swap/src/cli/api/tauri_bindings.rs +++ b/swap/src/cli/api/tauri_bindings.rs @@ -149,7 +149,7 @@ pub enum TauriSwapProgressEvent { min_bitcoin_lock_tx_fee: bitcoin::Amount, quote: BidQuote, }, - Started { + SwapSetupInflight { #[typeshare(serialized_as = "number")] #[serde(with = "::bitcoin::util::amount::serde::as_sat")] btc_lock_amount: bitcoin::Amount, diff --git a/swap/src/protocol/bob/swap.rs b/swap/src/protocol/bob/swap.rs index 0639e5a3..88063854 100644 --- a/swap/src/protocol/bob/swap.rs +++ b/swap/src/protocol/bob/swap.rs @@ -109,6 +109,16 @@ async fn next_state( .estimate_fee(TxCancel::weight(), btc_amount) .await?; + // Emit an event to tauri that we are negotiating with the swap provider to lock the Bitcoin + event_emitter.emit_swap_progress_event( + swap_id, + TauriSwapProgressEvent::SwapSetupInflight { + btc_lock_amount: btc_amount, + // TODO: Replace this with the actual fee + btc_tx_lock_fee: bitcoin::Amount::ZERO, + }, + ); + let state2 = event_loop_handle .setup_swap(NewSwap { swap_id, @@ -146,16 +156,6 @@ async fn next_state( // Publish the signed Bitcoin lock transaction let (..) = bitcoin_wallet.broadcast(signed_tx, "lock").await?; - // Emit an event to tauri that the the swap started - event_emitter.emit_swap_progress_event( - swap_id, - TauriSwapProgressEvent::Started { - btc_lock_amount: tx_lock.lock_amount(), - // TODO: Replace this with the actual fee - btc_tx_lock_fee: bitcoin::Amount::ZERO, - }, - ); - BobState::BtcLocked { state3, monero_wallet_restore_blockheight,