2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-03-13 22:41:53 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-03-15 15:48:39 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2023-03-22 15:25:21 +00:00
|
|
|
import 'package:stackwallet/db/isar/main_db.dart';
|
2023-03-13 22:41:53 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
2023-03-13 23:09:14 +00:00
|
|
|
import 'package:stackwallet/pages/coin_control/utxo_details_view.dart';
|
2023-03-14 16:26:35 +00:00
|
|
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-04-06 21:24:56 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
2023-05-29 21:10:55 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
2023-03-13 22:41:53 +00:00
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
2023-03-14 16:26:35 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-03-15 18:01:10 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
|
|
|
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
2023-03-13 22:41:53 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
|
|
|
import 'package:stackwallet/widgets/icon_widgets/utxo_status_icon.dart';
|
2023-03-15 18:01:10 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2023-03-13 22:41:53 +00:00
|
|
|
|
2023-03-14 16:26:35 +00:00
|
|
|
class UtxoRowData {
|
2023-03-15 15:48:39 +00:00
|
|
|
UtxoRowData(this.utxoId, this.selected);
|
2023-03-14 16:26:35 +00:00
|
|
|
|
2023-03-15 15:48:39 +00:00
|
|
|
Id utxoId;
|
2023-03-14 16:26:35 +00:00
|
|
|
bool selected;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
2023-03-15 15:48:39 +00:00
|
|
|
return "selected=$selected: $utxoId";
|
2023-03-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
2023-03-15 15:48:39 +00:00
|
|
|
return other is UtxoRowData && other.utxoId == utxoId;
|
2023-03-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-03-15 15:48:39 +00:00
|
|
|
int get hashCode => Object.hashAll([utxoId.hashCode]);
|
2023-03-14 16:26:35 +00:00
|
|
|
}
|
2023-03-13 22:41:53 +00:00
|
|
|
|
|
|
|
class UtxoRow extends ConsumerStatefulWidget {
|
|
|
|
const UtxoRow({
|
|
|
|
Key? key,
|
2023-03-14 16:26:35 +00:00
|
|
|
required this.data,
|
2023-03-13 22:41:53 +00:00
|
|
|
required this.walletId,
|
2023-03-14 16:26:35 +00:00
|
|
|
this.onSelectionChanged,
|
2023-03-15 18:01:10 +00:00
|
|
|
this.compact = false,
|
2023-03-16 18:10:59 +00:00
|
|
|
this.compactWithBorder = true,
|
|
|
|
this.raiseOnSelected = true,
|
2023-03-13 22:41:53 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String walletId;
|
2023-03-14 16:26:35 +00:00
|
|
|
final UtxoRowData data;
|
|
|
|
final void Function(UtxoRowData)? onSelectionChanged;
|
2023-03-15 18:01:10 +00:00
|
|
|
final bool compact;
|
2023-03-16 18:10:59 +00:00
|
|
|
final bool compactWithBorder;
|
|
|
|
final bool raiseOnSelected;
|
2023-03-13 22:41:53 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<UtxoRow> createState() => _UtxoRowState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|
|
|
late Stream<UTXO?> stream;
|
|
|
|
late UTXO utxo;
|
|
|
|
|
2023-03-15 18:01:10 +00:00
|
|
|
void _details() async {
|
|
|
|
await showDialog<String?>(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => UtxoDetailsView(
|
|
|
|
utxoId: utxo.id,
|
|
|
|
walletId: widget.walletId,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-03-13 22:41:53 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2023-03-15 15:48:39 +00:00
|
|
|
utxo = MainDB.instance.isar.utxos
|
|
|
|
.where()
|
|
|
|
.idEqualTo(widget.data.utxoId)
|
|
|
|
.findFirstSync()!;
|
2023-03-13 22:41:53 +00:00
|
|
|
|
|
|
|
stream = MainDB.instance.watchUTXO(id: utxo.id);
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
|
|
|
|
final coin = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManager(widget.walletId).coin));
|
|
|
|
|
|
|
|
final currentChainHeight = ref.watch(walletsChangeNotifierProvider
|
|
|
|
.select((value) => value.getManager(widget.walletId).currentHeight));
|
|
|
|
|
2023-03-13 23:09:14 +00:00
|
|
|
return StreamBuilder<UTXO?>(
|
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
utxo = snapshot.data!;
|
|
|
|
}
|
|
|
|
|
2023-03-15 18:01:10 +00:00
|
|
|
return RoundedContainer(
|
2023-03-16 18:10:59 +00:00
|
|
|
borderColor: widget.compact && widget.compactWithBorder
|
2023-03-15 18:01:10 +00:00
|
|
|
? Theme.of(context).extension<StackColors>()!.textFieldDefaultBG
|
|
|
|
: null,
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
2023-03-16 18:10:59 +00:00
|
|
|
boxShadow: widget.data.selected && widget.raiseOnSelected
|
2023-03-14 16:26:35 +00:00
|
|
|
? [
|
|
|
|
Theme.of(context).extension<StackColors>()!.standardBoxShadow,
|
|
|
|
]
|
|
|
|
: null,
|
2023-03-13 23:09:14 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
2023-03-16 18:10:59 +00:00
|
|
|
if (!(widget.compact && utxo.isBlocked))
|
|
|
|
Checkbox(
|
|
|
|
value: widget.data.selected,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
widget.data.selected = value!;
|
|
|
|
});
|
|
|
|
widget.onSelectionChanged?.call(widget.data);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (!(widget.compact && utxo.isBlocked))
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
2023-03-13 23:09:14 +00:00
|
|
|
UTXOStatusIcon(
|
|
|
|
blocked: utxo.isBlocked,
|
|
|
|
status: utxo.isConfirmed(
|
|
|
|
currentChainHeight,
|
|
|
|
coin.requiredConfirmations,
|
|
|
|
)
|
|
|
|
? UTXOStatusIconStatus.confirmed
|
|
|
|
: UTXOStatusIconStatus.unconfirmed,
|
|
|
|
background: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
selected: false,
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
2023-03-15 18:01:10 +00:00
|
|
|
if (!widget.compact)
|
|
|
|
Text(
|
2023-05-29 21:10:55 +00:00
|
|
|
ref.watch(pAmountFormatter(coin)).format(
|
|
|
|
Amount(
|
|
|
|
rawValue: BigInt.from(utxo.value),
|
|
|
|
fractionDigits: coin.decimals,
|
|
|
|
),
|
2023-04-05 22:06:31 +00:00
|
|
|
),
|
2023-03-15 18:01:10 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
style: STextStyles.w600_14(context),
|
|
|
|
),
|
|
|
|
if (!widget.compact)
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
2023-03-13 23:09:14 +00:00
|
|
|
Expanded(
|
2023-03-15 18:01:10 +00:00
|
|
|
child: ConditionalParent(
|
|
|
|
condition: widget.compact,
|
|
|
|
builder: (child) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
2023-05-29 21:10:55 +00:00
|
|
|
ref.watch(pAmountFormatter(coin)).format(
|
|
|
|
Amount(
|
|
|
|
rawValue: BigInt.from(utxo.value),
|
|
|
|
fractionDigits: coin.decimals,
|
|
|
|
),
|
2023-04-05 22:06:31 +00:00
|
|
|
),
|
2023-03-15 18:01:10 +00:00
|
|
|
textAlign: TextAlign.right,
|
|
|
|
style: STextStyles.w600_14(context),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
child,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
utxo.name.isNotEmpty
|
|
|
|
? utxo.name
|
|
|
|
: utxo.address ?? utxo.txid,
|
|
|
|
textAlign:
|
|
|
|
widget.compact ? TextAlign.left : TextAlign.center,
|
|
|
|
style: STextStyles.w500_12(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
2023-03-13 23:09:14 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
2023-03-15 18:01:10 +00:00
|
|
|
widget.compact
|
|
|
|
? CustomTextButton(
|
|
|
|
text: "Details",
|
|
|
|
onTap: _details,
|
|
|
|
)
|
|
|
|
: SecondaryButton(
|
|
|
|
width: 120,
|
|
|
|
buttonHeight: ButtonHeight.xs,
|
|
|
|
label: "Details",
|
|
|
|
onPressed: _details,
|
2023-03-13 23:09:14 +00:00
|
|
|
),
|
|
|
|
],
|
2023-03-13 22:41:53 +00:00
|
|
|
),
|
2023-03-13 23:09:14 +00:00
|
|
|
);
|
|
|
|
},
|
2023-03-13 22:41:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|