added edge case Logging

This commit is contained in:
julian 2022-08-30 16:47:40 -06:00
parent 88af88740b
commit 9276809e28

View file

@ -2,6 +2,7 @@ import 'package:decimal/decimal.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:stackwallet/models/exchange/change_now/currency.dart'; import 'package:stackwallet/models/exchange/change_now/currency.dart';
import 'package:stackwallet/services/change_now/change_now.dart'; import 'package:stackwallet/services/change_now/change_now.dart';
import 'package:stackwallet/utilities/logger.dart';
class ExchangeFormState extends ChangeNotifier { class ExchangeFormState extends ChangeNotifier {
Decimal? _fromAmount; Decimal? _fromAmount;
@ -57,111 +58,121 @@ class ExchangeFormState extends ChangeNotifier {
_toAmount == null ? "-" : _toAmount!.toStringAsFixed(8); _toAmount == null ? "-" : _toAmount!.toStringAsFixed(8);
Future<void> updateTo(Currency to, bool shouldNotifyListeners) async { Future<void> updateTo(Currency to, bool shouldNotifyListeners) async {
_to = to; try {
if (_from == null) { _to = to;
if (_from == null) {
rate = null;
notifyListeners();
return;
}
await _updateMinFromAmount(shouldNotifyListeners: shouldNotifyListeners);
// await _updateMinToAmount(shouldNotifyListeners: shouldNotifyListeners);
rate = null; rate = null;
notifyListeners();
return;
}
await _updateMinFromAmount(shouldNotifyListeners: shouldNotifyListeners); if (_fromAmount != null) {
// await _updateMinToAmount(shouldNotifyListeners: shouldNotifyListeners); Decimal? amt;
if (_minFromAmount != null) {
rate = null; if (_minFromAmount! > _fromAmount!) {
amt = await getStandardEstimatedToAmount(
if (_fromAmount != null) { fromAmount: _minFromAmount!, from: _from!, to: _to!);
Decimal? amt; if (amt != null) {
if (_minFromAmount != null) { rate = (amt / _minFromAmount!)
if (_minFromAmount! > _fromAmount!) { .toDecimal(scaleOnInfinitePrecision: 12);
amt = await getStandardEstimatedToAmount( }
debugPrint("A");
} else {
amt = await getStandardEstimatedToAmount(
fromAmount: _fromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate =
(amt / _fromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
debugPrint("B");
}
}
if (rate != null) {
_toAmount = (_fromAmount! * rate!);
}
debugPrint("C");
} else {
if (_minFromAmount != null) {
Decimal? amt = await getStandardEstimatedToAmount(
fromAmount: _minFromAmount!, from: _from!, to: _to!); fromAmount: _minFromAmount!, from: _from!, to: _to!);
if (amt != null) { if (amt != null) {
rate = rate =
(amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12); (amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
} }
debugPrint("A"); debugPrint("D");
} else {
amt = await getStandardEstimatedToAmount(
fromAmount: _fromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate = (amt / _fromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
debugPrint("B");
} }
} }
if (rate != null) {
_toAmount = (_fromAmount! * rate!);
}
debugPrint("C");
} else {
if (_minFromAmount != null) {
Decimal? amt = await getStandardEstimatedToAmount(
fromAmount: _minFromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate =
(amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
debugPrint("D");
}
}
debugPrint( debugPrint(
"_updated TO: _from=${_from!.ticker} _to=${_to!.ticker} _fromAmount=$_fromAmount _toAmount=$_toAmount rate:$rate"); "_updated TO: _from=${_from!.ticker} _to=${_to!.ticker} _fromAmount=$_fromAmount _toAmount=$_toAmount rate:$rate");
if (shouldNotifyListeners) { if (shouldNotifyListeners) {
notifyListeners(); notifyListeners();
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Fatal);
} }
} }
Future<void> updateFrom(Currency from, bool shouldNotifyListeners) async { Future<void> updateFrom(Currency from, bool shouldNotifyListeners) async {
_from = from; try {
_from = from;
if (_to == null) {
rate = null;
notifyListeners();
return;
}
await _updateMinFromAmount(shouldNotifyListeners: shouldNotifyListeners);
if (_to == null) {
rate = null; rate = null;
notifyListeners();
return;
}
await _updateMinFromAmount(shouldNotifyListeners: shouldNotifyListeners); if (_fromAmount != null) {
Decimal? amt;
rate = null; if (_minFromAmount != null) {
if (_minFromAmount! > _fromAmount!) {
if (_fromAmount != null) { amt = await getStandardEstimatedToAmount(
Decimal? amt; fromAmount: _minFromAmount!, from: _from!, to: _to!);
if (_minFromAmount != null) { if (amt != null) {
if (_minFromAmount! > _fromAmount!) { rate = (amt / _minFromAmount!)
amt = await getStandardEstimatedToAmount( .toDecimal(scaleOnInfinitePrecision: 12);
}
} else {
amt = await getStandardEstimatedToAmount(
fromAmount: _fromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate =
(amt / _fromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
}
}
if (rate != null) {
_toAmount = (_fromAmount! * rate!);
}
} else {
if (_minFromAmount != null) {
Decimal? amt = await getStandardEstimatedToAmount(
fromAmount: _minFromAmount!, from: _from!, to: _to!); fromAmount: _minFromAmount!, from: _from!, to: _to!);
if (amt != null) { if (amt != null) {
rate = rate =
(amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12); (amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
} }
} else {
amt = await getStandardEstimatedToAmount(
fromAmount: _fromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate = (amt / _fromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
} }
} }
if (rate != null) {
_toAmount = (_fromAmount! * rate!);
}
} else {
if (_minFromAmount != null) {
Decimal? amt = await getStandardEstimatedToAmount(
fromAmount: _minFromAmount!, from: _from!, to: _to!);
if (amt != null) {
rate =
(amt / _minFromAmount!).toDecimal(scaleOnInfinitePrecision: 12);
}
}
}
debugPrint( debugPrint(
"_updated FROM: _from=${_from!.ticker} _to=${_to!.ticker} _fromAmount=$_fromAmount _toAmount=$_toAmount rate:$rate"); "_updated FROM: _from=${_from!.ticker} _to=${_to!.ticker} _fromAmount=$_fromAmount _toAmount=$_toAmount rate:$rate");
if (shouldNotifyListeners) { if (shouldNotifyListeners) {
notifyListeners(); notifyListeners();
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Fatal);
} }
} }