reduce unneeded providers

This commit is contained in:
julian 2023-02-08 14:22:22 -06:00
parent 4630d616cd
commit 5c29a543a9
11 changed files with 42 additions and 65 deletions

View file

@ -386,7 +386,7 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
final sendAmount = ref.read(exchangeFormStateProvider).sendAmount!;
final estimate = ref.read(exchangeFormStateProvider).estimate!;
final exchangeName = ref.read(currentExchangeNameStateProvider.state).state;
final exchangeName = ref.read(exchangeFormStateProvider).exchange.name;
String rate;
@ -828,7 +828,8 @@ class _ExchangeFormState extends ConsumerState<ExchangeForm> {
currency: ref.watch(exchangeFormStateProvider
.select((value) => value.receiveCurrency)),
readOnly: (rateType) == ExchangeRateType.estimated &&
ref.watch(exchangeProvider).name ==
ref.watch(exchangeFormStateProvider
.select((value) => value.exchange.name)) ==
ChangeNowExchange.exchangeName,
),
if (ref

View file

@ -124,9 +124,9 @@ class _Step2ViewState extends ConsumerState<Step2View> {
@override
Widget build(BuildContext context) {
final supportsRefund =
ref.watch(currentExchangeNameStateProvider.state).state !=
MajesticBankExchange.exchangeName;
final supportsRefund = ref.watch(
exchangeFormStateProvider.select((value) => value.exchange.name)) !=
MajesticBankExchange.exchangeName;
return Background(
child: Scaffold(

View file

@ -7,9 +7,8 @@ import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/pages/exchange_view/exchange_step_views/step_4_view.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/step_row.dart';
import 'package:stackwallet/providers/exchange/current_exchange_name_state_provider.dart';
import 'package:stackwallet/providers/exchange/exchange_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart';
import 'package:stackwallet/services/notifications_api.dart';
@ -53,9 +52,9 @@ class _Step3ViewState extends ConsumerState<Step3View> {
@override
Widget build(BuildContext context) {
final supportsRefund =
ref.watch(currentExchangeNameStateProvider.state).state !=
MajesticBankExchange.exchangeName;
final supportsRefund = ref.watch(
exchangeFormStateProvider.select((value) => value.exchange.name)) !=
MajesticBankExchange.exchangeName;
return Background(
child: Scaffold(
@ -255,7 +254,8 @@ class _Step3ViewState extends ConsumerState<Step3View> {
final ExchangeResponse<Trade> response =
await ref
.read(exchangeProvider)
.read(exchangeFormStateProvider)
.exchange
.createTrade(
from: model.sendTicker,
to: model.receiveTicker,

View file

@ -65,8 +65,10 @@ class _Step4ViewState extends ConsumerState<Step4View> {
}
Future<void> _updateStatus() async {
final statusResponse =
await ref.read(exchangeProvider).updateTrade(model.trade!);
final statusResponse = await ref
.read(exchangeFormStateProvider)
.exchange
.updateTrade(model.trade!);
String status = "Waiting";
if (statusResponse.value != null) {
status = statusResponse.value!.status;

View file

@ -93,12 +93,10 @@ class _ExchangeProviderOptionsState
),
child: GestureDetector(
onTap: () {
if (ref.read(currentExchangeNameStateProvider.state).state !=
if (ref.read(exchangeFormStateProvider).exchange.name !=
ChangeNowExchange.exchangeName) {
ref.read(currentExchangeNameStateProvider.state).state =
ChangeNowExchange.exchangeName;
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
exchange: ChangeNowExchange.instance,
shouldUpdateData: true,
shouldNotifyListeners: true,
);
@ -124,23 +122,18 @@ class _ExchangeProviderOptionsState
.extension<StackColors>()!
.radioButtonIconEnabled,
value: ChangeNowExchange.exchangeName,
groupValue: ref
.watch(currentExchangeNameStateProvider.state)
.state,
groupValue: ref.watch(exchangeFormStateProvider
.select((value) => value.exchange.name)),
onChanged: (_) {
if (ref
.read(currentExchangeNameStateProvider
.state)
.state !=
.read(exchangeFormStateProvider)
.exchange
.name !=
ChangeNowExchange.exchangeName) {
ref
.read(currentExchangeNameStateProvider
.state)
.state = ChangeNowExchange.exchangeName;
ref
.read(exchangeFormStateProvider)
.updateExchange(
exchange: ref.read(exchangeProvider),
exchange: ChangeNowExchange.instance,
shouldUpdateData: true,
shouldNotifyListeners: true,
);
@ -337,12 +330,10 @@ class _ExchangeProviderOptionsState
),
child: GestureDetector(
onTap: () {
if (ref.read(currentExchangeNameStateProvider.state).state !=
if (ref.read(exchangeFormStateProvider).exchange.name !=
MajesticBankExchange.exchangeName) {
ref.read(currentExchangeNameStateProvider.state).state =
MajesticBankExchange.exchangeName;
ref.read(exchangeFormStateProvider).updateExchange(
exchange: ref.read(exchangeProvider),
exchange: MajesticBankExchange.instance,
shouldUpdateData: true,
shouldNotifyListeners: true,
);
@ -368,24 +359,18 @@ class _ExchangeProviderOptionsState
.extension<StackColors>()!
.radioButtonIconEnabled,
value: MajesticBankExchange.exchangeName,
groupValue: ref
.watch(currentExchangeNameStateProvider.state)
.state,
groupValue: ref.watch(exchangeFormStateProvider
.select((value) => value.exchange.name)),
onChanged: (_) {
if (ref
.read(currentExchangeNameStateProvider
.state)
.state !=
.read(exchangeFormStateProvider)
.exchange
.name !=
MajesticBankExchange.exchangeName) {
ref
.read(currentExchangeNameStateProvider
.state)
.state =
MajesticBankExchange.exchangeName;
ref
.read(exchangeFormStateProvider)
.updateExchange(
exchange: ref.read(exchangeProvider),
exchange: MajesticBankExchange.instance,
shouldUpdateData: true,
shouldNotifyListeners: true,
);

View file

@ -13,7 +13,7 @@ import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_ste
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/subwidgets/desktop_step_3.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/subwidgets/desktop_step_4.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/subwidgets/desktop_exchange_steps_indicator.dart';
import 'package:stackwallet/providers/exchange/exchange_provider.dart';
import 'package:stackwallet/providers/exchange/exchange_form_state_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/route_generator.dart';
import 'package:stackwallet/services/exchange/exchange_response.dart';
@ -83,7 +83,8 @@ class _StepScaffoldState extends ConsumerState<StepScaffold> {
);
final ExchangeResponse<Trade> response = await ref
.read(exchangeProvider)
.read(exchangeFormStateProvider)
.exchange
.createTrade(
from: ref.read(desktopExchangeModelProvider)!.sendTicker,
to: ref.read(desktopExchangeModelProvider)!.receiveTicker,

View file

@ -38,7 +38,8 @@ class DesktopStep1 extends ConsumerWidget {
children: [
DesktopStepItem(
label: "Exchange",
value: ref.watch(currentExchangeNameStateProvider.state).state,
value: ref.watch(exchangeFormStateProvider
.select((value) => value.exchange.name)),
),
Container(
height: 1,

View file

@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/exchange_view/sub_widgets/exchange_rate_sheet.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/step_scaffold.dart';
import 'package:stackwallet/pages_desktop_specific/desktop_exchange/exchange_steps/subwidgets/desktop_step_item.dart';
import 'package:stackwallet/providers/exchange/current_exchange_name_state_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
@ -36,7 +36,8 @@ class _DesktopStep3State extends ConsumerState<DesktopStep3> {
children: [
DesktopStepItem(
label: "Exchange",
value: ref.watch(currentExchangeNameStateProvider.state).state,
value: ref.watch(exchangeFormStateProvider
.select((value) => value.exchange.name)),
),
Container(
height: 1,

View file

@ -45,7 +45,8 @@ class _DesktopStep4State extends ConsumerState<DesktopStep4> {
return;
}
final statusResponse = await ref.read(exchangeProvider).updateTrade(trade);
final statusResponse =
await ref.read(exchangeFormStateProvider).exchange.updateTrade(trade);
String status = "Waiting";
if (statusResponse.value != null) {
status = statusResponse.value!.status;

View file

@ -1,6 +0,0 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/services/exchange/exchange.dart';
final currentExchangeNameStateProvider = StateProvider<String>(
(ref) => Exchange.defaultExchange.name,
);

View file

@ -1,9 +0,0 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/providers/exchange/current_exchange_name_state_provider.dart';
import 'package:stackwallet/services/exchange/exchange.dart';
final exchangeProvider = Provider<Exchange>(
(ref) => Exchange.fromName(
ref.watch(currentExchangeNameStateProvider.state).state,
),
);