Allow setting the new added node as the current selected node

This commit is contained in:
OmarHatem 2022-12-04 17:30:09 +02:00
parent 7e64399476
commit 9eb8a442d8
3 changed files with 18 additions and 8 deletions

View file

@ -500,8 +500,11 @@ Future setup(
getIt.registerFactory(() => OtherSettingsPage(getIt.get<OtherSettingsViewModel>()));
getIt.registerFactoryParam<NodeCreateOrEditViewModel, WalletType?, void>(
(WalletType? type, _) =>
NodeCreateOrEditViewModel(_nodeSource, type ?? getIt.get<AppStore>().wallet!.type));
(WalletType? type, _) => NodeCreateOrEditViewModel(
_nodeSource,
type ?? getIt.get<AppStore>().wallet!.type,
getIt.get<SettingsStore>(),
));
getIt.registerFactory(
() => NodeCreateOrEditPage(getIt.get<NodeCreateOrEditViewModel>()));

View file

@ -10,9 +10,9 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
class AdvancedPrivacySettingsPage extends BasePage {
AdvancedPrivacySettingsPage(this.privacySettingsViewModel, this.nodeViewModel);
AdvancedPrivacySettingsPage(this.advancedPrivacySettingsViewModel, this.nodeViewModel);
final AdvancedPrivacySettingsViewModel privacySettingsViewModel;
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
final NodeCreateOrEditViewModel nodeViewModel;
@override
@ -20,7 +20,7 @@ class AdvancedPrivacySettingsPage extends BasePage {
@override
Widget body(BuildContext context) =>
AdvancedPrivacySettingsBody(privacySettingsViewModel, nodeViewModel);
AdvancedPrivacySettingsBody(advancedPrivacySettingsViewModel, nodeViewModel);
}
class AdvancedPrivacySettingsBody extends StatefulWidget {
@ -78,7 +78,7 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
children: [
LoadingPrimaryButton(
onPressed: () {
widget.nodeViewModel.save();
widget.nodeViewModel.save(saveAsCurrent: true);
Navigator.pop(context);
},
text: S.of(context).continue_text,

View file

@ -1,4 +1,5 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cw_core/node.dart';
@ -10,7 +11,7 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
with _$NodeCreateOrEditViewModel;
abstract class NodeCreateOrEditViewModelBase with Store {
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType)
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType, this._settingsStore)
: state = InitialExecutionState(),
connectionState = InitialExecutionState(),
useSSL = false,
@ -63,6 +64,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
final WalletType _walletType;
final Box<Node> _nodeSource;
final SettingsStore _settingsStore;
@action
void reset() {
@ -75,13 +77,18 @@ abstract class NodeCreateOrEditViewModelBase with Store {
}
@action
Future<void> save() async {
Future<void> save({bool saveAsCurrent = false}) async {
try {
state = IsExecutingState();
final node =
Node(uri: uri, type: _walletType, login: login, password: password,
useSSL: useSSL, trusted: trusted);
await _nodeSource.add(node);
if (saveAsCurrent) {
_settingsStore.nodes[_walletType] = node;
}
state = ExecutedSuccessfullyState();
} catch (e) {
state = FailureState(e.toString());