diff --git a/cw_ethereum/lib/deuro/deuro_savings.dart b/cw_ethereum/lib/deuro/deuro_savings.dart index bce05905c..b00d26fcd 100644 --- a/cw_ethereum/lib/deuro/deuro_savings.dart +++ b/cw_ethereum/lib/deuro/deuro_savings.dart @@ -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')) { diff --git a/cw_evm/lib/evm_chain_client.dart b/cw_evm/lib/evm_chain_client.dart index 1fecc9c1e..b7377c54e 100644 --- a/cw_evm/lib/evm_chain_client.dart +++ b/cw_evm/lib/evm_chain_client.dart @@ -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', diff --git a/cw_evm/lib/evm_chain_wallet.dart b/cw_evm/lib/evm_chain_wallet.dart index a1285f0e4..fe97e4ea8 100644 --- a/cw_evm/lib/evm_chain_wallet.dart +++ b/cw_evm/lib/evm_chain_wallet.dart @@ -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 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, diff --git a/cw_evm/lib/pending_evm_chain_transaction.dart b/cw_evm/lib/pending_evm_chain_transaction.dart index 61b406470..892d858ef 100644 --- a/cw_evm/lib/pending_evm_chain_transaction.dart +++ b/cw_evm/lib/pending_evm_chain_transaction.dart @@ -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 diff --git a/lib/di.dart b/lib/di.dart index 5a7be0f1f..9583b85ed 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1518,7 +1518,12 @@ Future setup({ getIt.registerFactory(() => StartTorPage(StartTorViewModel(),)); - getIt.registerFactory(() => DEuroViewModel(getIt())); + getIt.registerFactory(() => DEuroViewModel( + getIt(), + getIt(), + getIt(), + getIt(), + )); getIt.registerFactory(() => DEuroSavingsPage(getIt())); diff --git a/lib/ethereum/cw_ethereum.dart b/lib/ethereum/cw_ethereum.dart index a6a6a7205..1e5530f8a 100644 --- a/lib/ethereum/cw_ethereum.dart +++ b/lib/ethereum/cw_ethereum.dart @@ -213,7 +213,7 @@ class CWEthereum extends Ethereum { Future 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 diff --git a/lib/polygon/cw_polygon.dart b/lib/polygon/cw_polygon.dart index 2e6e7dd13..85fd4bf4b 100644 --- a/lib/polygon/cw_polygon.dart +++ b/lib/polygon/cw_polygon.dart @@ -189,7 +189,7 @@ class CWPolygon extends Polygon { Future 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( diff --git a/lib/src/screens/integrations/deuro/savings_page.dart b/lib/src/screens/integrations/deuro/savings_page.dart index 0b0f4941a..232509c73 100644 --- a/lib/src/screens/integrations/deuro/savings_page.dart +++ b/lib/src/screens/integrations/deuro/savings_page.dart @@ -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); diff --git a/lib/view_model/integrations/deuro_view_model.dart b/lib/view_model/integrations/deuro_view_model.dart index a8bf34dbe..925df1760 100644 --- a/lib/view_model/integrations/deuro_view_model.dart +++ b/lib/view_model/integrations/deuro_view_model.dart @@ -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'; diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 4ba48790a..07d695430 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -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';