Skip to content

Commit

Permalink
Display payjoin toggle on send screen
Browse files Browse the repository at this point in the history
This also toggles the text on the Confirm screen to give user state context.
  • Loading branch information
DanGould committed Dec 20, 2024
1 parent d01b21a commit 18d6dd5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/send/advanced.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ class SendAllOption extends StatelessWidget {
}
}

class SendPayjoinOption extends StatelessWidget {
const SendPayjoinOption({super.key});

@override
Widget build(BuildContext context) {
final togglePayjoin =
context.select((SendCubit x) => x.state.togglePayjoin);
return Row(
children: [
const BBText.title('Send payjoin'),
const Spacer(),
BBSwitch(
value: togglePayjoin,
onChanged: (e) {
context.read<SendCubit>().togglePayjoin(e);
},
),
],
);
}
}

class EnableRBFOption extends StatelessWidget {
const EnableRBFOption({super.key});

Expand Down
4 changes: 4 additions & 0 deletions lib/send/bloc/send_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ class SendCubit extends Cubit<SendState> {
_checkBalance();
}

void togglePayjoin(bool toggle) {
emit(state.copyWith(togglePayjoin: toggle));
}

void utxoSelected(UTXO utxo) {
var selectedUtxos = state.selectedUtxos.toList();

Expand Down
5 changes: 4 additions & 1 deletion lib/send/bloc/send_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SendState with _$SendState {
@Default(false) bool disableRBF,
Uri? payjoinEndpoint,
Sender? payjoinSender,
@Default(true) bool togglePayjoin,
@Default(false) bool sendAllCoin,
@Default([]) List<UTXO> selectedUtxos,
@Default('') String errAddresses,
Expand Down Expand Up @@ -257,7 +258,9 @@ class SendState with _$SendState {
? payjoinSender != null
? 'Payjoining'
: 'Broadcasting'
: 'Confirm'
: payjoinSender != null
? 'Confirm Payjoin'
: 'Confirm'
: sending
? 'Building Tx'
: !isLn
Expand Down
3 changes: 3 additions & 0 deletions lib/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class _Screen extends StatelessWidget {
final signed = context.select((SendCubit cubit) => cubit.state.signed);
final sent = context.select((SendCubit cubit) => cubit.state.sent);
final isLn = context.select((SendCubit cubit) => cubit.state.isLnInvoice());
final isPj = context.select((SendCubit cubit) => cubit.state.hasPjParam());

final showWarning =
context.select((CreateSwapCubit x) => x.state.showWarning());
Expand Down Expand Up @@ -201,6 +202,8 @@ class _Screen extends StatelessWidget {
const AmountField(),
if (!isLn) const SendAllOption(),
const Gap(24),
if (isPj) const SendPayjoinOption(),
const Gap(24),
const DescriptionField(),
if (!isLn) ...[
const Gap(24),
Expand Down

0 comments on commit 18d6dd5

Please sign in to comment.