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

Oleksandr Sobol committed Feb 6, 2020 at 20:30 UTC 348d1080c9c8523ea83887dee641819007eeb764
2 files changed +25 -2
lib/src/domain/exchange/morphtoken/morphtoken_exchange_provider.dart
+23 -2
@@ -13,6 +13,7 @@ import 'package:cake_wallet/src/domain/exchange/trade_state.dart';
13 import 'package:cake_wallet/src/domain/exchange/morphtoken/morphtoken_request.dart';
14 import 'package:cake_wallet/src/domain/exchange/exchange_provider_description.dart';
15 import 'package:cake_wallet/src/domain/exchange/trade_not_created_exeption.dart';
16 +import 'package:cake_wallet/src/domain/monero/monero_amount_format.dart';
17
18 class MorphTokenExchangeProvider extends ExchangeProvider {
19 MorphTokenExchangeProvider()
@@ -50,7 +51,8 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
51 ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.eth),
52 ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.bch),
53 ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.ltc),
53 - ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash)
54 + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.dash),
55 + ExchangePair(from: CryptoCurrency.btc, to: CryptoCurrency.xmr)
56 ]);
57
58 final trades = Hive.box<Trade>(Trade.boxName);
@@ -70,6 +72,8 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
72
73 @override
74 Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
75 + const ethereumAmountDivider = 1000000000000000000;
76 + const defaultAmountDivider = 100000000;
77 final url = apiUri + _limitsURISuffix;
78 final headers = {'Content-type': 'application/json'};
79 final body =
@@ -87,8 +91,25 @@ class MorphTokenExchangeProvider extends ExchangeProvider {
91
92 final min = responseJSON['input']['limits']['min'] as int;
93 final max = responseJSON['input']['limits']['max'] as int;
94 + double minDouble;
95 + double maxDouble;
96
91 - return Limits(min: min.toDouble(), max: max.toDouble());
97 + switch (from) {
98 + case CryptoCurrency.xmr:
99 + minDouble = moneroAmountToDouble(amount: min);
100 + maxDouble = moneroAmountToDouble(amount: max);
101 + break;
102 + case CryptoCurrency.eth:
103 + minDouble = min/ethereumAmountDivider;
104 + maxDouble = max/ethereumAmountDivider;
105 + break;
106 + default:
107 + minDouble = min/defaultAmountDivider;
108 + maxDouble = max/defaultAmountDivider;
109 + break;
110 + }
111 +
112 + return Limits(min: minDouble, max: maxDouble);
113 }
114
115 @override
lib/src/stores/exchange/exchange_store.dart
+2
@@ -79,6 +79,7 @@ abstract class ExchangeStoreBase with Store {
79 this.provider = provider;
80 depositAmount = '';
81 receiveAmount = '';
82 + loadLimits();
83 }
84
85 @action
@@ -192,6 +193,7 @@ abstract class ExchangeStoreBase with Store {
193 provider = XMRTOExchangeProvider();
194 depositCurrency = CryptoCurrency.xmr;
195 receiveCurrency = CryptoCurrency.btc;
196 + loadLimits();
197 }
198
199 List<ExchangeProvider> providersForCurrentPair() {