look up v2 txns by address

This commit is contained in:
julian 2023-10-23 16:20:42 -06:00
parent 9ac429c6cd
commit bb0511d468

View file

@ -13,13 +13,19 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart'; import 'package:isar/isar.dart';
import 'package:qr_flutter/qr_flutter.dart'; import 'package:qr_flutter/qr_flutter.dart';
import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/db/isar/main_db.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/v2/input_v2.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/v2/output_v2.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart'; import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/pages/receive_view/addresses/address_tag.dart'; import 'package:stackwallet/pages/receive_view/addresses/address_tag.dart';
import 'package:stackwallet/pages/wallet_view/sub_widgets/no_transactions_found.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/no_transactions_found.dart';
import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart'; import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart';
import 'package:stackwallet/pages/wallet_view/transaction_views/tx_v2/transaction_v2_card.dart';
import 'package:stackwallet/providers/db/main_db_provider.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/address_utils.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/background.dart';
@ -145,6 +151,8 @@ class _AddressDetailsViewState extends ConsumerState<AddressDetailsView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final coin = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId).coin));
return ConditionalParent( return ConditionalParent(
condition: !isDesktop, condition: !isDesktop,
builder: (child) => Background( builder: (child) => Background(
@ -258,10 +266,16 @@ class _AddressDetailsViewState extends ConsumerState<AddressDetailsView> {
borderColor: Theme.of(context) borderColor: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.backgroundAppBar, .backgroundAppBar,
child: _AddressDetailsTxList( child: coin == Coin.bitcoincash ||
walletId: widget.walletId, coin == Coin.bitcoincashTestnet
address: address, ? _AddressDetailsTxV2List(
), walletId: widget.walletId,
address: address,
)
: _AddressDetailsTxList(
walletId: widget.walletId,
address: address,
),
), ),
], ],
), ),
@ -377,10 +391,15 @@ class _AddressDetailsViewState extends ConsumerState<AddressDetailsView> {
height: 12, height: 12,
), ),
if (!isDesktop) if (!isDesktop)
_AddressDetailsTxList( coin == Coin.bitcoincash || coin == Coin.bitcoincashTestnet
walletId: widget.walletId, ? _AddressDetailsTxV2List(
address: address, walletId: widget.walletId,
), address: address,
)
: _AddressDetailsTxList(
walletId: widget.walletId,
address: address,
),
], ],
), ),
); );
@ -445,6 +464,66 @@ class _AddressDetailsTxList extends StatelessWidget {
} }
} }
class _AddressDetailsTxV2List extends ConsumerWidget {
const _AddressDetailsTxV2List({
Key? key,
required this.walletId,
required this.address,
}) : super(key: key);
final String walletId;
final Address address;
@override
Widget build(BuildContext context, WidgetRef ref) {
final query = ref
.watch(mainDBProvider)
.isar
.transactionV2s
.where()
.walletIdEqualTo(walletId)
.filter()
.inputsElement((q) => q.addressesElementContains(address.value))
.or()
.outputsElement((q) => q.addressesElementContains(address.value))
.sortByTimestampDesc();
final count = query.countSync();
if (count > 0) {
if (Util.isDesktop) {
final txns = query.findAllSync();
return ListView.separated(
shrinkWrap: true,
primary: false,
itemBuilder: (_, index) => TransactionCardV2(
transaction: txns[index],
),
separatorBuilder: (_, __) => const _Div(height: 1),
itemCount: count,
);
} else {
return RoundedWhiteContainer(
padding: EdgeInsets.zero,
child: Column(
mainAxisSize: MainAxisSize.min,
children: query
.findAllSync()
.map(
(e) => TransactionCardV2(
transaction: e,
),
)
.toList(),
),
);
}
} else {
return const NoTransActionsFound();
}
}
}
class _Div extends StatelessWidget { class _Div extends StatelessWidget {
const _Div({ const _Div({
Key? key, Key? key,