@@ -767,7 +767,16 @@ impl<S: MutinyStorage> NodeManager<S> {
767767 . map_err ( |_| MutinyError :: IncorrectNetwork ) ?;
768768 let address = uri. address . clone ( ) ;
769769 let original_psbt = self . wallet . create_signed_psbt ( address, amount, fee_rate) ?;
770- // TODO ensure this creates a pending tx in the UI. Ensure locked UTXO.
770+ // Track this transaction in the wallet so it shows as an ActivityItem in UI.
771+ // We'll cancel it if and when this original_psbt fallback is replaced with a received payjoin.
772+ self . wallet
773+ . insert_tx (
774+ original_psbt. clone ( ) . extract_tx ( ) ,
775+ ConfirmationTime :: unconfirmed ( crate :: utils:: now ( ) . as_secs ( ) ) ,
776+ None ,
777+ )
778+ . await ?;
779+
771780 let fee_rate = if let Some ( rate) = fee_rate {
772781 FeeRate :: from_sat_per_vb ( rate)
773782 } else {
@@ -798,6 +807,7 @@ impl<S: MutinyStorage> NodeManager<S> {
798807 let proposal_psbt = match Self :: poll_payjoin_sender ( stop, req_ctx) . await {
799808 Ok ( psbt) => psbt,
800809 Err ( e) => {
810+ // self.wallet cancel_tx
801811 log_error ! ( logger, "Error polling payjoin sender: {e}" ) ;
802812 return ;
803813 }
@@ -867,11 +877,13 @@ impl<S: MutinyStorage> NodeManager<S> {
867877 labels : Vec < String > ,
868878 ) -> Result < Txid , MutinyError > {
869879 log_debug ! ( logger, "Sending payjoin.." ) ;
880+ let original_tx = original_psbt. clone ( ) . extract_tx ( ) ;
870881 let tx = wallet
871882 . send_payjoin ( original_psbt, proposal_psbt, labels)
872883 . await ?;
873884 let txid = tx. txid ( ) ;
874885 wallet. broadcast_transaction ( tx) . await ?;
886+ wallet. cancel_tx ( & original_tx) ?;
875887 log_info ! ( logger, "Payjoin broadcast! TXID: {txid}" ) ;
876888 Ok ( txid)
877889 }
@@ -899,12 +911,18 @@ impl<S: MutinyStorage> NodeManager<S> {
899911 let http_client = reqwest:: Client :: builder ( )
900912 . build ( )
901913 . map_err ( PayjoinError :: Reqwest ) ?;
902- let proposal: payjoin:: receive:: v2:: UncheckedProposal =
903- Self :: poll_for_fallback_psbt ( stop, storage, & http_client, & mut session)
904- . await
905- . map_err ( |e| PayjoinError :: ReceiverStateMachine ( e. to_string ( ) ) ) ?;
914+ let proposal: payjoin:: receive:: v2:: UncheckedProposal = Self :: poll_for_fallback_psbt (
915+ stop,
916+ wallet. clone ( ) ,
917+ storage. clone ( ) ,
918+ & http_client,
919+ & mut session,
920+ )
921+ . await
922+ . map_err ( |e| PayjoinError :: ReceiverStateMachine ( e. to_string ( ) ) ) ?;
906923 let mut payjoin_proposal = wallet
907924 . process_payjoin_proposal ( proposal)
925+ . await
908926 . map_err ( |e| PayjoinError :: ReceiverStateMachine ( e. to_string ( ) ) ) ?;
909927
910928 let ( req, ohttp_ctx) = payjoin_proposal
@@ -922,11 +940,23 @@ impl<S: MutinyStorage> NodeManager<S> {
922940 let _res = payjoin_proposal
923941 . deserialize_res ( res. to_vec ( ) , ohttp_ctx)
924942 . map_err ( |e| PayjoinError :: ReceiverStateMachine ( e. to_string ( ) ) ) ?;
925- Ok ( payjoin_proposal. psbt ( ) . clone ( ) . extract_tx ( ) . txid ( ) )
943+ let payjoin_tx = payjoin_proposal. psbt ( ) . clone ( ) . extract_tx ( ) ;
944+ let payjoin_txid = payjoin_tx. txid ( ) ;
945+ wallet
946+ . insert_tx (
947+ payjoin_tx. clone ( ) ,
948+ ConfirmationTime :: unconfirmed ( utils:: now ( ) . as_secs ( ) ) ,
949+ None ,
950+ )
951+ . await ?;
952+ session. payjoin_tx = Some ( payjoin_tx) ;
953+ storage. update_session ( session) ?;
954+ Ok ( payjoin_txid)
926955 }
927956
928957 async fn poll_for_fallback_psbt (
929958 stop : Arc < AtomicBool > ,
959+ wallet : Arc < OnChainWallet < S > > ,
930960 storage : Arc < S > ,
931961 client : & reqwest:: Client ,
932962 session : & mut crate :: payjoin:: Session ,
@@ -937,6 +967,11 @@ impl<S: MutinyStorage> NodeManager<S> {
937967 }
938968
939969 if session. expiry < utils:: now ( ) {
970+ if let Some ( payjoin_tx) = & session. payjoin_tx {
971+ wallet
972+ . cancel_tx ( payjoin_tx)
973+ . map_err ( |_| crate :: payjoin:: Error :: CancelPayjoinTx ) ?;
974+ }
940975 let _ = storage. delete_payjoin ( & session. enrolled . pubkey ( ) ) ;
941976 return Err ( crate :: payjoin:: Error :: SessionExpired ) ;
942977 }
0 commit comments