ensure exchange is updated properly

This commit is contained in:
julian 2023-02-06 17:49:27 -06:00
parent 287c226416
commit 842593d6b2
2 changed files with 12 additions and 14 deletions

View file

@ -646,17 +646,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
final rateType = ref.watch( final rateType = ref.watch(
prefsChangeNotifierProvider.select((value) => value.exchangeRateType)); prefsChangeNotifierProvider.select((value) => value.exchangeRateType));
ref.listen<String>(currentExchangeNameStateProvider, (previous, next) { final isEstimated = rateType == ExchangeRateType.estimated;
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
shouldUpdateData: true,
shouldNotifyListeners: true,
);
});
final isEstimated = ref.watch(prefsChangeNotifierProvider
.select((pref) => pref.exchangeRateType)) ==
ExchangeRateType.estimated;
ref.listen( ref.listen(
exchangeFormStateProvider.select((value) => value.toAmountString), exchangeFormStateProvider.select((value) => value.toAmountString),
@ -854,9 +844,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
to: ref.watch(exchangeFormStateProvider).toTicker, to: ref.watch(exchangeFormStateProvider).toTicker,
fromAmount: ref.watch(exchangeFormStateProvider).sendAmount, fromAmount: ref.watch(exchangeFormStateProvider).sendAmount,
toAmount: ref.watch(exchangeFormStateProvider).receiveAmount, toAmount: ref.watch(exchangeFormStateProvider).receiveAmount,
fixedRate: ref.watch(prefsChangeNotifierProvider fixedRate: rateType == ExchangeRateType.fixed,
.select((value) => value.exchangeRateType)) ==
ExchangeRateType.fixed,
reversed: ref.watch( reversed: ref.watch(
exchangeFormStateProvider.select((value) => value.reversed)), exchangeFormStateProvider.select((value) => value.reversed)),
), ),

View file

@ -60,6 +60,11 @@ class ExchangeProviderOptions extends ConsumerWidget {
ChangeNowExchange.exchangeName) { ChangeNowExchange.exchangeName) {
ref.read(currentExchangeNameStateProvider.state).state = ref.read(currentExchangeNameStateProvider.state).state =
ChangeNowExchange.exchangeName; ChangeNowExchange.exchangeName;
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
shouldUpdateData: true,
shouldNotifyListeners: true,
);
} }
}, },
child: Container( child: Container(
@ -290,6 +295,11 @@ class ExchangeProviderOptions extends ConsumerWidget {
MajesticBankExchange.exchangeName) { MajesticBankExchange.exchangeName) {
ref.read(currentExchangeNameStateProvider.state).state = ref.read(currentExchangeNameStateProvider.state).state =
MajesticBankExchange.exchangeName; MajesticBankExchange.exchangeName;
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
shouldUpdateData: true,
shouldNotifyListeners: true,
);
} }
}, },
child: Container( child: Container(