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,38 +107,38 @@ 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),
); );
unawaited( if (selectedCurrency != null) {
showDialog<void>( unawaited(
context: context, showDialog<void>(
barrierDismissible: false, context: context,
builder: (_) => WillPopScope( barrierDismissible: false,
onWillPop: () async => false, builder: (_) => WillPopScope(
child: Container( onWillPop: () async => false,
color: Theme.of(context) child: Container(
.extension<StackColors>()! color: Theme.of(context)
.overlay .extension<StackColors>()!
.withOpacity(0.6), .overlay
child: const CustomLoadingOverlay( .withOpacity(0.6),
message: "Updating exchange rate", child: const CustomLoadingOverlay(
eventBus: null, message: "Updating exchange rate",
eventBus: null,
),
), ),
), ),
), ),
), );
);
// 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,47 +146,46 @@ 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),
); );
unawaited( if (selectedCurrency != null) {
showDialog<void>( unawaited(
context: context, showDialog<void>(
barrierDismissible: false, context: context,
builder: (_) => WillPopScope( barrierDismissible: false,
onWillPop: () async => false, builder: (_) => WillPopScope(
child: Container( onWillPop: () async => false,
color: Theme.of(context) child: Container(
.extension<StackColors>()! color: Theme.of(context)
.overlay .extension<StackColors>()!
.withOpacity(0.6), .overlay
child: const CustomLoadingOverlay( .withOpacity(0.6),
message: "Updating exchange rate", child: const CustomLoadingOverlay(
eventBus: null, message: "Updating exchange rate",
eventBus: null,
),
), ),
), ),
), ),
), );
);
// 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;
} }
} }