mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user