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) ?? ""; String get toAmountString => toAmount?.toStringAsFixed(8) ?? "";
bool get canExchange { bool get canExchange {
switch (exchangeType) { if (exchange?.name == ChangeNowExchange.exchangeName &&
case ExchangeRateType.estimated: exchangeType == ExchangeRateType.fixed) {
return fromAmount != null && return _market != null &&
fromAmount != Decimal.zero && fromAmount != null &&
toAmount != null && toAmount != null &&
rate != null && warning.isEmpty;
warning.isEmpty; } else {
case ExchangeRateType.fixed: return fromAmount != null &&
return _market != null && fromAmount != Decimal.zero &&
fromAmount != null && toAmount != null &&
toAmount != null && rate != null &&
warning.isEmpty; 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/assets.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/flush_bar_type.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/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart'; import 'package:stackwallet/widgets/custom_loading_overlay.dart';
@ -308,6 +309,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
if (markets.isNotEmpty) { if (markets.isNotEmpty) {
await ref.read(exchangeFormStateProvider).swap(market: markets.first); await ref.read(exchangeFormStateProvider).swap(market: markets.first);
} else {
Logging.instance.log(
"swap to fixed rate market failed",
level: LogLevel.Warning,
);
} }
} }
} else { } else {

View file

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