Skip to content
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

CW-782: Show error report popup without cooldown #1739

Merged
merged 14 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cw_monero/lib/api/wallet_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,14 @@ void loadWallet(
txhistory = null;
final newWptr = monero.WalletManager_openWallet(wmPtr,
path: path, password: password);
_lastOpenedWallet = path;
final status = monero.Wallet_status(newWptr);
if (status != 0) {
final err = monero.Wallet_errorString(newWptr);
print(err);
print("loadWallet:"+err);
throw WalletOpeningException(message: err);
}
wptr = newWptr;
_lastOpenedWallet = path;
openedWalletsByPath[path] = wptr!;
}
}
Expand Down
2 changes: 1 addition & 1 deletion cw_monero/lib/monero_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class MoneroWalletService extends WalletService<
}

await restoreOrResetWalletFiles(name);
return openWallet(name, password, retryOnFailure: false);
return await openWallet(name, password, retryOnFailure: false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/anypay/anypay_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AnyPayApi {
final response = await post(url, headers: headers, body: utf8.encode(json.encode(body)));

if (response.statusCode != 200) {
ExceptionHandler.onError(FlutterErrorDetails(exception: response));
await ExceptionHandler.onError(FlutterErrorDetails(exception: response));
throw Exception('Unexpected response http code: ${response.statusCode}');
}

Expand Down
19 changes: 9 additions & 10 deletions lib/core/backup_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,16 @@ class BackupService {
json.decode(transactionDescriptionFile.readAsStringSync()) as Map<String, dynamic>;
final descriptionsMap = jsonData.map((key, value) =>
MapEntry(key, TransactionDescription.fromJson(value as Map<String, dynamic>)));

if (!_transactionDescriptionBox.isOpen) {
final transactionDescriptionsBoxKey = await getEncryptionKey(secureStorage: secureStorageShared, forKey: TransactionDescription.boxKey);
final transactionDescriptionBox = await CakeHive.openBox<TransactionDescription>(
var box = _transactionDescriptionBox;
if (!box.isOpen) {
final secureStorage = secureStorageShared;
final transactionDescriptionsBoxKey =
await getEncryptionKey(secureStorage: secureStorage, forKey: TransactionDescription.boxKey);
box = await CakeHive.openBox<TransactionDescription>(
TransactionDescription.boxName,
encryptionKey: transactionDescriptionsBoxKey,
);
await transactionDescriptionBox.putAll(descriptionsMap);
return;
}
await _transactionDescriptionBox.putAll(descriptionsMap);
encryptionKey: transactionDescriptionsBoxKey);
}
await box.putAll(descriptionsMap);
}

Future<void> _importPreferencesDump() async {
Expand Down
15 changes: 10 additions & 5 deletions lib/core/wallet_loading_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:cake_wallet/core/generate_wallet_password.dart';
import 'package:cake_wallet/core/key_service.dart';
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cake_wallet/entities/preferences_key.dart';
import 'package:cake_wallet/reactions/on_authentication_state_change.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
Expand Down Expand Up @@ -54,23 +55,25 @@ class WalletLoadingService {

return wallet;
} catch (error, stack) {
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
await ExceptionHandler.resetLastPopupDate();
await ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));

// try fetching the seeds of the corrupted wallet to show it to the user
String corruptedWalletsSeeds = "Corrupted wallets seeds (if retrievable, empty otherwise):";
try {
corruptedWalletsSeeds += await _getCorruptedWalletSeeds(name, type);
} catch (e) {
corruptedWalletsSeeds += "\nFailed to fetch $name seeds: $e";
corruptedWalletsSeeds += "\nFailed to fetch $name seeds: $e";
}
secureStorageShared.write(key: "corruptedWalletsSeed", value: corruptedWalletsSeeds);

// try opening another wallet that is not corrupted to give user access to the app
final walletInfoSource = await CakeHive.openBox<WalletInfo>(WalletInfo.boxName);

for (var walletInfo in walletInfoSource.values) {
try {
final walletService = walletServiceFactory.call(walletInfo.type);
final walletPassword = password ?? (await keyService.getWalletPassword(walletName: name));
final walletPassword = password ?? await keyService.getWalletPassword(walletName: name);
final wallet = await walletService.openWallet(walletInfo.name, walletPassword);

if (walletInfo.type == WalletType.monero) {
Expand All @@ -94,13 +97,15 @@ class WalletLoadingService {
corruptedWalletsSeeds += seeds;
}
} catch (e) {
corruptedWalletsSeeds += "\nFailed to fetch $name seeds: $e";
corruptedWalletsSeeds += "\nFailed to fetch $name seeds: $e";
}
secureStorageShared.write(key: "corruptedWalletsSeed", value: corruptedWalletsSeeds);
}
}

// if all user's wallets are corrupted throw exception
throw error.toString() + "\n\n" + corruptedWalletsSeeds;
secureStorageShared.write(key: "corruptedWalletsSeed", value: corruptedWalletsSeeds);
throw error.toString();
}
}

Expand Down
14 changes: 11 additions & 3 deletions lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ Future<void> setup({
totpAuthPageState.changeProcessText('Loading the wallet');

if (loginError != null) {
totpAuthPageState.changeProcessText('ERROR: ${loginError.toString()}');
final seeds = await secureStorage.read(key: "corruptedWalletsSeed");
await secureStorageShared.delete(key: "corruptedWalletsSeed");
totpAuthPageState.changeProcessText('ERROR: ${loginError.toString()}\n${seeds??""}'.trim());
}

ReactionDisposer? _reaction;
Expand Down Expand Up @@ -593,7 +595,10 @@ Future<void> setup({
authPageState.changeProcessText('Loading the wallet');

if (loginError != null) {
authPageState.changeProcessText('ERROR: ${loginError.toString()}');
secureStorage.read(key: "corruptedWalletsSeed").then((value) {
secureStorageShared.delete(key: "corruptedWalletsSeed");
authPageState.changeProcessText('ERROR: ${loginError.toString()}\n${value??""}'.trim());
});
loginError = null;
}

Expand All @@ -613,7 +618,10 @@ Future<void> setup({
}

if (loginError != null) {
authPageState.changeProcessText('ERROR: ${loginError.toString()}');
secureStorage.read(key: "corruptedWalletsSeed").then((value) {
secureStorageShared.delete(key: "corruptedWalletsSeed");
authPageState.changeProcessText('ERROR: ${loginError.toString()}\n${value??""}'.trim());
});
timer.cancel();
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Future<void> runAppWithZone({Key? topLevelKey}) async {
);
}

ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace));
await ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stackTrace));
});
}

Expand Down
5 changes: 3 additions & 2 deletions lib/reactions/on_authentication_state_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ void startAuthenticationStateChange(
await loadCurrentWallet();
} catch (error, stack) {
loginError = error;
ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
await ExceptionHandler.resetLastPopupDate();
await ExceptionHandler.onError(FlutterErrorDetails(exception: error, stack: stack));
}
return;
}

if (state == AuthenticationState.allowed) {
await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false);
if (!(await authenticatedErrorStreamController.stream.isEmpty)) {
ExceptionHandler.showError(
await ExceptionHandler.showError(
(await authenticatedErrorStreamController.stream.first).toString());
authenticatedErrorStreamController.stream.drain();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/backup/backup_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BackupPage extends BasePage {
File returnedFile = File(outputFile!);
await returnedFile.writeAsBytes(backup.content);
} catch (exception, stackTrace) {
ExceptionHandler.onError(FlutterErrorDetails(
await ExceptionHandler.onError(FlutterErrorDetails(
exception: exception,
stack: stackTrace,
library: "Export Backup",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cake_wallet/themes/extensions/menu_theme.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart';
Expand Down Expand Up @@ -206,6 +207,8 @@ class _DesktopWalletSelectionDropDownState extends State<DesktopWalletSelectionD
hideProgressText();
setState(() {});
} catch (e) {
await ExceptionHandler.resetLastPopupDate();
await ExceptionHandler.onError(FlutterErrorDetails(exception: e));
if (mounted) {
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/screens/wallet_list/wallet_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:cake_wallet/core/new_wallet_arguments.dart';
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cake_wallet/entities/wallet_edit_page_arguments.dart';
import 'package:cake_wallet/entities/wallet_list_order_types.dart';
import 'package:cake_wallet/src/screens/dashboard/widgets/filter_list_widget.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:cake_wallet/src/screens/auth/auth_page.dart';
import 'package:cake_wallet/core/auth_service.dart';
import 'package:cake_wallet/themes/extensions/filter_theme.dart';
import 'package:cake_wallet/themes/extensions/wallet_list_theme.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
import 'package:cake_wallet/utils/responsive_layout_util.dart';
import 'package:cake_wallet/utils/show_bar.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
Expand Down Expand Up @@ -454,8 +456,12 @@ class WalletListBodyState extends State<WalletListBody> {
});
}
} catch (e) {
await ExceptionHandler.resetLastPopupDate();
final err = e.toString() + ((await secureStorageShared.read(key: "corruptedWalletsSeed"))??"unable to retrieve seeds");
await secureStorageShared.delete(key: "corruptedWalletsSeed");
await ExceptionHandler.onError(FlutterErrorDetails(exception: err));
if (this.mounted) {
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString()));
changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, err));
}
}
},
Expand Down
25 changes: 16 additions & 9 deletions lib/src/widgets/base_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ class BaseAlertDialog extends StatelessWidget {
}

Widget content(BuildContext context) {
return Text(
contentText,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
decoration: TextDecoration.none,
return SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
contentText,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context).extension<CakeTextTheme>()!.titleColor,
decoration: TextDecoration.none,
),
),
],
),
);
}
Expand Down
Loading
Loading