From e9816ead4fe5562ab6153938fbb843cdc66ac757 Mon Sep 17 00:00:00 2001 From: ethicnology Date: Mon, 23 Dec 2024 14:34:19 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20payjoin=20is=20disabled=20if=20utxos=20?= =?UTF-8?q?are=20empty=20for=20the=20selected=20wallet=20=E2=80=93>=20Clos?= =?UTF-8?q?e=20#357?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/receive/bloc/receive_cubit.dart | 76 ++++++++--------------------- lib/receive/bloc/state.dart | 1 + lib/receive/receive_page.dart | 23 ++++++++- 3 files changed, 43 insertions(+), 57 deletions(-) diff --git a/lib/receive/bloc/receive_cubit.dart b/lib/receive/bloc/receive_cubit.dart index 83409f6c..e44340d6 100644 --- a/lib/receive/bloc/receive_cubit.dart +++ b/lib/receive/bloc/receive_cubit.dart @@ -31,11 +31,7 @@ class ReceiveCubit extends Cubit { final PayjoinManager _payjoinManager; Future updatePayjoinEndpoint(String payjoinEndpoint) async { - emit( - state.copyWith( - payjoinEndpoint: payjoinEndpoint, - ), - ); + emit(state.copyWith(payjoinEndpoint: payjoinEndpoint)); return; } @@ -45,7 +41,6 @@ class ReceiveCubit extends Cubit { state.copyWith( walletBloc: walletBloc, defaultAddress: null, - // privateLabel: '', savedDescription: '', description: '', ), @@ -60,24 +55,19 @@ class ReceiveCubit extends Cubit { emit(state.copyWith(paymentNetwork: PaymentNetwork.bitcoin)); } - // final watchOnly = walletBloc.state.wallet!.watchOnly(); - // if (watchOnly) - // emit(state.copyWith(paymentNetwork: ReceivePaymentNetwork.bitcoin)); + await isPayjoinEnabled(); await loadAddress(); if (state.paymentNetwork == PaymentNetwork.bitcoin && - state.defaultAddress != null) { + state.defaultAddress != null && + state.isPayjoin) { receivePayjoin( state.walletBloc!.state.wallet!.isTestnet(), state.defaultAddress!.address, ); } else { // Clear payjoin receiver - emit( - state.copyWith( - payjoinReceiver: null, - ), - ); + emit(state.copyWith(payjoinReceiver: null)); } } @@ -86,8 +76,6 @@ class ReceiveCubit extends Cubit { bool isTestnet, { bool onStart = false, }) { - // if (!isTestnet) return; - if (!state.allowedSwitch(selectedPaymentNetwork)) return; if (onStart) { @@ -124,33 +112,6 @@ class ReceiveCubit extends Cubit { emit(state.copyWith(switchToInstant: true)); return; } - - // if (walletType == BBWalletType.instant && - // currentPayNetwork != ReceivePaymentNetwork.bitcoin && - // selectedPaymentNetwork == ReceivePaymentNetwork.bitcoin) { - // emit(state.copyWith(switchToSecure: true)); - // return; - // } - - // if (walletType == BBWalletType.instant && - // currentPayNetwork != ReceivePaymentNetwork.liquid && - // selectedPaymentNetwork == ReceivePaymentNetwork.liquid) { - // return; - // } - - // if (walletType == BBWalletType.secure && - // currentPayNetwork != ReceivePaymentNetwork.lightning && - // selectedPaymentNetwork == ReceivePaymentNetwork.lightning) { - // // Allow LN -> BTC swap - // return; - // } - - // if (walletType == BBWalletType.secure && - // currentPayNetwork != ReceivePaymentNetwork.liquid && - // selectedPaymentNetwork == ReceivePaymentNetwork.liquid) { - // // Allow LBTC -> BTC swap - // return; - // } } void clearSwitch() { @@ -255,15 +216,11 @@ class ReceiveCubit extends Cubit { if (address == null) return; if (!isLiq && state.defaultAddress != null) { - emit( - state.copyWith(description: address.label ?? ''), - ); + emit(state.copyWith(description: address.label ?? '')); } if (isLiq && state.defaultLiquidAddress != null) { - emit( - state.copyWith(description: address.label ?? ''), - ); + emit(state.copyWith(description: address.label ?? '')); } } @@ -271,10 +228,7 @@ class ReceiveCubit extends Cubit { if (state.paymentNetwork == PaymentNetwork.lightning) return; emit( - state.copyWith( - errLoadingAddress: '', - savedInvoiceAmount: 0, - ), + state.copyWith(errLoadingAddress: '', savedInvoiceAmount: 0), ); if (state.walletBloc == null) return; @@ -315,7 +269,6 @@ class ReceiveCubit extends Cubit { 'WARNING! Electrum stop gap has been increased to $addressGap. This will affect your wallet sync time.\nGoto WalletSettings->Addresses to see all generated addresses.', ), ); - // _networkCubit.updateStopGapAndSave(addressGap + 1); emit(state.copyWith(updateAddressGap: addressGap + 1)); Future.delayed(const Duration(milliseconds: 100)); } @@ -337,7 +290,6 @@ class ReceiveCubit extends Cubit { state.copyWith( defaultLiquidAddress: updatedWallet.lastGeneratedAddress, defaultAddress: updatedWallet.lastGeneratedAddress, - // privateLabel: '', savedDescription: '', description: '', ), @@ -399,4 +351,16 @@ class ReceiveCubit extends Cubit { wallet: state.walletBloc!.state.wallet!, ); } + + Future isPayjoinEnabled() async { + final walletBloc = state.walletBloc; + final wallet = walletBloc?.state.wallet; + if (walletBloc == null || wallet == null) return; + + if (wallet.utxos.isEmpty) { + emit(state.copyWith(isPayjoin: false)); + } else { + emit(state.copyWith(isPayjoin: true)); + } + } } diff --git a/lib/receive/bloc/state.dart b/lib/receive/bloc/state.dart index ffc1e3a0..449e3541 100644 --- a/lib/receive/bloc/state.dart +++ b/lib/receive/bloc/state.dart @@ -11,6 +11,7 @@ part 'state.freezed.dart'; class ReceiveState with _$ReceiveState { const factory ReceiveState({ @Default(true) bool loadingAddress, + @Default(true) bool isPayjoin, @Default('') String errLoadingAddress, Address? defaultAddress, Address? defaultLiquidAddress, diff --git a/lib/receive/receive_page.dart b/lib/receive/receive_page.dart index 7e05f588..70c8b20d 100644 --- a/lib/receive/receive_page.dart +++ b/lib/receive/receive_page.dart @@ -1087,8 +1087,10 @@ class _ReceiveDisplayAddressState extends State { context.select((ReceiveCubit x) => x.state.paymentNetwork); String receiveAddressLabel = 'Payment invoice'; + final isPayjoin = context.select((ReceiveCubit _) => _.state.isPayjoin); + if (paymentNetwork == PaymentNetwork.bitcoin) { - receiveAddressLabel = 'Bitcoin address'; + receiveAddressLabel = isPayjoin ? 'Payjoin address' : 'Bitcoin address'; } else if (paymentNetwork == PaymentNetwork.liquid) { receiveAddressLabel = 'Liquid address'; } @@ -1122,6 +1124,25 @@ class _ReceiveDisplayAddressState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ BBText.body(receiveAddressLabel), + if (isPayjoin == false && paymentNetwork == PaymentNetwork.bitcoin) + Card( + color: Colors.yellow[100], + margin: const EdgeInsets.all(10), + child: const ListTile( + leading: Icon(Icons.warning, color: Colors.orange), + title: Text( + 'Payjoin transactions', + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + subtitle: Text( + 'Wallet does not meet the criteria', + style: TextStyle(color: Colors.black87), + ), + ), + ), Row( children: [ Expanded(