mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-22 10:34:17 +01:00
sp debugging (#2426)
* feat(sp): debug logging feature * fix(sp): Receiver * feat(sp): handle and log failures and early returns --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
@@ -141,6 +141,7 @@ import 'package:cake_wallet/src/screens/settings/other_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/privacy_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/security_backup_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/silent_payments_settings.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/silent_payments_logs_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/trocador_providers_page.dart';
|
||||
import 'package:cake_wallet/src/screens/setup_2fa/modify_2fa_page.dart';
|
||||
import 'package:cake_wallet/src/screens/setup_2fa/setup_2fa.dart';
|
||||
@@ -1024,6 +1025,8 @@ Future<void> setup({
|
||||
getIt.registerFactory(
|
||||
() => SilentPaymentsSettingsPage(getIt.get<SilentPaymentsSettingsViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => SilentPaymentsLogPage(getIt.get<SilentPaymentsSettingsViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => MwebSettingsPage(getIt.get<MwebSettingsViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => MwebLogsPage(getIt.get<MwebSettingsViewModel>()));
|
||||
|
||||
@@ -95,6 +95,7 @@ import 'package:cake_wallet/src/screens/settings/other_settings_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/privacy_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/security_backup_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/silent_payments_settings.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/silent_payments_logs_page.dart';
|
||||
import 'package:cake_wallet/src/screens/settings/trocador_providers_page.dart';
|
||||
import 'package:cake_wallet/src/screens/setup_2fa/modify_2fa_page.dart';
|
||||
import 'package:cake_wallet/src/screens/setup_2fa/setup_2fa.dart';
|
||||
@@ -489,6 +490,11 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
||||
(context) => getIt.get<SilentPaymentsSettingsPage>(),
|
||||
);
|
||||
|
||||
case Routes.silentPaymentsLogs:
|
||||
return handleRouteWithPlatformAwareness(
|
||||
(context) => getIt.get<SilentPaymentsLogPage>(),
|
||||
);
|
||||
|
||||
case Routes.mwebSettings:
|
||||
return handleRouteWithPlatformAwareness(
|
||||
(context) => getIt.get<MwebSettingsPage>(),
|
||||
|
||||
+3
-1
@@ -79,6 +79,7 @@ class Routes {
|
||||
static const cakePayAccountPage = '/cake_pay_account_page';
|
||||
static const webViewPage = '/web_view_page';
|
||||
static const silentPaymentsSettings = '/silent_payments_settings';
|
||||
static const silentPaymentsLogs = '/silent_payments_logs';
|
||||
static const mwebSettings = '/mweb_settings';
|
||||
static const mwebLogs = '/mweb_logs';
|
||||
static const mwebNode = '/mweb_node';
|
||||
@@ -127,7 +128,8 @@ class Routes {
|
||||
static const urqrAnimatedPage = '/urqr/animated_page';
|
||||
static const walletGroupsDisplayPage = '/wallet_groups_display_page';
|
||||
static const walletGroupDescription = '/wallet_group_description';
|
||||
static const walletGroupExistingSeedDescriptionPage = '/wallet_group_existing_seed_description_page';
|
||||
static const walletGroupExistingSeedDescriptionPage =
|
||||
'/wallet_group_existing_seed_description_page';
|
||||
static const walletSeedVerificationPage = '/wallet_seed_verification_page';
|
||||
static const exchangeTradeExternalSendPage = '/exchange_trade_external_send_page';
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import 'dart:io';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||
import 'package:cake_wallet/utils/share_util.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/settings/silent_payments_settings_view_model.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class SilentPaymentsLogPage extends BasePage {
|
||||
SilentPaymentsLogPage(this.silentPaymentsSettingsViewModelBase);
|
||||
|
||||
final SilentPaymentsSettingsViewModel silentPaymentsSettingsViewModelBase;
|
||||
|
||||
@override
|
||||
String get title => S.current.silent_payments_logs;
|
||||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
FutureBuilder<String>(
|
||||
future: silentPaymentsSettingsViewModelBase.getAbbreviatedLogs(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError || !snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return Center(child: Text('No logs found'));
|
||||
} else {
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
snapshot.data!,
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium!.copyWith(fontFamily: 'Monospace'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
child: LoadingPrimaryButton(
|
||||
onPressed: () => onExportLogs(context),
|
||||
text: S.of(context).export_logs,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
textColor: Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
bottom: 24,
|
||||
left: 24,
|
||||
right: 24,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void onExportLogs(BuildContext context) {
|
||||
if (Platform.isAndroid) {
|
||||
onExportAndroid(context);
|
||||
} else if (Platform.isIOS) {
|
||||
share(context);
|
||||
} else {
|
||||
_saveFile();
|
||||
}
|
||||
}
|
||||
|
||||
void onExportAndroid(BuildContext context) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertWithTwoActions(
|
||||
alertTitle: S.of(context).export_backup,
|
||||
alertContent: S.of(context).select_destination,
|
||||
rightButtonText: S.of(context).save,
|
||||
leftButtonText: S.of(context).cancel,
|
||||
actionLeftButton: () async {
|
||||
Navigator.of(dialogContext).pop();
|
||||
},
|
||||
actionRightButton: () async {
|
||||
Navigator.of(dialogContext).pop();
|
||||
try {
|
||||
await share(context);
|
||||
} catch (e, s) {
|
||||
ExceptionHandler.onError(FlutterErrorDetails(
|
||||
exception: e,
|
||||
stack: s,
|
||||
library: "Export Logs",
|
||||
));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> share(BuildContext context) async {
|
||||
final inAppPath = "${(await getApplicationSupportDirectory()).path}/logs/debug.log";
|
||||
await ShareUtil.shareFile(filePath: inAppPath, fileName: "debug.log", context: context);
|
||||
}
|
||||
|
||||
Future<void> _saveFile() async {
|
||||
String? outputFile = await FilePicker.platform
|
||||
.saveFile(dialogTitle: 'Save Your File to desired location', fileName: "debug.log");
|
||||
|
||||
try {
|
||||
final filePath = (await getApplicationSupportDirectory()).path + "/debug.log";
|
||||
File debugLogFile = File(filePath);
|
||||
await debugLogFile.copy(outputFile!);
|
||||
} catch (exception, stackTrace) {
|
||||
ExceptionHandler.onError(FlutterErrorDetails(
|
||||
exception: exception,
|
||||
stack: stackTrace,
|
||||
library: "Export Logs",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ class SilentPaymentsSettingsPage extends BasePage {
|
||||
title: S.current.silent_payments_scanning,
|
||||
handler: (BuildContext context) => Navigator.of(context).pushNamed(Routes.rescan),
|
||||
),
|
||||
SettingsCellWithArrow(
|
||||
title: S.current.silent_payments_logs,
|
||||
handler: (BuildContext context) =>
|
||||
Navigator.of(context).pushNamed(Routes.silentPaymentsLogs),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
part 'silent_payments_settings_view_model.g.dart';
|
||||
|
||||
@@ -30,4 +33,16 @@ abstract class SilentPaymentsSettingsViewModelBase with Store {
|
||||
bitcoin!.setIsAlwaysScanningSP(_wallet, value);
|
||||
if (value) bitcoin!.setScanningActive(_wallet, true);
|
||||
}
|
||||
|
||||
Future<String> getAbbreviatedLogs() async {
|
||||
final appSupportPath = (await getApplicationSupportDirectory()).path;
|
||||
final logsFile = File("$appSupportPath/logs/debug.log");
|
||||
if (!logsFile.existsSync()) {
|
||||
return "";
|
||||
}
|
||||
final logs = logsFile.readAsStringSync();
|
||||
|
||||
// return last 10000 characters:
|
||||
return logs.substring(logs.length > 10000 ? logs.length - 10000 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user