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

View file

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