Skip to content

Commit

Permalink
Merge pull request #1343 from get10101/fix/multiple-dialog-display
Browse files Browse the repository at this point in the history
fix: Show dialog only when submitting an order
  • Loading branch information
holzeis authored Sep 21, 2023
2 parents 8fa4e95 + 801e30a commit 307b191
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 366 deletions.
24 changes: 9 additions & 15 deletions mobile/lib/features/stable/bitcoinize_confirmation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,11 @@ class BitcoinizeBottomSheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
final stableValuesChangeNotifier = context.watch<StableValuesChangeNotifier>();
final submitOrderChangeNotifier = context.watch<SubmitOrderChangeNotifier>();

final stableValues = stableValuesChangeNotifier.stableValues();
stableValues.quantity = position.quantity;
stableValues.direction = Direction.long;

if (submitOrderChangeNotifier.pendingOrder != null &&
submitOrderChangeNotifier.pendingOrder!.state == PendingOrderState.submitting) {
final pendingOrder = submitOrderChangeNotifier.pendingOrder;

WidgetsBinding.instance.addPostFrameCallback((_) async {
return await showDialog(
context: context,
useRootNavigator: true,
barrierDismissible: false, // Prevent user from leaving
builder: (BuildContext context) {
return StableDialog(pendingOrder: pendingOrder!);
});
});
}
return Container(
padding: const EdgeInsets.all(20),
child: Column(
Expand Down Expand Up @@ -116,7 +101,16 @@ class BitcoinizeBottomSheet extends StatelessWidget {
submitOrderChangeNotifier.submitPendingOrder(
stableValues, PositionAction.close);

// Return to the stable screen before submitting the pending order so that the dialog is displayed under the correct context
GoRouter.of(context).pop();

showDialog(
context: context,
useRootNavigator: true,
barrierDismissible: false, // Prevent user from leaving
builder: (BuildContext context) {
return const StableDialog();
});
},
child: const Text("Confirm")),
],
Expand Down
34 changes: 12 additions & 22 deletions mobile/lib/features/stable/stable_confirmation_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,8 @@ class _StableBottomSheet extends State<StableBottomSheet> {

final ChannelInfoService channelInfoService = context.read<ChannelInfoService>();

SubmitOrderChangeNotifier submitOrderChangeNotifier =
context.watch<SubmitOrderChangeNotifier>();

WalletInfo walletInfo = context.watch<WalletChangeNotifier>().walletInfo;

if (submitOrderChangeNotifier.pendingOrder != null &&
submitOrderChangeNotifier.pendingOrder!.state == PendingOrderState.submitting) {
final pendingOrder = submitOrderChangeNotifier.pendingOrder;

WidgetsBinding.instance.addPostFrameCallback((_) async {
return await showDialog(
context: context,
useRootNavigator: true,
barrierDismissible: false, // Prevent user from leaving
builder: (BuildContext context) {
return StableDialog(
pendingOrder: pendingOrder!,
);
});
});
}

return Form(
key: _formKey,
child: Column(
Expand Down Expand Up @@ -246,15 +226,25 @@ class _StableBottomSheet extends State<StableBottomSheet> {
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
final submitOrderChangeNotifier =
context.read<SubmitOrderChangeNotifier>();

TradeValues tradeValues =
stableValuesChangeNotifier.stableValues();

final submitOrderChangeNotifier =
context.read<SubmitOrderChangeNotifier>();
submitOrderChangeNotifier.submitPendingOrder(
tradeValues, PositionAction.open);

// Return to the trade screen before submitting the pending order so that the dialog is displayed under the correct context
GoRouter.of(context).pop();

showDialog(
context: context,
useRootNavigator: true,
barrierDismissible: false, // Prevent user from leaving
builder: (BuildContext context) {
return const StableDialog();
});
}
},
child: const Text("Confirm")),
Expand Down
83 changes: 37 additions & 46 deletions mobile/lib/features/stable/stable_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,59 +1,50 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/domain/background_task.dart';
import 'package:get_10101/common/task_status_dialog.dart';
import 'package:get_10101/common/value_data_row.dart';
import 'package:get_10101/features/stable/stable_submission_status_dialog.dart';
import 'package:get_10101/features/trade/submit_order_change_notifier.dart';
import 'package:provider/provider.dart';

class StableDialog extends StatelessWidget {
final PendingOrder pendingOrder;

const StableDialog({super.key, required this.pendingOrder});
const StableDialog({super.key});

@override
Widget build(BuildContext context) {
return Selector<SubmitOrderChangeNotifier, PendingOrderState>(
selector: (_, provider) => provider.pendingOrder!.state,
builder: (context, state, child) {
Widget body = createSubmitWidget(pendingOrder, DefaultTextStyle.of(context).style);
final submitOrderChangeNotifier = context.watch<SubmitOrderChangeNotifier>();
final pendingOrder = submitOrderChangeNotifier.pendingOrder!;

switch (state) {
case PendingOrderState.submitting:
return StableSubmissionStatusDialog(
title: pendingOrder.positionAction == PositionAction.open
? "Stabilizing"
: "Bitcoinizing",
type: StableSubmissionStatusDialogType.pendingSubmit,
content: body);
case PendingOrderState.submittedSuccessfully:
return StableSubmissionStatusDialog(
title:
pendingOrder.positionAction == PositionAction.open ? "Stabilize" : "Bitcoinize",
type: StableSubmissionStatusDialogType.successfulSubmit,
content: body);
case PendingOrderState.submissionFailed:
// TODO: This failure case has to be handled differently; are we planning to show orders that failed to submit in the order history?
return StableSubmissionStatusDialog(
title: pendingOrder.positionAction == PositionAction.open
? "Stabilizing"
: "Bitcoinizing",
type: StableSubmissionStatusDialogType.failedSubmit,
content: body);
case PendingOrderState.orderFilled:
return StableSubmissionStatusDialog(
title:
pendingOrder.positionAction == PositionAction.open ? "Stabilize" : "Bitcoinize",
type: StableSubmissionStatusDialogType.filled,
content: body);
case PendingOrderState.orderFailed:
return StableSubmissionStatusDialog(
title: pendingOrder.positionAction == PositionAction.open
? "Stabilizing"
: "Bitcoinizing",
type: StableSubmissionStatusDialogType.failedFill,
content: body);
}
},
);
Widget body = createSubmitWidget(pendingOrder, DefaultTextStyle.of(context).style);

switch (pendingOrder.state) {
case PendingOrderState.submitting:
return TaskStatusDialog(
title:
pendingOrder.positionAction == PositionAction.open ? "Stabilizing" : "Bitcoinizing",
status: TaskStatus.pending,
content: body);
case PendingOrderState.submittedSuccessfully:
return TaskStatusDialog(
title: pendingOrder.positionAction == PositionAction.open ? "Stabilize" : "Bitcoinize",
status: TaskStatus.pending,
content: body);
case PendingOrderState.submissionFailed:
return TaskStatusDialog(
title:
pendingOrder.positionAction == PositionAction.open ? "Stabilizing" : "Bitcoinizing",
status: TaskStatus.failed,
content: body);
case PendingOrderState.orderFilled:
return TaskStatusDialog(
title: pendingOrder.positionAction == PositionAction.open ? "Stabilize" : "Bitcoinize",
status: TaskStatus.success,
content: body);
case PendingOrderState.orderFailed:
return TaskStatusDialog(
title:
pendingOrder.positionAction == PositionAction.open ? "Stabilizing" : "Bitcoinizing",
status: TaskStatus.failed,
content: body);
}
}
}

Expand Down
127 changes: 0 additions & 127 deletions mobile/lib/features/stable/stable_submission_status_dialog.dart

This file was deleted.

14 changes: 12 additions & 2 deletions mobile/lib/features/trade/trade_bottom_sheet_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:get_10101/features/trade/domain/trade_values.dart';
import 'package:get_10101/features/trade/leverage_slider.dart';
import 'package:get_10101/features/trade/submit_order_change_notifier.dart';
import 'package:get_10101/features/trade/trade_bottom_sheet_confirmation.dart';
import 'package:get_10101/features/trade/trade_dialog.dart';
import 'package:get_10101/features/trade/trade_theme.dart';
import 'package:get_10101/features/trade/trade_value_change_notifier.dart';
import 'package:get_10101/features/wallet/domain/wallet_info.dart';
Expand Down Expand Up @@ -193,10 +194,19 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab> {
submitOrderChangeNotifier.submitPendingOrder(
tradeValues, PositionAction.open);

// TODO: Explore if it would be easier / better handle the popups as routes
// Pop twice to navigate back to the trade screen.
// Return to the trade screen before submitting the pending order so that the dialog is displayed under the correct context
GoRouter.of(context).pop();
GoRouter.of(context).pop();

// Show immediately the pending dialog, when submitting a market order.
// TODO(holzeis): We should only show the dialog once we've received a match.
showDialog(
context: context,
useRootNavigator: true,
barrierDismissible: false, // Prevent user from leaving
builder: (BuildContext context) {
return const TradeDialog();
});
});
}
},
Expand Down
Loading

0 comments on commit 307b191

Please sign in to comment.