mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 11:45:59 +00:00
mounted checks and include fee in estimate for required amount in coin control selection view
This commit is contained in:
parent
4cc738fd3a
commit
210fac593a
1 changed files with 105 additions and 58 deletions
|
@ -159,6 +159,20 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
}
|
||||
}
|
||||
|
||||
int _currentFee = 0;
|
||||
|
||||
void _setCurrentFee(String fee, bool shouldSetState) {
|
||||
final value = Format.decimalAmountToSatoshis(
|
||||
Decimal.parse(fee),
|
||||
coin,
|
||||
);
|
||||
if (shouldSetState) {
|
||||
setState(() => _currentFee = value);
|
||||
} else {
|
||||
_currentFee = value;
|
||||
}
|
||||
}
|
||||
|
||||
String? _updateInvalidAddressText(String address, Manager manager) {
|
||||
if (_data != null && _data!.contactLabel == address) {
|
||||
return null;
|
||||
|
@ -328,7 +342,9 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
selectedUTXOs.isEmpty)) {
|
||||
// confirm send all
|
||||
if (amount == availableBalance) {
|
||||
final bool? shouldSendAll = await showDialog<bool>(
|
||||
bool? shouldSendAll;
|
||||
if (mounted) {
|
||||
shouldSendAll = await showDialog<bool>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: true,
|
||||
|
@ -367,6 +383,7 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldSendAll == null || shouldSendAll == false) {
|
||||
// cancel preview
|
||||
|
@ -378,8 +395,9 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
try {
|
||||
bool wasCancelled = false;
|
||||
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
showDialog<dynamic>(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: false,
|
||||
|
@ -394,6 +412,7 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> txData;
|
||||
|
||||
|
@ -1569,18 +1588,33 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
? "Select coins"
|
||||
: "Selected coins (${selectedUTXOs.length})",
|
||||
onTap: () async {
|
||||
final spendable = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.balance
|
||||
.spendable;
|
||||
|
||||
int? amount;
|
||||
if (_amountToSend != null) {
|
||||
amount = Format.decimalAmountToSatoshis(
|
||||
_amountToSend!,
|
||||
coin,
|
||||
);
|
||||
|
||||
if (spendable == amount) {
|
||||
// this is now a send all
|
||||
} else {
|
||||
amount += _currentFee;
|
||||
}
|
||||
}
|
||||
|
||||
final result =
|
||||
await Navigator.of(context).pushNamed(
|
||||
CoinControlView.routeName,
|
||||
arguments: Tuple4(
|
||||
walletId,
|
||||
CoinControlViewType.use,
|
||||
_amountToSend != null
|
||||
? Format.decimalAmountToSatoshis(
|
||||
_amountToSend!,
|
||||
coin,
|
||||
)
|
||||
: null,
|
||||
amount,
|
||||
selectedUTXOs,
|
||||
),
|
||||
);
|
||||
|
@ -1711,6 +1745,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
.text) ??
|
||||
Decimal.zero,
|
||||
updateChosen: (String fee) {
|
||||
_setCurrentFee(
|
||||
fee,
|
||||
true,
|
||||
);
|
||||
setState(() {
|
||||
_calculateFeesFuture =
|
||||
Future(() => fee);
|
||||
|
@ -1736,6 +1774,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
ConnectionState
|
||||
.done &&
|
||||
snapshot.hasData) {
|
||||
_setCurrentFee(
|
||||
snapshot.data! as String,
|
||||
false,
|
||||
);
|
||||
return Text(
|
||||
"~${snapshot.data! as String} ${coin.ticker}",
|
||||
style: STextStyles
|
||||
|
@ -1788,6 +1830,11 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
ConnectionState
|
||||
.done &&
|
||||
snapshot.hasData) {
|
||||
_setCurrentFee(
|
||||
snapshot.data!
|
||||
as String,
|
||||
false,
|
||||
);
|
||||
return Text(
|
||||
"~${snapshot.data! as String} ${coin.ticker}",
|
||||
style: STextStyles
|
||||
|
|
Loading…
Reference in a new issue