mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 09:47:35 +00:00
Allow setting the new added node as the current selected node
This commit is contained in:
parent
7e64399476
commit
9eb8a442d8
3 changed files with 18 additions and 8 deletions
|
@ -500,8 +500,11 @@ Future setup(
|
||||||
getIt.registerFactory(() => OtherSettingsPage(getIt.get<OtherSettingsViewModel>()));
|
getIt.registerFactory(() => OtherSettingsPage(getIt.get<OtherSettingsViewModel>()));
|
||||||
|
|
||||||
getIt.registerFactoryParam<NodeCreateOrEditViewModel, WalletType?, void>(
|
getIt.registerFactoryParam<NodeCreateOrEditViewModel, WalletType?, void>(
|
||||||
(WalletType? type, _) =>
|
(WalletType? type, _) => NodeCreateOrEditViewModel(
|
||||||
NodeCreateOrEditViewModel(_nodeSource, type ?? getIt.get<AppStore>().wallet!.type));
|
_nodeSource,
|
||||||
|
type ?? getIt.get<AppStore>().wallet!.type,
|
||||||
|
getIt.get<SettingsStore>(),
|
||||||
|
));
|
||||||
|
|
||||||
getIt.registerFactory(
|
getIt.registerFactory(
|
||||||
() => NodeCreateOrEditPage(getIt.get<NodeCreateOrEditViewModel>()));
|
() => NodeCreateOrEditPage(getIt.get<NodeCreateOrEditViewModel>()));
|
||||||
|
|
|
@ -10,9 +10,9 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||||
|
|
||||||
class AdvancedPrivacySettingsPage extends BasePage {
|
class AdvancedPrivacySettingsPage extends BasePage {
|
||||||
AdvancedPrivacySettingsPage(this.privacySettingsViewModel, this.nodeViewModel);
|
AdvancedPrivacySettingsPage(this.advancedPrivacySettingsViewModel, this.nodeViewModel);
|
||||||
|
|
||||||
final AdvancedPrivacySettingsViewModel privacySettingsViewModel;
|
final AdvancedPrivacySettingsViewModel advancedPrivacySettingsViewModel;
|
||||||
final NodeCreateOrEditViewModel nodeViewModel;
|
final NodeCreateOrEditViewModel nodeViewModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -20,7 +20,7 @@ class AdvancedPrivacySettingsPage extends BasePage {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) =>
|
Widget body(BuildContext context) =>
|
||||||
AdvancedPrivacySettingsBody(privacySettingsViewModel, nodeViewModel);
|
AdvancedPrivacySettingsBody(advancedPrivacySettingsViewModel, nodeViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdvancedPrivacySettingsBody extends StatefulWidget {
|
class AdvancedPrivacySettingsBody extends StatefulWidget {
|
||||||
|
@ -78,7 +78,7 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
|
||||||
children: [
|
children: [
|
||||||
LoadingPrimaryButton(
|
LoadingPrimaryButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
widget.nodeViewModel.save();
|
widget.nodeViewModel.save(saveAsCurrent: true);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
text: S.of(context).continue_text,
|
text: S.of(context).continue_text,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cake_wallet/core/execution_state.dart';
|
import 'package:cake_wallet/core/execution_state.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cw_core/node.dart';
|
import 'package:cw_core/node.dart';
|
||||||
|
@ -10,7 +11,7 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
|
||||||
with _$NodeCreateOrEditViewModel;
|
with _$NodeCreateOrEditViewModel;
|
||||||
|
|
||||||
abstract class NodeCreateOrEditViewModelBase with Store {
|
abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType)
|
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType, this._settingsStore)
|
||||||
: state = InitialExecutionState(),
|
: state = InitialExecutionState(),
|
||||||
connectionState = InitialExecutionState(),
|
connectionState = InitialExecutionState(),
|
||||||
useSSL = false,
|
useSSL = false,
|
||||||
|
@ -63,6 +64,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
|
|
||||||
final WalletType _walletType;
|
final WalletType _walletType;
|
||||||
final Box<Node> _nodeSource;
|
final Box<Node> _nodeSource;
|
||||||
|
final SettingsStore _settingsStore;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void reset() {
|
void reset() {
|
||||||
|
@ -75,13 +77,18 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> save() async {
|
Future<void> save({bool saveAsCurrent = false}) async {
|
||||||
try {
|
try {
|
||||||
state = IsExecutingState();
|
state = IsExecutingState();
|
||||||
final node =
|
final node =
|
||||||
Node(uri: uri, type: _walletType, login: login, password: password,
|
Node(uri: uri, type: _walletType, login: login, password: password,
|
||||||
useSSL: useSSL, trusted: trusted);
|
useSSL: useSSL, trusted: trusted);
|
||||||
await _nodeSource.add(node);
|
await _nodeSource.add(node);
|
||||||
|
|
||||||
|
if (saveAsCurrent) {
|
||||||
|
_settingsStore.nodes[_walletType] = node;
|
||||||
|
}
|
||||||
|
|
||||||
state = ExecutedSuccessfullyState();
|
state = ExecutedSuccessfullyState();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = FailureState(e.toString());
|
state = FailureState(e.toString());
|
||||||
|
|
Loading…
Reference in a new issue