can exchange check updated

This commit is contained in:
julian 2022-10-14 12:21:00 -06:00
parent b7d8e5db63
commit 8f2567f340
3 changed files with 25 additions and 14 deletions

View file

@ -115,18 +115,18 @@ class ExchangeFormState extends ChangeNotifier {
String get toAmountString => toAmount?.toStringAsFixed(8) ?? "";
bool get canExchange {
switch (exchangeType) {
case ExchangeRateType.estimated:
return fromAmount != null &&
fromAmount != Decimal.zero &&
toAmount != null &&
rate != null &&
warning.isEmpty;
case ExchangeRateType.fixed:
return _market != null &&
fromAmount != null &&
toAmount != null &&
warning.isEmpty;
if (exchange?.name == ChangeNowExchange.exchangeName &&
exchangeType == ExchangeRateType.fixed) {
return _market != null &&
fromAmount != null &&
toAmount != null &&
warning.isEmpty;
} else {
return fromAmount != null &&
fromAmount != Decimal.zero &&
toAmount != null &&
rate != null &&
warning.isEmpty;
}
}

View file

@ -24,6 +24,7 @@ import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dar
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart';
@ -308,6 +309,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
if (markets.isNotEmpty) {
await ref.read(exchangeFormStateProvider).swap(market: markets.first);
} else {
Logging.instance.log(
"swap to fixed rate market failed",
level: LogLevel.Warning,
);
}
}
} else {

View file

@ -32,17 +32,22 @@ class SimpleSwapAPI {
Future<dynamic> _makeGetRequest(Uri uri) async {
final client = this.client ?? http.Client();
int code = -1;
try {
final response = await client.get(
uri,
);
code = response.statusCode;
final parsed = jsonDecode(response.body);
return parsed;
} catch (e, s) {
Logging.instance
.log("_makeRequest($uri) threw: $e\n$s", level: LogLevel.Error);
Logging.instance.log(
"_makeRequest($uri) HTTP:$code threw: $e\n$s",
level: LogLevel.Error,
);
rethrow;
}
}