diff --git a/mutiny-core/src/nodemanager.rs b/mutiny-core/src/nodemanager.rs index 838c093f1..99b178101 100644 --- a/mutiny-core/src/nodemanager.rs +++ b/mutiny-core/src/nodemanager.rs @@ -821,7 +821,17 @@ impl NodeManager { let address = Address::from_str(&uri.address.to_string()) .map_err(|_| MutinyError::PayjoinConfigError)?; let original_psbt = self.wallet.create_signed_psbt(address, amount, fee_rate)?; - // TODO ensure this creates a pending tx in the UI. Ensure locked UTXO. + // Track this transaction in the wallet so it shows as an ActivityItem in UI. + // We'll cancel it if and when this original_psbt fallback is replaced with a payjoin. + // TODO mark as a payjoin + self.wallet + .insert_tx( + original_psbt.clone().extract_tx(), + ConfirmationTime::unconfirmed(crate::utils::now().as_secs()), + None, + ) + .await?; + let fee_rate = if let Some(rate) = fee_rate { FeeRate::from_sat_per_vb(rate) } else { @@ -856,6 +866,7 @@ impl NodeManager { let proposal_psbt = match Self::poll_payjoin_sender(stop, req_ctx).await { Ok(psbt) => psbt, Err(e) => { + // self.wallet cancel_tx log_error!(logger, "Error polling payjoin sender: {e}"); return; } @@ -924,11 +935,13 @@ impl NodeManager { labels: Vec, ) -> Result { log_debug!(logger, "Sending payjoin.."); + let original_tx = original_psbt.clone().extract_tx(); let tx = wallet .send_payjoin(original_psbt, proposal_psbt, labels) .await?; let txid = tx.txid(); wallet.broadcast_transaction(tx).await?; + wallet.cancel_tx(&original_tx)?; log_info!(logger, "Payjoin broadcast! TXID: {txid}"); Ok(txid) } diff --git a/mutiny-core/src/onchain.rs b/mutiny-core/src/onchain.rs index 3deee44d1..3544db7a7 100644 --- a/mutiny-core/src/onchain.rs +++ b/mutiny-core/src/onchain.rs @@ -279,6 +279,12 @@ impl OnChainWallet { Ok(()) } + pub(crate) fn cancel_tx(&self, tx: &Transaction) -> Result<(), MutinyError> { + let mut wallet = self.wallet.try_write()?; + wallet.cancel_tx(&tx); + Ok(()) + } + fn is_mine(&self, script: &Script) -> Result { Ok(self.wallet.try_read()?.is_mine(script)) }