show loading while updating rate on newly selected currency

This commit is contained in:
julian 2023-02-06 15:58:20 -06:00
parent 243acd09ba
commit aa3d6f4102

View file

@ -107,17 +107,14 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
return; return;
} }
// TODO: return currency and await update while showing loading final selectedCurrency = await _showCurrencySelectionSheet(
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider).sendCurrency, willChange: ref.read(exchangeFormStateProvider).sendCurrency,
willChangeIsSend: true, willChangeIsSend: true,
paired: ref.read(exchangeFormStateProvider).receiveCurrency, paired: ref.read(exchangeFormStateProvider).receiveCurrency,
isFixedRate: type == ExchangeRateType.fixed, isFixedRate: type == ExchangeRateType.fixed,
onSelected: (selectedCurrency) => ref
.read(exchangeFormStateProvider)
.updateSendCurrency(selectedCurrency, true),
); );
if (selectedCurrency != null) {
unawaited( unawaited(
showDialog<void>( showDialog<void>(
context: context, context: context,
@ -138,7 +135,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
), ),
); );
// await Future<void>.delayed(const Duration(milliseconds: 300)); await ref
.read(exchangeFormStateProvider)
.updateSendCurrency(selectedCurrency, true);
}
if (mounted) { if (mounted) {
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
@ -146,26 +146,22 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
} }
void selectReceiveCurrency() async { void selectReceiveCurrency() async {
final type = (ref.read(prefsChangeNotifierProvider).exchangeRateType);
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? ""; final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "";
if (walletInitiated && if (walletInitiated &&
toTicker.toLowerCase() == coin!.ticker.toLowerCase()) { toTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
// do not allow changing away from wallet coin // do not allow changing away from wallet coin
return; return;
} }
// TODO: return currency and await update while showing loading final selectedCurrency = await _showCurrencySelectionSheet(
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider).receiveCurrency, willChange: ref.read(exchangeFormStateProvider).receiveCurrency,
willChangeIsSend: false, willChangeIsSend: false,
paired: ref.read(exchangeFormStateProvider).sendCurrency, paired: ref.read(exchangeFormStateProvider).sendCurrency,
isFixedRate: type == ExchangeRateType.fixed, isFixedRate: ref.read(prefsChangeNotifierProvider).exchangeRateType ==
onSelected: (selectedCurrency) => ref ExchangeRateType.fixed,
.read(exchangeFormStateProvider)
.updateReceivingCurrency(selectedCurrency, true),
); );
if (selectedCurrency != null) {
unawaited( unawaited(
showDialog<void>( showDialog<void>(
context: context, context: context,
@ -186,7 +182,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
), ),
); );
// await Future<void>.delayed(const Duration(milliseconds: 300)); await ref
.read(exchangeFormStateProvider)
.updateReceivingCurrency(selectedCurrency, true);
}
if (mounted) { if (mounted) {
Navigator.of(context, rootNavigator: true).pop(); Navigator.of(context, rootNavigator: true).pop();
@ -226,12 +225,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
_swapLock = false; _swapLock = false;
} }
Future<void> _showCurrencySelectionSheet({ Future<Currency?> _showCurrencySelectionSheet({
required Currency? willChange, required Currency? willChange,
required Currency? paired, required Currency? paired,
required bool isFixedRate, required bool isFixedRate,
required bool willChangeIsSend, required bool willChangeIsSend,
required void Function(Currency) onSelected,
}) async { }) async {
_sendFocusNode.unfocus(); _sendFocusNode.unfocus();
_receiveFocusNode.unfocus(); _receiveFocusNode.unfocus();
@ -309,7 +307,9 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
); );
if (mounted && result is Currency) { if (mounted && result is Currency) {
onSelected(result); return result;
} else {
return null;
} }
} }