mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00: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:
parent
1afe4255a7
commit
6cd6139fb3
4 changed files with 97 additions and 5 deletions
lib
monero
src/screens/nodes
view_model/node_list
|
@ -147,7 +147,7 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance> with Store {
|
||||||
address: node.uri,
|
address: node.uri,
|
||||||
login: node.login,
|
login: node.login,
|
||||||
password: node.password,
|
password: node.password,
|
||||||
useSSL: false,
|
useSSL: true,
|
||||||
// FIXME: hardcoded value
|
// FIXME: hardcoded value
|
||||||
isLightWallet: false); // FIXME: hardcoded value
|
isLightWallet: false); // FIXME: hardcoded value
|
||||||
syncStatus = ConnectedSyncStatus();
|
syncStatus = ConnectedSyncStatus();
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.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/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
|
@ -10,6 +13,7 @@ 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/screens/base_page.dart';
|
||||||
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.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/node_create_or_edit_view_model.dart';
|
||||||
|
import 'package:cake_wallet/view_model/node_list/connection_state.dart';
|
||||||
|
|
||||||
class NodeCreateOrEditPage extends BasePage {
|
class NodeCreateOrEditPage extends BasePage {
|
||||||
NodeCreateOrEditPage(this.nodeCreateOrEditViewModel)
|
NodeCreateOrEditPage(this.nodeCreateOrEditViewModel)
|
||||||
|
@ -60,6 +64,8 @@ class NodeCreateOrEditPage extends BasePage {
|
||||||
final TextEditingController _loginController;
|
final TextEditingController _loginController;
|
||||||
final TextEditingController _passwordController;
|
final TextEditingController _passwordController;
|
||||||
|
|
||||||
|
bool _effectsInstalled = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get title => S.current.node_new;
|
String get title => S.current.node_new;
|
||||||
|
|
||||||
|
@ -67,6 +73,8 @@ class NodeCreateOrEditPage extends BasePage {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
|
_setEffects(context);
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: EdgeInsets.only(left: 24, right: 24),
|
padding: EdgeInsets.only(left: 24, right: 24),
|
||||||
child: ScrollableWithBottomSection(
|
child: ScrollableWithBottomSection(
|
||||||
|
@ -133,9 +141,18 @@ class NodeCreateOrEditPage extends BasePage {
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.only(right: 8.0),
|
padding: EdgeInsets.only(right: 8.0),
|
||||||
child: PrimaryButton(
|
child: LoadingPrimaryButton(
|
||||||
onPressed: () => nodeCreateOrEditViewModel.reset(),
|
onPressed: () async {
|
||||||
text: S.of(context).reset,
|
if (!_formKey.currentState.validate()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await nodeCreateOrEditViewModel.connect();
|
||||||
|
},
|
||||||
|
isLoading: nodeCreateOrEditViewModel
|
||||||
|
.connectionState is IsConnectingState,
|
||||||
|
text: 'Connect',
|
||||||
|
isDisabled: !nodeCreateOrEditViewModel.isReady,
|
||||||
color: Colors.orange,
|
color: Colors.orange,
|
||||||
textColor: Colors.white),
|
textColor: Colors.white),
|
||||||
)),
|
)),
|
||||||
|
@ -161,4 +178,44 @@ class NodeCreateOrEditPage extends BasePage {
|
||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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).node_new,
|
||||||
|
alertContent: state.isAlive
|
||||||
|
? 'Connected to node'
|
||||||
|
: 'Not connected to node',
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
17
lib/view_model/node_list/connection_state.dart
Normal file
17
lib/view_model/node_list/connection_state.dart
Normal file
|
@ -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/core/execution_state.dart';
|
||||||
|
import 'package:cake_wallet/view_model/node_list/connection_state.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cake_wallet/core/wallet_base.dart';
|
import 'package:cake_wallet/core/wallet_base.dart';
|
||||||
|
@ -12,7 +13,8 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
|
||||||
|
|
||||||
abstract class NodeCreateOrEditViewModelBase with Store {
|
abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
|
NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet)
|
||||||
: state = InitialExecutionState();
|
: state = InitialExecutionState(),
|
||||||
|
connectionState = InitialConnectionState();
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
ExecutionState state;
|
ExecutionState state;
|
||||||
|
@ -29,6 +31,9 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
@observable
|
@observable
|
||||||
String password;
|
String password;
|
||||||
|
|
||||||
|
@observable
|
||||||
|
ConnectionToNodeState connectionState;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
bool get isReady =>
|
bool get isReady =>
|
||||||
(address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false);
|
(address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false);
|
||||||
|
@ -68,4 +73,17 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
state = FailureState(e.toString());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue