2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-01 15:29:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:isar/isar.dart';
|
2024-05-27 23:56:22 +00:00
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../../db/isar/main_db.dart';
|
|
|
|
import '../../../models/isar/models/isar_models.dart';
|
|
|
|
import '../../../themes/stack_colors.dart';
|
|
|
|
import '../../../utilities/text_styles.dart';
|
|
|
|
import '../../../utilities/util.dart';
|
|
|
|
import '../../../wallets/isar/providers/wallet_info_provider.dart';
|
|
|
|
import '../../../widgets/background.dart';
|
|
|
|
import '../../../widgets/conditional_parent.dart';
|
|
|
|
import '../../../widgets/custom_buttons/app_bar_icon_button.dart';
|
|
|
|
import '../../../widgets/loading_indicator.dart';
|
2024-05-27 23:56:22 +00:00
|
|
|
import 'address_card.dart';
|
|
|
|
import 'address_details_view.dart';
|
2023-03-21 23:18:07 +00:00
|
|
|
|
2023-03-06 21:09:32 +00:00
|
|
|
class WalletAddressesView extends ConsumerStatefulWidget {
|
|
|
|
const WalletAddressesView({
|
2024-05-27 23:56:22 +00:00
|
|
|
super.key,
|
2023-02-01 15:29:51 +00:00
|
|
|
required this.walletId,
|
2024-05-27 23:56:22 +00:00
|
|
|
});
|
2023-02-01 15:29:51 +00:00
|
|
|
|
2023-03-06 21:09:32 +00:00
|
|
|
static const String routeName = "/walletAddressesView";
|
2023-02-01 15:29:51 +00:00
|
|
|
|
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
@override
|
2023-03-06 21:09:32 +00:00
|
|
|
ConsumerState<WalletAddressesView> createState() =>
|
|
|
|
_WalletAddressesViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WalletAddressesViewState extends ConsumerState<WalletAddressesView> {
|
|
|
|
final bool isDesktop = Util.isDesktop;
|
|
|
|
|
2024-04-24 23:17:29 +00:00
|
|
|
final String _searchString = "";
|
2023-03-21 23:18:07 +00:00
|
|
|
|
2024-04-24 23:17:29 +00:00
|
|
|
// late final TextEditingController _searchController;
|
|
|
|
// final searchFieldFocusNode = FocusNode();
|
2023-03-21 23:18:07 +00:00
|
|
|
|
|
|
|
Future<List<int>> _search(String term) async {
|
|
|
|
if (term.isEmpty) {
|
|
|
|
return MainDB.instance
|
|
|
|
.getAddresses(widget.walletId)
|
|
|
|
.filter()
|
2024-05-27 23:56:22 +00:00
|
|
|
.group(
|
|
|
|
(q) => q
|
|
|
|
.subTypeEqualTo(AddressSubType.change)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.receiving)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.paynymReceive)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.paynymNotification),
|
|
|
|
)
|
2023-03-21 23:18:07 +00:00
|
|
|
.and()
|
|
|
|
.not()
|
|
|
|
.typeEqualTo(AddressType.nonWallet)
|
|
|
|
.sortByDerivationIndex()
|
|
|
|
.idProperty()
|
|
|
|
.findAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
final labels = await MainDB.instance
|
|
|
|
.getAddressLabels(widget.walletId)
|
|
|
|
.filter()
|
|
|
|
.group(
|
|
|
|
(q) => q
|
|
|
|
.valueContains(term, caseSensitive: false)
|
|
|
|
.or()
|
|
|
|
.addressStringContains(term, caseSensitive: false)
|
|
|
|
.or()
|
|
|
|
.group(
|
|
|
|
(q) => q
|
|
|
|
.tagsIsNotNull()
|
|
|
|
.and()
|
|
|
|
.tagsElementContains(term, caseSensitive: false),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.findAll();
|
|
|
|
|
|
|
|
if (labels.isEmpty) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return MainDB.instance
|
|
|
|
.getAddresses(widget.walletId)
|
|
|
|
.filter()
|
|
|
|
.anyOf<AddressLabel, Address>(
|
2024-05-27 23:56:22 +00:00
|
|
|
labels,
|
|
|
|
(q, e) => q.valueEqualTo(e.addressString),
|
|
|
|
)
|
|
|
|
.group(
|
|
|
|
(q) => q
|
|
|
|
.subTypeEqualTo(AddressSubType.change)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.receiving)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.paynymReceive)
|
|
|
|
.or()
|
|
|
|
.subTypeEqualTo(AddressSubType.paynymNotification),
|
|
|
|
)
|
2023-03-21 23:18:07 +00:00
|
|
|
.and()
|
|
|
|
.not()
|
|
|
|
.typeEqualTo(AddressType.nonWallet)
|
|
|
|
.sortByDerivationIndex()
|
|
|
|
.idProperty()
|
|
|
|
.findAll();
|
|
|
|
}
|
|
|
|
|
2024-04-24 23:17:29 +00:00
|
|
|
// @override
|
|
|
|
// void initState() {
|
|
|
|
// _searchController = TextEditingController();
|
|
|
|
//
|
|
|
|
// super.initState();
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @override
|
|
|
|
// void dispose() {
|
|
|
|
// _searchController.dispose();
|
|
|
|
// searchFieldFocusNode.dispose();
|
|
|
|
// super.dispose();
|
|
|
|
// }
|
2023-03-06 21:09:32 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-11-03 19:46:55 +00:00
|
|
|
final coin = ref.watch(pWalletCoin(widget.walletId));
|
|
|
|
|
2023-02-01 15:29:51 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
builder: (child) => Background(
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.backgroundAppBar,
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
2023-03-06 21:09:32 +00:00
|
|
|
titleSpacing: 0,
|
2023-02-01 15:29:51 +00:00
|
|
|
title: Text(
|
2023-03-06 21:09:32 +00:00
|
|
|
"Wallet addresses",
|
2023-02-01 15:29:51 +00:00
|
|
|
style: STextStyles.navBarTitle(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-03-06 21:09:32 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
2024-04-24 23:17:29 +00:00
|
|
|
// SizedBox(
|
|
|
|
// width: isDesktop ? 490 : null,
|
|
|
|
// child: ClipRRect(
|
|
|
|
// borderRadius: BorderRadius.circular(
|
|
|
|
// Constants.size.circularBorderRadius,
|
|
|
|
// ),
|
|
|
|
// child: TextField(
|
|
|
|
// autocorrect: !isDesktop,
|
|
|
|
// enableSuggestions: !isDesktop,
|
|
|
|
// controller: _searchController,
|
|
|
|
// focusNode: searchFieldFocusNode,
|
|
|
|
// onChanged: (value) {
|
|
|
|
// setState(() {
|
|
|
|
// _searchString = value;
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// style: isDesktop
|
|
|
|
// ? STextStyles.desktopTextExtraSmall(context).copyWith(
|
|
|
|
// color: Theme.of(context)
|
|
|
|
// .extension<StackColors>()!
|
|
|
|
// .textFieldActiveText,
|
|
|
|
// height: 1.8,
|
|
|
|
// )
|
|
|
|
// : STextStyles.field(context),
|
|
|
|
// decoration: standardInputDecoration(
|
|
|
|
// "Search...",
|
|
|
|
// searchFieldFocusNode,
|
|
|
|
// context,
|
|
|
|
// desktopMed: isDesktop,
|
|
|
|
// ).copyWith(
|
|
|
|
// prefixIcon: Padding(
|
|
|
|
// padding: EdgeInsets.symmetric(
|
|
|
|
// horizontal: isDesktop ? 12 : 10,
|
|
|
|
// vertical: isDesktop ? 18 : 16,
|
|
|
|
// ),
|
|
|
|
// child: SvgPicture.asset(
|
|
|
|
// Assets.svg.search,
|
|
|
|
// width: isDesktop ? 20 : 16,
|
|
|
|
// height: isDesktop ? 20 : 16,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// suffixIcon: _searchController.text.isNotEmpty
|
|
|
|
// ? Padding(
|
|
|
|
// padding: const EdgeInsets.only(right: 0),
|
|
|
|
// child: UnconstrainedBox(
|
|
|
|
// child: Row(
|
|
|
|
// children: [
|
|
|
|
// TextFieldIconButton(
|
|
|
|
// child: const XIcon(),
|
|
|
|
// onTap: () async {
|
|
|
|
// setState(() {
|
|
|
|
// _searchController.text = "";
|
|
|
|
// _searchString = "";
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// )
|
|
|
|
// : null,
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// SizedBox(
|
|
|
|
// height: isDesktop ? 20 : 16,
|
|
|
|
// ),
|
2023-03-06 21:09:32 +00:00
|
|
|
Expanded(
|
|
|
|
child: FutureBuilder(
|
2023-03-21 23:18:07 +00:00
|
|
|
future: _search(_searchString),
|
2023-03-07 13:48:25 +00:00
|
|
|
builder: (context, AsyncSnapshot<List<int>> snapshot) {
|
2023-03-06 21:09:32 +00:00
|
|
|
if (snapshot.connectionState == ConnectionState.done &&
|
|
|
|
snapshot.data != null) {
|
|
|
|
// listview
|
|
|
|
return ListView.separated(
|
|
|
|
itemCount: snapshot.data!.length,
|
|
|
|
separatorBuilder: (_, __) => Container(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
itemBuilder: (_, index) => AddressCard(
|
|
|
|
walletId: widget.walletId,
|
2023-03-07 13:48:25 +00:00
|
|
|
addressId: snapshot.data![index],
|
2023-03-06 21:09:32 +00:00
|
|
|
coin: coin,
|
2024-04-24 23:17:29 +00:00
|
|
|
onPressed: !isDesktop
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
AddressDetailsView.routeName,
|
|
|
|
arguments: Tuple2(
|
|
|
|
snapshot.data![index],
|
|
|
|
widget.walletId,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-03-06 21:09:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Center(
|
|
|
|
child: LoadingIndicator(
|
|
|
|
height: 200,
|
|
|
|
width: 200,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2023-02-01 15:29:51 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|