mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
120 lines
3.4 KiB
Dart
120 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_svg/flutter_svg.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/assets.dart';
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
class UtxoCard extends ConsumerStatefulWidget {
|
|
const UtxoCard({
|
|
Key? key,
|
|
required this.utxo,
|
|
required this.walletId,
|
|
this.selectable = false,
|
|
}) : super(key: key);
|
|
|
|
final String walletId;
|
|
final UTXO utxo;
|
|
final bool selectable;
|
|
|
|
@override
|
|
ConsumerState<UtxoCard> createState() => _UtxoCardState();
|
|
}
|
|
|
|
class _UtxoCardState extends ConsumerState<UtxoCard> {
|
|
late final UTXO utxo;
|
|
|
|
bool _selected = false;
|
|
|
|
@override
|
|
void initState() {
|
|
utxo = widget.utxo;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
debugPrint("BUILD: $runtimeType");
|
|
|
|
final coin = ref.watch(walletsChangeNotifierProvider
|
|
.select((value) => value.getManager(widget.walletId).coin));
|
|
|
|
final addr = MainDB.instance.isar.transactions
|
|
.where()
|
|
.txidWalletIdEqualTo(
|
|
utxo.txid,
|
|
widget.walletId,
|
|
)
|
|
.findFirstSync()
|
|
?.address
|
|
.value
|
|
?.value;
|
|
|
|
String? label;
|
|
if (addr != null) {
|
|
label = MainDB.instance.isar.addressLabels
|
|
.where()
|
|
.addressStringWalletIdEqualTo(addr, widget.walletId)
|
|
.findFirstSync()
|
|
?.value;
|
|
}
|
|
|
|
return RoundedWhiteContainer(
|
|
child: Row(
|
|
children: [
|
|
SvgPicture.asset(
|
|
_selected
|
|
? Assets.svg.coinControl.selected
|
|
: utxo.isBlocked
|
|
? Assets.svg.coinControl.blocked
|
|
: Assets.svg.coinControl.unBlocked,
|
|
width: 32,
|
|
height: 32,
|
|
),
|
|
const SizedBox(
|
|
width: 10,
|
|
),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(
|
|
"${Format.satoshisToAmount(
|
|
utxo.value,
|
|
coin: coin,
|
|
).toStringAsFixed(coin.decimals)} ${coin.ticker}",
|
|
style: STextStyles.w600_14(context),
|
|
),
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
Row(
|
|
children: [
|
|
Flexible(
|
|
child: Text(
|
|
label ?? addr ?? utxo.txid,
|
|
style: STextStyles.w500_12(context).copyWith(
|
|
color: Theme.of(context)
|
|
.extension<StackColors>()!
|
|
.textSubtitle1,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|