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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
2024-05-13 20:08:52 +00:00
|
|
|
import 'package:stackwallet/app_config.dart';
|
2024-05-10 16:09:30 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/blockchain_data/address.dart';
|
2023-05-15 20:12:06 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/pages/address_book_views/subviews/add_address_book_entry_view.dart';
|
|
|
|
import 'package:stackwallet/pages/address_book_views/subviews/address_book_filter_view.dart';
|
2024-05-10 16:09:30 +00:00
|
|
|
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
|
|
|
import 'package:stackwallet/providers/ui/address_book_providers/address_book_filter_provider.dart';
|
2024-05-15 21:20:45 +00:00
|
|
|
import 'package:stackwallet/supported_coins.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-11-14 23:00:09 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2024-05-15 21:20:45 +00:00
|
|
|
import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart';
|
|
|
|
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
|
2024-05-10 16:09:30 +00:00
|
|
|
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/address_book_card.dart';
|
2022-11-25 19:24:01 +00:00
|
|
|
import 'package:stackwallet/widgets/background.dart';
|
2022-11-14 23:00:09 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
import 'package:stackwallet/widgets/stack_text_field.dart';
|
|
|
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
|
|
|
|
|
|
|
class AddressBookView extends ConsumerStatefulWidget {
|
2022-11-17 13:22:53 +00:00
|
|
|
const AddressBookView({
|
2024-05-10 16:09:30 +00:00
|
|
|
super.key,
|
2022-11-17 13:22:53 +00:00
|
|
|
this.coin,
|
|
|
|
this.filterTerm,
|
2024-05-10 16:09:30 +00:00
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
static const String routeName = "/addressBook";
|
|
|
|
|
2024-05-15 21:20:45 +00:00
|
|
|
final CryptoCurrency? coin;
|
2022-11-17 13:22:53 +00:00
|
|
|
final String? filterTerm;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<AddressBookView> createState() => _AddressBookViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
|
|
|
late TextEditingController _searchController;
|
|
|
|
|
|
|
|
final _searchFocusNode = FocusNode();
|
|
|
|
|
|
|
|
String _searchTerm = "";
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_searchController = TextEditingController();
|
|
|
|
ref.refresh(addressBookFilterProvider);
|
|
|
|
|
|
|
|
if (widget.coin == null) {
|
2024-05-21 18:10:09 +00:00
|
|
|
final coins = [...Coins.cryptocurrencies];
|
2024-05-15 21:20:45 +00:00
|
|
|
coins.removeWhere(
|
|
|
|
(e) => e is Firo && e.network == CryptoCurrencyNetwork.test,
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2024-05-10 16:09:30 +00:00
|
|
|
final bool showTestNet =
|
|
|
|
ref.read(prefsChangeNotifierProvider).showTestNetCoins;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
if (showTestNet) {
|
|
|
|
ref.read(addressBookFilterProvider).addAll(coins, false);
|
|
|
|
} else {
|
2024-05-15 21:20:45 +00:00
|
|
|
ref.read(addressBookFilterProvider).addAll(
|
|
|
|
coins.where((e) => e.network != CryptoCurrencyNetwork.test),
|
|
|
|
false,
|
|
|
|
);
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ref.read(addressBookFilterProvider).add(widget.coin!, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
2024-05-10 16:09:30 +00:00
|
|
|
final List<ContactAddressEntry> addresses = [];
|
2023-11-03 19:46:55 +00:00
|
|
|
final wallets = ref.read(pWallets).wallets;
|
|
|
|
for (final wallet in wallets) {
|
2024-05-10 16:09:30 +00:00
|
|
|
final String addressString;
|
|
|
|
if (wallet is SparkInterface) {
|
|
|
|
Address? address = await wallet.getCurrentReceivingSparkAddress();
|
|
|
|
if (address == null) {
|
|
|
|
address = await wallet.generateNextSparkAddress();
|
|
|
|
await ref.read(mainDBProvider).updateOrPutAddresses([address]);
|
|
|
|
}
|
|
|
|
addressString = address.value;
|
|
|
|
} else {
|
|
|
|
final address = await wallet.getCurrentReceivingAddress();
|
|
|
|
addressString = address?.value ?? wallet.info.cachedReceivingAddress;
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
addresses.add(
|
2023-05-15 20:12:06 +00:00
|
|
|
ContactAddressEntry()
|
2024-05-15 21:20:45 +00:00
|
|
|
..coinName = wallet.info.coin.identifier
|
2024-05-10 16:09:30 +00:00
|
|
|
..address = addressString
|
2023-05-15 20:12:06 +00:00
|
|
|
..label = "Current Receiving"
|
2023-11-03 19:46:55 +00:00
|
|
|
..other = wallet.info.name,
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
}
|
2023-05-15 20:12:06 +00:00
|
|
|
final self = ContactEntry(
|
2024-05-13 19:44:19 +00:00
|
|
|
name: "My ${AppConfig.prefix}",
|
2022-08-26 08:11:35 +00:00
|
|
|
addresses: addresses,
|
|
|
|
isFavorite: true,
|
2023-05-15 20:12:06 +00:00
|
|
|
customId: "default",
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
await ref.read(addressBookServiceProvider).editContact(self);
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_searchController.dispose();
|
|
|
|
_searchFocusNode.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
2023-05-15 20:12:06 +00:00
|
|
|
final contacts =
|
|
|
|
ref.watch(addressBookServiceProvider.select((value) => value.contacts));
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-11-14 23:00:09 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
return ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
builder: (child) {
|
2022-11-25 19:24:01 +00:00
|
|
|
return Background(
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
title: Text(
|
|
|
|
"Address book",
|
|
|
|
style: STextStyles.navBarTitle(context),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 10,
|
|
|
|
bottom: 10,
|
|
|
|
right: 10,
|
|
|
|
),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: AppBarIconButton(
|
|
|
|
key: const Key("addressBookFilterViewButton"),
|
|
|
|
size: 36,
|
|
|
|
shadows: const [],
|
2022-11-14 23:00:09 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-25 19:24:01 +00:00
|
|
|
.background,
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.filter,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
AddressBookFilterView.routeName,
|
|
|
|
);
|
|
|
|
},
|
2022-11-14 23:00:09 +00:00
|
|
|
),
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-11-25 19:24:01 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 10,
|
|
|
|
bottom: 10,
|
|
|
|
right: 10,
|
|
|
|
),
|
|
|
|
child: AspectRatio(
|
|
|
|
aspectRatio: 1,
|
|
|
|
child: AppBarIconButton(
|
|
|
|
key: const Key("addressBookAddNewContactViewButton"),
|
|
|
|
size: 36,
|
|
|
|
shadows: const [],
|
2022-11-14 23:00:09 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-25 19:24:01 +00:00
|
|
|
.background,
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.plus,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pushNamed(
|
|
|
|
AddAddressBookEntryView.routeName,
|
|
|
|
);
|
|
|
|
},
|
2022-11-14 23:00:09 +00:00
|
|
|
),
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-11-25 19:24:01 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
body: LayoutBuilder(
|
|
|
|
builder: (builderContext, constraints) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 12,
|
|
|
|
top: 12,
|
|
|
|
right: 12,
|
|
|
|
),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: constraints.maxHeight - 24,
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight:
|
|
|
|
MediaQuery.of(context).size.height - 271,
|
|
|
|
),
|
|
|
|
child: child,
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-14 23:00:09 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-11-25 19:24:01 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-11-14 23:00:09 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2022-11-17 13:22:53 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
child: !isDesktop
|
|
|
|
? TextField(
|
|
|
|
autocorrect: Util.isDesktop ? false : true,
|
|
|
|
enableSuggestions: Util.isDesktop ? false : true,
|
|
|
|
controller: _searchController,
|
|
|
|
focusNode: _searchFocusNode,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_searchTerm = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
style: STextStyles.field(context),
|
|
|
|
decoration: standardInputDecoration(
|
|
|
|
"Search",
|
|
|
|
_searchFocusNode,
|
|
|
|
context,
|
|
|
|
).copyWith(
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 10,
|
|
|
|
vertical: 16,
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.search,
|
|
|
|
width: 16,
|
|
|
|
height: 16,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-11-14 23:00:09 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
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 = "";
|
2022-11-17 15:04:54 +00:00
|
|
|
_searchTerm = "";
|
2022-11-17 13:22:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
if (!isDesktop) const SizedBox(height: 16),
|
|
|
|
Text(
|
|
|
|
"Favorites",
|
|
|
|
style: STextStyles.smallMed12(context),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
if (contacts.isNotEmpty)
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
padding: EdgeInsets.all(!isDesktop ? 0 : 15),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
...contacts
|
2024-05-10 16:09:30 +00:00
|
|
|
.where(
|
|
|
|
(element) => element.addressesSorted
|
|
|
|
.where(
|
|
|
|
(e) => ref.watch(
|
|
|
|
addressBookFilterProvider.select(
|
|
|
|
(value) => value.coins.contains(e.coin),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.isNotEmpty,
|
|
|
|
)
|
|
|
|
.where(
|
|
|
|
(e) =>
|
|
|
|
e.isFavorite &&
|
|
|
|
ref
|
|
|
|
.read(addressBookServiceProvider)
|
|
|
|
.matches(widget.filterTerm ?? _searchTerm, e),
|
|
|
|
)
|
2022-11-17 13:22:53 +00:00
|
|
|
.where((element) => element.isFavorite)
|
|
|
|
.map(
|
|
|
|
(e) => AddressBookCard(
|
2023-05-15 20:12:06 +00:00
|
|
|
key: Key("favContactCard_${e.customId}_key"),
|
|
|
|
contactId: e.customId,
|
2022-11-15 03:55:11 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
],
|
2022-11-17 13:10:28 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
if (contacts.isEmpty)
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
"Your favorite contacts will appear here",
|
|
|
|
style: STextStyles.itemSubtitle(context),
|
2022-11-17 13:10:28 +00:00
|
|
|
),
|
2022-11-17 13:02:56 +00:00
|
|
|
),
|
2022-11-15 03:55:11 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 16,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"All contacts",
|
|
|
|
style: STextStyles.smallMed12(context),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
|
|
|
if (contacts.isNotEmpty)
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
padding: EdgeInsets.all(!isDesktop ? 0 : 15),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
...contacts
|
2024-05-10 16:09:30 +00:00
|
|
|
.where(
|
|
|
|
(element) => element.addressesSorted
|
|
|
|
.where(
|
|
|
|
(e) => ref.watch(
|
|
|
|
addressBookFilterProvider.select(
|
|
|
|
(value) => value.coins.contains(e.coin),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.isNotEmpty,
|
|
|
|
)
|
|
|
|
.where(
|
|
|
|
(e) => ref
|
|
|
|
.read(addressBookServiceProvider)
|
|
|
|
.matches(widget.filterTerm ?? _searchTerm, e),
|
|
|
|
)
|
2022-11-17 13:22:53 +00:00
|
|
|
.map(
|
|
|
|
(e) => AddressBookCard(
|
2023-05-15 20:12:06 +00:00
|
|
|
key:
|
|
|
|
Key("desktopContactCard_${e.customId}_key"),
|
|
|
|
contactId: e.customId,
|
2022-11-17 13:02:56 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
],
|
2022-11-17 13:02:56 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (contacts.isEmpty)
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
"Your contacts will appear here",
|
|
|
|
style: STextStyles.itemSubtitle(context),
|
2022-11-17 13:02:56 +00:00
|
|
|
),
|
2022-11-17 13:10:28 +00:00
|
|
|
),
|
2022-11-17 13:22:53 +00:00
|
|
|
),
|
|
|
|
],
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|