2023-03-07 17:11:57 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-03-07 15:39:34 +00:00
|
|
|
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';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/widgets/background.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
2023-03-07 17:11:57 +00:00
|
|
|
import 'package:stackwallet/widgets/custom_buttons/simple_copy_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/simple_edit_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
|
|
|
class UtxoDetailsView extends ConsumerStatefulWidget {
|
|
|
|
const UtxoDetailsView({
|
|
|
|
Key? key,
|
|
|
|
required this.utxoId,
|
|
|
|
required this.walletId,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
static const routeName = "/utxoDetails";
|
|
|
|
|
|
|
|
final Id utxoId;
|
|
|
|
final String walletId;
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<UtxoDetailsView> createState() => _UtxoDetailsViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
|
2023-03-07 17:11:57 +00:00
|
|
|
static const double _spacing = 12;
|
2023-03-07 15:39:34 +00:00
|
|
|
|
2023-03-08 17:45:21 +00:00
|
|
|
late Stream<UTXO?> streamUTXO;
|
2023-03-07 15:39:34 +00:00
|
|
|
UTXO? utxo;
|
|
|
|
|
2023-03-08 17:45:21 +00:00
|
|
|
Stream<AddressLabel?>? streamLabel;
|
|
|
|
AddressLabel? label;
|
|
|
|
|
2023-03-07 17:11:57 +00:00
|
|
|
bool _popWithRefresh = false;
|
|
|
|
|
|
|
|
Future<void> _toggleFreeze() async {
|
|
|
|
_popWithRefresh = true;
|
|
|
|
await MainDB.instance.putUTXO(utxo!.copyWith(isBlocked: !utxo!.isBlocked));
|
|
|
|
}
|
|
|
|
|
2023-03-07 15:39:34 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
utxo = MainDB.instance.isar.utxos
|
|
|
|
.where()
|
|
|
|
.idEqualTo(widget.utxoId)
|
|
|
|
.findFirstSync()!;
|
|
|
|
|
2023-03-08 17:45:21 +00:00
|
|
|
streamUTXO = MainDB.instance.watchUTXO(id: widget.utxoId);
|
|
|
|
|
|
|
|
if (utxo?.address != null) {
|
|
|
|
label = MainDB.instance.getAddressLabelSync(
|
|
|
|
widget.walletId,
|
|
|
|
utxo!.address!,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (label != null) {
|
|
|
|
streamLabel = MainDB.instance.watchAddressLabel(id: label!.id);
|
|
|
|
}
|
|
|
|
}
|
2023-03-07 15:39:34 +00:00
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-03-07 17:11:57 +00:00
|
|
|
final coin = ref.watch(
|
|
|
|
walletsChangeNotifierProvider.select(
|
|
|
|
(value) => value.getManager(widget.walletId).coin,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
final currentHeight = ref.watch(
|
|
|
|
walletsChangeNotifierProvider.select(
|
|
|
|
(value) => value.getManager(widget.walletId).currentHeight,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-03-08 17:34:00 +00:00
|
|
|
final confirmed = utxo!.isConfirmed(
|
|
|
|
currentHeight,
|
|
|
|
coin.requiredConfirmations,
|
|
|
|
);
|
|
|
|
|
2023-03-07 17:11:57 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: !Util.isDesktop,
|
|
|
|
builder: (child) => Background(
|
|
|
|
child: Scaffold(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
appBar: AppBar(
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).extension<StackColors>()!.background,
|
|
|
|
leading: AppBarBackButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop(_popWithRefresh ? "refresh" : null);
|
|
|
|
},
|
|
|
|
),
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
2023-03-07 17:11:57 +00:00
|
|
|
body: SafeArea(
|
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
minHeight: constraints.maxHeight,
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
),
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
2023-03-07 17:11:57 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: StreamBuilder<UTXO?>(
|
2023-03-08 17:45:21 +00:00
|
|
|
stream: streamUTXO,
|
2023-03-07 17:11:57 +00:00
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
utxo = snapshot.data!;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"${Format.satoshisToAmount(
|
|
|
|
utxo!.value,
|
|
|
|
coin: coin,
|
|
|
|
).toStringAsFixed(
|
|
|
|
coin.decimals,
|
|
|
|
)} ${coin.ticker}",
|
|
|
|
style: STextStyles.pageTitleH2(context),
|
|
|
|
),
|
|
|
|
Text(
|
2023-03-08 17:34:00 +00:00
|
|
|
utxo!.isBlocked
|
|
|
|
? "Frozen"
|
|
|
|
: confirmed
|
|
|
|
? "Available"
|
|
|
|
: "Unconfirmed",
|
2023-03-07 17:11:57 +00:00
|
|
|
style: STextStyles.w500_14(context).copyWith(
|
|
|
|
color: utxo!.isBlocked
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorBlue
|
2023-03-08 17:34:00 +00:00
|
|
|
: confirmed
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorGreen
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorYellow,
|
2023-03-07 17:11:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-03-08 17:45:21 +00:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-03-07 17:11:57 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: _spacing,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2023-03-07 15:39:34 +00:00
|
|
|
children: [
|
|
|
|
Text(
|
2023-03-07 17:11:57 +00:00
|
|
|
"Address",
|
|
|
|
style: STextStyles.w500_14(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SimpleCopyButton(
|
|
|
|
data: utxo!.address!,
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-07 17:11:57 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
utxo!.address!,
|
|
|
|
style: STextStyles.w500_14(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: _spacing,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Transaction ID",
|
|
|
|
style: STextStyles.w500_14(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SimpleCopyButton(
|
|
|
|
data: utxo!.txid,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
utxo!.txid,
|
|
|
|
style: STextStyles.w500_14(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: _spacing,
|
|
|
|
),
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Confirmations",
|
|
|
|
style: STextStyles.w500_14(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
2023-03-07 18:40:47 +00:00
|
|
|
"${utxo!.getConfirmations(currentHeight)}",
|
2023-03-07 17:11:57 +00:00
|
|
|
style: STextStyles.w500_14(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
RoundedWhiteContainer(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Freeze reason",
|
|
|
|
style: STextStyles.w500_14(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SimpleEditButton(
|
|
|
|
editValue: utxo!.blockedReason ?? "",
|
|
|
|
editLabel: "freeze reason",
|
|
|
|
onValueChanged: (newReason) {
|
|
|
|
MainDB.instance.putUTXO(
|
|
|
|
utxo!.copyWith(
|
|
|
|
blockedReason: newReason,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
utxo!.blockedReason ?? "",
|
|
|
|
style: STextStyles.w500_14(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: _spacing,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
SecondaryButton(
|
|
|
|
label: utxo!.isBlocked ? "Unfreeze" : "Freeze",
|
|
|
|
onPressed: _toggleFreeze,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 16,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|