mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
CW-273-Don't-add-node-under-Advanced-Privacy-Settings-if-it-already-exists (#876)
* don't add existing node * minor fixes * Add back IsExecutingState to connect [skip ci] --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
375755919a
commit
3b69aa8686
6 changed files with 58 additions and 21 deletions
|
@ -746,5 +746,5 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.19.0 <3.0.0"
|
dart: ">=2.19.0 <4.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.0.0"
|
||||||
|
|
|
@ -73,6 +73,25 @@ class Node extends HiveObject with Keyable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(other) =>
|
||||||
|
other is Node &&
|
||||||
|
(other.uriRaw == uriRaw &&
|
||||||
|
other.login == login &&
|
||||||
|
other.password == password &&
|
||||||
|
other.typeRaw == typeRaw &&
|
||||||
|
other.useSSL == useSSL &&
|
||||||
|
other.trusted == trusted);
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
uriRaw.hashCode ^
|
||||||
|
login.hashCode ^
|
||||||
|
password.hashCode ^
|
||||||
|
typeRaw.hashCode ^
|
||||||
|
useSSL.hashCode ^
|
||||||
|
trusted.hashCode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
dynamic get keyIndex {
|
dynamic get keyIndex {
|
||||||
_keyIndex ??= key;
|
_keyIndex ??= key;
|
||||||
|
|
|
@ -665,5 +665,5 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.19.0 <3.0.0"
|
dart: ">=2.19.0 <4.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.0.0"
|
||||||
|
|
|
@ -672,5 +672,5 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.1"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.19.0 <3.0.0"
|
dart: ">=2.19.0 <4.0.0"
|
||||||
flutter: ">=3.0.0"
|
flutter: ">=3.0.0"
|
||||||
|
|
|
@ -105,7 +105,7 @@ class _AdvancedPrivacySettingsBodyState extends State<AdvancedPrivacySettingsBod
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.nodeViewModel.save(saveAsCurrent: true);
|
widget.nodeViewModel.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
|
|
|
@ -4,13 +4,11 @@ import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cw_core/node.dart';
|
import 'package:cw_core/node.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'node_list_view_model.dart';
|
|
||||||
|
|
||||||
part 'node_create_or_edit_view_model.g.dart';
|
part 'node_create_or_edit_view_model.g.dart';
|
||||||
|
|
||||||
class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase
|
class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase with _$NodeCreateOrEditViewModel;
|
||||||
with _$NodeCreateOrEditViewModel;
|
|
||||||
|
|
||||||
abstract class NodeCreateOrEditViewModelBase with Store {
|
abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType, this._settingsStore)
|
NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType, this._settingsStore)
|
||||||
|
@ -48,11 +46,10 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
bool trusted;
|
bool trusted;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
bool get isReady =>
|
bool get isReady => address.isNotEmpty && port.isNotEmpty;
|
||||||
address.isNotEmpty && port.isNotEmpty;
|
|
||||||
|
|
||||||
bool get hasAuthCredentials => _walletType == WalletType.monero ||
|
bool get hasAuthCredentials =>
|
||||||
_walletType == WalletType.haven;
|
_walletType == WalletType.monero || _walletType == WalletType.haven;
|
||||||
|
|
||||||
String get uri {
|
String get uri {
|
||||||
var uri = address;
|
var uri = address;
|
||||||
|
@ -79,22 +76,22 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setPort (String val) => port = val;
|
void setPort(String val) => port = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setAddress (String val) => address = val;
|
void setAddress(String val) => address = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setLogin (String val) => login = val;
|
void setLogin(String val) => login = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setPassword (String val) => password = val;
|
void setPassword(String val) => password = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setSSL (bool val) => useSSL = val;
|
void setSSL(bool val) => useSSL = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
void setTrusted (bool val) => trusted = val;
|
void setTrusted(bool val) => trusted = val;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> save({Node? editingNode, bool saveAsCurrent = false}) async {
|
Future<void> save({Node? editingNode, bool saveAsCurrent = false}) async {
|
||||||
|
@ -109,11 +106,14 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
state = IsExecutingState();
|
state = IsExecutingState();
|
||||||
if (editingNode != null) {
|
if (editingNode != null) {
|
||||||
await _nodeSource.put(editingNode.key, node);
|
await _nodeSource.put(editingNode.key, node);
|
||||||
|
} else if (existingNode(node) != null) {
|
||||||
|
setAsCurrent(existingNode(node)!);
|
||||||
} else {
|
} else {
|
||||||
await _nodeSource.add(node);
|
await _nodeSource.add(node);
|
||||||
|
setAsCurrent(_nodeSource.values.last);
|
||||||
}
|
}
|
||||||
if (saveAsCurrent) {
|
if (saveAsCurrent) {
|
||||||
_settingsStore.nodes[_walletType] = node;
|
setAsCurrent(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = ExecutedSuccessfullyState();
|
state = ExecutedSuccessfullyState();
|
||||||
|
@ -124,14 +124,32 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future<void> connect() async {
|
Future<void> connect() async {
|
||||||
|
final node = Node(
|
||||||
|
uri: uri,
|
||||||
|
type: _walletType,
|
||||||
|
login: login,
|
||||||
|
password: password,
|
||||||
|
useSSL: useSSL,
|
||||||
|
trusted: trusted);
|
||||||
try {
|
try {
|
||||||
connectionState = IsExecutingState();
|
connectionState = IsExecutingState();
|
||||||
final node =
|
|
||||||
Node(uri: uri, type: _walletType, login: login, password: password);
|
|
||||||
final isAlive = await node.requestNode();
|
final isAlive = await node.requestNode();
|
||||||
connectionState = ExecutedSuccessfullyState(payload: isAlive);
|
connectionState = ExecutedSuccessfullyState(payload: isAlive);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
connectionState = FailureState(e.toString());
|
connectionState = FailureState(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node? existingNode(Node node) {
|
||||||
|
final nodes = _nodeSource.values.toList();
|
||||||
|
nodes.forEach((item) {
|
||||||
|
item.login ??= '';
|
||||||
|
item.password ??= '';
|
||||||
|
item.useSSL ??= false;
|
||||||
|
});
|
||||||
|
return nodes.firstWhereOrNull((item) => item == node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
void setAsCurrent(Node node) => _settingsStore.nodes[_walletType] = node;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue