show receiving and change addresses

This commit is contained in:
julian 2023-03-06 15:09:32 -06:00
parent c70a8f415c
commit 5f4e8a6e58
4 changed files with 104 additions and 52 deletions

View file

@ -53,6 +53,10 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
.addressStringWalletIdEqualTo(utxo.address!, widget.walletId) .addressStringWalletIdEqualTo(utxo.address!, widget.walletId)
.findFirstSync() .findFirstSync()
?.value; ?.value;
if (label != null && label.isEmpty) {
label = null;
}
} }
return RoundedWhiteContainer( return RoundedWhiteContainer(

View file

@ -5,32 +5,40 @@ import 'package:stackwallet/db/main_db.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_card.dart'; import 'package:stackwallet/pages/receive_view/addresses/address_card.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart'; import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/constants.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/utilities/util.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';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/loading_indicator.dart'; import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/toggle.dart';
class ReceivingAddressesView extends ConsumerWidget { class WalletAddressesView extends ConsumerStatefulWidget {
const ReceivingAddressesView({ const WalletAddressesView({
Key? key, Key? key,
required this.walletId, required this.walletId,
required this.isDesktop,
this.clipboard = const ClipboardWrapper(),
}) : super(key: key); }) : super(key: key);
static const String routeName = "/receivingAddressesView"; static const String routeName = "/walletAddressesView";
final String walletId; final String walletId;
final bool isDesktop;
final ClipboardInterface clipboard;
@override @override
Widget build(BuildContext context, WidgetRef ref) { ConsumerState<WalletAddressesView> createState() =>
_WalletAddressesViewState();
}
class _WalletAddressesViewState extends ConsumerState<WalletAddressesView> {
final bool isDesktop = Util.isDesktop;
bool _showChange = false;
@override
Widget build(BuildContext context) {
final coin = ref.watch(walletsChangeNotifierProvider final coin = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(walletId).coin)); .select((value) => value.getManager(widget.walletId).coin));
return ConditionalParent( return ConditionalParent(
condition: !isDesktop, condition: !isDesktop,
builder: (child) => Background( builder: (child) => Background(
@ -45,8 +53,9 @@ class ReceivingAddressesView extends ConsumerWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
titleSpacing: 0,
title: Text( title: Text(
"Receiving addresses", "Wallet addresses",
style: STextStyles.navBarTitle(context), style: STextStyles.navBarTitle(context),
), ),
), ),
@ -56,40 +65,81 @@ class ReceivingAddressesView extends ConsumerWidget {
), ),
), ),
), ),
child: FutureBuilder( child: Column(
future: MainDB.instance children: [
.getAddresses(walletId) SizedBox(
.filter() height: isDesktop ? 56 : 48,
.subTypeEqualTo(AddressSubType.receiving) width: isDesktop ? 490 : null,
.and() child: Toggle(
.not() key: UniqueKey(),
.typeEqualTo(AddressType.nonWallet) onColor: Theme.of(context).extension<StackColors>()!.popupBG,
.sortByDerivationIndex() onText: "Receiving",
.findAll(), offColor: Theme.of(context)
builder: (context, AsyncSnapshot<List<Address>> snapshot) { .extension<StackColors>()!
if (snapshot.connectionState == ConnectionState.done && .textFieldDefaultBG,
snapshot.data != null) { offText: "Change",
// listview isOn: _showChange,
return ListView.separated( onValueChanged: (value) {
itemCount: snapshot.data!.length, setState(() {
separatorBuilder: (_, __) => Container( _showChange = value;
height: 10, });
},
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
), ),
itemBuilder: (_, index) => AddressCard( ),
walletId: walletId, ),
address: snapshot.data![index], SizedBox(
coin: coin, height: isDesktop ? 20 : 16,
), ),
); Expanded(
} else { child: FutureBuilder(
return const Center( future: MainDB.instance
child: LoadingIndicator( .getAddresses(widget.walletId)
height: 200, .filter()
width: 200, .group(
), (q) => _showChange
); ? q.subTypeEqualTo(AddressSubType.change)
} : q
}, .subTypeEqualTo(AddressSubType.receiving)
.or()
.subTypeEqualTo(AddressSubType.paynymReceive),
)
.and()
.not()
.typeEqualTo(AddressType.nonWallet)
.sortByDerivationIndex()
.findAll(),
builder: (context, AsyncSnapshot<List<Address>> snapshot) {
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,
address: snapshot.data![index],
coin: coin,
),
);
} else {
return const Center(
child: LoadingIndicator(
height: 200,
width: 200,
),
);
}
},
),
),
],
), ),
); );
} }

View file

@ -21,7 +21,6 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/custom_loading_overlay.dart'; import 'package:stackwallet/widgets/custom_loading_overlay.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:tuple/tuple.dart';
class ReceiveView extends ConsumerStatefulWidget { class ReceiveView extends ConsumerStatefulWidget {
const ReceiveView({ const ReceiveView({
@ -182,8 +181,8 @@ class _ReceiveViewState extends ConsumerState<ReceiveView> {
onTap: () { onTap: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
ReceivingAddressesView.routeName, WalletAddressesView.routeName,
arguments: Tuple2(walletId, false), arguments: walletId,
); );
}, },
child: RoundedWhiteContainer( child: RoundedWhiteContainer(

View file

@ -849,13 +849,12 @@ class RouteGenerator {
} }
return _routeError("${settings.name} invalid args: ${args.toString()}"); return _routeError("${settings.name} invalid args: ${args.toString()}");
case ReceivingAddressesView.routeName: case WalletAddressesView.routeName:
if (args is Tuple2<String, bool>) { if (args is String) {
return getRoute( return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute, shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => ReceivingAddressesView( builder: (_) => WalletAddressesView(
walletId: args.item1, walletId: args,
isDesktop: args.item2,
), ),
settings: RouteSettings( settings: RouteSettings(
name: settings.name, name: settings.name,