mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +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/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:stackwallet/models/contact.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stackwallet/models/paymint/transactions_model.dart';
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/notifications/show_flush_bar.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/add_new_contact_address_view.dart';
|
||||||
import 'package:stackwallet/pages/address_book_views/subviews/edit_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/assets.dart';
|
||||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.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/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
|
@ -50,15 +49,6 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
||||||
|
|
||||||
List<Tuple2<String, Transaction>> _cachedTransactions = [];
|
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(
|
Future<List<Tuple2<String, Transaction>>> _filteredTransactionsByContact(
|
||||||
List<Manager> managers,
|
List<Manager> managers,
|
||||||
) async {
|
) async {
|
||||||
|
@ -69,18 +59,17 @@ class _ContactDetailsViewState extends ConsumerState<ContactDetailsView> {
|
||||||
|
|
||||||
List<Tuple2<String, Transaction>> result = [];
|
List<Tuple2<String, Transaction>> result = [];
|
||||||
for (final manager in managers) {
|
for (final manager in managers) {
|
||||||
final transactions = (await manager.transactionData)
|
final transactions = await manager.db.transactions
|
||||||
.getAllTransactions()
|
.filter()
|
||||||
.values
|
.anyOf(contact.addresses.map((e) => e.address),
|
||||||
.toList()
|
(q, String e) => q.addressEqualTo(e))
|
||||||
.where((e) => _contactHasAddress(e.address, contact));
|
.sortByTimestampDesc()
|
||||||
|
.findAll();
|
||||||
|
|
||||||
for (final tx in transactions) {
|
for (final tx in transactions) {
|
||||||
result.add(Tuple2(manager.walletId, tx));
|
result.add(Tuple2(manager.walletId, tx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sort by date
|
|
||||||
result.sort((a, b) => b.item2.timestamp - a.item2.timestamp);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue