CW 781 replace all print statements with printV (#1733)

* replace all print statements with printV

* restore backup error message

* missing print statements, error fixes

* Update cw_core/lib/utils/print_verbose.dart [skip ci]

* Update cw_core/lib/utils/print_verbose.dart [skip ci]

* CW-846: Correctly display balance (#1848)

* Correctly display balance even with frozen coins

* remove package= from AndroidMainfest.xml

* update namespace

* print -> printV

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
cyan 2024-12-09 12:23:59 -06:00 committed by GitHub
parent c74194abf4
commit c78662fbfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
124 changed files with 578 additions and 343 deletions

View file

@ -1,3 +1,4 @@
import 'package:cw_core/utils/print_verbose.dart';
import 'package:flutter/services.dart';
const MethodChannel _channel = MethodChannel('com.cake_wallet/native_utils');
@ -6,17 +7,17 @@ Future<void> requestDisableBatteryOptimization() async {
try {
await _channel.invokeMethod('disableBatteryOptimization');
} on PlatformException catch (e) {
print("Failed to disable battery optimization: '${e.message}'.");
printV("Failed to disable battery optimization: '${e.message}'.");
}
}
Future<bool> isBatteryOptimizationDisabled() async {
try {
final bool isDisabled = await _channel.invokeMethod('isBatteryOptimizationDisabled') as bool;
print('It\'s actually disabled? $isDisabled');
printV('It\'s actually disabled? $isDisabled');
return isDisabled;
} on PlatformException catch (e) {
print("Failed to check battery optimization status: '${e.message}'.");
printV("Failed to check battery optimization status: '${e.message}'.");
return false;
}
}

View file

@ -1,3 +1,4 @@
import 'package:cw_core/utils/print_verbose.dart';
import 'package:intl/intl.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
@ -152,7 +153,7 @@ int getMoneroHeigthByDate({required DateTime date}) {
height = startHeight + daysHeight - heightPerDay;
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
return height;

View file

@ -0,0 +1,84 @@
void printV(dynamic content) {
CustomTrace programInfo = CustomTrace(StackTrace.current);
print("${programInfo.fileName}#${programInfo.lineNumber}:${programInfo.columnNumber} ${programInfo.callerFunctionName}: $content");
}
// https://stackoverflow.com/a/59386101
class CustomTrace {
final StackTrace _trace;
String? fileName;
String? functionName;
String? callerFunctionName;
int? lineNumber;
int? columnNumber;
CustomTrace(this._trace) {
try {
_parseTrace();
} catch (e) {
print("Unable to parse trace (printV): $e");
}
}
String _getFunctionNameFromFrame(String frame) {
/* Just giving another nickname to the frame */
var currentTrace = frame;
/* To get rid off the #number thing, get the index of the first whitespace */
var indexOfWhiteSpace = currentTrace.indexOf(' ');
/* Create a substring from the first whitespace index till the end of the string */
var subStr = currentTrace.substring(indexOfWhiteSpace);
/* Grab the function name using reg expr */
var indexOfFunction = subStr.indexOf(RegExp(r'[A-Za-z0-9_]'));
/* Create a new substring from the function name index till the end of string */
subStr = subStr.substring(indexOfFunction);
indexOfWhiteSpace = subStr.indexOf(RegExp(r'[ .]'));
/* Create a new substring from start to the first index of a whitespace. This substring gives us the function name */
subStr = subStr.substring(0, indexOfWhiteSpace);
return subStr;
}
void _parseTrace() {
/* The trace comes with multiple lines of strings, (each line is also known as a frame), so split the trace's string by lines to get all the frames */
var frames = this._trace.toString().split("\n");
/* The first frame is the current function */
this.functionName = _getFunctionNameFromFrame(frames[0]);
/* The second frame is the caller function */
this.callerFunctionName = _getFunctionNameFromFrame(frames[1]);
/* The first frame has all the information we need */
var traceString = frames[1];
/* Search through the string and find the index of the file name by looking for the '.dart' regex */
var indexOfFileName = traceString.indexOf(RegExp(r'[/A-Za-z_]+.dart'), 1); // 1 to offest and not print the printV function name
var fileInfo = traceString.substring(indexOfFileName);
var listOfInfos = fileInfo.split(":");
/* Splitting fileInfo by the character ":" separates the file name, the line number and the column counter nicely.
Example: main.dart:5:12
To get the file name, we split with ":" and get the first index
To get the line number, we would have to get the second index
To get the column number, we would have to get the third index
*/
try {
this.fileName = listOfInfos[0];
this.lineNumber = int.tryParse(listOfInfos[1]);
var columnStr = listOfInfos[2];
columnStr = columnStr.replaceFirst(")", "");
this.columnNumber = int.tryParse(columnStr);
} catch (e) {
}
}
}

View file

@ -1,4 +1,5 @@
import 'package:cw_core/address_info.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
@ -71,7 +72,7 @@ abstract class WalletAddresses {
await walletInfo.save();
}
} catch (e) {
print(e.toString());
printV(e.toString());
}
}

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:flutter/services.dart';
const MethodChannel _channel = MethodChannel('com.cake_wallet/native_utils');
@ -14,9 +15,9 @@ Future<void> setDefaultMinimumWindowSize() async {
) as bool;
if (!result) {
print("Failed to set minimum window size.");
printV("Failed to set minimum window size.");
}
} on PlatformException catch (e) {
print("Failed to set minimum window size: '${e.message}'.");
printV("Failed to set minimum window size: '${e.message}'.");
}
}