mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-11 13:14:32 +00:00
show current spark address as my stack contact address for firo wallets
This commit is contained in:
parent
ecadefef63
commit
cb70b5c92f
2 changed files with 115 additions and 47 deletions
lib
pages/address_book_views
pages_desktop_specific/address_book_view
|
@ -11,9 +11,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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/isar/models/blockchain_data/address.dart';
|
||||||
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
||||||
import 'package:stackwallet/pages/address_book_views/subviews/add_address_book_entry_view.dart';
|
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';
|
import 'package:stackwallet/pages/address_book_views/subviews/address_book_filter_view.dart';
|
||||||
|
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/providers/ui/address_book_providers/address_book_filter_provider.dart';
|
import 'package:stackwallet/providers/ui/address_book_providers/address_book_filter_provider.dart';
|
||||||
|
@ -23,6 +25,7 @@ import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.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/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||||
import 'package:stackwallet/widgets/address_book_card.dart';
|
import 'package:stackwallet/widgets/address_book_card.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||||
|
@ -34,10 +37,10 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||||
|
|
||||||
class AddressBookView extends ConsumerStatefulWidget {
|
class AddressBookView extends ConsumerStatefulWidget {
|
||||||
const AddressBookView({
|
const AddressBookView({
|
||||||
Key? key,
|
super.key,
|
||||||
this.coin,
|
this.coin,
|
||||||
this.filterTerm,
|
this.filterTerm,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
static const String routeName = "/addressBook";
|
static const String routeName = "/addressBook";
|
||||||
|
|
||||||
|
@ -61,10 +64,11 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
ref.refresh(addressBookFilterProvider);
|
ref.refresh(addressBookFilterProvider);
|
||||||
|
|
||||||
if (widget.coin == null) {
|
if (widget.coin == null) {
|
||||||
List<Coin> coins = Coin.values.toList();
|
final List<Coin> coins = Coin.values.toList();
|
||||||
coins.remove(Coin.firoTestNet);
|
coins.remove(Coin.firoTestNet);
|
||||||
|
|
||||||
bool showTestNet = ref.read(prefsChangeNotifierProvider).showTestNetCoins;
|
final bool showTestNet =
|
||||||
|
ref.read(prefsChangeNotifierProvider).showTestNetCoins;
|
||||||
|
|
||||||
if (showTestNet) {
|
if (showTestNet) {
|
||||||
ref.read(addressBookFilterProvider).addAll(coins, false);
|
ref.read(addressBookFilterProvider).addAll(coins, false);
|
||||||
|
@ -78,13 +82,26 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
List<ContactAddressEntry> addresses = [];
|
final List<ContactAddressEntry> addresses = [];
|
||||||
final wallets = ref.read(pWallets).wallets;
|
final wallets = ref.read(pWallets).wallets;
|
||||||
for (final wallet in wallets) {
|
for (final wallet in wallets) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
addresses.add(
|
addresses.add(
|
||||||
ContactAddressEntry()
|
ContactAddressEntry()
|
||||||
..coinName = wallet.info.coin.name
|
..coinName = wallet.info.coin.name
|
||||||
..address = (await wallet.getCurrentReceivingAddress())!.value
|
..address = addressString
|
||||||
..label = "Current Receiving"
|
..label = "Current Receiving"
|
||||||
..other = wallet.info.name,
|
..other = wallet.info.name,
|
||||||
);
|
);
|
||||||
|
@ -302,15 +319,24 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
...contacts
|
...contacts
|
||||||
.where((element) => element.addressesSorted
|
.where(
|
||||||
.where((e) => ref.watch(addressBookFilterProvider
|
(element) => element.addressesSorted
|
||||||
.select((value) => value.coins.contains(e.coin))))
|
.where(
|
||||||
.isNotEmpty)
|
(e) => ref.watch(
|
||||||
.where((e) =>
|
addressBookFilterProvider.select(
|
||||||
e.isFavorite &&
|
(value) => value.coins.contains(e.coin),
|
||||||
ref
|
),
|
||||||
.read(addressBookServiceProvider)
|
),
|
||||||
.matches(widget.filterTerm ?? _searchTerm, e))
|
)
|
||||||
|
.isNotEmpty,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(e) =>
|
||||||
|
e.isFavorite &&
|
||||||
|
ref
|
||||||
|
.read(addressBookServiceProvider)
|
||||||
|
.matches(widget.filterTerm ?? _searchTerm, e),
|
||||||
|
)
|
||||||
.where((element) => element.isFavorite)
|
.where((element) => element.isFavorite)
|
||||||
.map(
|
.map(
|
||||||
(e) => AddressBookCard(
|
(e) => AddressBookCard(
|
||||||
|
@ -350,14 +376,22 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
...contacts
|
...contacts
|
||||||
.where((element) => element.addressesSorted
|
.where(
|
||||||
.where((e) => ref.watch(
|
(element) => element.addressesSorted
|
||||||
addressBookFilterProvider.select((value) =>
|
.where(
|
||||||
value.coins.contains(e.coin))))
|
(e) => ref.watch(
|
||||||
.isNotEmpty)
|
addressBookFilterProvider.select(
|
||||||
.where((e) => ref
|
(value) => value.coins.contains(e.coin),
|
||||||
.read(addressBookServiceProvider)
|
),
|
||||||
.matches(widget.filterTerm ?? _searchTerm, e))
|
),
|
||||||
|
)
|
||||||
|
.isNotEmpty,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(e) => ref
|
||||||
|
.read(addressBookServiceProvider)
|
||||||
|
.matches(widget.filterTerm ?? _searchTerm, e),
|
||||||
|
)
|
||||||
.map(
|
.map(
|
||||||
(e) => AddressBookCard(
|
(e) => AddressBookCard(
|
||||||
key:
|
key:
|
||||||
|
|
|
@ -11,11 +11,13 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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/isar/models/blockchain_data/address.dart';
|
||||||
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
||||||
import 'package:stackwallet/pages/address_book_views/subviews/add_address_book_entry_view.dart';
|
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';
|
import 'package:stackwallet/pages/address_book_views/subviews/address_book_filter_view.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_address_book_scaffold.dart';
|
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_address_book_scaffold.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart';
|
import 'package:stackwallet/pages_desktop_specific/address_book_view/subwidgets/desktop_contact_details.dart';
|
||||||
|
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||||
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/providers/ui/address_book_providers/address_book_filter_provider.dart';
|
import 'package:stackwallet/providers/ui/address_book_providers/address_book_filter_provider.dart';
|
||||||
|
@ -25,6 +27,7 @@ import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.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/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart';
|
||||||
import 'package:stackwallet/widgets/address_book_card.dart';
|
import 'package:stackwallet/widgets/address_book_card.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
|
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
|
||||||
|
@ -38,7 +41,7 @@ import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||||
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||||
|
|
||||||
class DesktopAddressBook extends ConsumerStatefulWidget {
|
class DesktopAddressBook extends ConsumerStatefulWidget {
|
||||||
const DesktopAddressBook({Key? key}) : super(key: key);
|
const DesktopAddressBook({super.key});
|
||||||
|
|
||||||
static const String routeName = "/desktopAddressBook";
|
static const String routeName = "/desktopAddressBook";
|
||||||
|
|
||||||
|
@ -93,10 +96,11 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
ref.refresh(addressBookFilterProvider);
|
ref.refresh(addressBookFilterProvider);
|
||||||
|
|
||||||
// if (widget.coin == null) {
|
// if (widget.coin == null) {
|
||||||
List<Coin> coins = Coin.values.toList();
|
final List<Coin> coins = Coin.values.toList();
|
||||||
coins.remove(Coin.firoTestNet);
|
coins.remove(Coin.firoTestNet);
|
||||||
|
|
||||||
bool showTestNet = ref.read(prefsChangeNotifierProvider).showTestNetCoins;
|
final bool showTestNet =
|
||||||
|
ref.read(prefsChangeNotifierProvider).showTestNetCoins;
|
||||||
|
|
||||||
if (showTestNet) {
|
if (showTestNet) {
|
||||||
ref.read(addressBookFilterProvider).addAll(coins, false);
|
ref.read(addressBookFilterProvider).addAll(coins, false);
|
||||||
|
@ -110,13 +114,26 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
List<ContactAddressEntry> addresses = [];
|
final List<ContactAddressEntry> addresses = [];
|
||||||
final wallets = ref.read(pWallets).wallets;
|
final wallets = ref.read(pWallets).wallets;
|
||||||
for (final wallet in wallets) {
|
for (final wallet in wallets) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
addresses.add(
|
addresses.add(
|
||||||
ContactAddressEntry()
|
ContactAddressEntry()
|
||||||
..coinName = wallet.info.coin.name
|
..coinName = wallet.info.coin.name
|
||||||
..address = wallet.info.cachedReceivingAddress
|
..address = addressString
|
||||||
..label = "Current Receiving"
|
..label = "Current Receiving"
|
||||||
..other = wallet.info.name,
|
..other = wallet.info.name,
|
||||||
);
|
);
|
||||||
|
@ -148,26 +165,41 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
ref.watch(addressBookServiceProvider.select((value) => value.contacts));
|
ref.watch(addressBookServiceProvider.select((value) => value.contacts));
|
||||||
|
|
||||||
final allContacts = contacts
|
final allContacts = contacts
|
||||||
.where((element) =>
|
|
||||||
element.addresses.isEmpty ||
|
|
||||||
element.addresses
|
|
||||||
.where((e) => ref.watch(addressBookFilterProvider
|
|
||||||
.select((value) => value.coins.contains(e.coin))))
|
|
||||||
.isNotEmpty)
|
|
||||||
.where(
|
.where(
|
||||||
(e) => ref.read(addressBookServiceProvider).matches(_searchTerm, e))
|
(element) =>
|
||||||
|
element.addresses.isEmpty ||
|
||||||
|
element.addresses
|
||||||
|
.where(
|
||||||
|
(e) => ref.watch(
|
||||||
|
addressBookFilterProvider
|
||||||
|
.select((value) => value.coins.contains(e.coin)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.isNotEmpty,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(e) => ref.read(addressBookServiceProvider).matches(_searchTerm, e),
|
||||||
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
final favorites = contacts
|
final favorites = contacts
|
||||||
.where((element) =>
|
.where(
|
||||||
element.addresses.isEmpty ||
|
(element) =>
|
||||||
element.addresses
|
element.addresses.isEmpty ||
|
||||||
.where((e) => ref.watch(addressBookFilterProvider
|
element.addresses
|
||||||
.select((value) => value.coins.contains(e.coin))))
|
.where(
|
||||||
.isNotEmpty)
|
(e) => ref.watch(
|
||||||
.where((e) =>
|
addressBookFilterProvider
|
||||||
e.isFavorite &&
|
.select((value) => value.coins.contains(e.coin)),
|
||||||
ref.read(addressBookServiceProvider).matches(_searchTerm, e))
|
),
|
||||||
|
)
|
||||||
|
.isNotEmpty,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(e) =>
|
||||||
|
e.isFavorite &&
|
||||||
|
ref.read(addressBookServiceProvider).matches(_searchTerm, e),
|
||||||
|
)
|
||||||
.where((element) => element.isFavorite)
|
.where((element) => element.isFavorite)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
@ -182,7 +214,7 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
Text(
|
Text(
|
||||||
"Address Book",
|
"Address Book",
|
||||||
style: STextStyles.desktopH3(context),
|
style: STextStyles.desktopH3(context),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -354,7 +386,8 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
),
|
),
|
||||||
child: AddressBookCard(
|
child: AddressBookCard(
|
||||||
key: Key(
|
key: Key(
|
||||||
"favContactCard_${favorites[i].customId}_key"),
|
"favContactCard_${favorites[i].customId}_key",
|
||||||
|
),
|
||||||
contactId: favorites[i].customId,
|
contactId: favorites[i].customId,
|
||||||
desktopSendFrom: false,
|
desktopSendFrom: false,
|
||||||
),
|
),
|
||||||
|
@ -426,7 +459,8 @@ class _DesktopAddressBook extends ConsumerState<DesktopAddressBook> {
|
||||||
),
|
),
|
||||||
child: AddressBookCard(
|
child: AddressBookCard(
|
||||||
key: Key(
|
key: Key(
|
||||||
"favContactCard_${allContacts[i].customId}_key"),
|
"favContactCard_${allContacts[i].customId}_key",
|
||||||
|
),
|
||||||
contactId: allContacts[i].customId,
|
contactId: allContacts[i].customId,
|
||||||
desktopSendFrom: false,
|
desktopSendFrom: false,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue