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

* Update output.dart

* fix estimated fee calculation

* Update bitcoin_transaction_priority.dart
This commit is contained in:
Serhii 2024-04-26 19:18:26 +03:00 committed by GitHub
parent a5a3b4ac0e
commit 7fcf48f91d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 15 additions and 18 deletions

View file

@ -37,7 +37,7 @@ class BitcoinTransactionPriority extends TransactionPriority {
switch (this) { switch (this) {
case BitcoinTransactionPriority.slow: case BitcoinTransactionPriority.slow:
label = 'Slow ~24hrs'; // '${S.current.transaction_priority_slow} ~24hrs'; label = 'Slow ~24hrs+'; // '${S.current.transaction_priority_slow} ~24hrs';
break; break;
case BitcoinTransactionPriority.medium: case BitcoinTransactionPriority.medium:
label = 'Medium'; // S.current.transaction_priority_medium; label = 'Medium'; // S.current.transaction_priority_medium;

View file

@ -282,13 +282,14 @@ class CWBitcoin extends Bitcoin {
} }
@override @override
int getFeeAmountWithFeeRate(Object wallet, int feeRate, int inputsCount, int outputsCount, int getEstimatedFeeWithFeeRate(Object wallet, int feeRate, int? amount,
{int? size}) { {int? outputsCount, int? size}) {
final bitcoinWallet = wallet as ElectrumWallet; final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.feeAmountWithFeeRate( return bitcoinWallet.calculateEstimatedFeeWithFeeRate(
feeRate, feeRate,
inputsCount, amount,
outputsCount, outputsCount: outputsCount,
size: size,
); );
} }

View file

@ -126,8 +126,8 @@ abstract class OutputBase with Store {
if (_wallet.type == WalletType.bitcoin) { if (_wallet.type == WalletType.bitcoin) {
if (_settingsStore.priority[_wallet.type] == bitcoin!.getBitcoinTransactionPriorityCustom()) { if (_settingsStore.priority[_wallet.type] == bitcoin!.getBitcoinTransactionPriorityCustom()) {
fee = bitcoin!.getFeeAmountWithFeeRate( fee = bitcoin!.getEstimatedFeeWithFeeRate(_wallet,
_settingsStore.customBitcoinFeeRate, formattedCryptoAmount, 1, 1); _settingsStore.customBitcoinFeeRate,formattedCryptoAmount);
} }
return bitcoin!.formatterBitcoinAmountToDouble(amount: fee); return bitcoin!.formatterBitcoinAmountToDouble(amount: fee);

View file

@ -390,16 +390,12 @@ abstract class TransactionDetailsViewModelBase with Store {
String setNewFee({double? value, required TransactionPriority priority}) { String setNewFee({double? value, required TransactionPriority priority}) {
newFee = priority == bitcoin!.getBitcoinTransactionPriorityCustom() && value != null newFee = priority == bitcoin!.getBitcoinTransactionPriorityCustom() && value != null
? bitcoin!.getFeeAmountWithFeeRate( ? bitcoin!.getEstimatedFeeWithFeeRate(wallet, value.round(), transactionInfo.amount)
wallet,
value.round(),
transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1)
: bitcoin!.getFeeAmountForPriority( : bitcoin!.getFeeAmountForPriority(
wallet, wallet,
priority, priority,
transactionInfo.inputAddresses?.length ?? 1, transactionInfo.inputAddresses?.length ?? 1,
transactionInfo.outputAddresses?.length ?? 1); transactionInfo.outputAddresses?.length ?? 1);
return bitcoin!.formatterBitcoinAmountToString(amount: newFee); return bitcoin!.formatterBitcoinAmountToString(amount: newFee);
} }

View file

@ -158,7 +158,7 @@ abstract class Bitcoin {
Future<bool> canReplaceByFee(Object wallet, String transactionHash); Future<bool> canReplaceByFee(Object wallet, String transactionHash);
Future<bool> isChangeSufficientForFee(Object wallet, String txId, String newFee); Future<bool> isChangeSufficientForFee(Object wallet, String txId, String newFee);
int getFeeAmountForPriority(Object wallet, TransactionPriority priority, int inputsCount, int outputsCount, {int? size}); 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); int getMaxCustomFeeRate(Object wallet);
} }
"""; """;