Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/pages/coin_control/coin_control_rules.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

import '../../db/isar/main_db.dart';

CCFilter coinControlFilter({
required bool isSearching,
required bool showBlocked,
}) => isSearching
? CCFilter.all
: showBlocked
? CCFilter.frozen
: CCFilter.available;

bool canSelectCoinControlOutput({
required bool isManageMode,
required bool isBlocked,
required bool isConfirmed,
}) => isManageMode || (!isBlocked && isConfirmed);
134 changes: 63 additions & 71 deletions lib/pages/coin_control/coin_control_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import '../../widgets/icon_widgets/x_icon.dart';
import '../../widgets/rounded_container.dart';
import '../../widgets/rounded_white_container.dart';
import '../../widgets/toggle.dart';
import 'coin_control_rules.dart';
import 'utxo_card.dart';
import 'utxo_details_view.dart';

Expand Down Expand Up @@ -123,21 +124,19 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");

final minConfirms =
ref
.watch(pWallets)
.getWallet(widget.walletId)
.cryptoCurrency
.minConfirms;

final coin = ref.watch(pWalletCoin(widget.walletId));
final currentHeight = ref.watch(pWalletChainHeight(widget.walletId));

final filter = coinControlFilter(
isSearching: _isSearching,
showBlocked: _showBlocked,
);

if (_sort == CCSortDescriptor.address && !_isSearching) {
_list = null;
_map = MainDB.instance.queryUTXOsGroupedByAddressSync(
walletId: widget.walletId,
filter: CCFilter.all,
filter: filter,
sort: _sort,
searchTerm: "",
cryptoCurrency: coin,
Expand All @@ -146,12 +145,7 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
_map = null;
_list = MainDB.instance.queryUTXOsSync(
walletId: widget.walletId,
filter:
_isSearching
? CCFilter.all
: _showBlocked
? CCFilter.frozen
: CCFilter.available,
filter: filter,
sort: _sort,
searchTerm: _isSearching ? searchController.text : "",
cryptoCurrency: coin,
Expand Down Expand Up @@ -291,8 +285,8 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
RoundedWhiteContainer(
child: Text(
"This option allows you to control, freeze, and utilize "
"outputs at your discretion. Tap the output circle to "
"select.",
"outputs at your discretion. Tap an output to select it, "
"or use the options button for more actions.",
style: STextStyles.w500_14(context).copyWith(
color:
Theme.of(
Expand All @@ -302,7 +296,7 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
),
),
if (!_isSearching) const SizedBox(height: 10),
if (!(_isSearching || _map != null))
if (!_isSearching)
SizedBox(
height: 48,
child: Toggle(
Expand Down Expand Up @@ -355,22 +349,21 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
),
walletId: widget.walletId,
utxo: utxo,
canSelect:
widget.type ==
CoinControlViewType.manage ||
(widget.type == CoinControlViewType.use &&
!utxo.isBlocked &&
_isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(
widget.walletId,
),
),
),
)),
canSelect: canSelectCoinControlOutput(
isManageMode:
widget.type ==
CoinControlViewType.manage,
isBlocked: utxo.isBlocked,
isConfirmed: _isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(widget.walletId),
),
),
),
),
initialSelectedState: isSelected,
onSelectedChanged: (value) {
if (value) {
Expand All @@ -384,7 +377,7 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
}
setState(() {});
},
onPressed: () async {
onOptionsPressed: () async {
final result = await Navigator.of(
context,
).pushNamed(
Expand Down Expand Up @@ -428,23 +421,23 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
),
walletId: widget.walletId,
utxo: utxo,
canSelect:
widget.type ==
CoinControlViewType.manage ||
(widget.type ==
CoinControlViewType.use &&
!_showBlocked &&
_isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(
widget.walletId,
),
),
),
)),
canSelect: canSelectCoinControlOutput(
isManageMode:
widget.type ==
CoinControlViewType.manage,
isBlocked: utxo.isBlocked,
isConfirmed: _isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(
widget.walletId,
),
),
),
),
),
initialSelectedState: isSelected,
onSelectedChanged: (value) {
if (value) {
Expand All @@ -458,7 +451,7 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
}
setState(() {});
},
onPressed: () async {
onOptionsPressed: () async {
final result = await Navigator.of(
context,
).pushNamed(
Expand Down Expand Up @@ -583,24 +576,23 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
walletId: widget.walletId,
utxo: utxo,
canSelect:
widget.type ==
CoinControlViewType
.manage ||
(widget.type ==
CoinControlViewType
.use &&
!utxo.isBlocked &&
_isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(
widget.walletId,
),
),
),
)),
canSelectCoinControlOutput(
isManageMode:
widget.type ==
CoinControlViewType.manage,
isBlocked: utxo.isBlocked,
isConfirmed: _isConfirmed(
utxo,
currentHeight,
ref.watch(
pWallets.select(
(s) => s.getWallet(
widget.walletId,
),
),
),
),
),
initialSelectedState: isSelected,
onSelectedChanged: (value) {
if (value) {
Expand All @@ -621,7 +613,7 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
}
setState(() {});
},
onPressed: () async {
onOptionsPressed: () async {
final result =
await Navigator.of(
context,
Expand Down
57 changes: 57 additions & 0 deletions lib/pages/coin_control/selectable_utxo_surface.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/

import 'package:flutter/material.dart';

import '../../utilities/constants.dart';

class SelectableUtxoSurface extends StatelessWidget {
const SelectableUtxoSurface({
super.key,
required this.canSelect,
required this.selected,
required this.onToggle,
required this.child,
this.color,
});

final bool canSelect;
final bool selected;
final VoidCallback onToggle;
final Widget child;
final Color? color;

@override
Widget build(BuildContext context) {
if (!canSelect) {
return child;
}

return Semantics(
selected: selected,
child: MaterialButton(
minWidth: 0,
padding: EdgeInsets.zero,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
color: color,
elevation: 0,
disabledElevation: 0,
hoverElevation: 0,
focusElevation: 0,
highlightElevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: onToggle,
child: child,
),
);
}
}
Loading
Loading