mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
clean up exchange_form.dart
This commit is contained in:
parent
aa3d6f4102
commit
287c226416
1 changed files with 51 additions and 115 deletions
|
@ -19,7 +19,6 @@ import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_ste
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
||||||
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
||||||
// import 'package:stackwallet/services/exchange/simpleswap/simpleswap_exchange.dart';
|
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
@ -67,7 +66,39 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
bool _swapLock = false;
|
bool _swapLock = false;
|
||||||
|
|
||||||
// todo: check and adjust this value?
|
// todo: check and adjust this value?
|
||||||
static const _valueCheckInterval = Duration(milliseconds: 500);
|
static const _valueCheckInterval = Duration(milliseconds: 300);
|
||||||
|
|
||||||
|
Future<T> showUpdatingExchangeRate<T>({
|
||||||
|
required Future<T> whileFuture,
|
||||||
|
}) async {
|
||||||
|
unawaited(
|
||||||
|
showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (_) => WillPopScope(
|
||||||
|
onWillPop: () async => false,
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.overlay
|
||||||
|
.withOpacity(0.6),
|
||||||
|
child: const CustomLoadingOverlay(
|
||||||
|
message: "Updating exchange rate",
|
||||||
|
eventBus: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final result = await whileFuture;
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context, rootNavigator: isDesktop).pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Timer? _sendFieldOnChangedTimer;
|
Timer? _sendFieldOnChangedTimer;
|
||||||
void sendFieldOnChanged(String value) async {
|
void sendFieldOnChanged(String value) async {
|
||||||
|
@ -115,33 +146,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selectedCurrency != null) {
|
if (selectedCurrency != null) {
|
||||||
unawaited(
|
await showUpdatingExchangeRate(
|
||||||
showDialog<void>(
|
whileFuture: ref
|
||||||
context: context,
|
.read(exchangeFormStateProvider)
|
||||||
barrierDismissible: false,
|
.updateSendCurrency(selectedCurrency, true),
|
||||||
builder: (_) => WillPopScope(
|
|
||||||
onWillPop: () async => false,
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.overlay
|
|
||||||
.withOpacity(0.6),
|
|
||||||
child: const CustomLoadingOverlay(
|
|
||||||
message: "Updating exchange rate",
|
|
||||||
eventBus: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await ref
|
|
||||||
.read(exchangeFormStateProvider)
|
|
||||||
.updateSendCurrency(selectedCurrency, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context, rootNavigator: true).pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,33 +171,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selectedCurrency != null) {
|
if (selectedCurrency != null) {
|
||||||
unawaited(
|
await showUpdatingExchangeRate(
|
||||||
showDialog<void>(
|
whileFuture: ref
|
||||||
context: context,
|
.read(exchangeFormStateProvider)
|
||||||
barrierDismissible: false,
|
.updateReceivingCurrency(selectedCurrency, true),
|
||||||
builder: (_) => WillPopScope(
|
|
||||||
onWillPop: () async => false,
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.overlay
|
|
||||||
.withOpacity(0.6),
|
|
||||||
child: const CustomLoadingOverlay(
|
|
||||||
message: "Updating exchange rate",
|
|
||||||
eventBus: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await ref
|
|
||||||
.read(exchangeFormStateProvider)
|
|
||||||
.updateReceivingCurrency(selectedCurrency, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context, rootNavigator: true).pop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,31 +184,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
_sendFocusNode.unfocus();
|
_sendFocusNode.unfocus();
|
||||||
_receiveFocusNode.unfocus();
|
_receiveFocusNode.unfocus();
|
||||||
|
|
||||||
unawaited(
|
await showUpdatingExchangeRate(
|
||||||
showDialog<void>(
|
whileFuture:
|
||||||
context: context,
|
ref.read(exchangeFormStateProvider).swap(shouldNotifyListeners: true),
|
||||||
barrierDismissible: false,
|
|
||||||
builder: (_) => WillPopScope(
|
|
||||||
onWillPop: () async => false,
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.overlay
|
|
||||||
.withOpacity(0.6),
|
|
||||||
child: const CustomLoadingOverlay(
|
|
||||||
message: "Updating exchange rate",
|
|
||||||
eventBus: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await ref.read(exchangeFormStateProvider).swap(shouldNotifyListeners: true);
|
|
||||||
|
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
|
||||||
}
|
|
||||||
_swapLock = false;
|
_swapLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,26 +284,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
_receiveFocusNode.unfocus();
|
_receiveFocusNode.unfocus();
|
||||||
_sendFocusNode.unfocus();
|
_sendFocusNode.unfocus();
|
||||||
|
|
||||||
unawaited(
|
await showUpdatingExchangeRate(
|
||||||
showDialog<void>(
|
whileFuture: _onRateTypeChangedFuture(newType),
|
||||||
context: context,
|
|
||||||
barrierDismissible: false,
|
|
||||||
builder: (_) => WillPopScope(
|
|
||||||
onWillPop: () async => false,
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.overlay
|
|
||||||
.withOpacity(0.6),
|
|
||||||
child: const CustomLoadingOverlay(
|
|
||||||
message: "Updating exchange rate",
|
|
||||||
eventBus: null,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onRateTypeChangedFuture(ExchangeRateType newType) async {
|
||||||
ref.read(exchangeFormStateProvider).exchangeRateType = newType;
|
ref.read(exchangeFormStateProvider).exchangeRateType = newType;
|
||||||
|
|
||||||
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "-";
|
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "-";
|
||||||
|
@ -397,19 +350,6 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mounted) {
|
|
||||||
Navigator.of(context, rootNavigator: isDesktop).pop();
|
|
||||||
}
|
|
||||||
// if (!(fromTicker == "-" || toTicker == "-")) {
|
|
||||||
// unawaited(
|
|
||||||
// showFloatingFlushBar(
|
|
||||||
// type: FlushBarType.warning,
|
|
||||||
// message:
|
|
||||||
// "${ref.read(exchangeFormStateProvider).exchangeRateType.name} rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
|
|
||||||
// context: context,
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onExchangePressed() async {
|
void onExchangePressed() async {
|
||||||
|
@ -655,13 +595,9 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? ticker;
|
String? ticker = isSend
|
||||||
|
? ref.read(exchangeFormStateProvider).fromTicker
|
||||||
if (isSend) {
|
: ref.read(exchangeFormStateProvider).toTicker;
|
||||||
ticker = ref.read(exchangeFormStateProvider).fromTicker;
|
|
||||||
} else {
|
|
||||||
ticker = ref.read(exchangeFormStateProvider).toTicker;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticker == null) {
|
if (ticker == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue