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,7 +55,7 @@ function getActiveStep(state: SwapState | null): PathStep | null {
case "RequestingQuote": case "RequestingQuote":
case "ReceivedQuote": case "ReceivedQuote":
case "WaitingForBtcDeposit": case "WaitingForBtcDeposit":
case "Started": case "SwapSetupInflight":
return [PathType.HAPPY_PATH, 0, isReleased]; return [PathType.HAPPY_PATH, 0, isReleased];
// Step 1: Waiting for Bitcoin lock confirmation // Step 1: Waiting for Bitcoin lock confirmation

View file

@ -11,7 +11,7 @@ import BitcoinRedeemedPage from "./in_progress/BitcoinRedeemedPage";
import CancelTimelockExpiredPage from "./in_progress/CancelTimelockExpiredPage"; import CancelTimelockExpiredPage from "./in_progress/CancelTimelockExpiredPage";
import EncryptedSignatureSentPage from "./in_progress/EncryptedSignatureSentPage"; import EncryptedSignatureSentPage from "./in_progress/EncryptedSignatureSentPage";
import ReceivedQuotePage from "./in_progress/ReceivedQuotePage"; 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 XmrLockedPage from "./in_progress/XmrLockedPage";
import XmrLockTxInMempoolPage from "./in_progress/XmrLockInMempoolPage"; import XmrLockTxInMempoolPage from "./in_progress/XmrLockInMempoolPage";
import InitPage from "./init/InitPage"; import InitPage from "./init/InitPage";
@ -31,8 +31,8 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
return <ReceivedQuotePage />; return <ReceivedQuotePage />;
case "WaitingForBtcDeposit": case "WaitingForBtcDeposit":
return <WaitingForBitcoinDepositPage {...state.curr.content} />; return <WaitingForBitcoinDepositPage {...state.curr.content} />;
case "Started": case "SwapSetupInflight":
return <StartedPage {...state.curr.content} />; return <SwapSetupInflightPage {...state.curr.content} />;
case "BtcLockTxInMempool": case "BtcLockTxInMempool":
return <BitcoinLockTxInMempoolPage {...state.curr.content} />; return <BitcoinLockTxInMempoolPage {...state.curr.content} />;
case "XmrLockTxInMempool": case "XmrLockTxInMempool":

View file

@ -2,16 +2,15 @@ import { TauriSwapProgressEventContent } from "models/tauriModelExt";
import { SatsAmount } from "renderer/components/other/Units"; import { SatsAmount } from "renderer/components/other/Units";
import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle"; import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle";
export default function StartedPage({ export default function SwapSetupInflightPage({
btc_lock_amount, btc_lock_amount,
btc_tx_lock_fee, btc_tx_lock_fee,
}: TauriSwapProgressEventContent<"Started">) { }: TauriSwapProgressEventContent<"SwapSetupInflight">) {
return ( return (
<CircularProgressWithSubtitle <CircularProgressWithSubtitle
description={ description={
<> <>
Locking <SatsAmount amount={btc_lock_amount} /> with a network fee of{" "} Starting swap with provider to lock <SatsAmount amount={btc_lock_amount} />
<SatsAmount amount={btc_tx_lock_fee} />
</> </>
} }
/> />

View file

@ -24,12 +24,11 @@ export default function WaitingForBtcDepositPage({
min_deposit_until_swap_will_start, min_deposit_until_swap_will_start,
max_deposit_until_maximum_amount_is_reached, max_deposit_until_maximum_amount_is_reached,
min_bitcoin_lock_tx_fee, min_bitcoin_lock_tx_fee,
max_giveable,
quote, quote,
}: TauriSwapProgressEventContent<"WaitingForBtcDeposit">) { }: TauriSwapProgressEventContent<"WaitingForBtcDeposit">) {
const classes = useStyles(); const classes = useStyles();
const bitcoinBalance = useAppSelector((s) => s.rpc.state.balance) || 0;
// TODO: Account for BTC lock tx fees
return ( return (
<Box> <Box>
<DepositAddressInfoBox <DepositAddressInfoBox
@ -39,10 +38,10 @@ export default function WaitingForBtcDepositPage({
<Box className={classes.additionalContent}> <Box className={classes.additionalContent}>
<Typography variant="subtitle2"> <Typography variant="subtitle2">
<ul> <ul>
{bitcoinBalance > 0 ? ( {max_giveable > 0 ? (
<li> <li>
You have already deposited{" "} You have already deposited enough funds to swap
<SatsAmount amount={bitcoinBalance} /> <SatsAmount amount={max_giveable} />. However, that is below the minimum amount required to start the swap.
</li> </li>
) : null} ) : null}
<li> <li>
@ -52,7 +51,7 @@ export default function WaitingForBtcDepositPage({
amount={max_deposit_until_maximum_amount_is_reached} amount={max_deposit_until_maximum_amount_is_reached}
/>{" "} />{" "}
to the address above to the address above
{bitcoinBalance > 0 && ( {max_giveable > 0 && (
<> (on top of the already deposited funds)</> <> (on top of the already deposited funds)</>
)} )}
</li> </li>

View file

@ -149,7 +149,7 @@ pub enum TauriSwapProgressEvent {
min_bitcoin_lock_tx_fee: bitcoin::Amount, min_bitcoin_lock_tx_fee: bitcoin::Amount,
quote: BidQuote, quote: BidQuote,
}, },
Started { SwapSetupInflight {
#[typeshare(serialized_as = "number")] #[typeshare(serialized_as = "number")]
#[serde(with = "::bitcoin::util::amount::serde::as_sat")] #[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc_lock_amount: bitcoin::Amount, btc_lock_amount: bitcoin::Amount,

View file

@ -109,6 +109,16 @@ async fn next_state(
.estimate_fee(TxCancel::weight(), btc_amount) .estimate_fee(TxCancel::weight(), btc_amount)
.await?; .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 let state2 = event_loop_handle
.setup_swap(NewSwap { .setup_swap(NewSwap {
swap_id, swap_id,
@ -146,16 +156,6 @@ async fn next_state(
// Publish the signed Bitcoin lock transaction // Publish the signed Bitcoin lock transaction
let (..) = bitcoin_wallet.broadcast(signed_tx, "lock").await?; 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 { BobState::BtcLocked {
state3, state3,
monero_wallet_restore_blockheight, monero_wallet_restore_blockheight,