Skip to content

Commit

Permalink
chore: Move error details to task dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed May 4, 2024
1 parent 9221aa3 commit 3ac6226
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 94 deletions.
31 changes: 15 additions & 16 deletions mobile/lib/common/task_status_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/domain/background_task.dart';
import 'package:get_10101/features/trade/error_details.dart';
import 'package:go_router/go_router.dart';

/// Define Animation Type
Expand All @@ -18,21 +19,15 @@ class AppAnim {
}

class TaskStatusDialog extends StatefulWidget {
final String title;
final TaskStatus status;
final BackgroundTask task;
final Widget content;
final String buttonText;
final EdgeInsets insetPadding;
final VoidCallback? onClose;

const TaskStatusDialog({
super.key,
required this.title,
required this.status,
required this.task,
required this.content,
this.onClose,
this.buttonText = "Close",
this.insetPadding = const EdgeInsets.all(50),
});

@override
Expand All @@ -52,7 +47,7 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {

@override
Widget build(BuildContext context) {
bool isPending = widget.status == TaskStatus.pending;
bool isPending = widget.task.status == TaskStatus.pending;

if (_timeout != null) {
// cancel already running timeout timer if we receive a new update.
Expand All @@ -69,7 +64,7 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
}

Widget closeButton = SizedBox(
width: MediaQuery.of(context).size.width * 0.6,
width: MediaQuery.of(context).size.width * 0.65,
child: ElevatedButton(
onPressed: () {
GoRouter.of(context).pop();
Expand All @@ -82,7 +77,7 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.zero,
backgroundColor: tenTenOnePurple),
child: Text(widget.buttonText)),
child: const Text("Close")),
);

AlertDialog dialog = AlertDialog(
Expand All @@ -91,7 +86,7 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
borderRadius: BorderRadius.circular(18.0),
),
content: Container(
height: 330,
height: widget.task.status == TaskStatus.failed ? 450 : 330,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(18.0),
Expand All @@ -109,7 +104,7 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
color: Colors.white,
),
child: Image.asset(
switch (widget.status) {
switch (widget.task.status) {
TaskStatus.pending => AppAnim.loading,
TaskStatus.failed => AppAnim.error,
TaskStatus.success => AppAnim.success,
Expand All @@ -118,14 +113,19 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
),
),
const SizedBox(height: 15),
buildTitle(widget.status),
buildTitle(widget.task.status),
Padding(
padding: const EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: widget.content),
if (widget.task.status == TaskStatus.failed && widget.task.error != null)
Padding(
padding: const EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0),
child: ErrorDetails(details: widget.task.error!),
),
const Spacer(),
if (!isPending || timeout)
Padding(
padding: const EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0, bottom: 10.0),
padding: const EdgeInsets.only(top: 10.0, left: 15.0, right: 15.0, bottom: 15.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -137,7 +137,6 @@ class _TaskStatusDialog extends State<TaskStatusDialog> {
],
),
),
insetPadding: widget.insetPadding,
);

// If pending, prevent use of back button
Expand Down
43 changes: 18 additions & 25 deletions mobile/lib/common/xxi_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
import 'package:get_10101/common/background_task_change_notifier.dart';
import 'package:get_10101/common/domain/background_task.dart';
import 'package:get_10101/common/task_status_dialog.dart';
import 'package:get_10101/features/trade/error_details.dart';
import 'package:get_10101/logger/logger.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'dart:convert';
Expand Down Expand Up @@ -89,18 +88,21 @@ class _XXIScreenState extends State<XXIScreen> {
TaskStatusDialog? getTaskStatusDialog(BackgroundTask? task) {
return switch (task?.type) {
TaskType.rollover => TaskStatusDialog(
title: "Rollover",
status: task!.status,
content: const Text("Rolling over your position"),
task: task!,
content: switch (task.status) {
TaskStatus.pending => const Text(
"Please don't close the app while your position is rolled over to the next week."),
TaskStatus.failed => const Text("Oops, something went wrong!"),
TaskStatus.success =>
const Text("Your position has been successfully rolled over to the next week."),
},
onClose: () => activeTask = null),
TaskType.collaborativeRevert => TaskStatusDialog(
title: "Collaborative Channel Close!",
status: task!.status,
task: task!,
content: const Text("Your channel has been closed collaboratively!"),
onClose: () => activeTask = null),
TaskType.fullSync => TaskStatusDialog(
title: "Full wallet sync",
status: task!.status,
task: task!,
content: switch (task.status) {
TaskStatus.pending => const Text("Waiting for on-chain sync to complete"),
TaskStatus.success => const Text(
Expand All @@ -110,26 +112,17 @@ class _XXIScreenState extends State<XXIScreen> {
},
onClose: () => activeTask = null),
TaskType.recover => TaskStatusDialog(
title: "Catching up!",
status: task!.status,
task: task!,
content: const Text("Recovering your dlc channel"),
onClose: () => activeTask = null),
TaskType.asyncTrade => TaskStatusDialog(
title: "Executing Order!",
status: task!.status,
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
switch (task.status) {
TaskStatus.pending =>
const Text("Please do not close the app while the trade is executed."),
TaskStatus.success => const Text("The order has been successfully executed!"),
TaskStatus.failed => const Text("Something went wrong!")
},
if (task.status == TaskStatus.failed && task.error != null)
ErrorDetails(details: task.error!)
],
),
task: task!,
content: switch (task.status) {
TaskStatus.pending =>
const Text("Please do not close the app while the trade is executed."),
TaskStatus.success => const Text("The order has been successfully executed!"),
TaskStatus.failed => const Text("Oops, something went wrong!")
},
onClose: () => activeTask = null),
TaskType.unknown || null => null
};
Expand Down
101 changes: 48 additions & 53 deletions mobile/lib/features/trade/error_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,60 @@ class ErrorDetails extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 20, left: 10, right: 10, bottom: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Error details:",
style: TextStyle(fontSize: 15),
),
Padding(
padding: const EdgeInsets.all(5.0),
child: SizedBox.square(
child: Container(
padding: const EdgeInsets.fromLTRB(5, 25, 5, 10.0),
color: Colors.grey.shade300,
child: Column(
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Error details",
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
SizedBox.square(
child: Container(
padding: const EdgeInsets.fromLTRB(5, 25, 5, 10.0),
color: Colors.grey.shade300,
child: Column(
children: [
Text(
getPrettyJSONString(details),
style: const TextStyle(fontSize: 15),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
getPrettyJSONString(details),
style: const TextStyle(fontSize: 15),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
GestureDetector(
child: const Icon(Icons.content_copy, size: 16),
onTap: () {
Clipboard.setData(ClipboardData(text: details)).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Copied to clipboard"),
),
);
});
},
),
Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: GestureDetector(
child: const Icon(Icons.share, size: 16),
onTap: () => Share.share(details),
),
)
],
GestureDetector(
child: const Icon(Icons.content_copy, size: 16),
onTap: () {
Clipboard.setData(ClipboardData(text: details)).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Copied to clipboard"),
),
);
});
},
),
Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 8.0,
),
child: GestureDetector(
child: const Icon(Icons.share, size: 16),
onTap: () => Share.share(details),
),
)
],
),
),
],
),
),
ClickableHelpText(
text: "Please help us fix this issue and join our telegram group: ",
style: DefaultTextStyle.of(context).style),
],
),
),
const SizedBox(height: 5),
ClickableHelpText(
text: "Please help us fix this issue and join our telegram group: ",
style: DefaultTextStyle.of(context).style),
],
);
}
}
Expand Down

0 comments on commit 3ac6226

Please sign in to comment.