-
Notifications
You must be signed in to change notification settings - Fork 108
feat: delete button for trades in terminal states #1385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ import '../../widgets/conditional_parent.dart'; | |
| import '../../widgets/custom_buttons/app_bar_icon_button.dart'; | ||
| import '../../widgets/custom_buttons/blue_text_button.dart'; | ||
| import '../../widgets/desktop/desktop_dialog.dart'; | ||
| import '../../widgets/desktop/primary_button.dart'; | ||
| import '../../widgets/desktop/secondary_button.dart'; | ||
| import '../../widgets/qr.dart'; | ||
| import '../../widgets/rounded_container.dart'; | ||
|
|
@@ -212,6 +213,128 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> { | |
| trade.status == "wait" || | ||
| trade.status == "Waiting"); | ||
|
|
||
| final isTerminalStatus = trade.isTerminalStatus; | ||
|
|
||
| void deleteTrade() { | ||
| if (isDesktop) { | ||
| showDialog<void>( | ||
| context: context, | ||
| builder: (_) => DesktopDialog( | ||
| maxWidth: 450, | ||
| maxHeight: 300, | ||
| child: Padding( | ||
| padding: const EdgeInsets.all(32), | ||
| child: Column( | ||
| children: [ | ||
| Text( | ||
| isTerminalStatus | ||
| ? "Delete this trade?" | ||
| : "Delete an active trade?", | ||
| style: STextStyles.desktopH3(context), | ||
| ), | ||
| const SizedBox(height: 16), | ||
| Text( | ||
| isTerminalStatus | ||
| ? "Trade will be deleted permanently!" | ||
| : "This trade is still active and has not finished. " | ||
| "Deleting it will permanently remove it from your " | ||
| "device and you will no longer be able to track " | ||
| "its status. Proceed only if you know what you " | ||
| "are doing.", | ||
| style: STextStyles.desktopTextSmall(context), | ||
| ), | ||
| const Spacer(), | ||
| Row( | ||
| children: [ | ||
| Expanded( | ||
| child: SecondaryButton( | ||
| label: "Cancel", | ||
| buttonHeight: ButtonHeight.l, | ||
| onPressed: Navigator.of(context).pop, | ||
| ), | ||
| ), | ||
| const SizedBox(width: 16), | ||
| Expanded( | ||
| child: PrimaryButton( | ||
| label: "Delete", | ||
| buttonHeight: ButtonHeight.l, | ||
| onPressed: () async { | ||
| await ref | ||
| .read(tradesServiceProvider) | ||
| .delete( | ||
| trade: trade, | ||
| shouldNotifyListeners: true, | ||
| ); | ||
| if (context.mounted) { | ||
| Navigator.of( | ||
| context, | ||
| ).pop(); // close confirm dialog | ||
| Navigator.of( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confirm dialog should only pop itself. Let the details dialog decide to pop itself based on the response from the confirm dialog |
||
| context, | ||
| rootNavigator: true, | ||
| ).pop(); // close trade details dialog | ||
| } | ||
| }, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| return; | ||
| } | ||
| showDialog<dynamic>( | ||
| context: context, | ||
| useSafeArea: true, | ||
| barrierDismissible: true, | ||
| builder: (_) => StackDialog( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might as well use SDialog here as well and then a single dialog can be shown so there is less code to write and less code to maintain and less code to trouble shoot and l;ess code to test |
||
| title: isTerminalStatus | ||
| ? "Delete this trade?" | ||
| : "Delete an active trade?", | ||
| message: isTerminalStatus | ||
| ? "Trade will be deleted permanently!" | ||
| : "This trade is still active and has not finished. " | ||
| "Deleting it will permanently remove it from your " | ||
| "device and you will no longer be able to track its " | ||
| "status. Proceed only if you know what you are doing.", | ||
| leftButton: TextButton( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use SecondaryButton |
||
| style: Theme.of( | ||
| context, | ||
| ).extension<StackColors>()!.getSecondaryEnabledButtonStyle(context), | ||
| child: Text("Cancel", style: STextStyles.itemSubtitle12(context)), | ||
| onPressed: () { | ||
| Navigator.of(context).pop(); | ||
| }, | ||
| ), | ||
| rightButton: TextButton( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use PrimaryButton |
||
| style: Theme.of( | ||
| context, | ||
| ).extension<StackColors>()!.getPrimaryEnabledButtonStyle(context), | ||
| child: Text("Delete", style: STextStyles.button(context)), | ||
| onPressed: () async { | ||
| await ref | ||
| .read(tradesServiceProvider) | ||
| .delete(trade: trade, shouldNotifyListeners: true); | ||
| if (context.mounted) { | ||
| Navigator.of(context).pop(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again see above comment re pops |
||
| Navigator.of(context).pop(); | ||
| unawaited( | ||
| showFloatingFlushBar( | ||
| type: FlushBarType.success, | ||
| message: "Trade deleted", | ||
| context: context, | ||
| ), | ||
| ); | ||
| } | ||
| }, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| return ConditionalParent( | ||
| condition: !isDesktop, | ||
| builder: (child) => Background( | ||
|
|
@@ -232,6 +355,31 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> { | |
| "Trade details", | ||
| style: STextStyles.navBarTitle(context), | ||
| ), | ||
| actions: [ | ||
| Padding( | ||
| padding: const EdgeInsets.only(top: 10, bottom: 10, right: 10), | ||
| child: AspectRatio( | ||
| aspectRatio: 1, | ||
| child: AppBarIconButton( | ||
| key: const Key("tradeDetailsViewDeleteTradeButtonKey"), | ||
| size: 36, | ||
| shadows: const [], | ||
| color: Theme.of( | ||
| context, | ||
| ).extension<StackColors>()!.background, | ||
| icon: SvgPicture.asset( | ||
| Assets.svg.trash, | ||
| color: Theme.of( | ||
| context, | ||
| ).extension<StackColors>()!.accentColorDark, | ||
| width: 20, | ||
| height: 20, | ||
| ), | ||
| onPressed: deleteTrade, | ||
| ), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| body: SafeArea( | ||
| child: Padding( | ||
|
|
@@ -295,6 +443,12 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> { | |
| ); | ||
| }, | ||
| ), | ||
| const SizedBox(height: 16), | ||
| SecondaryButton( | ||
| label: "Delete trade", | ||
| buttonHeight: ButtonHeight.l, | ||
| onPressed: deleteTrade, | ||
| ), | ||
| const SizedBox(height: 32), | ||
| ], | ||
| ), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use SDIalog with dynamic height sizing to fit content (NO HARDCODED HEIGHT)