CWA-169 | added call of loadLimits() to changeProvider() and reset() in exchange store. Added btc-xmr pair, added conversion units to crypto amounts to fetchLimits() in MorphTokenExchangeProvider

This commit is contained in:
Oleksandr Sobol 2020-02-06 20:30:32 +02:00
parent 95222ecbae
commit 348d1080c9
2 changed files with 25 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart'; import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart';
import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart'; import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
class MorphTokenExchangeProvider extends ExchangeProvider { class MorphTokenExchangeProvider extends ExchangeProvider {
MorphTokenExchangeProvider() MorphTokenExchangeProvider()
@ -50,7 +51,8 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.eth), ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.eth),
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.bch), ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.bch),
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.ltc), ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.ltc),
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash) ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash),
ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.xmr)
]); ]);
final trades = Hive.box<Trade>(Trade.boxName); final trades = Hive.box<Trade>(Trade.boxName);
@ -70,6 +72,8 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
@override @override
Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async { Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
const ethereumAmountDivider = 1000000000000000000;
const defaultAmountDivider = 100000000;
final url = apiUri + _limitsURISuffix; final url = apiUri + _limitsURISuffix;
final headers = {'Content-type': 'application/json'}; final headers = {'Content-type': 'application/json'};
final body = final body =
@ -87,8 +91,25 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
final min = responseJSON['input']['limits']['min'] as int; final min = responseJSON['input']['limits']['min'] as int;
final max = responseJSON['input']['limits']['max'] as int; final max = responseJSON['input']['limits']['max'] as int;
double minDouble;
double maxDouble;
return Limits(min: min.toDouble(), max: max.toDouble()); switch (from) {
case CryptoCurrency.xmr:
minDouble = moneroAmountToDouble(amount: min);
maxDouble = moneroAmountToDouble(amount: max);
break;
case CryptoCurrency.eth:
minDouble = min/ethereumAmountDivider;
maxDouble = max/ethereumAmountDivider;
break;
default:
minDouble = min/defaultAmountDivider;
maxDouble = max/defaultAmountDivider;
break;
}
return Limits(min: minDouble, max: maxDouble);
} }
@override @override

View file

@ -79,6 +79,7 @@ abstract class ExchangeStoreBase with Store {
this.provider = provider; this.provider = provider;
depositAmount = ''; depositAmount = '';
receiveAmount = ''; receiveAmount = '';
loadLimits();
} }
@action @action
@ -192,6 +193,7 @@ abstract class ExchangeStoreBase with Store {
provider = XMRTOExchangeProvider(); provider = XMRTOExchangeProvider();
depositCurrency = CryptoCurrency.xmr; depositCurrency = CryptoCurrency.xmr;
receiveCurrency = CryptoCurrency.btc; receiveCurrency = CryptoCurrency.btc;
loadLimits();
} }
List<ExchangeProvider> providersForCurrentPair() { List<ExchangeProvider> providersForCurrentPair() {