Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkyq committed Sep 26, 2020
1 parent dcdc411 commit 51cf111
Show file tree
Hide file tree
Showing 21 changed files with 353 additions and 245 deletions.
4 changes: 2 additions & 2 deletions lib/core/contact_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ContactService {
if (index >= 0) {
_forceUpdateContactListStore();
} else {
contactListStore.contacts.add(contact);
// contactListStore.contacts.add(contact);
}
}

Expand All @@ -33,6 +33,6 @@ class ContactService {

void _forceUpdateContactListStore() {
contactListStore.contacts.clear();
contactListStore.contacts.addAll(contactSource.values);
// contactListStore.contacts.addAll(contactSource.values);
}
}
17 changes: 10 additions & 7 deletions lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart';
import 'package:cake_wallet/core/contact_service.dart';
import 'package:cake_wallet/core/wallet_service.dart';
import 'package:cake_wallet/entities/biometric_auth.dart';
import 'package:cake_wallet/entities/contact_record.dart';
import 'package:cake_wallet/monero/monero_wallet_service.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/node.dart';
Expand Down Expand Up @@ -197,7 +198,8 @@ Future setup(
getIt
.registerFactoryParam<AuthPage, void Function(bool, AuthPageState), bool>(
(onAuthFinished, closable) => AuthPage(getIt.get<AuthViewModel>(),
onAuthenticationFinished: onAuthFinished, closable: closable ?? false));
onAuthenticationFinished: onAuthFinished,
closable: closable ?? false));

getIt.registerFactory<DashboardPage>(() => DashboardPage(
walletViewModel: getIt.get<DashboardViewModel>(),
Expand Down Expand Up @@ -282,8 +284,8 @@ Future setup(

getIt.registerFactory(() => WalletKeysPage(getIt.get<WalletKeysViewModel>()));

getIt.registerFactoryParam<ContactViewModel, Contact, void>(
(Contact contact, _) => ContactViewModel(
getIt.registerFactoryParam<ContactViewModel, ContactRecord, void>(
(ContactRecord contact, _) => ContactViewModel(
contactSource, getIt.get<AppStore>().wallet,
contact: contact));

Expand All @@ -296,13 +298,14 @@ Future setup(
(bool isEditable, _) => ContactListPage(getIt.get<ContactListViewModel>(),
isEditable: isEditable));

getIt.registerFactoryParam<ContactPage, Contact, void>((Contact contact, _) =>
ContactPage(getIt.get<ContactViewModel>(param1: contact)));
getIt.registerFactoryParam<ContactPage, ContactRecord, void>(
(ContactRecord contact, _) =>
ContactPage(getIt.get<ContactViewModel>(param1: contact)));

getIt.registerFactory(() {
final appStore = getIt.get<AppStore>();
return NodeListViewModel(appStore.nodeListStore, nodeSource,
appStore.wallet, appStore.settingsStore);
return NodeListViewModel(
nodeSource, appStore.wallet, appStore.settingsStore);
});

getIt.registerFactory(() => NodeListPage(getIt.get<NodeListViewModel>()));
Expand Down
40 changes: 40 additions & 0 deletions lib/entities/contact_record.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/record.dart';

part 'contact_record.g.dart';

class ContactRecord = ContactRecordBase with _$ContactRecord;

abstract class ContactRecordBase extends Record<Contact> with Store {
ContactRecordBase(Box<Contact> source, Contact original)
: super(source, original);

@observable
String name;

@observable
String address;

@observable
CryptoCurrency type;

@override
void toBind(Contact original) {
reaction((_) => name, (String name) => original.name = name);
reaction((_) => address, (String address) => original.address = address);
reaction(
(_) => type,
(CryptoCurrency currency) =>
original.updateCryptoCurrency(currency: currency));
}

@override
void fromBind(Contact original) {
name = original.name;
address = original.address;
type = original.type;
}
}
3 changes: 3 additions & 0 deletions lib/entities/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Node extends HiveObject with Keyable {
@HiveField(3)
int typeRaw;

@override
dynamic get keyIndex => key;

WalletType get type => deserializeFromInt(typeRaw);

set type(WalletType type) => typeRaw = serializeToInt(type);
Expand Down
35 changes: 35 additions & 0 deletions lib/entities/record.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'dart:async';

import 'package:cake_wallet/utils/mobx.dart';
import 'package:hive/hive.dart';

abstract class Record<T extends HiveObject> with Keyable {
Record(this._source, this.original) {
_listener?.cancel();
_listener = _source.watch(key: original.key).listen((event) {
if (!event.deleted) {
fromBind(event.value as T);
}
});

fromBind(original);
toBind(original);
}

dynamic get key => original.key;

@override
dynamic get keyIndex => key;

final T original;

final Box<T> _source;

StreamSubscription<BoxEvent> _listener;

void fromBind(T original);

void toBind(T original);

Future<void> save() => original.save();
}
2 changes: 2 additions & 0 deletions lib/reactions/bootstrap.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'package:cake_wallet/reactions/on_current_node_change.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -31,4 +32,5 @@ Future<void> bootstrap(GlobalKey<NavigatorState> navigatorKey) async {
startCurrentWalletChangeReaction(
appStore, settingsStore, fiatConversionStore);
startCurrentFiatChangeReaction(appStore, settingsStore);
startOnCurrentNodeChangeReaction(appStore);
}
17 changes: 17 additions & 0 deletions lib/reactions/on_current_node_change.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/node.dart';
import 'package:cake_wallet/store/app_store.dart';

ReactionDisposer _onCurrentNodeChangeReaction;

void startOnCurrentNodeChangeReaction(AppStore appStore) {
_onCurrentNodeChangeReaction?.reaction?.dispose();
_onCurrentNodeChangeReaction =
reaction((_) => appStore.settingsStore.currentNode, (Node node) async {
try {
await appStore.wallet.connectToNode(node: node);
} catch (e) {
print(e.toString());
}
});
}
3 changes: 2 additions & 1 deletion lib/router.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cake_wallet/entities/contact_record.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart';
Expand Down Expand Up @@ -252,7 +253,7 @@ class Router {
case Routes.addressBookAddContact:
return CupertinoPageRoute<void>(
builder: (_) =>
getIt.get<ContactPage>(param1: settings.arguments as Contact));
getIt.get<ContactPage>(param1: settings.arguments as ContactRecord));

case Routes.showKeys:
return MaterialPageRoute<void>(
Expand Down
12 changes: 6 additions & 6 deletions lib/src/screens/contact/contact_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ class ContactListPage extends BasePage {
final isDelete =
await showAlertDialog(context) ?? false;

if (isDelete) {
await contactListViewModel
.delete(contact);
}
// if (isDelete) {
// await contactListViewModel
// .delete(contact);
// }
},
),
],
dismissal: SlidableDismissal(
child: SlidableDrawerDismissal(),
onDismissed: (actionType) async =>
await contactListViewModel.delete(contact),
onDismissed: (actionType) async => null,
// await contactListViewModel.delete(contact),
onWillDismiss: (actionType) async =>
showAlertDialog(context),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/screens/monero_accounts/widgets/account_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AccountTile extends StatelessWidget {
accountName,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w600,
fontFamily: 'Poppins',
color: textColor,
decoration: TextDecoration.none,
Expand Down
153 changes: 76 additions & 77 deletions lib/src/screens/nodes/nodes_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,87 +67,86 @@ class NodeListPage extends BasePage {
sectionCount: 2,
context: context,
itemBuilder: (_, sectionIndex, index) {
if (sectionIndex == 0) {
return NodeHeaderListRow(
title: S.of(context).add_new_node,
onTap: (_) async =>
await Navigator.of(context).pushNamed(Routes.newNode));
}
return Observer(builder: (_) {
if (sectionIndex == 0) {
return NodeHeaderListRow(
title: S.of(context).add_new_node,
onTap: (_) async => await Navigator.of(context)
.pushNamed(Routes.newNode));
}

final node = nodeListViewModel.nodes[index];
final nodeListRow = NodeListRow(
title: node.value.uri,
isSelected: node.isSelected,
isAlive: node.value.requestNode(),
onTap: (_) async {
if (node.isSelected) {
return;
}
final node = nodeListViewModel.nodes[index];
final isSelected = node.keyIndex ==
nodeListViewModel.settingsStore.currentNode.keyIndex;
final nodeListRow = NodeListRow(
title: node.uri,
isSelected: isSelected,
isAlive: node.requestNode(),
onTap: (_) async {
if (isSelected) {
return;
}

await showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content: Text(
S.of(context).change_current_node(node.value.uri),
textAlign: TextAlign.center,
),
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text(S.of(context).cancel)),
FlatButton(
onPressed: () async {
Navigator.of(context).pop();
await nodeListViewModel
.setAsCurrent(node.value);
},
child: Text(S.of(context).change)),
],
);
});
});
await showPopUp<void>(
context: context,
builder: (BuildContext context) {
// FIXME: Add translation.
return AlertWithTwoActions(
alertTitle: 'Change current node',
alertContent:
S.of(context).change_current_node(node.uri),
leftButtonText: S.of(context).cancel,
rightButtonText: S.of(context).change,
actionLeftButton: () =>
Navigator.of(context).pop(),
actionRightButton: () async {
await nodeListViewModel.setAsCurrent(node);
Navigator.of(context).pop();
});
});
});

final dismissibleRow = Dismissible(
key: Key('${node.keyIndex}'),
confirmDismiss: (direction) async {
return await showPopUp(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).remove_node,
alertContent: S.of(context).remove_node_message,
rightButtonText: S.of(context).remove,
leftButtonText: S.of(context).cancel,
actionRightButton: () =>
Navigator.pop(context, true),
actionLeftButton: () =>
Navigator.pop(context, false));
});
},
onDismissed: (direction) async =>
nodeListViewModel.delete(node.value),
direction: DismissDirection.endToStart,
background: Container(
padding: EdgeInsets.only(right: 10.0),
alignment: AlignmentDirectional.centerEnd,
color: Palette.red,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Icon(
CupertinoIcons.delete,
color: Colors.white,
),
Text(
S.of(context).delete,
style: TextStyle(color: Colors.white),
)
],
)),
child: nodeListRow);
final dismissibleRow = Dismissible(
key: Key('${node.keyIndex}'),
confirmDismiss: (direction) async {
return await showPopUp(
context: context,
builder: (BuildContext context) {
return AlertWithTwoActions(
alertTitle: S.of(context).remove_node,
alertContent: S.of(context).remove_node_message,
rightButtonText: S.of(context).remove,
leftButtonText: S.of(context).cancel,
actionRightButton: () =>
Navigator.pop(context, true),
actionLeftButton: () =>
Navigator.pop(context, false));
});
},
onDismissed: (direction) async =>
nodeListViewModel.delete(node),
direction: DismissDirection.endToStart,
background: Container(
padding: EdgeInsets.only(right: 10.0),
alignment: AlignmentDirectional.centerEnd,
color: Palette.red,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
const Icon(
CupertinoIcons.delete,
color: Colors.white,
),
Text(
S.of(context).delete,
style: TextStyle(color: Colors.white),
)
],
)),
child: nodeListRow);

return node.isSelected ? nodeListRow : dismissibleRow;
return isSelected ? nodeListRow : dismissibleRow;
});
},
itemCounter: (int sectionIndex) {
if (sectionIndex == 0) {
Expand Down
Loading

0 comments on commit 51cf111

Please sign in to comment.