mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 09:47:35 +00:00
Fix advance privacy setting set state
This commit is contained in:
parent
bf73fb24e5
commit
f770e095a1
2 changed files with 53 additions and 60 deletions
|
@ -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<AdvancedPrivacySettingsBod
|
|||
padding: EdgeInsets.only(top: 24),
|
||||
child: ScrollableWithBottomSection(
|
||||
contentPadding: EdgeInsets.only(bottom: 24),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
...widget.privacySettingsViewModel.settings.whereType<ChoicesListItem<FiatApiMode>>().map(
|
||||
(item) => Observer(
|
||||
builder: (_) => SettingsChoicesCell(item)
|
||||
),
|
||||
),
|
||||
...widget.privacySettingsViewModel.settings.whereType<SwitcherListItem>().map(
|
||||
(item) => Observer(
|
||||
builder: (_) => SettingsSwitcherCell(
|
||||
title: item.title,
|
||||
value: item.value(),
|
||||
onValueChange: item.onValueChange,
|
||||
content: Observer(
|
||||
builder: (_) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SettingsChoicesCell(
|
||||
ChoicesListItem<FiatApiMode>(
|
||||
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<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(),
|
||||
),
|
||||
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(
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
|
||||
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,
|
||||
),
|
||||
];
|
||||
}
|
||||
AdvancedPrivacySettingsViewModelBase(this.type, this._settingsStore) : _addCustomNode = false;
|
||||
|
||||
late List<SettingsListItem> 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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue