mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
selectable utxo row data
This commit is contained in:
parent
f79fe222a2
commit
c0ce75918c
2 changed files with 95 additions and 105 deletions
|
@ -5,7 +5,6 @@ import 'package:isar/isar.dart';
|
|||
import 'package:stackwallet/db/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
|
||||
import 'package:stackwallet/pages_desktop_specific/coin_control/utxo_row.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -13,6 +12,7 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
|||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
|
||||
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
|
||||
import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
||||
import 'package:stackwallet/widgets/stack_text_field.dart';
|
||||
|
@ -50,10 +50,28 @@ class _DesktopCoinControlViewState
|
|||
late final TextEditingController _searchController;
|
||||
final searchFieldFocusNode = FocusNode();
|
||||
|
||||
final Set<UtxoRowData> _selectedUTXOs = {};
|
||||
|
||||
String _searchString = "";
|
||||
String _freezeLabelCache = "Freeze";
|
||||
|
||||
CCFilter _filter = CCFilter.all;
|
||||
CCSortDescriptor _sort = CCSortDescriptor.age;
|
||||
|
||||
String _freezeLabel(Set<UtxoRowData> dataSet) {
|
||||
if (dataSet.isEmpty) return _freezeLabelCache;
|
||||
|
||||
bool hasUnblocked = false;
|
||||
for (final data in dataSet) {
|
||||
if (!data.utxo.isBlocked) {
|
||||
hasUnblocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_freezeLabelCache = hasUnblocked ? "Freeze" : "Unfreeze";
|
||||
return _freezeLabelCache;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_searchController = TextEditingController();
|
||||
|
@ -72,26 +90,6 @@ class _DesktopCoinControlViewState
|
|||
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,
|
||||
),
|
||||
);
|
||||
|
||||
final ids = MainDB.instance
|
||||
.getUTXOs(widget.walletId)
|
||||
.filter()
|
||||
|
@ -232,13 +230,29 @@ class _DesktopCoinControlViewState
|
|||
const SizedBox(
|
||||
width: 24,
|
||||
),
|
||||
SecondaryButton(
|
||||
buttonHeight: ButtonHeight.l,
|
||||
width: 200,
|
||||
label: "Show all outputs",
|
||||
onPressed: () {
|
||||
//
|
||||
},
|
||||
AnimatedCrossFade(
|
||||
firstChild: SecondaryButton(
|
||||
buttonHeight: ButtonHeight.l,
|
||||
width: 200,
|
||||
label: "Show all outputs",
|
||||
onPressed: () {
|
||||
//
|
||||
},
|
||||
),
|
||||
secondChild: PrimaryButton(
|
||||
buttonHeight: ButtonHeight.l,
|
||||
width: 200,
|
||||
label: _freezeLabel(_selectedUTXOs),
|
||||
onPressed: () {
|
||||
//
|
||||
},
|
||||
),
|
||||
crossFadeState: _selectedUTXOs.isEmpty
|
||||
? CrossFadeState.showFirst
|
||||
: CrossFadeState.showSecond,
|
||||
duration: const Duration(
|
||||
milliseconds: 200,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 24,
|
||||
|
@ -269,67 +283,23 @@ class _DesktopCoinControlViewState
|
|||
.where()
|
||||
.idEqualTo(ids[index])
|
||||
.findFirstSync()!;
|
||||
|
||||
// final isSelected = _showBlocked
|
||||
// ? _selectedBlocked.contains(utxo)
|
||||
// : _selectedAvailable.contains(utxo);
|
||||
final data = UtxoRowData(utxo, false);
|
||||
data.selected = _selectedUTXOs.contains(data);
|
||||
|
||||
return UtxoRow(
|
||||
key: Key("${utxo.walletId}_${utxo.id}_${utxo.isBlocked}"),
|
||||
utxo: utxo,
|
||||
data: data,
|
||||
walletId: widget.walletId,
|
||||
onSelectedChanged: (value) {
|
||||
// if (value) {
|
||||
// _showBlocked
|
||||
// ? _selectedBlocked.add(utxo)
|
||||
// : _selectedAvailable.add(utxo);
|
||||
// } else {
|
||||
// _showBlocked
|
||||
// ? _selectedBlocked.remove(utxo)
|
||||
// : _selectedAvailable.remove(utxo);
|
||||
// }
|
||||
// setState(() {});
|
||||
onSelectionChanged: (value) {
|
||||
setState(() {
|
||||
if (data.selected) {
|
||||
_selectedUTXOs.add(value);
|
||||
} else {
|
||||
_selectedUTXOs.remove(value);
|
||||
}
|
||||
});
|
||||
},
|
||||
initialSelectedState: false,
|
||||
);
|
||||
|
||||
// return UtxoCard(
|
||||
// key: Key("${utxo.walletId}_${utxo.id}_$isSelected"),
|
||||
// walletId: widget.walletId,
|
||||
// utxo: utxo,
|
||||
// canSelect: widget.type == CoinControlViewType.manage ||
|
||||
// (widget.type == CoinControlViewType.use &&
|
||||
// !_showBlocked &&
|
||||
// utxo.isConfirmed(
|
||||
// currentChainHeight,
|
||||
// coin.requiredConfirmations,
|
||||
// )),
|
||||
// initialSelectedState: isSelected,
|
||||
// onSelectedChanged: (value) {
|
||||
// if (value) {
|
||||
// _showBlocked
|
||||
// ? _selectedBlocked.add(utxo)
|
||||
// : _selectedAvailable.add(utxo);
|
||||
// } else {
|
||||
// _showBlocked
|
||||
// ? _selectedBlocked.remove(utxo)
|
||||
// : _selectedAvailable.remove(utxo);
|
||||
// }
|
||||
// setState(() {});
|
||||
// },
|
||||
// onPressed: () async {
|
||||
// final result = await Navigator.of(context).pushNamed(
|
||||
// UtxoDetailsView.routeName,
|
||||
// arguments: Tuple2(
|
||||
// utxo.id,
|
||||
// widget.walletId,
|
||||
// ),
|
||||
// );
|
||||
// if (mounted && result == "refresh") {
|
||||
// setState(() {});
|
||||
// }
|
||||
// },
|
||||
// );
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,33 +1,48 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/db/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/pages/coin_control/utxo_details_view.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.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/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/icon_widgets/utxo_status_icon.dart';
|
||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||
|
||||
import '../../db/main_db.dart';
|
||||
import '../../providers/global/wallets_provider.dart';
|
||||
import '../../utilities/format.dart';
|
||||
import '../../utilities/text_styles.dart';
|
||||
import '../../utilities/theme/stack_colors.dart';
|
||||
class UtxoRowData {
|
||||
UtxoRowData(this.utxo, this.selected);
|
||||
|
||||
UTXO utxo;
|
||||
bool selected;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "selected=$selected: $utxo";
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is UtxoRowData && other.utxo == utxo;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hashAll([utxo.hashCode]);
|
||||
}
|
||||
|
||||
class UtxoRow extends ConsumerStatefulWidget {
|
||||
const UtxoRow({
|
||||
Key? key,
|
||||
required this.utxo,
|
||||
required this.data,
|
||||
required this.walletId,
|
||||
required this.onSelectedChanged,
|
||||
required this.initialSelectedState,
|
||||
this.onPressed,
|
||||
this.onSelectionChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
final String walletId;
|
||||
final UTXO utxo;
|
||||
final void Function(bool) onSelectedChanged;
|
||||
final bool initialSelectedState;
|
||||
final VoidCallback? onPressed;
|
||||
final UtxoRowData data;
|
||||
final void Function(UtxoRowData)? onSelectionChanged;
|
||||
|
||||
@override
|
||||
ConsumerState<UtxoRow> createState() => _UtxoRowState();
|
||||
|
@ -37,12 +52,9 @@ class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|||
late Stream<UTXO?> stream;
|
||||
late UTXO utxo;
|
||||
|
||||
late bool _selected;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_selected = widget.initialSelectedState;
|
||||
utxo = widget.utxo;
|
||||
utxo = widget.data.utxo;
|
||||
|
||||
stream = MainDB.instance.watchUTXO(id: utxo.id);
|
||||
super.initState();
|
||||
|
@ -66,13 +78,21 @@ class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|||
}
|
||||
|
||||
return RoundedWhiteContainer(
|
||||
boxShadow: widget.data.selected
|
||||
? [
|
||||
Theme.of(context).extension<StackColors>()!.standardBoxShadow,
|
||||
]
|
||||
: null,
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _selected,
|
||||
onChanged: (value) => setState(() {
|
||||
_selected = value!;
|
||||
}),
|
||||
value: widget.data.selected,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
widget.data.selected = value!;
|
||||
});
|
||||
widget.onSelectionChanged?.call(widget.data);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
|
@ -132,7 +152,7 @@ class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue