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-06 18:11:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2023-03-22 15:25:21 +00:00
|
|
|
import 'package:stackwallet/db/isar/main_db.dart';
|
2023-03-06 18:11:13 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
|
|
|
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-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
2023-03-06 18:11:13 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2023-03-08 17:23:28 +00:00
|
|
|
import 'package:stackwallet/widgets/icon_widgets/utxo_status_icon.dart';
|
2023-03-07 15:39:34 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2023-03-06 18:11:13 +00:00
|
|
|
|
|
|
|
class UtxoCard extends ConsumerStatefulWidget {
|
|
|
|
const UtxoCard({
|
|
|
|
Key? key,
|
|
|
|
required this.utxo,
|
|
|
|
required this.walletId,
|
2023-03-07 19:51:06 +00:00
|
|
|
required this.onSelectedChanged,
|
|
|
|
required this.initialSelectedState,
|
2023-03-07 21:45:22 +00:00
|
|
|
required this.canSelect,
|
2023-03-07 15:39:34 +00:00
|
|
|
this.onPressed,
|
2023-03-06 18:11:13 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String walletId;
|
|
|
|
final UTXO utxo;
|
2023-03-07 19:51:06 +00:00
|
|
|
final void Function(bool) onSelectedChanged;
|
|
|
|
final bool initialSelectedState;
|
2023-03-07 15:39:34 +00:00
|
|
|
final VoidCallback? onPressed;
|
2023-03-07 21:45:22 +00:00
|
|
|
final bool canSelect;
|
2023-03-06 18:11:13 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<UtxoCard> createState() => _UtxoCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UtxoCardState extends ConsumerState<UtxoCard> {
|
2023-03-09 22:50:25 +00:00
|
|
|
late Stream<UTXO?> stream;
|
|
|
|
late UTXO utxo;
|
2023-03-06 18:11:13 +00:00
|
|
|
|
2023-03-07 19:51:06 +00:00
|
|
|
late bool _selected;
|
2023-03-06 18:11:13 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2023-03-07 19:51:06 +00:00
|
|
|
_selected = widget.initialSelectedState;
|
2023-03-06 18:11:13 +00:00
|
|
|
utxo = widget.utxo;
|
2023-03-09 22:50:25 +00:00
|
|
|
|
|
|
|
stream = MainDB.instance.watchUTXO(id: utxo.id);
|
2023-03-06 18:11:13 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
|
2023-10-31 17:15:59 +00:00
|
|
|
final coin = ref.watch(
|
|
|
|
pWallets.select((value) => value.getManager(widget.walletId).coin));
|
2023-03-06 18:11:13 +00:00
|
|
|
|
2023-10-31 17:15:59 +00:00
|
|
|
final currentChainHeight = ref.watch(pWallets
|
2023-03-08 17:23:28 +00:00
|
|
|
.select((value) => value.getManager(widget.walletId).currentHeight));
|
|
|
|
|
2023-03-07 15:39:34 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: widget.onPressed != null,
|
|
|
|
builder: (child) => MaterialButton(
|
|
|
|
padding: const EdgeInsets.all(0),
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
elevation: 0,
|
|
|
|
disabledElevation: 0,
|
|
|
|
hoverElevation: 0,
|
|
|
|
focusElevation: 0,
|
|
|
|
highlightElevation: 0,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(Constants.size.circularBorderRadius),
|
|
|
|
),
|
|
|
|
onPressed: widget.onPressed,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: RoundedContainer(
|
|
|
|
color: widget.onPressed == null
|
|
|
|
? Theme.of(context).extension<StackColors>()!.popupBG
|
|
|
|
: Colors.transparent,
|
2023-03-09 22:50:25 +00:00
|
|
|
child: StreamBuilder<UTXO?>(
|
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
utxo = snapshot.data!;
|
|
|
|
}
|
|
|
|
return Row(
|
2023-03-07 15:39:34 +00:00
|
|
|
children: [
|
2023-03-09 22:50:25 +00:00
|
|
|
ConditionalParent(
|
|
|
|
condition: widget.canSelect,
|
|
|
|
builder: (child) => GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
_selected = !_selected;
|
|
|
|
widget.onSelectedChanged(_selected);
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
child: UTXOStatusIcon(
|
|
|
|
blocked: utxo.isBlocked,
|
|
|
|
status: utxo.isConfirmed(
|
|
|
|
currentChainHeight,
|
|
|
|
coin.requiredConfirmations,
|
|
|
|
)
|
|
|
|
? UTXOStatusIconStatus.confirmed
|
|
|
|
: UTXOStatusIconStatus.unconfirmed,
|
|
|
|
background:
|
|
|
|
Theme.of(context).extension<StackColors>()!.popupBG,
|
|
|
|
selected: _selected,
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
),
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
2023-03-09 22:50:25 +00:00
|
|
|
width: 10,
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
2023-03-09 22:50:25 +00:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(
|
2023-05-29 21:10:55 +00:00
|
|
|
ref.watch(pAmountFormatter(coin)).format(
|
|
|
|
utxo.value.toAmountAsRaw(
|
|
|
|
fractionDigits: coin.decimals,
|
2023-04-05 22:06:31 +00:00
|
|
|
),
|
2023-05-29 21:10:55 +00:00
|
|
|
),
|
2023-03-09 22:50:25 +00:00
|
|
|
style: STextStyles.w600_14(context),
|
2023-03-06 18:11:13 +00:00
|
|
|
),
|
2023-03-09 22:50:25 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
utxo.name.isNotEmpty
|
|
|
|
? utxo.name
|
|
|
|
: utxo.address ?? utxo.txid,
|
|
|
|
style: STextStyles.w500_12(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textSubtitle1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-07 15:39:34 +00:00
|
|
|
),
|
|
|
|
],
|
2023-03-09 22:50:25 +00:00
|
|
|
);
|
|
|
|
}),
|
2023-03-06 18:11:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|