CAKE-169 | added NodeSSL class with getter useSSl; applied useSSL in the connectToNode() method in the monero_wallet.dart; added dynamic parameter to ExecutedSuccessfullyState class; applied ExecuteState class to connect() method in the node_create_or_edit_view_model.dart; deleted connection_state.dart; deleted _isEffectsInstalled parameter from node_create_or_edit_page.dart

OleksandrSobol committed Dec 2, 2020 at 20:26 UTC 4f280e103ee0ad7667cd8712eb3c6853bc6eb618
6 files changed +59 -72
lib/core/execution_state.dart
+5 -1
@@ -4,7 +4,11 @@ class InitialExecutionState extends ExecutionState {}
4
5 class IsExecutingState extends ExecutionState {}
6
7 -class ExecutedSuccessfullyState extends ExecutionState {}
7 +class ExecutedSuccessfullyState extends ExecutionState {
8 + ExecutedSuccessfullyState({this.payload});
9 +
10 + final dynamic payload;
11 +}
12
13 class FailureState extends ExecutionState {
14 FailureState(this.error);
lib/entities/node_ssl.dart new
+11
@@ -0,0 +1,11 @@
1 +import 'package:cake_wallet/entities/node.dart';
2 +
3 +class NodeSSL {
4 + NodeSSL(this._node) :
5 + _useSSL = _node.useSSL ?? false;
6 +
7 + final Node _node;
8 + final bool _useSSL;
9 +
10 + bool get useSSL => _useSSL;
11 +}
\ No newline at end of file
lib/monero/monero_wallet.dart
+3 -1
@@ -1,5 +1,6 @@
1 import 'dart:async';
2
3 +import 'package:cake_wallet/entities/node_ssl.dart';
4 import 'package:cake_wallet/monero/monero_amount_format.dart';
5 import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart';
6 import 'package:flutter/foundation.dart';
@@ -143,11 +144,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
144 Future<void> connectToNode({@required Node node}) async {
145 try {
146 syncStatus = ConnectingSyncStatus();
147 + final nodeSSL = NodeSSL(node);
148 await monero_wallet.setupNode(
149 address: node.uri,
150 login: node.login,
151 password: node.password,
150 - useSSL: node.useSSL ?? false,
152 + useSSL: nodeSSL.useSSL,
153 isLightWallet: false); // FIXME: hardcoded value
154 syncStatus = ConnectedSyncStatus();
155 } catch (e) {
lib/src/screens/nodes/node_create_or_edit_page.dart
+35 -47
@@ -1,7 +1,7 @@
1 +import 'package:cake_wallet/core/execution_state.dart';
2 import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
3 import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
4 import 'package:cake_wallet/utils/show_pop_up.dart';
4 -import 'package:cake_wallet/view_model/node_list/connection_state.dart';
5 import 'package:flutter/material.dart';
6 import 'package:flutter/cupertino.dart';
7 import 'package:flutter_mobx/flutter_mobx.dart';
@@ -14,7 +14,6 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
14 import 'package:cake_wallet/src/screens/base_page.dart';
15 import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
16 import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
17 -import 'package:cake_wallet/view_model/node_list/connection_state.dart';
17
18 class NodeCreateOrEditPage extends BasePage {
19 NodeCreateOrEditPage(this.nodeCreateOrEditViewModel)
@@ -65,8 +64,6 @@ class NodeCreateOrEditPage extends BasePage {
64 final TextEditingController _loginController;
65 final TextEditingController _passwordController;
66
68 - bool _effectsInstalled = false;
69 -
67 @override
68 String get title => S.current.node_new;
69
@@ -74,7 +71,38 @@ class NodeCreateOrEditPage extends BasePage {
71
72 @override
73 Widget body(BuildContext context) {
77 - _setEffects(context);
74 +
75 + reaction((_) => nodeCreateOrEditViewModel.connectionState,
76 + (ExecutionState state) {
77 + if (state is ExecutedSuccessfullyState) {
78 + WidgetsBinding.instance.addPostFrameCallback((_) {
79 + showPopUp<void>(
80 + context: context,
81 + builder: (BuildContext context) =>
82 + AlertWithOneAction(
83 + alertTitle: S.of(context).new_node_testing,
84 + alertContent: state.payload as bool
85 + ? S.of(context).node_connection_successful
86 + : S.of(context).node_connection_failed,
87 + buttonText: S.of(context).ok,
88 + buttonAction: () => Navigator.of(context).pop()));
89 + });
90 + }
91 +
92 + if (state is FailureState) {
93 + WidgetsBinding.instance.addPostFrameCallback((_) {
94 + showPopUp<void>(
95 + context: context,
96 + builder: (BuildContext context) {
97 + return AlertWithOneAction(
98 + alertTitle: S.of(context).error,
99 + alertContent: state.error,
100 + buttonText: S.of(context).ok,
101 + buttonAction: () => Navigator.of(context).pop());
102 + });
103 + });
104 + }
105 + });
106
107 return Container(
108 padding: EdgeInsets.only(left: 24, right: 24),
@@ -166,7 +194,7 @@ class NodeCreateOrEditPage extends BasePage {
194 await nodeCreateOrEditViewModel.connect();
195 },
196 isLoading: nodeCreateOrEditViewModel
169 - .connectionState is IsConnectingState,
197 + .connectionState is IsExecutingState,
198 text: S.of(context).node_test,
199 isDisabled: !nodeCreateOrEditViewModel.isReady,
200 color: Colors.orange,
@@ -189,51 +217,11 @@ class NodeCreateOrEditPage extends BasePage {
217 textColor: Colors.white,
218 isDisabled: (!nodeCreateOrEditViewModel.isReady)||
219 (nodeCreateOrEditViewModel
192 - .connectionState is IsConnectingState),
220 + .connectionState is IsExecutingState),
221 ),
222 )),
223 ],
224 )),
225 ));
226 }
199 -
200 - void _setEffects(BuildContext context) {
201 - if (_effectsInstalled) {
202 - return;
203 - }
204 -
205 - reaction((_) => nodeCreateOrEditViewModel.connectionState,
206 - (ConnectionToNodeState state) {
207 - if (state is ConnectedSuccessfullyState) {
208 - WidgetsBinding.instance.addPostFrameCallback((_) {
209 - showPopUp<void>(
210 - context: context,
211 - builder: (BuildContext context) =>
212 - AlertWithOneAction(
213 - alertTitle: S.of(context).new_node_testing,
214 - alertContent: state.isAlive
215 - ? S.of(context).node_connection_successful
216 - : S.of(context).node_connection_failed,
217 - buttonText: S.of(context).ok,
218 - buttonAction: () => Navigator.of(context).pop()));
219 - });
220 - }
221 -
222 - if (state is FailureConnectedState) {
223 - WidgetsBinding.instance.addPostFrameCallback((_) {
224 - showPopUp<void>(
225 - context: context,
226 - builder: (BuildContext context) {
227 - return AlertWithOneAction(
228 - alertTitle: S.of(context).error,
229 - alertContent: state.error,
230 - buttonText: S.of(context).ok,
231 - buttonAction: () => Navigator.of(context).pop());
232 - });
233 - });
234 - }
235 - });
236 -
237 - _effectsInstalled = true;
238 - }
227 }
lib/view_model/node_list/connection_state.dart deleted
-17
@@ -1,17 +0,0 @@
1 -abstract class ConnectionToNodeState {}
2 -
3 -class InitialConnectionState extends ConnectionToNodeState {}
4 -
5 -class IsConnectingState extends ConnectionToNodeState {}
6 -
7 -class ConnectedSuccessfullyState extends ConnectionToNodeState {
8 - ConnectedSuccessfullyState(this.isAlive);
9 -
10 - final bool isAlive;
11 -}
12 -
13 -class FailureConnectedState extends ConnectionToNodeState {
14 - FailureConnectedState(this.error);
15 -
16 - final String error;
17 -}
\ No newline at end of file
lib/view_model/node_list/node_create_or_edit_view_model.dart
+5 -6
@@ -1,5 +1,4 @@
1 import 'package:cake_wallet/core/execution_state.dart';
2 -import 'package:cake_wallet/view_model/node_list/connection_state.dart';
2 import 'package:hive/hive.dart';
3 import 'package:mobx/mobx.dart';
4 import 'package:cake_wallet/core/wallet_base.dart';
@@ -14,7 +13,7 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
13 abstract class NodeCreateOrEditViewModelBase with Store {
14 NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
15 : state = InitialExecutionState(),
17 - connectionState = InitialConnectionState(),
16 + connectionState = InitialExecutionState(),
17 useSSL = false;
18
19 @observable
@@ -33,7 +32,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
32 String password;
33
34 @observable
36 - ConnectionToNodeState connectionState;
35 + ExecutionState connectionState;
36
37 @observable
38 bool useSSL;
@@ -83,13 +82,13 @@ abstract class NodeCreateOrEditViewModelBase with Store {
82 @action
83 Future<void> connect() async {
84 try {
86 - connectionState = IsConnectingState();
85 + connectionState = IsExecutingState();
86 final node =
87 Node(uri: uri, type: _wallet.type, login: login, password: password);
88 final isAlive = await node.requestNode();
90 - connectionState = ConnectedSuccessfullyState(isAlive);
89 + connectionState = ExecutedSuccessfullyState(payload: isAlive);
90 } catch (e) {
92 - connectionState = FailureConnectedState(e.toString());
91 + connectionState = FailureState(e.toString());
92 }
93 }
94 }