feat: introduce feeFormattedValue and feeFormatted to remove string parsing in view model (#2366)

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
cyan
2025-07-11 03:31:12 +03:00
committed by GitHub
co-authored by Omar Hatem
parent 342269a496
commit 0e23138040
13 changed files with 47 additions and 15 deletions
@@ -59,7 +59,10 @@ class PendingBitcoinTransaction with PendingTransaction {
String get amountFormatted => bitcoinAmountToString(amount: amount);
@override
String get feeFormatted => bitcoinAmountToString(amount: fee);
String get feeFormatted => "$feeFormattedValue BTC";
@override
String get feeFormattedValue => bitcoinAmountToString(amount: fee);
@override
int? get outputCount => _tx.outputs.length;
@@ -34,7 +34,10 @@ class PendingBitcoinCashTransaction with PendingTransaction {
String get amountFormatted => bitcoinAmountToString(amount: amount);
@override
String get feeFormatted => bitcoinAmountToString(amount: fee);
String get feeFormatted => "$feeFormattedValue BCH";
@override
String get feeFormattedValue => bitcoinAmountToString(amount: fee);
final List<void Function(ElectrumTransactionInfo transaction)> _listeners;
+1
View File
@@ -9,6 +9,7 @@ mixin PendingTransaction {
String get id;
String get amountFormatted;
String get feeFormatted;
String get feeFormattedValue;
String? feeRate;
String get hex;
int? get outputCount => null;
+4 -1
View File
@@ -22,7 +22,10 @@ class DecredPendingTransaction with PendingTransaction {
String get amountFormatted => decredAmountToString(amount: amount);
@override
String get feeFormatted => decredAmountToString(amount: fee);
String get feeFormatted => "$feeFormattedValue DCR";
@override
String get feeFormattedValue => decredAmountToString(amount: fee);
@override
String get hex => rawHex;
@@ -36,8 +36,13 @@ class PendingEVMChainTransaction with PendingTransaction {
@override
String get feeFormatted {
return "$feeFormattedValue $feeCurrency";
}
@override
String get feeFormattedValue {
final _fee = (fee / BigInt.from(pow(10, 18))).toString();
return "${_fee.substring(0, min(10, _fee.length))} $feeCurrency";
return _fee.substring(0, min(10, _fee.length));
}
@override
@@ -36,7 +36,10 @@ class PendingMoneroTransaction with PendingTransaction {
CryptoCurrency.xmr, pendingTransactionDescription.amount);
@override
String get feeFormatted => AmountConverter.amountIntToString(
String get feeFormatted => "$feeFormattedValue XMR";
@override
String get feeFormattedValue => AmountConverter.amountIntToString(
CryptoCurrency.xmr, pendingTransactionDescription.fee);
bool shouldCommitUR() => isViewOnly;
+4 -1
View File
@@ -29,7 +29,10 @@ class PendingNanoTransaction with PendingTransaction {
}
@override
String get feeFormatted => "0";
String get feeFormatted => "$feeFormattedValue XNO";
@override
String get feeFormattedValue => "0";
@override
Future<void> commit() async {
@@ -32,7 +32,10 @@ class PendingSolanaTransaction with PendingTransaction {
}
@override
String get feeFormatted => fee.toString();
String get feeFormatted => "$feeFormattedValue SOL";
@override
String get feeFormattedValue => fee.toString();
@override
String get hex => serializedTransaction;
+4 -1
View File
@@ -23,7 +23,10 @@ class PendingTronTransaction with PendingTransaction {
Future<void> commit() async => await sendTransaction();
@override
String get feeFormatted => fee;
String get feeFormatted => "$feeFormattedValue TRX";
@override
String get feeFormattedValue => fee;
@override
String get hex => bytesToHex(signedTransaction);
@@ -32,7 +32,10 @@ class PendingWowneroTransaction with PendingTransaction {
AmountConverter.amountIntToString(CryptoCurrency.wow, pendingTransactionDescription.amount);
@override
String get feeFormatted =>
String get feeFormatted => "$feeFormattedValue WOW";
@override
String get feeFormattedValue =>
AmountConverter.amountIntToString(CryptoCurrency.wow, pendingTransactionDescription.fee);
@override
@@ -35,7 +35,10 @@ class PendingZanoTransaction with PendingTransaction {
String get amountFormatted => ZanoFormatter.bigIntAmountToString(amount, decimalPoint);
@override
String get feeFormatted => ZanoFormatter.bigIntAmountToString(fee);
String get feeFormatted => "$feeFormattedValue ZANO";
@override
String get feeFormattedValue => ZanoFormatter.bigIntAmountToString(fee);
TransferResult? transferResult;
@@ -64,10 +64,9 @@ abstract class DEuroViewModelBase with Store {
if (transaction != null) {
final currency = CryptoCurrency.eth;
return calculateFiatAmount(
price: _fiatConversationStore.prices[currency]!,
cryptoAmount:
transaction!.feeFormatted.substring(0, transaction!.feeFormatted.indexOf(" ")),
);
price: _fiatConversationStore.prices[currency]!,
cryptoAmount: transaction!.feeFormattedValue,
);
} else {
return '0.00';
}
+1 -1
View File
@@ -183,7 +183,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
final currency = pendingTransactionFeeCurrency(walletType);
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[currency]!,
cryptoAmount: pendingTransaction!.feeFormatted.substring(0, pendingTransaction!.feeFormatted.indexOf(" ")),
cryptoAmount: pendingTransaction!.feeFormattedValue,
);
return fiat;
} else {