mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-25 05:58:42 +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:
@@ -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),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user