clean up and exchange form state bug fixes

This commit is contained in:
julian 2023-02-06 10:27:24 -06:00
parent be2a52301e
commit f174efcec0
4 changed files with 94 additions and 438 deletions

View file

@ -7,12 +7,16 @@ import 'package:stackwallet/services/exchange/exchange.dart';
import 'package:stackwallet/utilities/logger.dart';
class ExchangeFormState extends ChangeNotifier {
ExchangeFormState(this.exchangeRateType);
final ExchangeRateType exchangeRateType;
Exchange? _exchange;
Exchange get exchange => _exchange ??= Exchange.defaultExchange;
ExchangeRateType _exchangeRateType = ExchangeRateType.estimated;
ExchangeRateType get exchangeRateType => _exchangeRateType;
set exchangeRateType(ExchangeRateType exchangeRateType) {
_exchangeRateType = exchangeRateType;
//
}
Estimate? _estimate;
Estimate? get estimate => _estimate;
@ -104,6 +108,8 @@ class ExchangeFormState extends ChangeNotifier {
receiveAmount != null &&
rate != null &&
rate! >= Decimal.zero &&
exchange.name == sendCurrency!.exchangeName &&
exchange.name == receiveCurrency!.exchangeName &&
warning.isEmpty;
}
@ -206,7 +212,7 @@ class ExchangeFormState extends ChangeNotifier {
}
}
Future<void> setToAmountAndCalculateFromAmount(
Future<void> setReceivingAmountAndCalculateSendAmount(
Decimal? newReceiveAmount,
bool shouldNotifyListeners,
) async {

View file

@ -9,7 +9,6 @@ import 'package:isar/isar.dart';
import 'package:stackwallet/models/exchange/incomplete_exchange.dart';
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
import 'package:stackwallet/models/isar/exchange_cache/pair.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_1_view.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_2_view.dart';
@ -72,8 +71,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
final newFromAmount = Decimal.tryParse(value);
await ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.read(exchangeFormStateProvider)
.setSendAmountAndCalculateReceiveAmount(
newFromAmount ?? Decimal.zero, true);
@ -95,10 +93,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
if (!(isEstimated &&
ref.read(currentExchangeNameStateProvider.state).state ==
ChangeNowExchange.exchangeName)) {
ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.receiveAmount = newToAmount;
ref.read(exchangeFormStateProvider).receiveAmount = newToAmount;
}
if (newToAmount == null) {
_sendController.text = "";
@ -107,8 +102,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
void selectSendCurrency() async {
final type = (ref.read(prefsChangeNotifierProvider).exchangeRateType);
final fromTicker =
ref.read(exchangeFormStateProvider(type)).fromTicker ?? "";
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "";
if (walletInitiated &&
fromTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
@ -117,11 +111,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
}
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider(type)).sendCurrency,
paired: ref.read(exchangeFormStateProvider(type)).receiveCurrency,
willChange: ref.read(exchangeFormStateProvider).sendCurrency,
paired: ref.read(exchangeFormStateProvider).receiveCurrency,
isFixedRate: type == ExchangeRateType.fixed,
onSelected: (selectedCurrency) => ref
.read(exchangeFormStateProvider(type))
.read(exchangeFormStateProvider)
.updateSendCurrency(selectedCurrency, true),
);
@ -154,7 +148,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
void selectReceiveCurrency() async {
final type = (ref.read(prefsChangeNotifierProvider).exchangeRateType);
final toTicker = ref.read(exchangeFormStateProvider(type)).toTicker ?? "";
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "";
if (walletInitiated &&
toTicker.toLowerCase() == coin!.ticker.toLowerCase()) {
@ -163,11 +157,11 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
}
await _showCurrencySelectionSheet(
willChange: ref.read(exchangeFormStateProvider(type)).receiveCurrency,
paired: ref.read(exchangeFormStateProvider(type)).sendCurrency,
willChange: ref.read(exchangeFormStateProvider).receiveCurrency,
paired: ref.read(exchangeFormStateProvider).sendCurrency,
isFixedRate: type == ExchangeRateType.fixed,
onSelected: (selectedCurrency) => ref
.read(exchangeFormStateProvider(type))
.read(exchangeFormStateProvider)
.updateReceivingCurrency(selectedCurrency, true),
);
@ -223,10 +217,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
),
);
await ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.swap(shouldNotifyListeners: true);
await ref.read(exchangeFormStateProvider).swap(shouldNotifyListeners: true);
if (mounted) {
Navigator.of(context, rootNavigator: isDesktop).pop();
@ -318,7 +309,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
}
}
void onRateTypeChanged() async {
void onRateTypeChanged(ExchangeRateType newType) async {
_receiveFocusNode.unfocus();
_sendFocusNode.unfocus();
@ -342,15 +333,13 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
),
);
final type = (ref.read(prefsChangeNotifierProvider).exchangeRateType);
ref.read(exchangeFormStateProvider).exchangeRateType = newType;
final fromTicker =
ref.read(exchangeFormStateProvider(type)).fromTicker ?? "-";
final toTicker = ref.read(exchangeFormStateProvider(type)).toTicker ?? "-";
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "-";
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "-";
ref.read(exchangeFormStateProvider).reversed = false;
ref.read(exchangeFormStateProvider(type)).reversed = false;
// switch (rateType) {
// case ExchangeRateType.estimated:
if (!(toTicker == "-" || fromTicker == "-")) {
final available = await ExchangeDataLoadingService.instance.isar.pairs
.where()
@ -381,23 +370,22 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
availableCurrencies.firstWhere((e) => e.ticker == toTicker);
final newFromAmount = Decimal.tryParse(_sendController.text);
ref.read(exchangeFormStateProvider(type)).receiveAmount =
newFromAmount;
ref.read(exchangeFormStateProvider).receiveAmount = newFromAmount;
if (newFromAmount == null) {
_receiveController.text = "";
}
await ref
.read(exchangeFormStateProvider(type))
.read(exchangeFormStateProvider)
.updateReceivingCurrency(to, false);
await ref
.read(exchangeFormStateProvider(type))
.read(exchangeFormStateProvider)
.updateSendCurrency(from, true);
_receiveController.text =
ref.read(exchangeFormStateProvider(type)).toAmountString.isEmpty
ref.read(exchangeFormStateProvider).toAmountString.isEmpty
? "-"
: ref.read(exchangeFormStateProvider(type)).toAmountString;
: ref.read(exchangeFormStateProvider).toAmountString;
if (mounted) {
Navigator.of(context, rootNavigator: isDesktop).pop();
}
@ -408,122 +396,24 @@ 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(type)).exchangeRateType.name} rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last estimated rate pair.",
context: context,
),
);
}
// break;
// case ExchangeRateType.fixed:
// if (!(toTicker == "-" || fromTicker == "-")) {
// switch (ref.read(currentExchangeNameStateProvider.state).state) {
// case ChangeNowExchange.exchangeName:
// FixedRateMarket? market;
// try {
// market = ref
// .read(availableChangeNowCurrenciesProvider)
// .markets
// .firstWhere(
// (e) => e.from == fromTicker && e.to == toTicker);
// } catch (_) {
// market = null;
// }
//
// final newFromAmount = Decimal.tryParse(_sendController.text);
// ref.read(exchangeFormStateProvider).fromAmount =
// newFromAmount ?? Decimal.zero;
//
// if (newFromAmount == null) {
// _receiveController.text = "";
// }
//
// await ref
// .read(exchangeFormStateProvider)
// .updateMarket(market, false);
// await ref
// .read(exchangeFormStateProvider)
// .setSendAmountAndCalculateReceiveAmount(
// Decimal.tryParse(_sendController.text) ?? Decimal.zero,
// true,
// );
// if (mounted) {
// Navigator.of(context, rootNavigator: isDesktop).pop();
// }
// return;
// case SimpleSwapExchange.exchangeName:
// final available = ref
// .read(availableSimpleswapCurrenciesProvider)
// .floatingRatePairs
// .where((e) => e.to == toTicker && e.from == fromTicker);
// if (available.isNotEmpty) {
// final availableCurrencies = ref
// .read(availableSimpleswapCurrenciesProvider)
// .fixedRateCurrencies
// .where(
// (e) => e.ticker == fromTicker || e.ticker == toTicker);
// if (availableCurrencies.length > 1) {
// final from = availableCurrencies
// .firstWhere((e) => e.ticker == fromTicker);
// final to = availableCurrencies
// .firstWhere((e) => e.ticker == toTicker);
//
// final newFromAmount = Decimal.tryParse(_sendController.text);
// ref.read(exchangeFormStateProvider).fromAmount =
// newFromAmount ?? Decimal.zero;
// if (newFromAmount == null) {
// _receiveController.text = "";
// }
//
// await ref.read(exchangeFormStateProvider).updateTo(to, false);
// await ref
// .read(exchangeFormStateProvider)
// .updateFrom(from, true);
//
// _receiveController.text =
// ref.read(exchangeFormStateProvider).toAmountString.isEmpty
// ? "-"
// : ref.read(exchangeFormStateProvider).toAmountString;
// if (mounted) {
// Navigator.of(context, rootNavigator: isDesktop).pop();
// }
// return;
// }
// }
//
// break;
// default:
// //
// }
// }
// if (mounted) {
// Navigator.of(context, rootNavigator: isDesktop).pop();
// }
// unawaited(
// showFloatingFlushBar(
// type: FlushBarType.warning,
// message:
// "Fixed rate trade pair \"$fromTicker-$toTicker\" unavailable. Reverting to last fixed rate pair.",
// context: context,
// ),
// );
// break;
// 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 {
final rateType = ref.read(prefsChangeNotifierProvider).exchangeRateType;
final fromTicker =
ref.read(exchangeFormStateProvider(rateType)).fromTicker ?? "";
final toTicker =
ref.read(exchangeFormStateProvider(rateType)).toTicker ?? "";
final sendAmount =
ref.read(exchangeFormStateProvider(rateType)).sendAmount!;
final estimate = ref.read(exchangeFormStateProvider(rateType)).estimate!;
final fromTicker = ref.read(exchangeFormStateProvider).fromTicker ?? "";
final toTicker = ref.read(exchangeFormStateProvider).toTicker ?? "";
final sendAmount = ref.read(exchangeFormStateProvider).sendAmount!;
final estimate = ref.read(exchangeFormStateProvider).estimate!;
final exchangeName = ref.read(currentExchangeNameStateProvider.state).state;
@ -682,7 +572,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
return;
}
rate =
"1 ${fromTicker.toUpperCase()} ~${ref.read(exchangeFormStateProvider(rateType)).rate!.toStringAsFixed(8)} ${toTicker.toUpperCase()}";
"1 ${fromTicker.toUpperCase()} ~${ref.read(exchangeFormStateProvider).rate!.toStringAsFixed(8)} ${toTicker.toUpperCase()}";
break;
}
@ -692,7 +582,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
rateInfo: rate,
sendAmount: estimate.reversed ? estimate.estimatedAmount : sendAmount,
receiveAmount: estimate.reversed
? ref.read(exchangeFormStateProvider(rateType)).receiveAmount!
? ref.read(exchangeFormStateProvider).receiveAmount!
: estimate.estimatedAmount,
rateType: rateType,
rateId: estimate.rateId,
@ -764,15 +654,9 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
String? ticker;
if (isSend) {
ticker = ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.fromTicker;
ticker = ref.read(exchangeFormStateProvider).fromTicker;
} else {
ticker = ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.toTicker;
ticker = ref.read(exchangeFormStateProvider).toTicker;
}
if (ticker == null) {
@ -793,60 +677,19 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
if (walletInitiated) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
ref
.read(exchangeFormStateProvider(
ref.read(prefsChangeNotifierProvider).exchangeRateType))
.reset(shouldNotifyListeners: true);
ref.read(exchangeFormStateProvider).reset(shouldNotifyListeners: true);
// ref.read(fixedRateExchangeFormProvider);
});
} else {
final rateType = (ref.read(prefsChangeNotifierProvider).exchangeRateType);
final isEstimated = rateType == ExchangeRateType.estimated;
_sendController.text =
ref.read(exchangeFormStateProvider(rateType)).fromAmountString;
ref.read(exchangeFormStateProvider).fromAmountString;
_receiveController.text = isEstimated
? "-" //ref.read(estimatedRateExchangeFormProvider).toAmountString
: ref.read(exchangeFormStateProvider(rateType)).toAmountString;
: ref.read(exchangeFormStateProvider).toAmountString;
}
// _sendFocusNode.addListener(() async {
// if (!_sendFocusNode.hasFocus) {
// final newFromAmount = Decimal.tryParse(_sendController.text);
// await ref
// .read(exchangeFormStateProvider)
// .setFromAmountAndCalculateToAmount(
// newFromAmount ?? Decimal.zero, true);
//
// debugPrint("SendFocusNode has fired");
//
// if (newFromAmount == null) {
// _receiveController.text =
// ref.read(prefsChangeNotifierProvider).exchangeRateType ==
// ExchangeRateType.estimated
// ? "-"
// : "";
// }
// }
// });
//
// _receiveFocusNode.addListener(() async {
// if (!_receiveFocusNode.hasFocus) {
// final newToAmount = Decimal.tryParse(_receiveController.text);
// if (ref.read(prefsChangeNotifierProvider).exchangeRateType !=
// ExchangeRateType.estimated) {
// await ref
// .read(exchangeFormStateProvider)
// .setToAmountAndCalculateFromAmount(
// newToAmount ?? Decimal.zero, true);
//
// debugPrint("ReceiveFocusNode has fired");
// }
// if (newToAmount == null) {
// _sendController.text = "";
// }
// }
// });
super.initState();
}
@ -866,7 +709,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
// provider for simpleswap; not called rn
ref.listen<String>(currentExchangeNameStateProvider, (previous, next) {
ref.read(exchangeFormStateProvider(rateType)).updateExchange(
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
shouldUpdateData: true,
shouldNotifyListeners: true,
@ -878,8 +721,8 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
ExchangeRateType.estimated;
ref.listen(
exchangeFormStateProvider(rateType)
.select((value) => value.toAmountString), (previous, String next) {
exchangeFormStateProvider.select((value) => value.toAmountString),
(previous, String next) {
if (!_receiveFocusNode.hasFocus) {
// ref.watch(exchangeProvider).name ==
// SimpleSwapExchange.exchangeName &&
@ -888,13 +731,12 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
// debugPrint("RECEIVE AMOUNT LISTENER ACTIVATED");
if (_swapLock) {
_sendController.text =
ref.read(exchangeFormStateProvider(rateType)).fromAmountString;
ref.read(exchangeFormStateProvider).fromAmountString;
}
}
});
ref.listen(
exchangeFormStateProvider(rateType)
.select((value) => value.fromAmountString),
exchangeFormStateProvider.select((value) => value.fromAmountString),
(previous, String next) {
if (!_sendFocusNode.hasFocus) {
_sendController.text = next;
@ -902,13 +744,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
// debugPrint("SEND AMOUNT LISTENER ACTIVATED");
if (_swapLock) {
_receiveController.text = isEstimated
? ref
.read(exchangeFormStateProvider(rateType))
.toAmountString
.isEmpty
? ref.read(exchangeFormStateProvider).toAmountString.isEmpty
? "-"
: ref.read(exchangeFormStateProvider(rateType)).toAmountString
: ref.read(exchangeFormStateProvider(rateType)).toAmountString;
: ref.read(exchangeFormStateProvider).toAmountString
: ref.read(exchangeFormStateProvider).toAmountString;
}
}
});
@ -945,10 +784,10 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
onChanged: sendFieldOnChanged,
onButtonTap: selectSendCurrency,
isWalletCoin: isWalletCoin(coin, true),
image: ref.watch(exchangeFormStateProvider(rateType)
image: ref.watch(exchangeFormStateProvider
.select((value) => value.sendCurrency?.image)),
ticker: ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.fromTicker)),
ticker: ref.watch(
exchangeFormStateProvider.select((value) => value.fromTicker)),
),
SizedBox(
height: isDesktop ? 10 : 4,
@ -957,14 +796,14 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
height: isDesktop ? 10 : 4,
),
if (ref
.watch(exchangeFormStateProvider(rateType)
.select((value) => value.warning))
.watch(
exchangeFormStateProvider.select((value) => value.warning))
.isNotEmpty &&
!ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.reversed)))
!ref.watch(
exchangeFormStateProvider.select((value) => value.reversed)))
Text(
ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.warning)),
ref.watch(
exchangeFormStateProvider.select((value) => value.warning)),
style: STextStyles.errorSmall(context),
),
Row(
@ -1035,25 +874,25 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
onChanged: receiveFieldOnChanged,
onButtonTap: selectReceiveCurrency,
isWalletCoin: isWalletCoin(coin, true),
image: ref.watch(exchangeFormStateProvider(rateType)
image: ref.watch(exchangeFormStateProvider
.select((value) => value.receiveCurrency?.image)) ??
"",
ticker: ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.toTicker)),
ticker: ref.watch(
exchangeFormStateProvider.select((value) => value.toTicker)),
readOnly: (rateType) == ExchangeRateType.estimated,
// ||
// ref.watch(exchangeProvider).name ==
// SimpleSwapExchange.exchangeName,
),
if (ref
.watch(exchangeFormStateProvider(rateType)
.select((value) => value.warning))
.watch(
exchangeFormStateProvider.select((value) => value.warning))
.isNotEmpty &&
ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.reversed)))
ref.watch(
exchangeFormStateProvider.select((value) => value.reversed)))
Text(
ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.warning)),
ref.watch(
exchangeFormStateProvider.select((value) => value.warning)),
style: STextStyles.errorSmall(context),
),
SizedBox(
@ -1066,36 +905,32 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
),
),
// these reads should be watch
if (ref.watch(exchangeFormStateProvider(rateType)).sendAmount != null &&
ref.watch(exchangeFormStateProvider(rateType)).sendAmount !=
Decimal.zero)
if (ref.watch(exchangeFormStateProvider).sendAmount != null &&
ref.watch(exchangeFormStateProvider).sendAmount != Decimal.zero)
SizedBox(
height: isDesktop ? 20 : 12,
),
// these reads should be watch
if (ref.watch(exchangeFormStateProvider(rateType)).sendAmount != null &&
ref.watch(exchangeFormStateProvider(rateType)).sendAmount !=
Decimal.zero)
if (ref.watch(exchangeFormStateProvider).sendAmount != null &&
ref.watch(exchangeFormStateProvider).sendAmount != Decimal.zero)
ExchangeProviderOptions(
from: ref.watch(exchangeFormStateProvider(rateType)).fromTicker,
to: ref.watch(exchangeFormStateProvider(rateType)).toTicker,
fromAmount:
ref.watch(exchangeFormStateProvider(rateType)).sendAmount,
toAmount:
ref.watch(exchangeFormStateProvider(rateType)).receiveAmount,
from: ref.watch(exchangeFormStateProvider).fromTicker,
to: ref.watch(exchangeFormStateProvider).toTicker,
fromAmount: ref.watch(exchangeFormStateProvider).sendAmount,
toAmount: ref.watch(exchangeFormStateProvider).receiveAmount,
fixedRate: ref.watch(prefsChangeNotifierProvider
.select((value) => value.exchangeRateType)) ==
ExchangeRateType.fixed,
reversed: ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.reversed)),
reversed: ref.watch(
exchangeFormStateProvider.select((value) => value.reversed)),
),
SizedBox(
height: isDesktop ? 20 : 12,
),
PrimaryButton(
buttonHeight: isDesktop ? ButtonHeight.l : null,
enabled: ref.watch(exchangeFormStateProvider(rateType)
.select((value) => value.canExchange)),
enabled: ref.watch(
exchangeFormStateProvider.select((value) => value.canExchange)),
onPressed: onExchangePressed,
label: "Exchange",
)

View file

@ -14,7 +14,7 @@ class RateTypeToggle extends ConsumerWidget {
this.onChanged,
}) : super(key: key);
final void Function()? onChanged;
final void Function(ExchangeRateType)? onChanged;
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -26,11 +26,12 @@ class RateTypeToggle extends ConsumerWidget {
if (value) {
ref.read(prefsChangeNotifierProvider).exchangeRateType =
ExchangeRateType.fixed;
onChanged?.call(ExchangeRateType.fixed);
} else {
ref.read(prefsChangeNotifierProvider).exchangeRateType =
ExchangeRateType.estimated;
onChanged?.call(ExchangeRateType.estimated);
}
onChanged?.call();
},
isOn: ref.watch(prefsChangeNotifierProvider
.select((value) => value.exchangeRateType)) ==
@ -55,178 +56,5 @@ class RateTypeToggle extends ConsumerWidget {
offIcon: Assets.svg.lock,
offText: "Fixed rate",
);
//
// return RoundedContainer(
// padding: const EdgeInsets.all(0),
// color: isDesktop
// ? Theme.of(context).extension<StackColors>()!.buttonBackSecondary
// : Theme.of(context).extension<StackColors>()!.popupBG,
// child: Row(
// children: [
// Expanded(
// child: ConditionalParent(
// condition: isDesktop,
// builder: (child) => MouseRegion(
// cursor: estimated
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// child: child,
// ),
// child: GestureDetector(
// onTap: () {
// if (!estimated) {
// ref.read(prefsChangeNotifierProvider).exchangeRateType =
// ExchangeRateType.estimated;
// onChanged?.call(ExchangeRateType.estimated);
// }
// },
// child: RoundedContainer(
// padding: isDesktop
// ? const EdgeInsets.all(17)
// : const EdgeInsets.all(12),
// color: estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textFieldDefaultBG
// : Colors.transparent,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// SvgPicture.asset(
// Assets.svg.lockOpen,
// width: 12,
// height: 14,
// color: isDesktop
// ? estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .accentColorBlue
// : Theme.of(context)
// .extension<StackColors>()!
// .buttonTextSecondary
// : estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textDark
// : Theme.of(context)
// .extension<StackColors>()!
// .textSubtitle1,
// ),
// const SizedBox(
// width: 5,
// ),
// Text(
// "Estimate rate",
// style: isDesktop
// ? STextStyles.desktopTextExtraExtraSmall(context)
// .copyWith(
// color: estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .accentColorBlue
// : Theme.of(context)
// .extension<StackColors>()!
// .buttonTextSecondary,
// )
// : STextStyles.smallMed12(context).copyWith(
// color: estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textDark
// : Theme.of(context)
// .extension<StackColors>()!
// .textSubtitle1,
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// ),
// Expanded(
// child: ConditionalParent(
// condition: isDesktop,
// builder: (child) => MouseRegion(
// cursor: !estimated
// ? SystemMouseCursors.basic
// : SystemMouseCursors.click,
// child: child,
// ),
// child: GestureDetector(
// onTap: () {
// if (estimated) {
// ref.read(prefsChangeNotifierProvider).exchangeRateType =
// ExchangeRateType.fixed;
// onChanged?.call(ExchangeRateType.fixed);
// }
// },
// child: RoundedContainer(
// padding: isDesktop
// ? const EdgeInsets.all(17)
// : const EdgeInsets.all(12),
// color: !estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textFieldDefaultBG
// : Colors.transparent,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// SvgPicture.asset(
// Assets.svg.lock,
// width: 12,
// height: 14,
// color: isDesktop
// ? !estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .accentColorBlue
// : Theme.of(context)
// .extension<StackColors>()!
// .buttonTextSecondary
// : !estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textDark
// : Theme.of(context)
// .extension<StackColors>()!
// .textSubtitle1,
// ),
// const SizedBox(
// width: 5,
// ),
// Text(
// "Fixed rate",
// style: isDesktop
// ? STextStyles.desktopTextExtraExtraSmall(context)
// .copyWith(
// color: !estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .accentColorBlue
// : Theme.of(context)
// .extension<StackColors>()!
// .buttonTextSecondary,
// )
// : STextStyles.smallMed12(context).copyWith(
// color: !estimated
// ? Theme.of(context)
// .extension<StackColors>()!
// .textDark
// : Theme.of(context)
// .extension<StackColors>()!
// .textSubtitle1,
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// ),
// ],
// ),
// );
}
}

View file

@ -1,18 +1,5 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/models/exchange/exchange_form_state.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
final exchangeFormStateProvider =
ChangeNotifierProvider.family<ExchangeFormState, ExchangeRateType>(
(ref, type) {
switch (type) {
case ExchangeRateType.estimated:
return _estimatedInstance;
case ExchangeRateType.fixed:
return _fixedInstance;
}
});
final _fixedInstance = ExchangeFormState(ExchangeRateType.fixed);
final _estimatedInstance = ExchangeFormState(ExchangeRateType.estimated);
ChangeNotifierProvider<ExchangeFormState>((ref) => ExchangeFormState());