mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 19:16:09 +00:00
filter contacts and wallets by type
This commit is contained in:
parent
d40cd3ebad
commit
2cd748c151
7 changed files with 51 additions and 19 deletions
|
@ -153,6 +153,7 @@ import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
|||
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
|
||||
import 'package:cake_wallet/src/screens/receive/fullscreen_qr_page.dart';
|
||||
import 'package:cake_wallet/core/wallet_loading_service.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
final getIt = GetIt.instance;
|
||||
|
||||
|
@ -461,9 +462,11 @@ Future setup(
|
|||
getIt.registerFactory(
|
||||
() => ContactListViewModel(_contactSource, _walletInfoSource));
|
||||
|
||||
getIt.registerFactoryParam<ContactListPage, bool, void>(
|
||||
(bool isEditable, _) => ContactListPage(getIt.get<ContactListViewModel>(),
|
||||
isEditable: isEditable));
|
||||
getIt.registerFactoryParam<ContactListPage, bool, CryptoCurrency?>((bool isEditable, CryptoCurrency? cur)
|
||||
=> ContactListPage(
|
||||
getIt.get<ContactListViewModel>(),
|
||||
isEditable: isEditable,
|
||||
selectedCurrency: cur));
|
||||
|
||||
getIt.registerFactoryParam<ContactPage, ContactRecord?, void>(
|
||||
(ContactRecord? contact, _) =>
|
||||
|
|
|
@ -74,6 +74,7 @@ import 'package:cake_wallet/src/screens/ionia/ionia.dart';
|
|||
import 'package:cake_wallet/src/screens/ionia/cards/ionia_payment_status_page.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_any_pay_payment_info.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
late RouteSettings currentRouteSettings;
|
||||
|
||||
|
@ -298,11 +299,14 @@ Route<dynamic> createRoute(RouteSettings settings) {
|
|||
|
||||
case Routes.addressBook:
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (_) => getIt.get<ContactListPage>(param1: true));
|
||||
builder: (_) =>
|
||||
getIt.get<ContactListPage>(param1: true, param2: null));
|
||||
|
||||
case Routes.pickerAddressBook:
|
||||
final selectedCurrency = settings.arguments as CryptoCurrency;
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (_) => getIt.get<ContactListPage>(param1: false));
|
||||
builder: (_) => getIt.get<ContactListPage>(param1: false,
|
||||
param2: selectedCurrency));
|
||||
|
||||
case Routes.addressBookAddContact:
|
||||
return CupertinoPageRoute<void>(
|
||||
|
|
|
@ -16,10 +16,12 @@ import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart
|
|||
import 'package:cake_wallet/src/widgets/collapsible_standart_list.dart';
|
||||
|
||||
class ContactListPage extends BasePage {
|
||||
ContactListPage(this.contactListViewModel, {this.isEditable = true});
|
||||
ContactListPage(this.contactListViewModel,
|
||||
{this.isEditable = true, required this.selectedCurrency});
|
||||
|
||||
final ContactListViewModel contactListViewModel;
|
||||
final bool isEditable;
|
||||
final CryptoCurrency? selectedCurrency;
|
||||
|
||||
@override
|
||||
String get title => S.current.address_book;
|
||||
|
@ -60,11 +62,13 @@ class ContactListPage extends BasePage {
|
|||
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
final contacts =
|
||||
contactListViewModel.getContacts(isEditable, selectedCurrency);
|
||||
final walletContacts =
|
||||
contactListViewModel.getWallets(isEditable, selectedCurrency);
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 20.0, bottom: 20.0),
|
||||
child: Observer(
|
||||
builder: (_) {
|
||||
return CollapsibleSectionList(
|
||||
child: CollapsibleSectionList(
|
||||
context: context,
|
||||
sectionCount: 2,
|
||||
themeColor: Theme.of(context).primaryTextTheme.headline6!.color!,
|
||||
|
@ -82,15 +86,15 @@ class ContactListPage extends BasePage {
|
|||
child: Text(title, style: TextStyle(fontSize: 36)));
|
||||
},
|
||||
itemCounter: (int sectionIndex) => sectionIndex == 0
|
||||
? contactListViewModel.walletContacts.length
|
||||
: contactListViewModel.contacts.length,
|
||||
? walletContacts.length
|
||||
: contacts.length,
|
||||
itemBuilder: (_, sectionIndex, index) {
|
||||
if (sectionIndex == 0) {
|
||||
final walletInfo = contactListViewModel.walletContacts[index];
|
||||
final walletInfo = walletContacts[index];
|
||||
return generateRaw(context, walletInfo);
|
||||
}
|
||||
|
||||
final contact = contactListViewModel.contacts[index];
|
||||
final contact = contacts[index];
|
||||
final content = generateRaw(context, contact);
|
||||
return !isEditable
|
||||
? content
|
||||
|
@ -100,9 +104,8 @@ class ContactListPage extends BasePage {
|
|||
child: content,
|
||||
);
|
||||
},
|
||||
)
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
Widget generateRaw(BuildContext context, ContactBase contact) {
|
||||
|
|
|
@ -395,7 +395,8 @@ class ExchangeCardState extends State<ExchangeCard> {
|
|||
buttonColor: widget.addressButtonsColor,
|
||||
validator: widget.addressTextFieldValidator,
|
||||
onPushPasteButton: widget.onPushPasteButton,
|
||||
onPushAddressBookButton: widget.onPushAddressBookButton
|
||||
onPushAddressBookButton: widget.onPushAddressBookButton,
|
||||
selectedCurrency: _selectedCurrency
|
||||
),
|
||||
|
||||
)
|
||||
|
|
|
@ -155,6 +155,7 @@ class SendCardState extends State<SendCard>
|
|||
await output.fetchParsedAddress(context);
|
||||
},
|
||||
validator: validator,
|
||||
selectedCurrency: sendViewModel.currency,
|
||||
);
|
||||
}),
|
||||
if (output.isParsedAddress) Padding(
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:cake_wallet/routes.dart';
|
|||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/entities/qr_scanner.dart';
|
||||
import 'package:cake_wallet/entities/contact_base.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
enum AddressTextFieldOption { paste, qrCode, addressBook }
|
||||
|
||||
|
@ -26,7 +27,8 @@ class AddressTextField extends StatelessWidget {
|
|||
this.hintStyle,
|
||||
this.validator,
|
||||
this.onPushPasteButton,
|
||||
this.onPushAddressBookButton});
|
||||
this.onPushAddressBookButton,
|
||||
this.selectedCurrency});
|
||||
|
||||
static const prefixIconWidth = 34.0;
|
||||
static const prefixIconHeight = 34.0;
|
||||
|
@ -47,6 +49,7 @@ class AddressTextField extends StatelessWidget {
|
|||
final FocusNode? focusNode;
|
||||
final Function(BuildContext context)? onPushPasteButton;
|
||||
final Function(BuildContext context)? onPushAddressBookButton;
|
||||
final CryptoCurrency? selectedCurrency;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -207,7 +210,7 @@ class AddressTextField extends StatelessWidget {
|
|||
|
||||
Future<void> _presetAddressBookPicker(BuildContext context) async {
|
||||
final contact = await Navigator.of(context, rootNavigator: true)
|
||||
.pushNamed(Routes.pickerAddressBook);
|
||||
.pushNamed(Routes.pickerAddressBook,arguments: selectedCurrency);
|
||||
|
||||
if (contact is ContactBase && contact.address != null) {
|
||||
controller?.text = contact.address;
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:mobx/mobx.dart';
|
|||
import 'package:cake_wallet/entities/contact_record.dart';
|
||||
import 'package:cake_wallet/entities/contact.dart';
|
||||
import 'package:cake_wallet/utils/mobx.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
||||
part 'contact_list_view_model.g.dart';
|
||||
|
||||
|
@ -44,4 +45,20 @@ abstract class ContactListViewModelBase with Store {
|
|||
StreamSubscription<BoxEvent>? _subscription;
|
||||
|
||||
Future<void> delete(ContactRecord contact) async => contact.original.delete();
|
||||
|
||||
List<ContactRecord> getContacts(bool isEditable, CryptoCurrency? cur) {
|
||||
if (!isEditable) {
|
||||
return contacts.where((element) => element.type == cur).toList();
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
List<WalletContact> getWallets(bool isEditable, CryptoCurrency? cur) {
|
||||
if (!isEditable) {
|
||||
return walletContacts.where((element) => element.type == cur).toList();
|
||||
}
|
||||
|
||||
return walletContacts;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue