feat: show gas conversion rate for dEURO savings (#2351)

* feat: show gas currency on EVM chains

* feat: show gas conversion rate for dEURO savings

* Update lib/polygon/cw_polygon.dart [skip ci]

* Update cw_evm/lib/evm_chain_wallet.dart [skip ci]

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
cyan
2025-07-03 04:09:07 +03:00
committed by GitHub
co-authored by Omar Hatem
parent db9cb0dd32
commit ae3c4d24f9
10 changed files with 96 additions and 9 deletions
+3
View File
@@ -89,6 +89,7 @@ class DEuro {
final sendTransaction = () => _wallet.getWeb3Client()!.sendRawTransaction(signedTransaction);
return PendingEVMChainTransaction(
feeCurrency: "ETH",
sendTransaction: sendTransaction,
signedTransaction: signedTransaction,
fee: BigInt.from(fee.estimatedGasFee),
@@ -131,6 +132,7 @@ class DEuro {
signedTransaction: signedTransaction,
fee: BigInt.from(fee.estimatedGasFee),
amount: amount.toString(),
feeCurrency: "ETH",
exponent: 18);
} catch (e) {
if (e.toString().contains('insufficient funds for gas')) {
@@ -156,6 +158,7 @@ class DEuro {
_savingsGateway.self.address.hexEip55,
CryptoCurrency.deuro,
priority,
"ETH"
)) as PendingEVMChainTransaction;
} catch (e) {
if (e.toString().contains('insufficient funds for gas')) {
+4
View File
@@ -161,6 +161,7 @@ abstract class EVMChainClient {
required int maxFeePerGas,
required EVMChainTransactionPriority priority,
required CryptoCurrency currency,
required String feeCurrency,
required int exponent,
String? contractAddress,
String? data,
@@ -210,6 +211,7 @@ abstract class EVMChainClient {
signedTransaction: prepareSignedTransactionForSending(signedTransaction),
amount: amount.toString(),
fee: gasFee,
feeCurrency: feeCurrency,
sendTransaction: _sendTransaction,
exponent: exponent,
);
@@ -220,6 +222,7 @@ abstract class EVMChainClient {
required String spender,
required BigInt amount,
required BigInt gasFee,
required String feeCurrency,
required int estimatedGasUnits,
required int maxFeePerGas,
required EVMChainTransactionPriority priority,
@@ -255,6 +258,7 @@ abstract class EVMChainClient {
signedTransaction: prepareSignedTransactionForSending(signedTransaction),
amount: amount.toString(),
fee: gasFee,
feeCurrency: feeCurrency,
sendTransaction: () => sendTransaction(signedTransaction),
exponent: exponent,
isInfiniteApproval: amount.toRadixString(16) == 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
+7 -1
View File
@@ -515,6 +515,11 @@ abstract class EVMChainWalletBase
gasFee: estimatedFeesForTransaction,
priority: _credentials.priority!,
currency: transactionCurrency,
feeCurrency: switch (_client.chainId) {
1 => "ETH",
137 => "POL",
_ => ""
},
maxFeePerGas: maxFeePerGasForTransaction,
exponent: exponent,
contractAddress:
@@ -527,7 +532,7 @@ abstract class EVMChainWalletBase
}
Future<PendingTransaction> createApprovalTransaction(BigInt amount, String spender,
CryptoCurrency token, EVMChainTransactionPriority priority) async {
CryptoCurrency token, EVMChainTransactionPriority priority, String feeCurrency) async {
final CryptoCurrency transactionCurrency =
balance.keys.firstWhere((element) => element.title == token.title);
assert(transactionCurrency is Erc20Token);
@@ -553,6 +558,7 @@ abstract class EVMChainWalletBase
priority: priority,
gasFee: BigInt.from(gasFeesModel.estimatedGasFee),
maxFeePerGas: gasFeesModel.maxFeePerGas,
feeCurrency: feeCurrency,
estimatedGasUnits: gasFeesModel.estimatedGasUnits,
exponent: transactionCurrency.decimal,
contractAddress: transactionCurrency.contractAddress,
@@ -9,6 +9,7 @@ class PendingEVMChainTransaction with PendingTransaction {
final Function sendTransaction;
final Uint8List signedTransaction;
final BigInt fee;
final String feeCurrency;
final String amount;
final int exponent;
final bool isInfiniteApproval;
@@ -17,6 +18,7 @@ class PendingEVMChainTransaction with PendingTransaction {
required this.sendTransaction,
required this.signedTransaction,
required this.fee,
required this.feeCurrency,
required this.amount,
required this.exponent,
this.isInfiniteApproval = false,
@@ -35,7 +37,7 @@ class PendingEVMChainTransaction with PendingTransaction {
@override
String get feeFormatted {
final _fee = (fee / BigInt.from(pow(10, 18))).toString();
return _fee.substring(0, min(10, _fee.length));
return "${_fee.substring(0, min(10, _fee.length))} $feeCurrency";
}
@override
+6 -1
View File
@@ -1518,7 +1518,12 @@ Future<void> setup({
getIt.registerFactory(() => StartTorPage(StartTorViewModel(),));
getIt.registerFactory(() => DEuroViewModel(getIt<AppStore>()));
getIt.registerFactory(() => DEuroViewModel(
getIt<AppStore>(),
getIt<BalanceViewModel>(),
getIt<SettingsStore>(),
getIt<FiatConversionStore>(),
));
getIt.registerFactory(() => DEuroSavingsPage(getIt<DEuroViewModel>()));
+1 -1
View File
@@ -213,7 +213,7 @@ class CWEthereum extends Ethereum {
Future<PendingTransaction> createTokenApproval(WalletBase wallet, BigInt amount, String spender,
CryptoCurrency token, TransactionPriority priority) =>
(wallet as EVMChainWallet).createApprovalTransaction(
amount, spender, token, priority as EVMChainTransactionPriority);
amount, spender, token, priority as EVMChainTransactionPriority, "ETH");
// Integrations
@override
+1 -1
View File
@@ -189,7 +189,7 @@ class CWPolygon extends Polygon {
Future<PendingTransaction> createTokenApproval(WalletBase wallet,
BigInt amount, String spender, CryptoCurrency token, TransactionPriority priority) =>
(wallet as EVMChainWallet)
.createApprovalTransaction(amount, spender, token, priority as EVMChainTransactionPriority);
.createApprovalTransaction(amount, spender, token, priority as EVMChainTransactionPriority, "POL");
@override
void setLedgerConnection(
@@ -125,10 +125,10 @@ class DEuroSavingsPage extends BasePage {
currency: CryptoCurrency.deuro,
amount: S.of(bottomSheetContext).send_amount,
amountValue: tx.amountFormatted,
fiatAmountValue: "",
fiatAmountValue: _dEuroViewModel.pendingTransactionFiatAmountFormatted,
fee: S.of(bottomSheetContext).send_estimated_fee,
feeValue: tx.feeFormatted,
feeFiatAmount: "",
feeFiatAmount: _dEuroViewModel.pendingTransactionFeeFiatAmountFormatted,
outputs: [],
onSlideComplete: () async {
Navigator.of(bottomSheetContext).pop(true);
@@ -1,8 +1,15 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/ethereum/ethereum.dart';
import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_core/parse_fixed.dart';
import 'package:mobx/mobx.dart';
@@ -14,10 +21,69 @@ class DEuroViewModel = DEuroViewModelBase with _$DEuroViewModel;
abstract class DEuroViewModelBase with Store {
final AppStore _appStore;
DEuroViewModelBase(this._appStore) {
DEuroViewModelBase(this._appStore, this.balanceViewModel, this._settingsStore, this._fiatConversationStore) {
reloadInterestRate();
reloadSavingsUserData();
}
final BalanceViewModel balanceViewModel;
final SettingsStore _settingsStore;
final FiatConversionStore _fiatConversationStore;
@computed
bool get isFiatDisabled => balanceViewModel.isFiatDisabled;
@computed
String get pendingTransactionFiatAmountFormatted =>
isFiatDisabled ? '' : pendingTransactionFiatAmount + ' ' + fiat.title;
@computed
String get pendingTransactionFeeFiatAmountFormatted =>
isFiatDisabled ? '' : pendingTransactionFeeFiatAmount + ' ' + fiat.title;
FiatCurrency get fiat => _settingsStore.fiatCurrency;
@computed
String get pendingTransactionFiatAmount {
if (transaction == null) {
return '0.00';
}
try {
final keys = _fiatConversationStore.prices.keys.toList();
CryptoCurrency deuro = CryptoCurrency.deuro;
for (var i = 0; i < keys.length; i++) {
if (keys[i].title == "DEURO") {
deuro = keys[i];
}
}
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[deuro]!,
cryptoAmount: transaction!.amountFormatted);
return fiat;
} catch (e) {
printV(e);
return '0.02';
}
}
@computed
String get pendingTransactionFeeFiatAmount {
try {
if (transaction != null) {
final currency = CryptoCurrency.eth;
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[currency]!,
cryptoAmount: transaction!.feeFormatted.substring(0, transaction!.feeFormatted.indexOf(" ")),
);
return fiat;
} else {
return '0.00';
}
} catch (_) {
return '0.00';
}
}
@observable
String savingsBalance = '0.00';
+2 -1
View File
@@ -183,7 +183,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
final currency = pendingTransactionFeeCurrency(walletType);
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[currency]!,
cryptoAmount: pendingTransaction!.feeFormatted);
cryptoAmount: pendingTransaction!.feeFormatted.substring(0, pendingTransaction!.feeFormatted.indexOf(" ")),
);
return fiat;
} else {
return '0.00';