mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
use isar query to fetch contact transactions
This commit is contained in:
parent
a73e18df75
commit
eb915a0927
1 changed files with 8 additions and 19 deletions
|
@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/models/contact.dart';
|
||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/address_book_views/subviews/add_new_contact_address_view.dart';
|
||||
import 'package:stackwallet/pages/address_book_views/subviews/edit_contact_address_view.dart';
|
||||
|
@ -15,7 +15,6 @@ import 'package:stackwallet/services/coins/manager.dart';
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/widgets/background.dart';
|
||||
|
@ -50,15 +49,6 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
|||
|
||||
List<Tuple2<String, Transaction>> _cachedTransactions = [];
|
||||
|
||||
bool _contactHasAddress(String address, Contact 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 {
|
||||
|
@ -69,18 +59,17 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
|||
|
||||
List<Tuple2<String, Transaction>> result = [];
|
||||
for (final manager in managers) {
|
||||
final transactions = (await manager.transactionData)
|
||||
.getAllTransactions()
|
||||
.values
|
||||
.toList()
|
||||
.where((e) => _contactHasAddress(e.address, contact));
|
||||
final transactions = await manager.db.transactions
|
||||
.filter()
|
||||
.anyOf(contact.addresses.map((e) => e.address),
|
||||
(q, String e) => q.addressEqualTo(e))
|
||||
.sortByTimestampDesc()
|
||||
.findAll();
|
||||
|
||||
for (final tx in transactions) {
|
||||
result.add(Tuple2(manager.walletId, tx));
|
||||
}
|
||||
}
|
||||
// sort by date
|
||||
result.sort((a, b) => b.item2.timestamp - a.item2.timestamp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue