diff --git a/lib/db/isar/main_db.dart b/lib/db/isar/main_db.dart index ed73c398d..bb6ea5e8d 100644 --- a/lib/db/isar/main_db.dart +++ b/lib/db/isar/main_db.dart @@ -66,7 +66,7 @@ class MainDB { // contact entries List getContactEntries() { - return isar.contactEntrys.where().findAllSync(); + return isar.contactEntrys.where().sortByName().findAllSync(); } Future deleteContactEntry({required String id}) { diff --git a/lib/models/isar/models/contact_entry.dart b/lib/models/isar/models/contact_entry.dart index 0ed9a8fb2..6289e8d18 100644 --- a/lib/models/isar/models/contact_entry.dart +++ b/lib/models/isar/models/contact_entry.dart @@ -33,6 +33,22 @@ class ContactEntry { @Index(unique: true, replace: true) late final String customId; + @ignore + List get addressesSorted { + final List sorted = []; + for (final coin in Coin.values) { + final slice = addresses.where((e) => e.coin == coin).toList(); + if (slice.isNotEmpty) { + slice.sort( + (a, b) => (a.other ?? a.label).compareTo(b.other ?? b.label), + ); + sorted.addAll(slice); + } + } + + return sorted; + } + ContactEntry copyWith({ bool shouldCopyEmojiWithNull = false, String? emojiChar, diff --git a/lib/pages/address_book_views/address_book_view.dart b/lib/pages/address_book_views/address_book_view.dart index 037a9772b..d50eaee70 100644 --- a/lib/pages/address_book_views/address_book_view.dart +++ b/lib/pages/address_book_views/address_book_view.dart @@ -302,7 +302,7 @@ class _AddressBookViewState extends ConsumerState { child: Column( children: [ ...contacts - .where((element) => element.addresses + .where((element) => element.addressesSorted .where((e) => ref.watch(addressBookFilterProvider .select((value) => value.coins.contains(e.coin)))) .isNotEmpty) @@ -350,7 +350,7 @@ class _AddressBookViewState extends ConsumerState { child: Column( children: [ ...contacts - .where((element) => element.addresses + .where((element) => element.addressesSorted .where((e) => ref.watch( addressBookFilterProvider.select((value) => value.coins.contains(e.coin)))) diff --git a/lib/pages/address_book_views/subviews/add_new_contact_address_view.dart b/lib/pages/address_book_views/subviews/add_new_contact_address_view.dart index 4916ec69d..11d6566a2 100644 --- a/lib/pages/address_book_views/subviews/add_new_contact_address_view.dart +++ b/lib/pages/address_book_views/subviews/add_new_contact_address_view.dart @@ -211,7 +211,8 @@ class _AddNewContactAddressViewState const Duration(milliseconds: 75), ); } - List entries = contact.addresses; + List entries = + contact.addresses.toList(); entries.add(ref .read(addressEntryDataProvider(0)) diff --git a/lib/pages/address_book_views/subviews/contact_details_view.dart b/lib/pages/address_book_views/subviews/contact_details_view.dart index ce543e04f..01e8ef3c3 100644 --- a/lib/pages/address_book_views/subviews/contact_details_view.dart +++ b/lib/pages/address_book_views/subviews/contact_details_view.dart @@ -341,7 +341,7 @@ class _ContactDetailsViewState extends ConsumerState { padding: const EdgeInsets.all(0), child: Column( children: [ - ..._contact.addresses.map( + ..._contact.addressesSorted.map( (e) => Padding( padding: const EdgeInsets.all(12), child: Row( diff --git a/lib/pages/address_book_views/subviews/contact_popup.dart b/lib/pages/address_book_views/subviews/contact_popup.dart index a82eca283..4315ef7e1 100644 --- a/lib/pages/address_book_views/subviews/contact_popup.dart +++ b/lib/pages/address_book_views/subviews/contact_popup.dart @@ -63,7 +63,7 @@ class ContactPopUp extends ConsumerWidget { bool isExchangeFlow = ref.watch(exchangeFlowIsActiveStateProvider.state).state; - final addresses = contact.addresses.where((e) { + final addresses = contact.addressesSorted.where((e) { if (hasActiveWallet && !isExchangeFlow) { return e.coin == active[0].coin; } else { diff --git a/lib/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart b/lib/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart index 267a7c2b9..e1825a3a6 100644 --- a/lib/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart +++ b/lib/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart @@ -53,15 +53,6 @@ class DesktopContactDetails extends ConsumerStatefulWidget { class _DesktopContactDetailsState extends ConsumerState { List> _cachedTransactions = []; - bool _contactHasAddress(String address, ContactEntry contact) { - for (final entry in contact.addresses) { - if (entry.address == address) { - return true; - } - } - return false; - } - Future>> _filteredTransactionsByContact( List managers, ) async { @@ -259,7 +250,9 @@ class _DesktopContactDetailsState extends ConsumerState { child: Column( mainAxisSize: MainAxisSize.min, children: [ - for (int i = 0; i < contact.addresses.length; i++) + for (int i = 0; + i < contact.addressesSorted.length; + i++) Column( mainAxisSize: MainAxisSize.min, children: [ @@ -273,7 +266,7 @@ class _DesktopContactDetailsState extends ConsumerState { Padding( padding: const EdgeInsets.all(18), child: DesktopAddressCard( - entry: contact.addresses[i], + entry: contact.addressesSorted[i], contactId: contact.customId, ), ), diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart index 13c501f70..ee10acb54 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/address_book_address_chooser.dart @@ -69,8 +69,8 @@ class _AddressBookAddressChooserState extends State { List filter(List contacts, String searchTerm) { if (widget.coin != null) { - contacts.removeWhere( - (e) => e.addresses.where((a) => a.coin == widget.coin!).isEmpty); + contacts.removeWhere((e) => + e.addressesSorted.where((a) => a.coin == widget.coin!).isEmpty); } contacts.retainWhere((e) => _matches(searchTerm, e)); diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/sub_widgets/contact_list_item.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/sub_widgets/contact_list_item.dart index 4d05f73a4..7d0be498e 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/sub_widgets/contact_list_item.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/address_book_address_chooser/sub_widgets/contact_list_item.dart @@ -78,7 +78,7 @@ class _ContactListItemState extends ConsumerState { mainAxisSize: MainAxisSize.min, children: [ // filter addresses by coin is provided before building address list - ...contact.addresses + ...contact.addressesSorted .where((e) => filterByCoin != null ? e.coin == filterByCoin! : true) .map( diff --git a/lib/widgets/address_book_card.dart b/lib/widgets/address_book_card.dart index fed6deb03..f40f4f432 100644 --- a/lib/widgets/address_book_card.dart +++ b/lib/widgets/address_book_card.dart @@ -70,9 +70,10 @@ class _AddressBookCardState extends ConsumerState { final contact = _contact!; final List coins = []; - for (var element in contact.addresses) { - if (!coins.contains(element.coin)) { - coins.add(element.coin); + + for (final coin in Coin.values) { + if (contact.addresses.where((e) => e.coin == coin).isNotEmpty) { + coins.add(coin); } }