mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-25 08:38:45 +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
|
// contact entries
|
||||||
List<ContactEntry> getContactEntries() {
|
List<ContactEntry> getContactEntries() {
|
||||||
return isar.contactEntrys.where().findAllSync();
|
return isar.contactEntrys.where().sortByName().findAllSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deleteContactEntry({required String id}) {
|
Future<bool> deleteContactEntry({required String id}) {
|
||||||
|
|
|
@ -33,6 +33,22 @@ class ContactEntry {
|
||||||
@Index(unique: true, replace: true)
|
@Index(unique: true, replace: true)
|
||||||
late final String customId;
|
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({
|
ContactEntry copyWith({
|
||||||
bool shouldCopyEmojiWithNull = false,
|
bool shouldCopyEmojiWithNull = false,
|
||||||
String? emojiChar,
|
String? emojiChar,
|
||||||
|
|
|
@ -302,7 +302,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
...contacts
|
...contacts
|
||||||
.where((element) => element.addresses
|
.where((element) => element.addressesSorted
|
||||||
.where((e) => ref.watch(addressBookFilterProvider
|
.where((e) => ref.watch(addressBookFilterProvider
|
||||||
.select((value) => value.coins.contains(e.coin))))
|
.select((value) => value.coins.contains(e.coin))))
|
||||||
.isNotEmpty)
|
.isNotEmpty)
|
||||||
|
@ -350,7 +350,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
...contacts
|
...contacts
|
||||||
.where((element) => element.addresses
|
.where((element) => element.addressesSorted
|
||||||
.where((e) => ref.watch(
|
.where((e) => ref.watch(
|
||||||
addressBookFilterProvider.select((value) =>
|
addressBookFilterProvider.select((value) =>
|
||||||
value.coins.contains(e.coin))))
|
value.coins.contains(e.coin))))
|
||||||
|
|
|
@ -211,7 +211,8 @@ class _AddNewContactAddressViewState
|
||||||
const Duration(milliseconds: 75),
|
const Duration(milliseconds: 75),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
List<ContactAddressEntry> entries = contact.addresses;
|
List<ContactAddressEntry> entries =
|
||||||
|
contact.addresses.toList();
|
||||||
|
|
||||||
entries.add(ref
|
entries.add(ref
|
||||||
.read(addressEntryDataProvider(0))
|
.read(addressEntryDataProvider(0))
|
||||||
|
|
|
@ -341,7 +341,7 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
||||||
padding: const EdgeInsets.all(0),
|
padding: const EdgeInsets.all(0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
..._contact.addresses.map(
|
..._contact.addressesSorted.map(
|
||||||
(e) => Padding(
|
(e) => Padding(
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
|
@ -63,7 +63,7 @@ class ContactPopUp extends ConsumerWidget {
|
||||||
bool isExchangeFlow =
|
bool isExchangeFlow =
|
||||||
ref.watch(exchangeFlowIsActiveStateProvider.state).state;
|
ref.watch(exchangeFlowIsActiveStateProvider.state).state;
|
||||||
|
|
||||||
final addresses = contact.addresses.where((e) {
|
final addresses = contact.addressesSorted.where((e) {
|
||||||
if (hasActiveWallet && !isExchangeFlow) {
|
if (hasActiveWallet && !isExchangeFlow) {
|
||||||
return e.coin == active[0].coin;
|
return e.coin == active[0].coin;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -53,15 +53,6 @@ class DesktopContactDetails extends ConsumerStatefulWidget {
|
||||||
class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
||||||
List<Tuple2<String, Transaction>> _cachedTransactions = [];
|
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(
|
Future<List<Tuple2<String, Transaction>>> _filteredTransactionsByContact(
|
||||||
List<Manager> managers,
|
List<Manager> managers,
|
||||||
) async {
|
) async {
|
||||||
|
@ -259,7 +250,9 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
for (int i = 0; i < contact.addresses.length; i++)
|
for (int i = 0;
|
||||||
|
i < contact.addressesSorted.length;
|
||||||
|
i++)
|
||||||
Column(
|
Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
@ -273,7 +266,7 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(18),
|
padding: const EdgeInsets.all(18),
|
||||||
child: DesktopAddressCard(
|
child: DesktopAddressCard(
|
||||||
entry: contact.addresses[i],
|
entry: contact.addressesSorted[i],
|
||||||
contactId: contact.customId,
|
contactId: contact.customId,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -69,8 +69,8 @@ class _AddressBookAddressChooserState extends State<AddressBookAddressChooser> {
|
||||||
|
|
||||||
List<ContactEntry> filter(List<ContactEntry> contacts, String searchTerm) {
|
List<ContactEntry> filter(List<ContactEntry> contacts, String searchTerm) {
|
||||||
if (widget.coin != null) {
|
if (widget.coin != null) {
|
||||||
contacts.removeWhere(
|
contacts.removeWhere((e) =>
|
||||||
(e) => e.addresses.where((a) => a.coin == widget.coin!).isEmpty);
|
e.addressesSorted.where((a) => a.coin == widget.coin!).isEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
contacts.retainWhere((e) => _matches(searchTerm, e));
|
contacts.retainWhere((e) => _matches(searchTerm, e));
|
||||||
|
|
|
@ -78,7 +78,7 @@ class _ContactListItemState extends ConsumerState<ContactListItem> {
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
// filter addresses by coin is provided before building address list
|
// filter addresses by coin is provided before building address list
|
||||||
...contact.addresses
|
...contact.addressesSorted
|
||||||
.where((e) =>
|
.where((e) =>
|
||||||
filterByCoin != null ? e.coin == filterByCoin! : true)
|
filterByCoin != null ? e.coin == filterByCoin! : true)
|
||||||
.map(
|
.map(
|
||||||
|
|
|
@ -70,9 +70,10 @@ class _AddressBookCardState extends ConsumerState<AddressBookCard> {
|
||||||
final contact = _contact!;
|
final contact = _contact!;
|
||||||
|
|
||||||
final List<Coin> coins = [];
|
final List<Coin> coins = [];
|
||||||
for (var element in contact.addresses) {
|
|
||||||
if (!coins.contains(element.coin)) {
|
for (final coin in Coin.values) {
|
||||||
coins.add(element.coin);
|
if (contact.addresses.where((e) => e.coin == coin).isNotEmpty) {
|
||||||
|
coins.add(coin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue