mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 11:39:22 +00:00
Merge pull request #46 from cake-tech/CWA-199-changes-for-xmrTo-exchange
CWA-199 | changed possibility to enter amount in the deposit card onl…
This commit is contained in:
commit
2673ecd45e
3 changed files with 39 additions and 42 deletions
|
@ -54,14 +54,31 @@ class XMRTOExchangeProvider extends ExchangeProvider {
|
|||
Future<Limits> fetchLimits({CryptoCurrency from, CryptoCurrency to}) async {
|
||||
final url = await getApiUri() + _orderParameterUriSufix;
|
||||
final response = await get(url);
|
||||
final correction = 0.001;
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return Limits(min: 0, max: 0);
|
||||
}
|
||||
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final min = responseJSON['lower_limit'] as double;
|
||||
final max = responseJSON['upper_limit'] as double;
|
||||
double min = responseJSON['lower_limit'] as double;
|
||||
double max = responseJSON['upper_limit'] as double;
|
||||
final price = responseJSON['price'] as double;
|
||||
|
||||
if (price > 0) {
|
||||
try {
|
||||
min = min/price + correction;
|
||||
min = _limitsFormat(min);
|
||||
max = max/price - correction;
|
||||
max = _limitsFormat(max);
|
||||
} catch (e) {
|
||||
min = 0;
|
||||
max = 0;
|
||||
}
|
||||
} else {
|
||||
min = 0;
|
||||
max = 0;
|
||||
}
|
||||
|
||||
return Limits(min: min, max: max);
|
||||
}
|
||||
|
@ -71,7 +88,7 @@ class XMRTOExchangeProvider extends ExchangeProvider {
|
|||
final _request = request as XMRTOTradeRequest;
|
||||
final url = await getApiUri() + _orderCreateUriSufix;
|
||||
final body = {
|
||||
'btc_amount': _request.amount,
|
||||
'xmr_amount': _request.amount,
|
||||
'btc_dest_address': _request.address
|
||||
};
|
||||
final response = await post(url,
|
||||
|
@ -168,8 +185,7 @@ class XMRTOExchangeProvider extends ExchangeProvider {
|
|||
final response =
|
||||
await get(url, headers: {'Content-Type': 'application/json'});
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final btcprice = responseJSON['price'] as double;
|
||||
final price = 1 / btcprice;
|
||||
final price = responseJSON['price'] as double;
|
||||
|
||||
return price;
|
||||
} catch (e) {
|
||||
|
@ -177,4 +193,6 @@ class XMRTOExchangeProvider extends ExchangeProvider {
|
|||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
double _limitsFormat(double limit) => double.parse(limit.toStringAsFixed(3));
|
||||
}
|
||||
|
|
|
@ -168,12 +168,9 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
exchangeStore.depositCurrency == walletStore.type
|
||||
? walletStore.address
|
||||
: null,
|
||||
initialIsAmountEditable:
|
||||
!(exchangeStore.provider is XMRTOExchangeProvider),
|
||||
initialIsAddressEditable:
|
||||
!(exchangeStore.provider is XMRTOExchangeProvider),
|
||||
isAmountEstimated:
|
||||
exchangeStore.provider is XMRTOExchangeProvider,
|
||||
initialIsAmountEditable: true,
|
||||
initialIsAddressEditable: true,
|
||||
isAmountEstimated: false,
|
||||
currencies: CryptoCurrency.all,
|
||||
onCurrencySelected: (currency) =>
|
||||
exchangeStore.changeDepositCurrency(currency: currency),
|
||||
|
@ -209,12 +206,9 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
exchangeStore.receiveCurrency == walletStore.type
|
||||
? walletStore.address
|
||||
: null,
|
||||
initialIsAmountEditable:
|
||||
exchangeStore.provider is XMRTOExchangeProvider,
|
||||
initialIsAddressEditable:
|
||||
exchangeStore.provider is XMRTOExchangeProvider,
|
||||
isAmountEstimated: !(exchangeStore.provider
|
||||
is XMRTOExchangeProvider),
|
||||
initialIsAmountEditable: false,
|
||||
initialIsAddressEditable: true,
|
||||
isAmountEstimated: true,
|
||||
currencies: CryptoCurrency.all,
|
||||
onCurrencySelected: (currency) => exchangeStore
|
||||
.changeReceiveCurrency(currency: currency),
|
||||
|
@ -321,8 +315,7 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
final max = limitsState.limits.max != null
|
||||
? limitsState.limits.max.toString()
|
||||
: null;
|
||||
final key =
|
||||
store.provider is XMRTOExchangeProvider ? receiveKey : depositKey;
|
||||
final key = depositKey;
|
||||
key.currentState.changeLimits(min: min, max: max);
|
||||
}
|
||||
|
||||
|
@ -363,22 +356,12 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
});
|
||||
|
||||
reaction((_) => store.provider, (ExchangeProvider provider) {
|
||||
final isReversed = provider is XMRTOExchangeProvider;
|
||||
|
||||
if (isReversed) {
|
||||
receiveKey.currentState.isAddressEditable(isEditable: true);
|
||||
receiveKey.currentState.isAmountEditable(isEditable: true);
|
||||
depositKey.currentState.isAddressEditable(isEditable: false);
|
||||
depositKey.currentState.isAmountEditable(isEditable: false);
|
||||
} else {
|
||||
receiveKey.currentState.isAddressEditable(isEditable: true);
|
||||
receiveKey.currentState.isAmountEditable(isEditable: false);
|
||||
depositKey.currentState.isAddressEditable(isEditable: true);
|
||||
depositKey.currentState.isAmountEditable(isEditable: true);
|
||||
}
|
||||
|
||||
depositKey.currentState.changeIsAmountEstimated(isReversed);
|
||||
receiveKey.currentState.changeIsAmountEstimated(!isReversed);
|
||||
receiveKey.currentState.changeIsAmountEstimated(true);
|
||||
});
|
||||
|
||||
reaction((_) => store.tradeState, (ExchangeTradeState state) {
|
||||
|
@ -406,7 +389,6 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
});
|
||||
|
||||
reaction((_) => store.limitsState, (LimitsState state) {
|
||||
final isXMRTO = store.provider is XMRTOExchangeProvider;
|
||||
String min;
|
||||
String max;
|
||||
|
||||
|
@ -425,13 +407,8 @@ class ExchangeFormState extends State<ExchangeForm> {
|
|||
max = '...';
|
||||
}
|
||||
|
||||
final depositMin = isXMRTO ? null : min;
|
||||
final depositMax = isXMRTO ? null : max;
|
||||
final receiveMin = isXMRTO ? min : null;
|
||||
final receiveMax = isXMRTO ? max : null;
|
||||
|
||||
depositKey.currentState.changeLimits(min: depositMin, max: depositMax);
|
||||
receiveKey.currentState.changeLimits(min: receiveMin, max: receiveMax);
|
||||
depositKey.currentState.changeLimits(min: min, max: max);
|
||||
receiveKey.currentState.changeLimits(min: null, max: null);
|
||||
});
|
||||
|
||||
depositAddressController.addListener(
|
||||
|
|
|
@ -107,6 +107,7 @@ abstract class ExchangeStoreBase with Store {
|
|||
|
||||
if (amount == null || amount.isEmpty) {
|
||||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -125,6 +126,7 @@ abstract class ExchangeStoreBase with Store {
|
|||
|
||||
if (amount == null || amount.isEmpty) {
|
||||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -157,13 +159,13 @@ abstract class ExchangeStoreBase with Store {
|
|||
|
||||
if (provider is XMRTOExchangeProvider) {
|
||||
request = XMRTOTradeRequest(
|
||||
to: receiveCurrency,
|
||||
from: depositCurrency,
|
||||
amount: receiveAmount,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount,
|
||||
address: receiveAddress,
|
||||
refundAddress: depositAddress);
|
||||
amount = receiveAmount;
|
||||
currency = receiveCurrency;
|
||||
amount = depositAmount;
|
||||
currency = depositCurrency;
|
||||
}
|
||||
|
||||
if (provider is ChangeNowExchangeProvider) {
|
||||
|
|
Loading…
Reference in a new issue