mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-10 12:44:31 +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,45 +342,48 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
selectedUTXOs.isEmpty)) {
|
||||
// confirm send all
|
||||
if (amount == availableBalance) {
|
||||
final bool? shouldSendAll = await showDialog<bool>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: true,
|
||||
builder: (context) {
|
||||
return StackDialog(
|
||||
title: "Confirm send all",
|
||||
message:
|
||||
"You are about to send your entire balance. Would you like to continue?",
|
||||
leftButton: TextButton(
|
||||
style: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.getSecondaryEnabledButtonStyle(context),
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: STextStyles.button(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.accentColorDark),
|
||||
bool? shouldSendAll;
|
||||
if (mounted) {
|
||||
shouldSendAll = await showDialog<bool>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: true,
|
||||
builder: (context) {
|
||||
return StackDialog(
|
||||
title: "Confirm send all",
|
||||
message:
|
||||
"You are about to send your entire balance. Would you like to continue?",
|
||||
leftButton: TextButton(
|
||||
style: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.getSecondaryEnabledButtonStyle(context),
|
||||
child: Text(
|
||||
"Cancel",
|
||||
style: STextStyles.button(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.accentColorDark),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
),
|
||||
rightButton: TextButton(
|
||||
style: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.getPrimaryEnabledButtonStyle(context),
|
||||
child: Text(
|
||||
"Yes",
|
||||
style: STextStyles.button(context),
|
||||
rightButton: TextButton(
|
||||
style: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.getPrimaryEnabledButtonStyle(context),
|
||||
child: Text(
|
||||
"Yes",
|
||||
style: STextStyles.button(context),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (shouldSendAll == null || shouldSendAll == false) {
|
||||
// cancel preview
|
||||
|
@ -378,22 +395,24 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
try {
|
||||
bool wasCancelled = false;
|
||||
|
||||
unawaited(
|
||||
showDialog<dynamic>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return BuildingTransactionDialog(
|
||||
onCancel: () {
|
||||
wasCancelled = true;
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
useSafeArea: false,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return BuildingTransactionDialog(
|
||||
onCancel: () {
|
||||
wasCancelled = true;
|
||||
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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