mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
CW-1125-d-euro-ui-enhancements (#2369)
* feat: enhance dEuro Savings UI and functionality with fiat support and tooltips * feat: add "Reinvest Interest" feature and improve dEuro Savings functionality - Implemented the "Reinvest Interest" feature for dEuro Savings. - Updated localized strings for multiple languages. - Enhanced error handling for insufficient gas fees. - Incorporated loading state and tooltips in Savings Card and Interest Card. - Improved UI responsiveness and button state management. * feat: localize deuro tooltips * feat: enhance dEuro Savings with reinvestment feature and localized strings - Added "Reinvest Interest" functionality for dEuro Savings. - Updated localized strings across multiple languages. - Improved modal bottom sheet handling for savings add/remove operations. - Enhanced tooltips and UI responsiveness. * feat: improve dEuro Savings page with info chips and localized strings * Update res/values/strings_de.arb * fix: update dEuro action type reset in transaction handling
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/core/utilities.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';
|
||||
@@ -8,10 +9,9 @@ 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:cw_core/pending_transaction.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
||||
part 'deuro_view_model.g.dart';
|
||||
@@ -21,62 +21,47 @@ class DEuroViewModel = DEuroViewModelBase with _$DEuroViewModel;
|
||||
abstract class DEuroViewModelBase with Store {
|
||||
final AppStore _appStore;
|
||||
|
||||
DEuroViewModelBase(this._appStore, this.balanceViewModel, this._settingsStore, this._fiatConversationStore) {
|
||||
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;
|
||||
isFiatDisabled ? '' : '$pendingTransactionFiatAmount ${fiat.title}';
|
||||
|
||||
@computed
|
||||
String get pendingTransactionFeeFiatAmountFormatted =>
|
||||
isFiatDisabled ? '' : pendingTransactionFeeFiatAmount + ' ' + fiat.title;
|
||||
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';
|
||||
}
|
||||
}
|
||||
String get pendingTransactionFiatAmount =>
|
||||
transaction == null ? '0.00' : _getDEuroFiatAmount(transaction!.amountFormatted);
|
||||
|
||||
@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;
|
||||
return calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[currency]!,
|
||||
cryptoAmount:
|
||||
transaction!.feeFormatted.substring(0, transaction!.feeFormatted.indexOf(" ")),
|
||||
);
|
||||
} else {
|
||||
return '0.00';
|
||||
}
|
||||
@@ -85,9 +70,20 @@ abstract class DEuroViewModelBase with Store {
|
||||
}
|
||||
}
|
||||
|
||||
@computed
|
||||
String get accountBalance {
|
||||
final dEuroKey = balanceViewModel.balances.keys
|
||||
.firstWhereOrNull((e) => e.title == CryptoCurrency.deuro.title);
|
||||
if (dEuroKey == null) return '0.00';
|
||||
return balanceViewModel.balances[dEuroKey]?.availableBalance ?? '0.00';
|
||||
}
|
||||
|
||||
@observable
|
||||
String savingsBalance = '0.00';
|
||||
|
||||
@computed
|
||||
String get fiatSavingsBalance => _getDEuroFiatAmount(savingsBalance);
|
||||
|
||||
@observable
|
||||
ExecutionState state = InitialExecutionState();
|
||||
|
||||
@@ -97,12 +93,21 @@ abstract class DEuroViewModelBase with Store {
|
||||
@observable
|
||||
String accruedInterest = '0.00';
|
||||
|
||||
@computed
|
||||
String get fiatAccruedInterest => _getDEuroFiatAmount(accruedInterest);
|
||||
|
||||
@observable
|
||||
BigInt approvedTokens = BigInt.zero;
|
||||
|
||||
@computed
|
||||
bool get isEnabled => approvedTokens > BigInt.zero;
|
||||
|
||||
@observable
|
||||
bool isLoading = true;
|
||||
|
||||
@observable
|
||||
DEuroActionType actionType = DEuroActionType.none;
|
||||
|
||||
@observable
|
||||
PendingTransaction? transaction = null;
|
||||
|
||||
@@ -122,6 +127,7 @@ abstract class DEuroViewModelBase with Store {
|
||||
accruedInterest = ethereum!
|
||||
.formatterEthereumAmountToDouble(amount: await accruedInterestRaw)
|
||||
.toStringAsFixed(6);
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -133,6 +139,11 @@ abstract class DEuroViewModelBase with Store {
|
||||
|
||||
@action
|
||||
Future<void> prepareApproval() async {
|
||||
final ethBalance = balanceViewModel.balances[CryptoCurrency.eth]?.availableBalance ?? "0";
|
||||
if ((double.tryParse(ethBalance) ?? 0) == 0) {
|
||||
state = NoEtherState();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
@@ -149,6 +160,7 @@ abstract class DEuroViewModelBase with Store {
|
||||
state = TransactionCommitting();
|
||||
final amount = parseFixed(amountRaw, 18);
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
actionType = isAdding ? DEuroActionType.deposit : DEuroActionType.withdraw;
|
||||
transaction = await (isAdding
|
||||
? ethereum!.addDEuroSaving(_appStore.wallet!, amount, priority)
|
||||
: ethereum!.removeDEuroSaving(_appStore.wallet!, amount, priority));
|
||||
@@ -160,6 +172,18 @@ abstract class DEuroViewModelBase with Store {
|
||||
|
||||
Future<void> prepareCollectInterest() => prepareSavingsEdit(accruedInterest, false);
|
||||
|
||||
Future<void> prepareReinvestInterest() async {
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
actionType = DEuroActionType.reinvest;
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
transaction = await ethereum!.reinvestDEuroInterest(_appStore.wallet!, priority);
|
||||
state = InitialExecutionState();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> commitTransaction() async {
|
||||
if (transaction != null) {
|
||||
@@ -167,6 +191,7 @@ abstract class DEuroViewModelBase with Store {
|
||||
state = TransactionCommitting();
|
||||
await transaction!.commit();
|
||||
transaction = null;
|
||||
actionType = DEuroActionType.none;
|
||||
reloadSavingsUserData();
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
@@ -194,6 +219,32 @@ abstract class DEuroViewModelBase with Store {
|
||||
void dismissTransaction() {
|
||||
transaction = null;
|
||||
approvalTransaction = null;
|
||||
actionType = DEuroActionType.none;
|
||||
state = InitialExecutionState();
|
||||
}
|
||||
|
||||
String _getDEuroFiatAmount(String amount) {
|
||||
try {
|
||||
CryptoCurrency deuro = CryptoCurrency.deuro;
|
||||
final keys = _fiatConversationStore.prices.keys.toList();
|
||||
for (final key in keys) {
|
||||
if (key.title == "DEURO") deuro = key;
|
||||
}
|
||||
return calculateFiatAmount(
|
||||
price: _fiatConversationStore.prices[deuro]!,
|
||||
cryptoAmount: amount,
|
||||
);
|
||||
} catch (_) {
|
||||
return '0.00';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NoEtherState extends ExecutionState {}
|
||||
|
||||
enum DEuroActionType {
|
||||
deposit,
|
||||
withdraw,
|
||||
reinvest,
|
||||
none;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user