mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-04 12:34:14 +01:00
Cw 897 stable coins exchanges rate issue (#1939)
* update amount in UI when best rate changes * minor fixes * update rate when amount has changed
This commit is contained in:
@@ -115,9 +115,9 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
.toList());
|
||||
|
||||
_setAvailableProviders();
|
||||
_calculateBestRate();
|
||||
calculateBestRate();
|
||||
|
||||
bestRateSync = Timer.periodic(Duration(seconds: 10), (timer) => _calculateBestRate());
|
||||
bestRateSync = Timer.periodic(Duration(seconds: 10), (timer) => calculateBestRate());
|
||||
|
||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||
depositAmount = '';
|
||||
@@ -144,8 +144,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
loadLimits();
|
||||
reaction((_) => isFixedRateMode, (Object _) {
|
||||
loadLimits();
|
||||
_bestRate = 0;
|
||||
_calculateBestRate();
|
||||
bestRate = 0;
|
||||
calculateBestRate();
|
||||
});
|
||||
|
||||
if (isElectrumWallet) {
|
||||
@@ -334,7 +334,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
final ContactListViewModel contactListViewModel;
|
||||
|
||||
double _bestRate = 0.0;
|
||||
@observable
|
||||
double bestRate = 0.0;
|
||||
|
||||
late Timer bestRateSync;
|
||||
|
||||
@@ -366,15 +367,15 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
final _enteredAmount = double.tryParse(amount.replaceAll(',', '.')) ?? 0;
|
||||
|
||||
if (_bestRate == 0) {
|
||||
if (bestRate == 0) {
|
||||
depositAmount = S.current.fetching;
|
||||
|
||||
await _calculateBestRate();
|
||||
await calculateBestRate();
|
||||
}
|
||||
_cryptoNumberFormat.maximumFractionDigits = depositMaxDigits;
|
||||
|
||||
depositAmount = _cryptoNumberFormat
|
||||
.format(_enteredAmount / _bestRate)
|
||||
.format(_enteredAmount / bestRate)
|
||||
.toString()
|
||||
.replaceAll(RegExp('\\,'), '');
|
||||
}
|
||||
@@ -392,15 +393,15 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
final _enteredAmount = double.tryParse(amount.replaceAll(',', '.')) ?? 0;
|
||||
|
||||
/// in case the best rate was not calculated yet
|
||||
if (_bestRate == 0) {
|
||||
if (bestRate == 0) {
|
||||
receiveAmount = S.current.fetching;
|
||||
|
||||
await _calculateBestRate();
|
||||
await calculateBestRate();
|
||||
}
|
||||
_cryptoNumberFormat.maximumFractionDigits = receiveMaxDigits;
|
||||
|
||||
receiveAmount = _cryptoNumberFormat
|
||||
.format(_bestRate * _enteredAmount)
|
||||
.format(bestRate * _enteredAmount)
|
||||
.toString()
|
||||
.replaceAll(RegExp('\\,'), '');
|
||||
}
|
||||
@@ -416,8 +417,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> _calculateBestRate() async {
|
||||
Future<void> calculateBestRate() async {
|
||||
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;
|
||||
|
||||
final _providers = _tradeAvailableProviders
|
||||
@@ -453,7 +453,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_sortedAvailableProviders.isNotEmpty) _bestRate = _sortedAvailableProviders.keys.first;
|
||||
if (_sortedAvailableProviders.isNotEmpty) bestRate = _sortedAvailableProviders.keys.first;
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -533,7 +533,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
if (!(await provider.checkIsAvailable())) continue;
|
||||
|
||||
_bestRate = providerRate;
|
||||
bestRate = providerRate;
|
||||
await changeDepositAmount(amount: depositAmount);
|
||||
|
||||
final request = TradeRequest(
|
||||
@@ -693,8 +693,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
receiveAmount = '';
|
||||
loadLimits();
|
||||
_setAvailableProviders();
|
||||
_bestRate = 0;
|
||||
_calculateBestRate();
|
||||
bestRate = 0;
|
||||
calculateBestRate();
|
||||
}
|
||||
|
||||
void _initialPairBasedOnWallet() {
|
||||
@@ -785,8 +785,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
isFixedRateMode = false;
|
||||
_defineIsReceiveAmountEditable();
|
||||
loadLimits();
|
||||
_bestRate = 0;
|
||||
_calculateBestRate();
|
||||
bestRate = 0;
|
||||
calculateBestRate();
|
||||
|
||||
final Map<String, dynamic> exchangeProvidersSelection =
|
||||
json.decode(sharedPreferences.getString(PreferencesKey.exchangeProvidersSelection) ?? "{}")
|
||||
|
||||
Reference in New Issue
Block a user