mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
Calculate Estimated fee and deduct it from the Fiat Amount on "ALL" transactions
This commit is contained in:
parent
0b4acd33af
commit
3f71755fe5
2 changed files with 23 additions and 10 deletions
|
@ -560,7 +560,9 @@ class SendCardState extends State<SendCard>
|
|||
|
||||
reaction((_) => output.fiatAmount, (String amount) {
|
||||
if (amount != fiatAmountController.text) {
|
||||
fiatAmountController.text = amount;
|
||||
final doubleAmount = double.tryParse(amount) ?? 0;
|
||||
final doubleFee = double.tryParse(sendViewModel.estimatedFiatFee(sendViewModel.balance)) ?? 0;
|
||||
fiatAmountController.text = doubleAmount - doubleFee > 0 ? "${doubleAmount - doubleFee}" : "0.00";
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/core/amount_converter.dart';
|
||||
import 'package:cake_wallet/entities/balance_display_mode.dart';
|
||||
import 'package:cake_wallet/entities/transaction_description.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
|
||||
|
@ -83,10 +84,7 @@ abstract class SendViewModelBase with Store {
|
|||
String get pendingTransactionFiatAmount {
|
||||
try {
|
||||
if (pendingTransaction != null) {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency],
|
||||
cryptoAmount: pendingTransaction.amountFormatted);
|
||||
return fiat;
|
||||
return _calculateFiatAmount(pendingTransaction.amountFormatted);
|
||||
} else {
|
||||
return '0.00';
|
||||
}
|
||||
|
@ -99,10 +97,7 @@ abstract class SendViewModelBase with Store {
|
|||
String get pendingTransactionFeeFiatAmount {
|
||||
try {
|
||||
if (pendingTransaction != null) {
|
||||
final fiat = calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency],
|
||||
cryptoAmount: pendingTransaction.feeFormatted);
|
||||
return fiat;
|
||||
return _calculateFiatAmount(pendingTransaction.feeFormatted);
|
||||
} else {
|
||||
return '0.00';
|
||||
}
|
||||
|
@ -111,6 +106,12 @@ abstract class SendViewModelBase with Store {
|
|||
}
|
||||
}
|
||||
|
||||
String _calculateFiatAmount(String cryptoAmount) {
|
||||
return calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[selectedCryptoCurrency],
|
||||
cryptoAmount: cryptoAmount);
|
||||
}
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
TransactionPriority get transactionPriority =>
|
||||
|
@ -159,6 +160,16 @@ abstract class SendViewModelBase with Store {
|
|||
|
||||
bool get hasCurrecyChanger => walletType == WalletType.haven;
|
||||
|
||||
int estimatedFee(String amount) {
|
||||
return _wallet.calculateEstimatedFee(_settingsStore.priority[_wallet.type], AmountConverter.amountStringToInt(
|
||||
selectedCryptoCurrency, amount));
|
||||
}
|
||||
|
||||
String estimatedFiatFee(String amount) {
|
||||
return _calculateFiatAmount(AmountConverter.amountIntToString(
|
||||
selectedCryptoCurrency, estimatedFee(amount)));
|
||||
}
|
||||
|
||||
final WalletBase _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final SendTemplateViewModel sendTemplateViewModel;
|
||||
|
|
Loading…
Reference in a new issue