mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-02 12:14:09 +01:00
rbf fixes issues sum utxo and fee calculation (#1625)
* total out amount issue * fix empty inputs and outputs addresses for new tx * fix sum value of utxo not spending * Update configure.dart * Update electrum_wallet.dart * receiving address * review fixes
This commit is contained in:
@@ -18,6 +18,7 @@ import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart';
|
||||
import 'package:cake_wallet/wownero/wownero.dart';
|
||||
import 'package:cw_core/exceptions.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
||||
@@ -392,25 +393,38 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> replaceByFee(String txId, String newFee) async {
|
||||
Future<void> replaceByFee(TransactionInfo tx, String newFee) async {
|
||||
state = IsExecutingState();
|
||||
|
||||
final isSufficient = await bitcoin!.isChangeSufficientForFee(wallet, txId, newFee);
|
||||
try {
|
||||
final isSufficient = await bitcoin!.isChangeSufficientForFee(wallet, tx.id, newFee);
|
||||
|
||||
if (!isSufficient) {
|
||||
state = AwaitingConfirmationState(
|
||||
title: S.current.confirm_fee_deduction,
|
||||
message: S.current.confirm_fee_deduction_content,
|
||||
onConfirm: () async {
|
||||
pendingTransaction = await bitcoin!.replaceByFee(wallet, txId, newFee);
|
||||
state = ExecutedSuccessfullyState();
|
||||
},
|
||||
onCancel: () {
|
||||
state = FailureState('Insufficient change for fee');
|
||||
});
|
||||
} else {
|
||||
pendingTransaction = await bitcoin!.replaceByFee(wallet, txId, newFee);
|
||||
if (!isSufficient) {
|
||||
state = AwaitingConfirmationState(
|
||||
title: S.current.confirm_fee_deduction,
|
||||
message: S.current.confirm_fee_deduction_content,
|
||||
onConfirm: () async => await _executeReplaceByFee(tx, newFee),
|
||||
onCancel: () => state = FailureState('Insufficient change for fee'));
|
||||
} else {
|
||||
await _executeReplaceByFee(tx, newFee);
|
||||
}
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _executeReplaceByFee(TransactionInfo tx, String newFee) async {
|
||||
|
||||
|
||||
clearOutputs();
|
||||
final output = outputs.first;
|
||||
output.address = tx.outputAddresses?.first ?? '';
|
||||
|
||||
try {
|
||||
pendingTransaction = await bitcoin!.replaceByFee(wallet, tx.id, newFee);
|
||||
state = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user