Skip to content

Commit

Permalink
feat: payjoin is disabled if utxos are empty for the selected wallet –>
Browse files Browse the repository at this point in the history
Close #357
  • Loading branch information
ethicnology authored and DanGould committed Dec 20, 2024
1 parent 21c9bda commit 253c5c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/receive/bloc/receive_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ReceiveCubit extends Cubit<ReceiveState> {
WalletBloc? walletBloc,
required WalletAddress walletAddress,
required WalletsStorageRepository walletsStorageRepository,
required bool defaultPayjoin,
required PayjoinSessionStorage payjoinSessionStorage,
required PayjoinManager payjoinManager,
}) : _walletsStorageRepository = walletsStorageRepository,
Expand All @@ -33,11 +32,6 @@ class ReceiveCubit extends Cubit<ReceiveState> {
oneWallet: walletBloc != null,
),
) {
emit(
state.copyWith(
disablePayjoin: !defaultPayjoin,
),
);
loadAddress();
}

Expand Down Expand Up @@ -69,6 +63,7 @@ class ReceiveCubit extends Cubit<ReceiveState> {
// 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 &&
Expand Down Expand Up @@ -506,4 +501,20 @@ class ReceiveCubit extends Cubit<ReceiveState> {
);
return InputPair.newInstance(txin, psbtin);
}

Future<void> 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));
}
}
}
23 changes: 22 additions & 1 deletion lib/receive/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class _ReceivePageState extends State<ReceivePage> {
walletAddress: locator<WalletAddress>(),
walletsStorageRepository: locator<WalletsStorageRepository>(),
walletBloc: widget.walletBloc,
defaultPayjoin: locator<SettingsCubit>().state.defaultPayjoin,
payjoinSessionStorage: locator<PayjoinSessionStorage>(),
payjoinManager: locator<PayjoinManager>(),
);
Expand Down Expand Up @@ -1136,13 +1135,35 @@ class _ReceiveDisplayAddressState extends State<ReceiveDisplayAddress> {

final addr = bip21Address.isNotEmpty ? bip21Address : widget.addressQr;

final isPayjoinDisabled =
context.select((ReceiveCubit _) => _.state.disablePayjoin);

return AnimatedSwitcher(
duration: const Duration(milliseconds: 350),
child: !showToast
? Column(
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(
Expand Down

0 comments on commit 253c5c6

Please sign in to comment.