mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
contact address sorting
This commit is contained in:
parent
065063c600
commit
d894d60c1e
10 changed files with 34 additions and 23 deletions
|
@ -66,7 +66,7 @@ class MainDB {
|
|||
|
||||
// contact entries
|
||||
List<ContactEntry> getContactEntries() {
|
||||
return isar.contactEntrys.where().findAllSync();
|
||||
return isar.contactEntrys.where().sortByName().findAllSync();
|
||||
}
|
||||
|
||||
Future<bool> deleteContactEntry({required String id}) {
|
||||
|
|
|
@ -33,6 +33,22 @@ class ContactEntry {
|
|||
@Index(unique: true, replace: true)
|
||||
late final String customId;
|
||||
|
||||
@ignore
|
||||
List<ContactAddressEntry> get addressesSorted {
|
||||
final List<ContactAddressEntry> 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,
|
||||
|
|
|
@ -302,7 +302,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
|||
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<AddressBookView> {
|
|||
child: Column(
|
||||
children: [
|
||||
...contacts
|
||||
.where((element) => element.addresses
|
||||
.where((element) => element.addressesSorted
|
||||
.where((e) => ref.watch(
|
||||
addressBookFilterProvider.select((value) =>
|
||||
value.coins.contains(e.coin))))
|
||||
|
|
|
@ -211,7 +211,8 @@ class _AddNewContactAddressViewState
|
|||
const Duration(milliseconds: 75),
|
||||
);
|
||||
}
|
||||
List<ContactAddressEntry> entries = contact.addresses;
|
||||
List<ContactAddressEntry> entries =
|
||||
contact.addresses.toList();
|
||||
|
||||
entries.add(ref
|
||||
.read(addressEntryDataProvider(0))
|
||||
|
|
|
@ -341,7 +341,7 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
|||
padding: const EdgeInsets.all(0),
|
||||
child: Column(
|
||||
children: [
|
||||
..._contact.addresses.map(
|
||||
..._contact.addressesSorted.map(
|
||||
(e) => Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -53,15 +53,6 @@ class DesktopContactDetails extends ConsumerStatefulWidget {
|
|||
class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
||||
List<Tuple2<String, Transaction>> _cachedTransactions = [];
|
||||
|
||||
bool _contactHasAddress(String address, ContactEntry contact) {
|
||||
for (final entry in contact.addresses) {
|
||||
if (entry.address == address) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<List<Tuple2<String, Transaction>>> _filteredTransactionsByContact(
|
||||
List<Manager> managers,
|
||||
) async {
|
||||
|
@ -259,7 +250,9 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
|||
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<DesktopContactDetails> {
|
|||
Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: DesktopAddressCard(
|
||||
entry: contact.addresses[i],
|
||||
entry: contact.addressesSorted[i],
|
||||
contactId: contact.customId,
|
||||
),
|
||||
),
|
||||
|
|
|
@ -69,8 +69,8 @@ class _AddressBookAddressChooserState extends State<AddressBookAddressChooser> {
|
|||
|
||||
List<ContactEntry> filter(List<ContactEntry> 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));
|
||||
|
|
|
@ -78,7 +78,7 @@ class _ContactListItemState extends ConsumerState<ContactListItem> {
|
|||
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(
|
||||
|
|
|
@ -70,9 +70,10 @@ class _AddressBookCardState extends ConsumerState<AddressBookCard> {
|
|||
final contact = _contact!;
|
||||
|
||||
final List<Coin> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue