Skip to content

Commit

Permalink
log fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fossephate committed Jan 16, 2025
1 parent 2dce782 commit 86a6812
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
9 changes: 6 additions & 3 deletions cw_bitcoin/lib/litecoin_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
// throw Exception("MWEB is not enabled! can't calculate fee without starting the mweb server!");
// rather than throwing an exception, filter out mweb inputs and outputs:
utxos = utxos.where((utxo) => utxo.utxo.scriptType != SegwitAddresType.mweb).toList();
outputs = outputs.where((output) => output.toOutput.scriptPubKey.getAddressType() != SegwitAddresType.mweb).toList();
outputs = outputs
.where((output) => output.toOutput.scriptPubKey.getAddressType() != SegwitAddresType.mweb)
.toList();
paysToMweb = false;
spendsMweb = false;
printV("FILTERED OUT MWEB INPUTS AND OUTPUTS!");
Expand All @@ -991,7 +993,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
);
}


if (outputs.length == 1 && outputs[0].toOutput.amount == BigInt.zero) {
outputs = [
BitcoinScriptOutput(
Expand Down Expand Up @@ -1219,7 +1220,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}

Future<void> setMwebEnabled(bool enabled) async {
if (mwebEnabled == enabled) {
if (mwebEnabled == enabled &&
alwaysScan == enabled &&
(walletAddresses as LitecoinWalletAddresses).mwebEnabled == enabled) {
return;
}

Expand Down
15 changes: 8 additions & 7 deletions lib/src/screens/settings/mweb_logs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class MwebLogsPage extends BasePage {
rightButtonText: S.of(context).save_to_downloads,
leftButtonText: S.of(context).share,
actionRightButton: () async {
const downloadDirPath = "/storage/emulated/0/Download";
final filePath = downloadDirPath + "/debug.log";
await mwebSettingsViewModelBase.saveLogsLocally(filePath);
final inAppPath = "${(await getApplicationSupportDirectory()).path}/logs/debug.log";
final localPath = "/storage/emulated/0/Download/debug.log";
await mwebSettingsViewModelBase.saveLogsLocally(inAppPath, localPath);
Navigator.of(dialogContext).pop();
},
actionLeftButton: () async {
Expand All @@ -101,11 +101,12 @@ class MwebLogsPage extends BasePage {
}

Future<void> share(BuildContext context) async {
final filePath = (await getAppDir()).path + "/debug.log";
bool success = await mwebSettingsViewModelBase.saveLogsLocally(filePath);
final inAppPath = "${(await getApplicationSupportDirectory()).path}/logs/debug.log";
final localPath = "/storage/emulated/0/Download/debug.log";
bool success = await mwebSettingsViewModelBase.saveLogsLocally(inAppPath, localPath);
if (!success) return;
await ShareUtil.shareFile(filePath: filePath, fileName: "debug.log", context: context);
await mwebSettingsViewModelBase.removeLogsLocally(filePath);
await ShareUtil.shareFile(filePath: localPath, fileName: "debug.log", context: context);
await mwebSettingsViewModelBase.removeLogsLocally(localPath);
}

Future<void> _saveFile() async {
Expand Down
10 changes: 6 additions & 4 deletions lib/view_model/settings/mweb_settings_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:io';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/utils/exception_handler.dart';
import 'package:cw_core/root_dir.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:flutter/widgets.dart';
import 'package:mobx/mobx.dart';
Expand Down Expand Up @@ -47,16 +49,16 @@ abstract class MwebSettingsViewModelBase with Store {
_settingsStore.mwebAlwaysScan = value;
}

Future<bool> saveLogsLocally(String filePath) async {
Future<bool> saveLogsLocally(String inAppPath, String localPath) async {
try {
final appSupportPath = (await getApplicationSupportDirectory()).path;
final logsFile = File("$appSupportPath/logs/debug.log");
final logsFile = File(inAppPath);
if (!logsFile.existsSync()) {
throw Exception('Logs file does not exist');
}
await logsFile.copy(filePath);
await logsFile.copy(localPath);
return true;
} catch (e, s) {
printV("@@@@@ ERROR SAVING LOGS @@@@@@@@");
ExceptionHandler.onError(FlutterErrorDetails(
exception: e,
stack: s,
Expand Down

0 comments on commit 86a6812

Please sign in to comment.