diff --git a/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart b/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart index 2a9f4d291..7d720e4e5 100644 --- a/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart +++ b/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart @@ -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,38 +48,43 @@ class _AdvancedPrivacySettingsBodyState extends State>().map( - (item) => Observer( - builder: (_) => SettingsChoicesCell(item) - ), - ), - ...widget.privacySettingsViewModel.settings.whereType().map( - (item) => Observer( - builder: (_) => SettingsSwitcherCell( - title: item.title, - value: item.value(), - onValueChange: item.onValueChange, + content: Observer( + builder: (_) => Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SettingsChoicesCell( + ChoicesListItem( + title: S.current.fiat_api, + items: FiatApiMode.all, + selectedItem: widget.privacySettingsViewModel.fiatApi, + onItemSelected: (FiatApiMode mode) => + widget.privacySettingsViewModel.setFiatMode(mode), ), ), - ), - Observer( - builder: (_) { - if (widget.privacySettingsViewModel.addCustomNode) { - return Padding( - padding: EdgeInsets.only(left: 24, right: 24, top: 24), - child: NodeForm( - formKey: _formKey, - nodeViewModel: widget.nodeViewModel, - ), - ); - } - return const SizedBox(); - }, - ), - ], + SettingsChoicesCell( + ChoicesListItem( + 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(), + ), + if (widget.privacySettingsViewModel.addCustomNode) + Padding( + padding: EdgeInsets.only(left: 24, right: 24, top: 24), + child: NodeForm( + formKey: _formKey, + nodeViewModel: widget.nodeViewModel, + ), + ) + ], + ), ), bottomSectionPadding: EdgeInsets.all(24), bottomSection: Column( diff --git a/lib/view_model/advanced_privacy_settings_view_model.dart b/lib/view_model/advanced_privacy_settings_view_model.dart index 80b62fdd0..7d526047d 100644 --- a/lib/view_model/advanced_privacy_settings_view_model.dart +++ b/lib/view_model/advanced_privacy_settings_view_model.dart @@ -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( - title: S.current.fiat_api, - items: FiatApiMode.all, - selectedItem: _settingsStore.fiatApiMode, - onItemSelected: (FiatApiMode mode) => setFiatMode(mode), - ), - - ChoicesListItem( - 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, - ), - ]; - } + AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false; - late List settings; + @computed + FiatApiMode get exchangeStatus => _settingsStore.exchangeStatus; + + @computed + FiatApiMode get fiatApi => _settingsStore.fiatApiMode; @observable bool _addCustomNode = false; final WalletType type; + final SettingsStore _settingsStore; @computed @@ -50,6 +29,16 @@ abstract class AdvancedPrivacySettingsViewModelBase with Store { @action void setFiatMode(FiatApiMode value) { - _settingsStore.fiatApiMode = value; + _settingsStore.fiatApiMode = value; + } + + @action + void setEnableExchange(FiatApiMode value) { + _settingsStore.exchangeStatus = value; + } + + @action + void toggleAddCustomNode() { + _addCustomNode = !_addCustomNode; } }