Fix advance privacy setting set state

This commit is contained in:
Godwin Asuquo 2023-02-07 17:12:34 +02:00
parent bf73fb24e5
commit f770e095a1
2 changed files with 53 additions and 60 deletions

View file

@ -5,7 +5,6 @@ import 'package:cake_wallet/src/screens/settings/widgets/settings_switcher_cell.
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
import 'package:cake_wallet/view_model/advanced_privacy_settings_view_model.dart';
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/generated/i18n.dart';
@ -49,39 +48,44 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
padding: EdgeInsets.only(top: 24),
child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(bottom: 24),
content: Column(
content: Observer(
builder: (_) => Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
...widget.privacySettingsViewModel.settings.whereType<ChoicesListItem<FiatApiMode>>().map(
(item) => Observer(
builder: (_) => SettingsChoicesCell(item)
SettingsChoicesCell(
ChoicesListItem<FiatApiMode>(
title: S.current.fiat_api,
items: FiatApiMode.all,
selectedItem: widget.privacySettingsViewModel.fiatApi,
onItemSelected: (FiatApiMode mode) =>
widget.privacySettingsViewModel.setFiatMode(mode),
),
),
...widget.privacySettingsViewModel.settings.whereType<SwitcherListItem>().map(
(item) => Observer(
builder: (_) => SettingsSwitcherCell(
title: item.title,
value: item.value(),
onValueChange: item.onValueChange,
SettingsChoicesCell(
ChoicesListItem<FiatApiMode>(
title: S.current.exchange,
items: FiatApiMode.all,
selectedItem: widget.privacySettingsViewModel.exchangeStatus,
onItemSelected: (FiatApiMode mode) =>
widget.privacySettingsViewModel.setEnableExchange(mode),
),
),
SettingsSwitcherCell(
title: S.current.add_custom_node,
value: widget.privacySettingsViewModel.addCustomNode,
onValueChange: (_, __) => widget.privacySettingsViewModel.toggleAddCustomNode(),
),
Observer(
builder: (_) {
if (widget.privacySettingsViewModel.addCustomNode) {
return Padding(
if (widget.privacySettingsViewModel.addCustomNode)
Padding(
padding: EdgeInsets.only(left: 24, right: 24, top: 24),
child: NodeForm(
formKey: _formKey,
nodeViewModel: widget.nodeViewModel,
),
);
}
return const SizedBox();
},
),
)
],
),
),
bottomSectionPadding: EdgeInsets.all(24),
bottomSection: Column(
children: [

View file

@ -1,11 +1,7 @@
import 'package:cake_wallet/entities/fiat_api_mode.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
import 'package:cake_wallet/view_model/settings/settings_list_item.dart';
import 'package:cake_wallet/view_model/settings/switcher_list_item.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/generated/i18n.dart';
part 'advanced_privacy_settings_view_model.g.dart';
@ -13,36 +9,19 @@ class AdvancedPrivacySettingsViewModel = AdvancedPrivacySettingsViewModelBase
with _$AdvancedPrivacySettingsViewModel;
abstract class AdvancedPrivacySettingsViewModelBase with Store {
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore)
: _addCustomNode = false {
settings = [
ChoicesListItem<FiatApiMode>(
title: S.current.fiat_api,
items: FiatApiMode.all,
selectedItem: _settingsStore.fiatApiMode,
onItemSelected: (FiatApiMode mode) => setFiatMode(mode),
),
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false;
ChoicesListItem<FiatApiMode>(
title: S.current.exchange,
items: FiatApiMode.all,
selectedItem: _settingsStore.exchangeStatus,
onItemSelected: (FiatApiMode mode) => _settingsStore.exchangeStatus = mode,
),
SwitcherListItem(
title: S.current.add_custom_node,
value: () => _addCustomNode,
onValueChange: (_, bool value) => _addCustomNode = value,
),
];
}
@computed
FiatApiMode get exchangeStatus => _settingsStore.exchangeStatus;
late List<SettingsListItem> settings;
@computed
FiatApiMode get fiatApi => _settingsStore.fiatApiMode;
@observable
bool _addCustomNode = false;
final WalletType type;
final SettingsStore _settingsStore;
@computed
@ -52,4 +31,14 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store {
void setFiatMode(FiatApiMode value) {
_settingsStore.fiatApiMode = value;
}
@action
void setEnableExchange(FiatApiMode value) {
_settingsStore.exchangeStatus = value;
}
@action
void toggleAddCustomNode() {
_addCustomNode = !_addCustomNode;
}
}