2023-02-02 21:37:59 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2023-02-03 19:22:21 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2023-03-01 21:52:13 +00:00
|
|
|
import 'package:stackwallet/db/isar/main_db.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
2023-03-21 23:18:07 +00:00
|
|
|
import 'package:stackwallet/pages/receive_view/addresses/address_tag.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
2023-02-03 19:22:21 +00:00
|
|
|
class AddressCard extends StatefulWidget {
|
2023-02-02 21:37:59 +00:00
|
|
|
const AddressCard({
|
|
|
|
Key? key,
|
2023-03-07 13:48:25 +00:00
|
|
|
required this.addressId,
|
2023-02-02 21:37:59 +00:00
|
|
|
required this.walletId,
|
|
|
|
required this.coin,
|
2023-03-21 23:18:07 +00:00
|
|
|
this.onPressed,
|
2023-02-02 21:37:59 +00:00
|
|
|
this.clipboard = const ClipboardWrapper(),
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2023-03-07 13:48:25 +00:00
|
|
|
final int addressId;
|
2023-02-02 21:37:59 +00:00
|
|
|
final String walletId;
|
|
|
|
final Coin coin;
|
|
|
|
final ClipboardInterface clipboard;
|
2023-03-21 23:18:07 +00:00
|
|
|
final VoidCallback? onPressed;
|
2023-02-02 21:37:59 +00:00
|
|
|
|
2023-02-03 19:22:21 +00:00
|
|
|
@override
|
|
|
|
State<AddressCard> createState() => _AddressCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddressCardState extends State<AddressCard> {
|
|
|
|
late Stream<AddressLabel?> stream;
|
2023-03-07 13:48:25 +00:00
|
|
|
late final Address address;
|
2023-02-03 19:22:21 +00:00
|
|
|
|
|
|
|
AddressLabel? label;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2023-03-07 13:48:25 +00:00
|
|
|
address = MainDB.instance.isar.addresses
|
|
|
|
.where()
|
|
|
|
.idEqualTo(widget.addressId)
|
|
|
|
.findFirstSync()!;
|
|
|
|
|
|
|
|
label = MainDB.instance.getAddressLabelSync(widget.walletId, address.value);
|
2023-02-03 19:22:21 +00:00
|
|
|
Id? id = label?.id;
|
|
|
|
if (id == null) {
|
|
|
|
label = AddressLabel(
|
|
|
|
walletId: widget.walletId,
|
2023-03-07 13:48:25 +00:00
|
|
|
addressString: address.value,
|
2023-02-03 19:22:21 +00:00
|
|
|
value: "",
|
2023-03-21 16:01:04 +00:00
|
|
|
tags: address.subType == AddressSubType.receiving
|
|
|
|
? ["receiving"]
|
|
|
|
: address.subType == AddressSubType.change
|
|
|
|
? ["change"]
|
|
|
|
: null,
|
2023-02-03 19:22:21 +00:00
|
|
|
);
|
|
|
|
id = MainDB.instance.putAddressLabelSync(label!);
|
|
|
|
}
|
|
|
|
stream = MainDB.instance.watchAddressLabel(id: id);
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-02-02 21:37:59 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RoundedWhiteContainer(
|
2023-03-21 23:18:07 +00:00
|
|
|
onPressed: widget.onPressed,
|
2023-02-03 19:22:21 +00:00
|
|
|
child: StreamBuilder<AddressLabel?>(
|
2023-03-21 23:18:07 +00:00
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
label = snapshot.data!;
|
|
|
|
}
|
2023-02-03 19:22:21 +00:00
|
|
|
|
2023-03-21 23:18:07 +00:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (label!.value.isNotEmpty)
|
|
|
|
Text(
|
|
|
|
label!.value,
|
|
|
|
style: STextStyles.itemSubtitle(context),
|
|
|
|
textAlign: TextAlign.left,
|
2023-02-02 21:37:59 +00:00
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
// Row(
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
// children: [
|
|
|
|
//
|
|
|
|
// CustomTextButton(
|
|
|
|
// text: "Edit label",
|
|
|
|
// textSize: 14,
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.of(context).pushNamed(
|
|
|
|
// EditAddressLabelView.routeName,
|
|
|
|
// arguments: label!.id,
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
if (label!.value.isNotEmpty)
|
2023-02-03 19:22:21 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
2023-02-02 21:37:59 +00:00
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
2023-03-22 19:28:28 +00:00
|
|
|
child: Text(
|
2023-03-21 23:18:07 +00:00
|
|
|
address.value,
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
2023-02-03 19:22:21 +00:00
|
|
|
),
|
2023-03-22 19:28:28 +00:00
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
|
|
|
|
if (label!.tags != null && label!.tags!.isNotEmpty)
|
|
|
|
Wrap(
|
|
|
|
spacing: 10,
|
|
|
|
runSpacing: 10,
|
|
|
|
children: label!.tags!
|
|
|
|
.map(
|
|
|
|
(e) => AddressTag(
|
|
|
|
tag: e,
|
2023-02-03 19:22:21 +00:00
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
// Row(
|
|
|
|
// children: [
|
|
|
|
// Expanded(
|
|
|
|
// child: SecondaryButton(
|
|
|
|
// label: "Copy address",
|
|
|
|
// icon: CopyIcon(
|
|
|
|
// color: Theme.of(context)
|
|
|
|
// .extension<StackColors>()!
|
|
|
|
// .buttonTextSecondary,
|
|
|
|
// ),
|
|
|
|
// onPressed: () async {
|
|
|
|
// await widget.clipboard.setData(
|
|
|
|
// ClipboardData(
|
|
|
|
// text: address.value,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// if (mounted) {
|
|
|
|
// unawaited(
|
|
|
|
// showFloatingFlushBar(
|
|
|
|
// type: FlushBarType.info,
|
|
|
|
// message: "Copied to clipboard",
|
|
|
|
// context: context,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// const SizedBox(
|
|
|
|
// width: 12,
|
|
|
|
// ),
|
|
|
|
// Expanded(
|
|
|
|
// child: SecondaryButton(
|
|
|
|
// label: "Show QR Code",
|
|
|
|
// icon: QrCodeIcon(
|
|
|
|
// color: Theme.of(context)
|
|
|
|
// .extension<StackColors>()!
|
|
|
|
// .buttonTextSecondary,
|
|
|
|
// ),
|
|
|
|
// onPressed: () {
|
|
|
|
// showDialog<void>(
|
|
|
|
// context: context,
|
|
|
|
// builder: (context) => AddressQrPopup(
|
|
|
|
// addressString: address.value,
|
|
|
|
// coin: widget.coin,
|
|
|
|
// clipboard: widget.clipboard,
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// )
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-02-02 21:37:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|