From 5ee278237f3efa446126fb31331df14fc91942b3 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 30 Nov 2020 19:05:49 +0200 Subject: [PATCH] CAKE-169 | added useSSL parameter to node.dart and to node_create_or_edit_view_model.dart; applied useSSL parameter in the connectToNode() method (monero_wallet.dart) and in the save() method (node_create_or_edit_view_model.dart); created standard_checkbox.dart and applied StandardCheckbox widget in the node_create_or_edit_page.dart --- lib/entities/node.dart | 9 ++- lib/monero/monero_wallet.dart | 3 +- .../nodes/node_create_or_edit_page.dart | 19 ++++- lib/src/widgets/standard_checkbox.dart | 76 +++++++++++++++++++ .../node_create_or_edit_view_model.dart | 10 ++- 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 lib/src/widgets/standard_checkbox.dart diff --git a/lib/entities/node.dart b/lib/entities/node.dart index f307111d2..0b8da1acb 100644 --- a/lib/entities/node.dart +++ b/lib/entities/node.dart @@ -14,7 +14,8 @@ class Node extends HiveObject with Keyable { {@required this.uri, @required WalletType type, this.login, - this.password}) { + this.password, + this.useSSL}) { this.type = type; } @@ -22,7 +23,8 @@ class Node extends HiveObject with Keyable { : uri = map['uri'] as String ?? '', login = map['login'] as String, password = map['password'] as String, - typeRaw = map['typeRaw'] as int; + typeRaw = map['typeRaw'] as int, + useSSL = map['useSSL'] as bool; static const boxName = 'Nodes'; @@ -38,6 +40,9 @@ class Node extends HiveObject with Keyable { @HiveField(3) int typeRaw; + @HiveField(4) + bool useSSL; + @override dynamic get keyIndex { _keyIndex ??= key; diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index a064ed337..6c801b6e3 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -147,8 +147,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { address: node.uri, login: node.login, password: node.password, - useSSL: true, - // FIXME: hardcoded value + useSSL: node.useSSL ?? false, isLightWallet: false); // FIXME: hardcoded value syncStatus = ConnectedSyncStatus(); } catch (e) { diff --git a/lib/src/screens/nodes/node_create_or_edit_page.dart b/lib/src/screens/nodes/node_create_or_edit_page.dart index 63009b089..b1ff60763 100644 --- a/lib/src/screens/nodes/node_create_or_edit_page.dart +++ b/lib/src/screens/nodes/node_create_or_edit_page.dart @@ -1,4 +1,6 @@ import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; +import 'package:cake_wallet/src/widgets/checkbox_widget.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'; @@ -130,7 +132,22 @@ class NodeCreateOrEditPage extends BasePage { ) ) ], - ) + ), + Padding( + padding: EdgeInsets.only(top: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Observer( + builder: (_) => StandardCheckbox( + value: nodeCreateOrEditViewModel.useSSL, + onChanged: (value) => + nodeCreateOrEditViewModel.useSSL = value, + caption: 'Use SSL', + )) + ], + )) ] ], )), diff --git a/lib/src/widgets/standard_checkbox.dart b/lib/src/widgets/standard_checkbox.dart new file mode 100644 index 000000000..774acc9b7 --- /dev/null +++ b/lib/src/widgets/standard_checkbox.dart @@ -0,0 +1,76 @@ +import 'dart:ui'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class StandardCheckbox extends StatefulWidget { + StandardCheckbox({ + @required this.value, + this.caption = '', + @required this.onChanged}); + + final bool value; + final String caption; + final Function(bool) onChanged; + + @override + StandardCheckboxState createState() => + StandardCheckboxState(value, caption, onChanged); +} + +class StandardCheckboxState extends State { + StandardCheckboxState(this.value, this.caption, this.onChanged); + + bool value; + String caption; + Function(bool) onChanged; + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + value = !value; + onChanged(value); + setState(() {}); + }, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + height: 24.0, + width: 24.0, + margin: EdgeInsets.only( + right: 10.0, + ), + decoration: BoxDecoration( + border: Border.all( + color: Theme.of(context) + .primaryTextTheme + .caption + .color, + width: 1.0), + borderRadius: BorderRadius.all( + Radius.circular(8.0)), + color: Theme.of(context).backgroundColor), + child: value + ? Icon( + Icons.check, + color: Colors.blue, + size: 20.0, + ) + : Offstage(), + ), + Text( + caption, + style: TextStyle( + fontSize: 16.0, + color: Theme.of(context) + .primaryTextTheme + .title + .color), + ) + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/view_model/node_list/node_create_or_edit_view_model.dart b/lib/view_model/node_list/node_create_or_edit_view_model.dart index df07f6789..ce4404051 100644 --- a/lib/view_model/node_list/node_create_or_edit_view_model.dart +++ b/lib/view_model/node_list/node_create_or_edit_view_model.dart @@ -14,7 +14,8 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase abstract class NodeCreateOrEditViewModelBase with Store { NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet) : state = InitialExecutionState(), - connectionState = InitialConnectionState(); + connectionState = InitialConnectionState(), + useSSL = false; @observable ExecutionState state; @@ -34,6 +35,9 @@ abstract class NodeCreateOrEditViewModelBase with Store { @observable ConnectionToNodeState connectionState; + @observable + bool useSSL; + @computed bool get isReady => (address?.isNotEmpty ?? false) && (port?.isNotEmpty ?? false); @@ -59,6 +63,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { port = ''; login = ''; password = ''; + useSSL = false; } @action @@ -66,7 +71,8 @@ abstract class NodeCreateOrEditViewModelBase with Store { try { state = IsExecutingState(); final node = - Node(uri: uri, type: _wallet.type, login: login, password: password); + Node(uri: uri, type: _wallet.type, login: login, password: password, + useSSL: useSSL); await _nodeSource.add(node); state = ExecutedSuccessfullyState(); } catch (e) {