mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +00:00
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
This commit is contained in:
parent
ee666db21b
commit
4f280e103e
6 changed files with 59 additions and 72 deletions
|
@ -4,7 +4,11 @@ class InitialExecutionState extends ExecutionState {}
|
|||
|
||||
class IsExecutingState extends ExecutionState {}
|
||||
|
||||
class ExecutedSuccessfullyState extends ExecutionState {}
|
||||
class ExecutedSuccessfullyState extends ExecutionState {
|
||||
ExecutedSuccessfullyState({this.payload});
|
||||
|
||||
final dynamic payload;
|
||||
}
|
||||
|
||||
class FailureState extends ExecutionState {
|
||||
FailureState(this.error);
|
||||
|
|
11
lib/entities/node_ssl.dart
Normal file
11
lib/entities/node_ssl.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
import 'package:cake_wallet/entities/node.dart';
|
||||
|
||||
class NodeSSL {
|
||||
NodeSSL(this._node) :
|
||||
_useSSL = _node.useSSL ?? false;
|
||||
|
||||
final Node _node;
|
||||
final bool _useSSL;
|
||||
|
||||
bool get useSSL => _useSSL;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/entities/node_ssl.dart';
|
||||
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
@ -143,11 +144,12 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
|||
Future<void> connectToNode({@required Node node}) async {
|
||||
try {
|
||||
syncStatus = ConnectingSyncStatus();
|
||||
final nodeSSL = NodeSSL(node);
|
||||
await monero_wallet.setupNode(
|
||||
address: node.uri,
|
||||
login: node.login,
|
||||
password: node.password,
|
||||
useSSL: node.useSSL ?? false,
|
||||
useSSL: nodeSSL.useSSL,
|
||||
isLightWallet: false); // FIXME: hardcoded value
|
||||
syncStatus = ConnectedSyncStatus();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/connection_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
|
@ -14,7 +14,6 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
|
|||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/node_list/connection_state.dart';
|
||||
|
||||
class NodeCreateOrEditPage extends BasePage {
|
||||
NodeCreateOrEditPage(this.nodeCreateOrEditViewModel)
|
||||
|
@ -65,8 +64,6 @@ class NodeCreateOrEditPage extends BasePage {
|
|||
final TextEditingController _loginController;
|
||||
final TextEditingController _passwordController;
|
||||
|
||||
bool _effectsInstalled = false;
|
||||
|
||||
@override
|
||||
String get title => S.current.node_new;
|
||||
|
||||
|
@ -74,7 +71,38 @@ class NodeCreateOrEditPage extends BasePage {
|
|||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
_setEffects(context);
|
||||
|
||||
reaction((_) => nodeCreateOrEditViewModel.connectionState,
|
||||
(ExecutionState state) {
|
||||
if (state is ExecutedSuccessfullyState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) =>
|
||||
AlertWithOneAction(
|
||||
alertTitle: S.of(context).new_node_testing,
|
||||
alertContent: state.payload as bool
|
||||
? S.of(context).node_connection_successful
|
||||
: S.of(context).node_connection_failed,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop()));
|
||||
});
|
||||
}
|
||||
|
||||
if (state is FailureState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: state.error,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 24, right: 24),
|
||||
|
@ -166,7 +194,7 @@ class NodeCreateOrEditPage extends BasePage {
|
|||
await nodeCreateOrEditViewModel.connect();
|
||||
},
|
||||
isLoading: nodeCreateOrEditViewModel
|
||||
.connectionState is IsConnectingState,
|
||||
.connectionState is IsExecutingState,
|
||||
text: S.of(context).node_test,
|
||||
isDisabled: !nodeCreateOrEditViewModel.isReady,
|
||||
color: Colors.orange,
|
||||
|
@ -189,51 +217,11 @@ class NodeCreateOrEditPage extends BasePage {
|
|||
textColor: Colors.white,
|
||||
isDisabled: (!nodeCreateOrEditViewModel.isReady)||
|
||||
(nodeCreateOrEditViewModel
|
||||
.connectionState is IsConnectingState),
|
||||
.connectionState is IsExecutingState),
|
||||
),
|
||||
)),
|
||||
],
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
void _setEffects(BuildContext context) {
|
||||
if (_effectsInstalled) {
|
||||
return;
|
||||
}
|
||||
|
||||
reaction((_) => nodeCreateOrEditViewModel.connectionState,
|
||||
(ConnectionToNodeState state) {
|
||||
if (state is ConnectedSuccessfullyState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) =>
|
||||
AlertWithOneAction(
|
||||
alertTitle: S.of(context).new_node_testing,
|
||||
alertContent: state.isAlive
|
||||
? S.of(context).node_connection_successful
|
||||
: S.of(context).node_connection_failed,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop()));
|
||||
});
|
||||
}
|
||||
|
||||
if (state is FailureConnectedState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).error,
|
||||
alertContent: state.error,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_effectsInstalled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
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,5 +1,4 @@
|
|||
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';
|
||||
|
@ -14,7 +13,7 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
|
|||
abstract class NodeCreateOrEditViewModelBase with Store {
|
||||
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
|
||||
: state = InitialExecutionState(),
|
||||
connectionState = InitialConnectionState(),
|
||||
connectionState = InitialExecutionState(),
|
||||
useSSL = false;
|
||||
|
||||
@observable
|
||||
|
@ -33,7 +32,7 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
String password;
|
||||
|
||||
@observable
|
||||
ConnectionToNodeState connectionState;
|
||||
ExecutionState connectionState;
|
||||
|
||||
@observable
|
||||
bool useSSL;
|
||||
|
@ -83,13 +82,13 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
@action
|
||||
Future<void> connect() async {
|
||||
try {
|
||||
connectionState = IsConnectingState();
|
||||
connectionState = IsExecutingState();
|
||||
final node =
|
||||
Node(uri: uri, type: _wallet.type, login: login, password: password);
|
||||
final isAlive = await node.requestNode();
|
||||
connectionState = ConnectedSuccessfullyState(isAlive);
|
||||
connectionState = ExecutedSuccessfullyState(payload: isAlive);
|
||||
} catch (e) {
|
||||
connectionState = FailureConnectedState(e.toString());
|
||||
connectionState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue