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

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>

cyan committed Jul 11, 2025 at 02:31 UTC 0e23138040c191bebdec985f43e0fa6f1cf09486
13 files changed +47 -15
cw_bitcoin/lib/pending_bitcoin_transaction.dart
+4 -1
@@ -59,7 +59,10 @@ class PendingBitcoinTransaction with PendingTransaction {
59 String get amountFormatted => bitcoinAmountToString(amount: amount);
60
61 @override
62 - String get feeFormatted => bitcoinAmountToString(amount: fee);
62 + String get feeFormatted => "$feeFormattedValue BTC";
63 +
64 + @override
65 + String get feeFormattedValue => bitcoinAmountToString(amount: fee);
66
67 @override
68 int? get outputCount => _tx.outputs.length;
cw_bitcoin_cash/lib/src/pending_bitcoin_cash_transaction.dart
+4 -1
@@ -34,7 +34,10 @@ class PendingBitcoinCashTransaction with PendingTransaction {
34 String get amountFormatted => bitcoinAmountToString(amount: amount);
35
36 @override
37 - String get feeFormatted => bitcoinAmountToString(amount: fee);
37 + String get feeFormatted => "$feeFormattedValue BCH";
38 +
39 + @override
40 + String get feeFormattedValue => bitcoinAmountToString(amount: fee);
41
42 final List<void Function(ElectrumTransactionInfo transaction)> _listeners;
43
cw_core/lib/pending_transaction.dart
+1
@@ -9,6 +9,7 @@ mixin PendingTransaction {
9 String get id;
10 String get amountFormatted;
11 String get feeFormatted;
12 + String get feeFormattedValue;
13 String? feeRate;
14 String get hex;
15 int? get outputCount => null;
cw_decred/lib/pending_transaction.dart
+4 -1
@@ -22,7 +22,10 @@ class DecredPendingTransaction with PendingTransaction {
22 String get amountFormatted => decredAmountToString(amount: amount);
23
24 @override
25 - String get feeFormatted => decredAmountToString(amount: fee);
25 + String get feeFormatted => "$feeFormattedValue DCR";
26 +
27 + @override
28 + String get feeFormattedValue => decredAmountToString(amount: fee);
29
30 @override
31 String get hex => rawHex;
cw_evm/lib/pending_evm_chain_transaction.dart
+6 -1
@@ -36,8 +36,13 @@ class PendingEVMChainTransaction with PendingTransaction {
36
37 @override
38 String get feeFormatted {
39 + return "$feeFormattedValue $feeCurrency";
40 + }
41 +
42 + @override
43 + String get feeFormattedValue {
44 final _fee = (fee / BigInt.from(pow(10, 18))).toString();
40 - return "${_fee.substring(0, min(10, _fee.length))} $feeCurrency";
45 + return _fee.substring(0, min(10, _fee.length));
46 }
47
48 @override
cw_monero/lib/pending_monero_transaction.dart
+4 -1
@@ -36,7 +36,10 @@ class PendingMoneroTransaction with PendingTransaction {
36 CryptoCurrency.xmr, pendingTransactionDescription.amount);
37
38 @override
39 - String get feeFormatted => AmountConverter.amountIntToString(
39 + String get feeFormatted => "$feeFormattedValue XMR";
40 +
41 + @override
42 + String get feeFormattedValue => AmountConverter.amountIntToString(
43 CryptoCurrency.xmr, pendingTransactionDescription.fee);
44
45 bool shouldCommitUR() => isViewOnly;
cw_nano/lib/pending_nano_transaction.dart
+4 -1
@@ -29,7 +29,10 @@ class PendingNanoTransaction with PendingTransaction {
29 }
30
31 @override
32 - String get feeFormatted => "0";
32 + String get feeFormatted => "$feeFormattedValue XNO";
33 +
34 + @override
35 + String get feeFormattedValue => "0";
36
37 @override
38 Future<void> commit() async {
cw_solana/lib/pending_solana_transaction.dart
+4 -1
@@ -32,7 +32,10 @@ class PendingSolanaTransaction with PendingTransaction {
32 }
33
34 @override
35 - String get feeFormatted => fee.toString();
35 + String get feeFormatted => "$feeFormattedValue SOL";
36 +
37 + @override
38 + String get feeFormattedValue => fee.toString();
39
40 @override
41 String get hex => serializedTransaction;
cw_tron/lib/pending_tron_transaction.dart
+4 -1
@@ -23,7 +23,10 @@ class PendingTronTransaction with PendingTransaction {
23 Future<void> commit() async => await sendTransaction();
24
25 @override
26 - String get feeFormatted => fee;
26 + String get feeFormatted => "$feeFormattedValue TRX";
27 +
28 + @override
29 + String get feeFormattedValue => fee;
30
31 @override
32 String get hex => bytesToHex(signedTransaction);
cw_wownero/lib/pending_wownero_transaction.dart
+4 -1
@@ -32,7 +32,10 @@ class PendingWowneroTransaction with PendingTransaction {
32 AmountConverter.amountIntToString(CryptoCurrency.wow, pendingTransactionDescription.amount);
33
34 @override
35 - String get feeFormatted =>
35 + String get feeFormatted => "$feeFormattedValue WOW";
36 +
37 + @override
38 + String get feeFormattedValue =>
39 AmountConverter.amountIntToString(CryptoCurrency.wow, pendingTransactionDescription.fee);
40
41 @override
cw_zano/lib/model/pending_zano_transaction.dart
+4 -1
@@ -35,7 +35,10 @@ class PendingZanoTransaction with PendingTransaction {
35 String get amountFormatted => ZanoFormatter.bigIntAmountToString(amount, decimalPoint);
36
37 @override
38 - String get feeFormatted => ZanoFormatter.bigIntAmountToString(fee);
38 + String get feeFormatted => "$feeFormattedValue ZANO";
39 +
40 + @override
41 + String get feeFormattedValue => ZanoFormatter.bigIntAmountToString(fee);
42
43 TransferResult? transferResult;
44
lib/view_model/integrations/deuro_view_model.dart
+3 -4
@@ -64,10 +64,9 @@ abstract class DEuroViewModelBase with Store {
64 if (transaction != null) {
65 final currency = CryptoCurrency.eth;
66 return calculateFiatAmount(
67 - price: _fiatConversationStore.prices[currency]!,
68 - cryptoAmount:
69 - transaction!.feeFormatted.substring(0, transaction!.feeFormatted.indexOf(" ")),
70 - );
67 + price: _fiatConversationStore.prices[currency]!,
68 + cryptoAmount: transaction!.feeFormattedValue,
69 + );
70 } else {
71 return '0.00';
72 }
lib/view_model/send/send_view_model.dart
+1 -1
@@ -183,7 +183,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
183 final currency = pendingTransactionFeeCurrency(walletType);
184 final fiat = calculateFiatAmount(
185 price: _fiatConversationStore.prices[currency]!,
186 - cryptoAmount: pendingTransaction!.feeFormatted.substring(0, pendingTransaction!.feeFormatted.indexOf(" ")),
186 + cryptoAmount: pendingTransaction!.feeFormattedValue,
187 );
188 return fiat;
189 } else {