mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-15 16:12:16 +00:00
show unsupported pair message per exchange
This commit is contained in:
parent
3fde042c8e
commit
f4737c5d95
5 changed files with 78 additions and 5 deletions
5
lib/exceptions/exchange/pair_unavailable_exception.dart
Normal file
5
lib/exceptions/exchange/pair_unavailable_exception.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||
|
||||
class PairUnavailableException extends ExchangeException {
|
||||
PairUnavailableException(super.message, super.type);
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:decimal/decimal.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
||||
import 'package:stackwallet/models/exchange/response_objects/estimate.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||
|
@ -84,7 +85,7 @@ class ExchangeProviderOptions extends ConsumerWidget {
|
|||
groupValue: ref
|
||||
.watch(currentExchangeNameStateProvider.state)
|
||||
.state,
|
||||
onChanged: (value) {
|
||||
onChanged: (_) {
|
||||
// if (value is String) {
|
||||
// ref
|
||||
// .read(
|
||||
|
@ -194,6 +195,18 @@ class ExchangeProviderOptions extends ConsumerWidget {
|
|||
.textSubtitle1,
|
||||
),
|
||||
);
|
||||
} else if (snapshot.data?.exception
|
||||
is PairUnavailableException) {
|
||||
return Text(
|
||||
"Unsupported pair",
|
||||
style:
|
||||
STextStyles.itemSubtitle12(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"$runtimeType failed to fetch rate for ChangeNOW: ${snapshot.data}",
|
||||
|
@ -298,7 +311,7 @@ class ExchangeProviderOptions extends ConsumerWidget {
|
|||
groupValue: ref
|
||||
.watch(currentExchangeNameStateProvider.state)
|
||||
.state,
|
||||
onChanged: (value) {
|
||||
onChanged: (_) {
|
||||
// if (value is String) {
|
||||
// ref
|
||||
// .read(
|
||||
|
@ -409,6 +422,18 @@ class ExchangeProviderOptions extends ConsumerWidget {
|
|||
.textSubtitle1,
|
||||
),
|
||||
);
|
||||
} else if (snapshot.data?.exception
|
||||
is PairUnavailableException) {
|
||||
return Text(
|
||||
"Unsupported pair",
|
||||
style:
|
||||
STextStyles.itemSubtitle12(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textSubtitle1,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Logging.instance.log(
|
||||
"$runtimeType failed to fetch rate for ChangeNOW: ${snapshot.data}",
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:decimal/decimal.dart';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
||||
import 'package:stackwallet/external_api_keys.dart';
|
||||
import 'package:stackwallet/models/exchange/change_now/cn_exchange_estimate.dart';
|
||||
import 'package:stackwallet/models/exchange/change_now/estimated_exchange_amount.dart';
|
||||
|
@ -350,8 +351,27 @@ class ChangeNowAPI {
|
|||
final json = await _makeGetRequest(uri);
|
||||
|
||||
try {
|
||||
final value = EstimatedExchangeAmount.fromJson(
|
||||
Map<String, dynamic>.from(json as Map));
|
||||
final map = Map<String, dynamic>.from(json as Map);
|
||||
|
||||
if (map["error"] != null) {
|
||||
if (map["error"] == "pair_is_inactive") {
|
||||
return ExchangeResponse(
|
||||
exception: PairUnavailableException(
|
||||
map["message"] as String,
|
||||
ExchangeExceptionType.generic,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ExchangeResponse(
|
||||
exception: ExchangeException(
|
||||
map["message"] as String,
|
||||
ExchangeExceptionType.generic,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final value = EstimatedExchangeAmount.fromJson(map);
|
||||
return ExchangeResponse(
|
||||
value: Estimate(
|
||||
estimatedAmount: value.estimatedAmount,
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||
import 'package:decimal/decimal.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:stackwallet/exceptions/exchange/exchange_exception.dart';
|
||||
import 'package:stackwallet/exceptions/exchange/pair_unavailable_exception.dart';
|
||||
import 'package:stackwallet/models/exchange/majestic_bank/mb_limit.dart';
|
||||
import 'package:stackwallet/models/exchange/majestic_bank/mb_order.dart';
|
||||
import 'package:stackwallet/models/exchange/majestic_bank/mb_order_calculation.dart';
|
||||
|
@ -39,7 +40,6 @@ class MajesticBankAPI {
|
|||
);
|
||||
|
||||
code = response.statusCode;
|
||||
print(response.body);
|
||||
|
||||
final parsed = jsonDecode(response.body);
|
||||
|
||||
|
@ -180,6 +180,28 @@ class MajesticBankAPI {
|
|||
try {
|
||||
final jsonObject = await _makeGetRequest(uri);
|
||||
final map = Map<String, dynamic>.from(jsonObject as Map);
|
||||
|
||||
if (map["error"] != null) {
|
||||
final errorMessage = map["extra"] as String?;
|
||||
if (errorMessage != null &&
|
||||
errorMessage.startsWith("Bad") &&
|
||||
errorMessage.endsWith("currency symbol")) {
|
||||
return ExchangeResponse(
|
||||
exception: PairUnavailableException(
|
||||
errorMessage,
|
||||
ExchangeExceptionType.generic,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return ExchangeResponse(
|
||||
exception: ExchangeException(
|
||||
errorMessage ?? "Error: ${map["error"]}",
|
||||
ExchangeExceptionType.generic,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final result = MBOrderCalculation(
|
||||
fromCurrency: map["from_currency"] as String,
|
||||
fromAmount: Decimal.parse(map["from_amount"].toString()),
|
||||
|
|
|
@ -162,6 +162,7 @@ class MajesticBankExchange extends Exchange {
|
|||
receiveCurrency: to,
|
||||
);
|
||||
if (response.value == null) {
|
||||
print("AAAAAAAAAAAAAAAAAAAA ${response.exception}");
|
||||
return ExchangeResponse(exception: response.exception);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue