currency select function fix

This commit is contained in:
julian 2023-02-05 15:25:35 -06:00
parent 5aab115b96
commit 4345a67d3f
2 changed files with 20 additions and 18 deletions

View file

@ -654,7 +654,7 @@ class ExchangeFormState extends ChangeNotifier {
}
}
Future<void> updateFrom(
Future<void> updateSendCurrency(
Currency sendCurrency,
bool shouldNotifyListeners,
) async {
@ -667,15 +667,15 @@ class ExchangeFormState extends ChangeNotifier {
shouldNotifyListeners: false,
);
}
if (shouldNotifyListeners) {
notifyListeners();
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Error);
}
if (shouldNotifyListeners) {
notifyListeners();
}
}
Future<void> updateTo(
Future<void> updateReceivingCurrency(
Currency receiveCurrency,
bool shouldNotifyListeners,
) async {
@ -689,12 +689,12 @@ class ExchangeFormState extends ChangeNotifier {
shouldNotifyListeners: false,
);
}
if (shouldNotifyListeners) {
notifyListeners();
}
} catch (e, s) {
Logging.instance.log("$e\n$s", level: LogLevel.Error);
}
if (shouldNotifyListeners) {
notifyListeners();
}
}
Future<void> swap({

View file

@ -121,10 +121,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider(type)).sendCurrency,
paired: ref.read(exchangeFormStateProvider(type)).receiveCurrency,
isFixedRate: ref.read(prefsChangeNotifierProvider).exchangeRateType ==
ExchangeRateType.fixed,
onSelected: (to) =>
ref.read(exchangeFormStateProvider(type)).updateTo(to, true),
isFixedRate: type == ExchangeRateType.fixed,
onSelected: (selectedCurrency) => ref
.read(exchangeFormStateProvider(type))
.updateSendCurrency(selectedCurrency, true),
);
unawaited(
@ -167,10 +167,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider(type)).receiveCurrency,
paired: ref.read(exchangeFormStateProvider(type)).sendCurrency,
isFixedRate: ref.read(prefsChangeNotifierProvider).exchangeRateType ==
ExchangeRateType.fixed,
onSelected: (to) =>
ref.read(exchangeFormStateProvider(type)).updateTo(to, true),
isFixedRate: type == ExchangeRateType.fixed,
onSelected: (selectedCurrency) => ref
.read(exchangeFormStateProvider(type))
.updateReceivingCurrency(selectedCurrency, true),
);
unawaited(
@ -389,10 +389,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
_receiveController.text = "";
}
await ref.read(exchangeFormStateProvider(type)).updateTo(to, false);
await ref
.read(exchangeFormStateProvider(type))
.updateFrom(from, true);
.updateReceivingCurrency(to, false);
await ref
.read(exchangeFormStateProvider(type))
.updateSendCurrency(from, true);
_receiveController.text =
ref.read(exchangeFormStateProvider(type)).toAmountString.isEmpty