CAKE-169 | created connection_state.dart; added connect() method and connectionState parameter to node_create_or_edit_view_model.dart; replaced Reset button to Connect button and added _setEffects() method to node_create_or_edit_page.dart; changed useSSL parameter from false to true in the connectToNode() method (monero_wallet.dart)

This commit is contained in:
OleksandrSobol
2020-11-19 21:13:54 +02:00
parent 1afe4255a7
commit 6cd6139fb3
4 changed files with 97 additions and 5 deletions
@@ -0,0 +1,17 @@
abstract class ConnectionToNodeState {}
class InitialConnectionState extends ConnectionToNodeState {}
class IsConnectingState extends ConnectionToNodeState {}
class ConnectedSuccessfullyState extends ConnectionToNodeState {
ConnectedSuccessfullyState(this.isAlive);
final bool isAlive;
}
class FailureConnectedState extends ConnectionToNodeState {
FailureConnectedState(this.error);
final String error;
}
@@ -1,4 +1,5 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/view_model/node_list/connection_state.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/wallet_base.dart';
@@ -12,7 +13,8 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
abstract class NodeCreateOrEditViewModelBase with Store {
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
: state = InitialExecutionState();
: state = InitialExecutionState(),
connectionState = InitialConnectionState();
@observable
ExecutionState state;
@@ -29,6 +31,9 @@ abstract class NodeCreateOrEditViewModelBase with Store {
@observable
String password;
@observable
ConnectionToNodeState connectionState;
@computed
bool get isReady =>
(address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false);
@@ -68,4 +73,17 @@ abstract class NodeCreateOrEditViewModelBase with Store {
state = FailureState(e.toString());
}
}
@action
Future<void> connect() async {
try {
connectionState = IsConnectingState();
final node =
Node(uri: uri, type: _wallet.type, login: login, password: password);
final isAlive = await node.requestNode();
connectionState = ConnectedSuccessfullyState(isAlive);
} catch (e) {
connectionState = FailureConnectedState(e.toString());
}
}
}