diff --git a/lib/receive/bloc/receive_cubit.dart b/lib/receive/bloc/receive_cubit.dart index 2d963969..1dd76f12 100644 --- a/lib/receive/bloc/receive_cubit.dart +++ b/lib/receive/bloc/receive_cubit.dart @@ -20,7 +20,6 @@ class ReceiveCubit extends Cubit { WalletBloc? walletBloc, required WalletAddress walletAddress, required WalletsStorageRepository walletsStorageRepository, - required bool defaultPayjoin, required PayjoinSessionStorage payjoinSessionStorage, required PayjoinManager payjoinManager, }) : _walletsStorageRepository = walletsStorageRepository, @@ -33,11 +32,6 @@ class ReceiveCubit extends Cubit { oneWallet: walletBloc != null, ), ) { - emit( - state.copyWith( - disablePayjoin: !defaultPayjoin, - ), - ); loadAddress(); } @@ -69,6 +63,7 @@ class ReceiveCubit extends Cubit { // final watchOnly = walletBloc.state.wallet!.watchOnly(); // if (watchOnly) // emit(state.copyWith(paymentNetwork: ReceivePaymentNetwork.bitcoin)); + isPayjoinDisabled(); loadAddress(); print('state.paymentNetwork: ${state.paymentNetwork}'); if (state.paymentNetwork == PaymentNetwork.bitcoin && @@ -506,4 +501,20 @@ class ReceiveCubit extends Cubit { ); return InputPair.newInstance(txin, psbtin); } + + Future isPayjoinDisabled() async { + final walletBloc = state.walletBloc; + final wallet = walletBloc?.state.wallet; + if (walletBloc == null || wallet == null) return; + + print( + 'payjoin disabled: ${wallet.utxos.isEmpty} –> utxos: ${wallet.utxos.length}', + ); + + if (wallet.utxos.isEmpty) { + emit(state.copyWith(disablePayjoin: true)); + } else { + emit(state.copyWith(disablePayjoin: false)); + } + } } diff --git a/lib/receive/receive_page.dart b/lib/receive/receive_page.dart index 8a517547..34cd6874 100644 --- a/lib/receive/receive_page.dart +++ b/lib/receive/receive_page.dart @@ -83,7 +83,6 @@ class _ReceivePageState extends State { walletAddress: locator(), walletsStorageRepository: locator(), walletBloc: widget.walletBloc, - defaultPayjoin: locator().state.defaultPayjoin, payjoinSessionStorage: locator(), payjoinManager: locator(), ); @@ -1136,6 +1135,9 @@ class _ReceiveDisplayAddressState extends State { final addr = bip21Address.isNotEmpty ? bip21Address : widget.addressQr; + final isPayjoinDisabled = + context.select((ReceiveCubit _) => _.state.disablePayjoin); + return AnimatedSwitcher( duration: const Duration(milliseconds: 350), child: !showToast @@ -1143,6 +1145,25 @@ class _ReceiveDisplayAddressState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ BBText.body(receiveAddressLabel), + if (isPayjoinDisabled) + 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(