mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-22 06:28:39 +02:00
CAKE-278 | fixed calculating estimated amount when receive amount is entered; fixed applyTemplate() method in the exchange_page.dart and reset() method in the exchange_view_model.dart
This commit is contained in:
@@ -173,8 +173,32 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
|||||||
double amount,
|
double amount,
|
||||||
bool isFixedRateMode,
|
bool isFixedRateMode,
|
||||||
bool isReceiveAmount}) async {
|
bool isReceiveAmount}) async {
|
||||||
final url = isFixedRateMode
|
if (isReceiveAmount && isFixedRateMode) {
|
||||||
? apiUri +
|
final url = apiUri + _marketInfoUriSufix + _fixedRateUriSufix + apiKey;
|
||||||
|
final response = await get(url);
|
||||||
|
final responseJSON = json.decode(response.body) as List<dynamic>;
|
||||||
|
var rate = 0.0;
|
||||||
|
var fee = 0.0;
|
||||||
|
|
||||||
|
for (var elem in responseJSON) {
|
||||||
|
final elemFrom = elem["from"] as String;
|
||||||
|
final elemTo = elem["to"] as String;
|
||||||
|
|
||||||
|
if ((elemFrom == to.toString().toLowerCase()) &&
|
||||||
|
(elemTo == from.toString().toLowerCase())) {
|
||||||
|
rate = elem["rate"] as double;
|
||||||
|
fee = elem["minerFee"] as double;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final estimatedAmount = (amount == 0.0)||(rate == 0.0) ? 0.0
|
||||||
|
: (amount + fee)/rate;
|
||||||
|
|
||||||
|
return estimatedAmount;
|
||||||
|
} else {
|
||||||
|
final url = isFixedRateMode
|
||||||
|
? apiUri +
|
||||||
_exchangeAmountUriSufix +
|
_exchangeAmountUriSufix +
|
||||||
_fixedRateUriSufix +
|
_fixedRateUriSufix +
|
||||||
amount.toString() +
|
amount.toString() +
|
||||||
@@ -183,17 +207,18 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
|||||||
'_' +
|
'_' +
|
||||||
to.toString() +
|
to.toString() +
|
||||||
'?api_key=' + apiKey
|
'?api_key=' + apiKey
|
||||||
: apiUri +
|
: apiUri +
|
||||||
_exchangeAmountUriSufix +
|
_exchangeAmountUriSufix +
|
||||||
amount.toString() +
|
amount.toString() +
|
||||||
'/' +
|
'/' +
|
||||||
from.toString() +
|
from.toString() +
|
||||||
'_' +
|
'_' +
|
||||||
to.toString();
|
to.toString();
|
||||||
final response = await get(url);
|
final response = await get(url);
|
||||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
final estimatedAmount = responseJSON['estimatedAmount'] as double;
|
final estimatedAmount = responseJSON['estimatedAmount'] as double;
|
||||||
|
|
||||||
return estimatedAmount;
|
return estimatedAmount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,17 +480,9 @@ class ExchangePage extends BasePage {
|
|||||||
currency: CryptoCurrency.fromString(template.receiveCurrency));
|
currency: CryptoCurrency.fromString(template.receiveCurrency));
|
||||||
|
|
||||||
switch (template.provider) {
|
switch (template.provider) {
|
||||||
case 'XMR.TO':
|
|
||||||
exchangeViewModel.changeProvider(
|
|
||||||
provider: exchangeViewModel.providerList[0]);
|
|
||||||
break;
|
|
||||||
case 'ChangeNOW':
|
case 'ChangeNOW':
|
||||||
exchangeViewModel.changeProvider(
|
exchangeViewModel.changeProvider(
|
||||||
provider: exchangeViewModel.providerList[1]);
|
provider: exchangeViewModel.providerList[0]);
|
||||||
break;
|
|
||||||
case 'MorphToken':
|
|
||||||
exchangeViewModel.changeProvider(
|
|
||||||
provider: exchangeViewModel.providerList[2]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,6 +490,7 @@ class ExchangePage extends BasePage {
|
|||||||
exchangeViewModel.depositAddress = template.depositAddress;
|
exchangeViewModel.depositAddress = template.depositAddress;
|
||||||
exchangeViewModel.receiveAddress = template.receiveAddress;
|
exchangeViewModel.receiveAddress = template.receiveAddress;
|
||||||
exchangeViewModel.isReceiveAmountEntered = false;
|
exchangeViewModel.isReceiveAmountEntered = false;
|
||||||
|
exchangeViewModel.isFixedRateMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setReactions(
|
void _setReactions(
|
||||||
@@ -670,12 +663,11 @@ class ExchangePage extends BasePage {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertWithTwoActions(
|
return AlertWithTwoActions(
|
||||||
alertTitle: S.of(context).exchange,
|
alertTitle: S.of(context).exchange,
|
||||||
alertContent: 'You will be able to enter receive amount when fixed rate is checked. Do you want to check fixed rate?', //FIXME
|
alertContent: 'You will be able to enter receive amount when fixed rate mode is checked. Do you want to switch to fixed rate mode?', //FIXME
|
||||||
leftButtonText: S.of(context).cancel,
|
leftButtonText: S.of(context).cancel,
|
||||||
rightButtonText: S.of(context).ok,
|
rightButtonText: S.of(context).ok,
|
||||||
actionLeftButton: () {
|
actionLeftButton: () {
|
||||||
FocusScope.of(context).unfocus();
|
FocusScope.of(context).unfocus();
|
||||||
receiveAmountController.text = '';
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
actionRightButton: () {
|
actionRightButton: () {
|
||||||
|
|||||||
@@ -301,11 +301,10 @@ abstract class ExchangeViewModelBase with Store {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
void reset() {
|
void reset() {
|
||||||
|
_initialPairBasedOnWallet();
|
||||||
isReceiveAmountEntered = false;
|
isReceiveAmountEntered = false;
|
||||||
depositAmount = '';
|
depositAmount = '';
|
||||||
receiveAmount = '';
|
receiveAmount = '';
|
||||||
depositCurrency = CryptoCurrency.xmr;
|
|
||||||
receiveCurrency = CryptoCurrency.btc;
|
|
||||||
depositAddress = depositCurrency == wallet.currency ? wallet.address : '';
|
depositAddress = depositCurrency == wallet.currency ? wallet.address : '';
|
||||||
receiveAddress = receiveCurrency == wallet.currency ? wallet.address : '';
|
receiveAddress = receiveCurrency == wallet.currency ? wallet.address : '';
|
||||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||||
|
|||||||
Reference in New Issue
Block a user