diff --git a/lib/_model/transaction.dart b/lib/_model/transaction.dart index dee4a991..38e8e397 100644 --- a/lib/_model/transaction.dart +++ b/lib/_model/transaction.dart @@ -46,6 +46,7 @@ class Transaction with _$Transaction { bdk.TransactionDetails? bdkTx, // Wallet? wallet, @Default(false) bool isSwap, + @Default(false) bool isPayjoin, SwapTx? swapTx, @Default(false) bool isLiquid, @Default('') String unblindedUrl, diff --git a/lib/_pkg/wallet/bdk/transaction.dart b/lib/_pkg/wallet/bdk/transaction.dart index 8c48259e..1be372c5 100644 --- a/lib/_pkg/wallet/bdk/transaction.dart +++ b/lib/_pkg/wallet/bdk/transaction.dart @@ -439,6 +439,7 @@ class BDKTransactions { required List selectedUtxos, int? absFee, String? note, + bool isPayjoin = false, }) async { try { final isMainnet = wallet.network == BBNetwork.Mainnet; @@ -569,9 +570,10 @@ class BDKTransactions { label: (note == null || note == '') ? labelsString : note, // for now we just take the first label - toAddress: address, + toAddress: isPayjoin ? null : address, outAddrs: outAddrs, psbt: base64Encode(psbtStr), + isPayjoin: isPayjoin, ); return ((tx, feeAmt?.toInt(), base64Encode(psbtStr)), null); } on Exception catch (e) { diff --git a/lib/_pkg/wallet/transaction.dart b/lib/_pkg/wallet/transaction.dart index 8de103be..482e9fc7 100644 --- a/lib/_pkg/wallet/transaction.dart +++ b/lib/_pkg/wallet/transaction.dart @@ -140,6 +140,7 @@ class WalletTx implements IWalletTransactions { required bool enableRbf, List? selectedUtxos, int? absFee, + bool isPayjoin = false, }) async { try { switch (wallet.baseWalletType) { @@ -159,6 +160,7 @@ class WalletTx implements IWalletTransactions { selectedUtxos: selectedUtxos ?? [], note: note, absFee: absFee, + isPayjoin: isPayjoin, ); if (err != null) throw err; final (tx, feeAmt, psbt) = buildResp!; @@ -176,6 +178,15 @@ class WalletTx implements IWalletTransactions { bdkWallet: bdkSignerWallet!, ); if (errSign != null) throw errSign; + if (isPayjoin) { + final signedTx = tx!.copyWith(psbt: signed!.$2); + final txs = wallet.transactions.toList(); + txs.add(signedTx); + final (w, errAdd) = await addUnsignedTxToWallet( + transaction: signedTx, wallet: wallet); + if (errAdd != null) throw errAdd; + return ((w, signedTx, feeAmt), null); + } return ((wallet, tx!.copyWith(psbt: signed!.$2), feeAmt), null); } else { final txs = wallet.transactions.toList(); diff --git a/lib/send/bloc/send_cubit.dart b/lib/send/bloc/send_cubit.dart index e0ccce5d..b0203403 100644 --- a/lib/send/bloc/send_cubit.dart +++ b/lib/send/bloc/send_cubit.dart @@ -900,6 +900,14 @@ class SendCubit extends Cubit { final (wallet, tx, feeAmt) = buildResp!; if (!wallet!.watchOnly()) { + if (state.hasPjParam()) { + await payjoinBuild( + networkFees: networkFees, + originalPsbt: tx!.psbt!, + wallet: wallet, + ); + } + emit( state.copyWith( sending: false, @@ -951,8 +959,16 @@ class SendCubit extends Cubit { if (state.selectedWalletBloc == null) return; if (state.payjoinSender == null) return; - // TODO copy originalPsbt.extractTx() to state.tx - // emit(state.copyWith(tx: originalPsbtTxWithId)); + // Save originalPsbt to history + state.selectedWalletBloc!.add( + UpdateWallet( + wallet, + updateTypes: [ + UpdateWalletTypes.transactions, + ], + ), + ); + emit(state.copyWith(sending: true, sent: false)); await _payjoinManager.spawnSender( isTestnet: _networkCubit.state.testnet, @@ -1170,14 +1186,6 @@ class SendCubit extends Cubit { if (!isLn) { final fees = _networkFeesCubit.state.selectedOrFirst(false); await baseLayerBuild(networkFees: fees); - if (state.hasPjParam()) { - await payjoinBuild( - networkFees: fees, - originalPsbt: state.psbtSigned!, - wallet: wallet, - ); - return; - } return; } // context.read().state.wallet; diff --git a/lib/transaction/transaction_page.dart b/lib/transaction/transaction_page.dart index c3687108..15df4eb0 100644 --- a/lib/transaction/transaction_page.dart +++ b/lib/transaction/transaction_page.dart @@ -285,6 +285,11 @@ class _TxDetails extends StatelessWidget { const Gap(4), AmountValue(isReceived: isReceived, amtStr: amtStr, units: units), const Gap(24), + if (tx.isPayjoin) ...[ + const Gap(24), + const BBText.title('Payjoin'), + const Gap(4), + ], if (!isSwapPending) ...[ const BBText.title('Transaction ID'), const Gap(4),