Skip to content

Commit

Permalink
Fix estimated fee calculation for customs fee rate (#1406)
Browse files Browse the repository at this point in the history
* Update output.dart

* fix estimated fee calculation

* Update bitcoin_transaction_priority.dart
  • Loading branch information
Serhii-Borodenko authored Apr 26, 2024
1 parent a5a3b4a commit 7fcf48f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cw_bitcoin/lib/bitcoin_transaction_priority.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class BitcoinTransactionPriority extends TransactionPriority {

switch (this) {
case BitcoinTransactionPriority.slow:
label = 'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs';
label = 'Slow ~24hrs+'; // '${S.current.transaction_priority_slow} ~24hrs';
break;
case BitcoinTransactionPriority.medium:
label = 'Medium'; // S.current.transaction_priority_medium;
Expand Down
11 changes: 6 additions & 5 deletions lib/bitcoin/cw_bitcoin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ class CWBitcoin extends Bitcoin {
}

@override
int getFeeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount,
{int? size}) {
int getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount,
{int? outputsCount, int? size}) {
final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.feeAmountWithFeeRate(
return bitcoinWallet.calculateEstimatedFeeWithFeeRate(
feeRate,
inputsCount,
outputsCount,
amount,
outputsCount: outputsCount,
size: size,
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/view_model/send/output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ abstract class OutputBase with Store {

if (_wallet.type == WalletType.bitcoin) {
if (_settingsStore.priority[_wallet.type] == bitcoin!.getBitcoinTransactionPriorityCustom()) {
fee = bitcoin!.getFeeAmountWithFeeRate(
_settingsStore.customBitcoinFeeRate, formattedCryptoAmount, 1, 1);
fee = bitcoin!.getEstimatedFeeWithFeeRate(_wallet,
_settingsStore.customBitcoinFeeRate,formattedCryptoAmount);
}

return bitcoin!.formatterBitcoinAmountToDouble(amount: fee);
Expand Down
14 changes: 5 additions & 9 deletions lib/view_model/transaction_details_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,12 @@ abstract class TransactionDetailsViewModelBase with Store {

String setNewFee({double? value, required TransactionPriority priority}) {
newFee = priority == bitcoin!.getBitcoinTransactionPriorityCustom() && value != null
? bitcoin!.getFeeAmountWithFeeRate(
wallet,
value.round(),
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1)
? bitcoin!.getEstimatedFeeWithFeeRate(wallet, value.round(), transactionInfo.amount)
: bitcoin!.getFeeAmountForPriority(
wallet,
priority,
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1);
wallet,
priority,
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1);

return bitcoin!.formatterBitcoinAmountToString(amount: newFee);
}
Expand Down
2 changes: 1 addition & 1 deletion tool/configure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ abstract class Bitcoin {
Future<bool> canReplaceByFee(Object wallet, String transactionHash);
Future<bool> isChangeSufficientForFee(Object wallet, String txId, String newFee);
int getFeeAmountForPriority(Object wallet, TransactionPriority priority, int inputsCount, int outputsCount, {int? size});
int getFeeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount, {int? size});
int getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount, {int? outputsCount, int? size});
int getMaxCustomFeeRate(Object wallet);
}
""";
Expand Down

0 comments on commit 7fcf48f

Please sign in to comment.