Skip to content

Commit

Permalink
display more descriptive texts to user, and offer pre-filled issue su…
Browse files Browse the repository at this point in the history
…bmission to github (#70)
  • Loading branch information
ozgunozerk authored Jan 4, 2024
1 parent 09e7a66 commit 3383493
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/controllers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class LoginController extends GetxController {
await prefs.clear();
}
} catch (e) {
showErrorDialog("Couldn't delete account: $e");
showErrorDialog("Couldn't delete account", "$e");
}
}

Expand All @@ -187,7 +187,7 @@ class LoginController extends GetxController {

await _firebaseUser!.delete();
} catch (e) {
showErrorDialog("An error occurred during re-authentication: $e");
showErrorDialog("An error occurred during re-authentication", "$e");
}
}
}
7 changes: 3 additions & 4 deletions lib/controllers/fetch/asset_table_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ class AssetTableController extends GetxController {
await _setLastFetchTimestamp(DateTime.now());
} catch (e) {
if (kDebugMode) {
print('Failed to fetch asset table: $e');
print("Failed to fetch asset table due to: $e");
}
showErrorDialog(
"There was a problem communicating with the server. Please try again later.");
showErrorDialog("Failed to fetch asset table", "$e");
}
}

Expand Down Expand Up @@ -127,7 +126,7 @@ class AssetTableController extends GetxController {
if (kDebugMode) {
print("cannot parse asset table json from device, because: $e");
}
showErrorDialog("Couldn't parse asset table json from device.");
showErrorDialog("Couldn't parse asset table from device", "$e");
}
}
return null;
Expand Down
5 changes: 2 additions & 3 deletions lib/controllers/fetch/price_tables_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class PriceTablesController extends GetxController with WidgetsBindingObserver {
priceTables = PriceTables.fromMap(jsonDecode(storedPriceTables));
lastPriceTableDateUTC = priceTables.priceTableMap.keys.last;
} catch (e) {
showErrorDialog("cannot parse price tables json from device");
if (kDebugMode) {
print("cannot parse price tables json from device, because: $e");
}
showErrorDialog("cannot parse price tables from device", "$e");
}
} else {
// there may be no local priceTable in device (i.e. first install)
Expand Down Expand Up @@ -82,8 +82,7 @@ class PriceTablesController extends GetxController with WidgetsBindingObserver {
if (kDebugMode) {
print("fetching and setting the price tables failed due to error: $e");
}
showErrorDialog(
"There was a problem communicating with the server. Please try again later.");
showErrorDialog("fetching and setting price tables", "$e");
}
}

Expand Down
7 changes: 3 additions & 4 deletions lib/controllers/fetch/transactions_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransactionsController extends GetxController {
final HttpsCallableResult result = await callable.call();

if (result.data is! Map) {
throw 'transaction data is not a map';
throw "transaction data is not a map";
}

if (result.data.isEmpty) {
Expand All @@ -39,10 +39,9 @@ class TransactionsController extends GetxController {
await _processTransactions(transactions);
} catch (e) {
if (kDebugMode) {
print('Failed to fetch transactions: $e');
print("Failed to fetch transactions due to: $e");
}
showErrorDialog(
"There was a problem communicating with the server. Please try again later.");
showErrorDialog("Failed to fetch transactions", "$e");
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/snapshots_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SnapshotsController extends GetxController {
if (kDebugMode) {
print("loading/setting snapshots from device failed with error: $e");
}
showErrorDialog("cannot load snapshots from device!");
showErrorDialog("loading snapshots from device failed", "$e");
}
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/controllers/user_assets_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ class UserAssetsController extends GetxController {
try {
await callable.call(_transactions.value.toMap());
} catch (e) {
showErrorDialog(
"There was a problem communicating with the server. Please try again later.");
showErrorDialog("Couldn't send transaction to server", "$e");
return;
}

Expand Down
25 changes: 23 additions & 2 deletions lib/util/helper_funcs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';

import 'package:how_much/controllers/fetch/asset_table_controller.dart';
import 'package:how_much/controllers/user_assets_controller.dart';
Expand Down Expand Up @@ -127,21 +128,41 @@ loadingAnimation() {
);
}

void showErrorDialog(String errorText) {
void showErrorDialog(String errorText, String detail) {
Get.dialog(
AlertDialog(
title: const Text("Error"),
content: Text(errorText),
actions: <Widget>[
TextButton(
onPressed: () {
launchUrl(Uri.parse(fillIssue(errorText, detail)));
Get.back();
},
child: const Text("Submit this to GitHub"),
),
TextButton(
onPressed: () => Get.back(),
child: const Text("OK"),
child: const Text("Ok"),
),
],
),
);
}

String fillIssue(String error, String detail) {
String encodedError = Uri.encodeComponent(error);
String encodedDetail = Uri.encodeComponent(detail);

String baseURL =
'https://github.com/ozgunozerk/howmuch/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml';

String titleParam = 'title=$encodedError';
String whatHappenedParam = 'what-happened=$encodedDetail';

return '$baseURL&$titleParam&$whatHappenedParam';
}

String getPreviousUpdateTime(DateTime timestamp) {
// round the hour part to it's nearest 6th multiple (00, 06, 12, 18)
// server is doing updates on these hours
Expand Down

0 comments on commit 3383493

Please sign in to comment.