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.
This commit is contained in:
binarybaron 2024-11-13 20:18:13 +01:00 committed by GitHub
parent 6b6737c056
commit eac435aba6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 30 deletions

View file

@ -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);
}
}

View file

@ -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 <InitPage />;
}
switch (state.curr.type) {
case "RequestingQuote":
return <CircularProgressWithSubtitle description="Requesting quote..." />;
@ -31,8 +31,8 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
return <ReceivedQuotePage />;
case "WaitingForBtcDeposit":
return <WaitingForBitcoinDepositPage {...state.curr.content} />;
case "Started":
return <StartedPage {...state.curr.content} />;
case "SwapSetupInflight":
return <SwapSetupInflightPage {...state.curr.content} />;
case "BtcLockTxInMempool":
return <BitcoinLockTxInMempoolPage {...state.curr.content} />;
case "XmrLockTxInMempool":

View file

@ -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 (
<CircularProgressWithSubtitle
description={
<>
Locking <SatsAmount amount={btc_lock_amount} /> with a network fee of{" "}
<SatsAmount amount={btc_tx_lock_fee} />
Starting swap with provider to lock <SatsAmount amount={btc_lock_amount} />
</>
}
/>

View file

@ -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 (
<Box>
<DepositAddressInfoBox
@ -39,10 +38,10 @@ export default function WaitingForBtcDepositPage({
<Box className={classes.additionalContent}>
<Typography variant="subtitle2">
<ul>
{bitcoinBalance > 0 ? (
{max_giveable > 0 ? (
<li>
You have already deposited{" "}
<SatsAmount amount={bitcoinBalance} />
You have already deposited enough funds to swap
<SatsAmount amount={max_giveable} />. However, that is below the minimum amount required to start the swap.
</li>
) : null}
<li>
@ -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)</>
)}
</li>

View file

@ -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,

View file

@ -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,