Skip to content

Commit

Permalink
DRAFT push payjoin details to transaction model
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Dec 22, 2024
1 parent 5dff85b commit eb177e6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/_model/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/_pkg/wallet/bdk/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ class BDKTransactions {
required List<UTXO> selectedUtxos,
int? absFee,
String? note,
bool isPayjoin = false,
}) async {
try {
final isMainnet = wallet.network == BBNetwork.Mainnet;
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions lib/_pkg/wallet/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class WalletTx implements IWalletTransactions {
required bool enableRbf,
List<UTXO>? selectedUtxos,
int? absFee,
bool isPayjoin = false,
}) async {
try {
switch (wallet.baseWalletType) {
Expand All @@ -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!;
Expand All @@ -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();
Expand Down
28 changes: 18 additions & 10 deletions lib/send/bloc/send_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,14 @@ class SendCubit extends Cubit<SendState> {
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,
Expand Down Expand Up @@ -951,8 +959,16 @@ class SendCubit extends Cubit<SendState> {
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,
Expand Down Expand Up @@ -1170,14 +1186,6 @@ class SendCubit extends Cubit<SendState> {
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<WalletBloc>().state.wallet;
Expand Down
5 changes: 5 additions & 0 deletions lib/transaction/transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit eb177e6

Please sign in to comment.