utxo label display

This commit is contained in:
julian 2023-03-09 16:50:25 -06:00
parent 5fc53a9935
commit 9ed1897c87
2 changed files with 146 additions and 147 deletions

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/providers/global/wallets_provider.dart';
@ -36,7 +35,8 @@ class UtxoCard extends ConsumerStatefulWidget {
}
class _UtxoCardState extends ConsumerState<UtxoCard> {
late final UTXO utxo;
late Stream<UTXO?> stream;
late UTXO utxo;
late bool _selected;
@ -44,6 +44,8 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
void initState() {
_selected = widget.initialSelectedState;
utxo = widget.utxo;
stream = MainDB.instance.watchUTXO(id: utxo.id);
super.initState();
}
@ -57,19 +59,6 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
final currentChainHeight = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId).currentHeight));
String? label;
if (utxo.address != null) {
label = MainDB.instance.isar.addressLabels
.where()
.addressStringWalletIdEqualTo(utxo.address!, widget.walletId)
.findFirstSync()
?.value;
if (label != null && label.isEmpty) {
label = null;
}
}
return ConditionalParent(
condition: widget.onPressed != null,
builder: (child) => MaterialButton(
@ -92,7 +81,13 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
color: widget.onPressed == null
? Theme.of(context).extension<StackColors>()!.popupBG
: Colors.transparent,
child: Row(
child: StreamBuilder<UTXO?>(
stream: stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
utxo = snapshot.data!;
}
return Row(
children: [
ConditionalParent(
condition: widget.canSelect,
@ -112,7 +107,8 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
)
? UTXOStatusIconStatus.confirmed
: UTXOStatusIconStatus.unconfirmed,
background: Theme.of(context).extension<StackColors>()!.popupBG,
background:
Theme.of(context).extension<StackColors>()!.popupBG,
selected: _selected,
width: 32,
height: 32,
@ -140,7 +136,9 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
children: [
Flexible(
child: Text(
label ?? utxo.address ?? utxo.txid,
utxo.name.isNotEmpty
? utxo.name
: utxo.address ?? utxo.txid,
style: STextStyles.w500_12(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
@ -154,7 +152,8 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
),
),
],
),
);
}),
),
);
}

View file

@ -176,11 +176,9 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
],
),
),
if (label != null && label!.value.isNotEmpty)
const SizedBox(
height: _spacing,
),
if (label != null && label!.value.isNotEmpty)
RoundedWhiteContainer(
child: Column(
mainAxisSize: MainAxisSize.min,
@ -190,15 +188,23 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Address label",
"Label",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleCopyButton(
data: label!.value,
SimpleEditButton(
editValue: utxo!.name,
editLabel: "label",
onValueChanged: (newName) {
MainDB.instance.putUTXO(
utxo!.copyWith(
name: newName,
),
);
},
),
],
),
@ -206,7 +212,7 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
height: 4,
),
Text(
label!.value,
utxo!.name,
style: STextStyles.w500_14(context),
),
],
@ -246,6 +252,42 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
],
),
),
if (label != null && label!.value.isNotEmpty)
const SizedBox(
height: _spacing,
),
if (label != null && label!.value.isNotEmpty)
RoundedWhiteContainer(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Address label",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleCopyButton(
data: label!.value,
),
],
),
const SizedBox(
height: 4,
),
Text(
label!.value,
style: STextStyles.w500_14(context),
),
],
),
),
const SizedBox(
height: _spacing,
),
@ -309,48 +351,6 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
const SizedBox(
height: _spacing,
),
RoundedWhiteContainer(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Note",
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.textSubtitle1,
),
),
SimpleEditButton(
editValue: utxo!.name,
editLabel: "note",
onValueChanged: (newName) {
MainDB.instance.putUTXO(
utxo!.copyWith(
name: newName,
),
);
},
),
],
),
const SizedBox(
height: 4,
),
Text(
utxo!.name,
style: STextStyles.w500_14(context),
),
],
),
),
const SizedBox(
height: _spacing,
),
if (utxo!.isBlocked)
Column(
mainAxisSize: MainAxisSize.min,