Fix estimated fee calculation for customs fee rate (#1406)

* Update output.dart * fix estimated fee calculation * Update bitcoin_transaction_priority.dart

Serhii committed Apr 26, 2024 at 19:18 UTC 7fcf48f91da3d82121704bf25c530549a24c9322
5 files changed +15 -18
cw_bitcoin/lib/bitcoin_transaction_priority.dart
+1 -1
@@ -37,7 +37,7 @@ class BitcoinTransactionPriority extends TransactionPriority {
37
38 switch (this) {
39 case BitcoinTransactionPriority.slow:
40 - label = 'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs';
40 + label = 'Slow ~24hrs+'; // '${S.current.transaction_priority_slow} ~24hrs';
41 break;
42 case BitcoinTransactionPriority.medium:
43 label = 'Medium'; // S.current.transaction_priority_medium;
lib/bitcoin/cw_bitcoin.dart
+6 -5
@@ -282,13 +282,14 @@ class CWBitcoin extends Bitcoin {
282 }
283
284 @override
285 - int getFeeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount,
286 - {int? size}) {
285 + int getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount,
286 + {int? outputsCount, int? size}) {
287 final bitcoinWallet = wallet as ElectrumWallet;
288 - return bitcoinWallet.feeAmountWithFeeRate(
288 + return bitcoinWallet.calculateEstimatedFeeWithFeeRate(
289 feeRate,
290 - inputsCount,
291 - outputsCount,
290 + amount,
291 + outputsCount: outputsCount,
292 + size: size,
293 );
294 }
295
lib/view_model/send/output.dart
+2 -2
@@ -126,8 +126,8 @@ abstract class OutputBase with Store {
126
127 if (_wallet.type == WalletType.bitcoin) {
128 if (_settingsStore.priority[_wallet.type] == bitcoin!.getBitcoinTransactionPriorityCustom()) {
129 - fee = bitcoin!.getFeeAmountWithFeeRate(
130 - _settingsStore.customBitcoinFeeRate, formattedCryptoAmount, 1, 1);
129 + fee = bitcoin!.getEstimatedFeeWithFeeRate(_wallet,
130 + _settingsStore.customBitcoinFeeRate,formattedCryptoAmount);
131 }
132
133 return bitcoin!.formatterBitcoinAmountToDouble(amount: fee);
lib/view_model/transaction_details_view_model.dart
+5 -9
@@ -390,16 +390,12 @@ abstract class TransactionDetailsViewModelBase with Store {
390
391 String setNewFee({double? value, required TransactionPriority priority}) {
392 newFee = priority == bitcoin!.getBitcoinTransactionPriorityCustom() && value != null
393 - ? bitcoin!.getFeeAmountWithFeeRate(
394 - wallet,
395 - value.round(),
396 - transactionInfo.inputAddresses?.length ?? 1,
397 - transactionInfo.outputAddresses?.length ?? 1)
393 + ? bitcoin!.getEstimatedFeeWithFeeRate(wallet, value.round(), transactionInfo.amount)
394 : bitcoin!.getFeeAmountForPriority(
399 - wallet,
400 - priority,
401 - transactionInfo.inputAddresses?.length ?? 1,
402 - transactionInfo.outputAddresses?.length ?? 1);
395 + wallet,
396 + priority,
397 + transactionInfo.inputAddresses?.length ?? 1,
398 + transactionInfo.outputAddresses?.length ?? 1);
399
400 return bitcoin!.formatterBitcoinAmountToString(amount: newFee);
401 }
tool/configure.dart
+1 -1
@@ -158,7 +158,7 @@ abstract class Bitcoin {
158 Future<bool> canReplaceByFee(Object wallet, String transactionHash);
159 Future<bool> isChangeSufficientForFee(Object wallet, String txId, String newFee);
160 int getFeeAmountForPriority(Object wallet, TransactionPriority priority, int inputsCount, int outputsCount, {int? size});
161 - int getFeeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount, {int? size});
161 + int getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount, {int? outputsCount, int? size});
162 int getMaxCustomFeeRate(Object wallet);
163 }
164 """;