From ba783982e43216fea584cc2cea096020adcf491b Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Wed, 9 Nov 2022 17:53:50 +0200 Subject: [PATCH] Update branch to null safety Fix Conflicts with main --- cw_core/lib/node.dart | 6 ++---- lib/di.dart | 5 +++-- .../advanced_privacy_settings_page.dart | 7 +++---- lib/src/screens/nodes/widgets/node_form.dart | 4 ++-- .../node_create_or_edit_view_model.dart | 13 ++++++------- .../privacy_settings_view_model.dart | 18 +++++++++--------- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 28a54947c..5fce69a8e 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -17,7 +17,7 @@ class Node extends HiveObject with Keyable { {this.login, this.password, this.useSSL, - this.trusted, + this.trusted = false, String? uri, WalletType? type,}) { if (uri != null) { @@ -33,7 +33,7 @@ class Node extends HiveObject with Keyable { login = map['login'] as String?, password = map['password'] as String?, useSSL = map['useSSL'] as bool?, - useSSL = map['trusted'] as bool? ?? false; + trusted = map['trusted'] as bool? ?? false; static const typeId = 1; static const boxName = 'Nodes'; @@ -58,8 +58,6 @@ class Node extends HiveObject with Keyable { bool get isSSL => useSSL ?? false; - bool get isTrusted => trusted ?? false; - Uri get uri { switch (type) { case WalletType.monero: diff --git a/lib/di.dart b/lib/di.dart index 73421c989..7a3a8631c 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -478,8 +478,9 @@ Future setup( getIt.registerFactory(() => NodeListPage(getIt.get())); - getIt.registerFactory(() => - NodeCreateOrEditViewModel(_nodeSource, getIt.get().wallet!)); + getIt.registerFactoryParam( + (WalletType? type, _) => + NodeCreateOrEditViewModel(_nodeSource, type ?? getIt.get().wallet!.type)); getIt.registerFactory( () => NodeCreateOrEditPage(getIt.get())); diff --git a/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart b/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart index cb3e4e8dc..58adc9d99 100644 --- a/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart +++ b/lib/src/screens/new_wallet/advanced_privacy_settings_page.dart @@ -4,7 +4,6 @@ import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model. import 'package:cake_wallet/view_model/privacy_settings_view_model.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; @@ -25,7 +24,7 @@ class AdvancedPrivacySettingsPage extends BasePage { } class AdvancedPrivacySettingsBody extends StatefulWidget { - const AdvancedPrivacySettingsBody(this.privacySettingsViewModel, this.nodeViewModel, {Key key}) + const AdvancedPrivacySettingsBody(this.privacySettingsViewModel, this.nodeViewModel, {Key? key}) : super(key: key); final PrivacySettingsViewModel privacySettingsViewModel; @@ -85,7 +84,7 @@ class _AdvancedPrivacySettingsBodyState LoadingPrimaryButton( onPressed: () {}, text: S.of(context).continue_text, - color: Theme.of(context).accentTextTheme.body2.color, + color: Theme.of(context).accentTextTheme.bodyText1!.color!, textColor: Colors.white, ), const SizedBox(height: 25), @@ -96,7 +95,7 @@ class _AdvancedPrivacySettingsBodyState S.of(context).settings_can_be_changed_later, textAlign: TextAlign.center, style: TextStyle( - color: Theme.of(context).accentTextTheme.display3.color, + color: Theme.of(context).accentTextTheme.headline2?.color, ), ), ), diff --git a/lib/src/screens/nodes/widgets/node_form.dart b/lib/src/screens/nodes/widgets/node_form.dart index 757032a2a..52851e063 100644 --- a/lib/src/screens/nodes/widgets/node_form.dart +++ b/lib/src/screens/nodes/widgets/node_form.dart @@ -10,8 +10,8 @@ import 'package:mobx/mobx.dart'; class NodeForm extends StatelessWidget { NodeForm({ - @required this.nodeViewModel, - @required this.formKey, + required this.nodeViewModel, + required this.formKey, }) : _addressController = TextEditingController(), _portController = TextEditingController(), _loginController = TextEditingController(), 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 7137cdd2c..34167ae0a 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 @@ -1,7 +1,6 @@ import 'package:cake_wallet/core/execution_state.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; -import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/node.dart'; import 'package:cw_core/wallet_type.dart'; @@ -11,7 +10,7 @@ class NodeCreateOrEditViewModel = NodeCreateOrEditViewModelBase with _$NodeCreateOrEditViewModel; abstract class NodeCreateOrEditViewModelBase with Store { - NodeCreateOrEditViewModelBase(this._nodeSource, this._wallet) + NodeCreateOrEditViewModelBase(this._nodeSource, this._walletType) : state = InitialExecutionState(), connectionState = InitialExecutionState(), useSSL = false, @@ -49,8 +48,8 @@ abstract class NodeCreateOrEditViewModelBase with Store { bool get isReady => address.isNotEmpty && port.isNotEmpty; - bool get hasAuthCredentials => _wallet.type == WalletType.monero || - _wallet.type == WalletType.haven; + bool get hasAuthCredentials => _walletType == WalletType.monero || + _walletType == WalletType.haven; String get uri { var uri = address; @@ -62,7 +61,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { return uri; } - final WalletBase _wallet; + final WalletType _walletType; final Box _nodeSource; @action @@ -80,7 +79,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { try { state = IsExecutingState(); final node = - Node(uri: uri, type: _wallet.type, login: login, password: password, + Node(uri: uri, type: _walletType, login: login, password: password, useSSL: useSSL, trusted: trusted); await _nodeSource.add(node); state = ExecutedSuccessfullyState(); @@ -94,7 +93,7 @@ abstract class NodeCreateOrEditViewModelBase with Store { try { connectionState = IsExecutingState(); final node = - Node(uri: uri, type: _wallet.type, login: login, password: password); + Node(uri: uri, type: _walletType, login: login, password: password); final isAlive = await node.requestNode(); connectionState = ExecutedSuccessfullyState(payload: isAlive); } catch (e) { diff --git a/lib/view_model/privacy_settings_view_model.dart b/lib/view_model/privacy_settings_view_model.dart index ce5a3f7a6..760c577ef 100644 --- a/lib/view_model/privacy_settings_view_model.dart +++ b/lib/view_model/privacy_settings_view_model.dart @@ -9,13 +9,13 @@ class PrivacySettingsViewModel = PrivacySettingsViewModelBase with _$PrivacySettingsViewModel; abstract class PrivacySettingsViewModelBase with Store { - PrivacySettingsViewModelBase(this.type) { - _disableFiat = false; - _disableExchange = false; - _addCustomNode = false; - + PrivacySettingsViewModelBase(this.type) + : _disableFiat = false, + _disableExchange = false, + _addCustomNode = false { settings = [ SwitcherListItem( + // TODO: replace when Disable Fiat PR is merged title: "Disable Fiat API", // title: S.current.disable_fiat, value: () => _disableFiat, @@ -36,16 +36,16 @@ abstract class PrivacySettingsViewModelBase with Store { ]; } - List settings; + late List settings; @observable - bool _disableFiat; + bool _disableFiat = false; @observable - bool _disableExchange; + bool _disableExchange = false; @observable - bool _addCustomNode; + bool _addCustomNode = false; final WalletType type;