mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
Deuro Savings Error Handling (#2340)
* feat(deuro): Enhance gas fee handling and error management for Deuro Savings Transactions. This change: - Introduces DeuroGasFeeException to handle insufficient ETH for gas fees. - Adds check for ETH balance before savings transactions to prevent failures due to insufficient funds. - Updates savings transaction methods to include error handling. - Adds UI feedback for transaction failures in DEuroSavingsPage. * Fix conflicts * Update cw_ethereum/lib/deuro/deuro_savings.dart Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com>
This commit is contained in:
co-authored by
Konstantin Ullrich
Omar Hatem
parent
b3c20a5818
commit
5aeb6b7522
@@ -4,9 +4,11 @@ import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
import 'package:cake_wallet/src/screens/integrations/deuro/widgets/interest_card_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/integrations/deuro/widgets/savings_card_widget.dart';
|
||||
import 'package:cake_wallet/src/screens/integrations/deuro/widgets/savings_edit_sheet.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||
import 'package:cake_wallet/src/widgets/bottom_sheet/confirm_sending_bottom_sheet_widget.dart';
|
||||
import 'package:cake_wallet/src/widgets/bottom_sheet/info_bottom_sheet_widget.dart';
|
||||
import 'package:cake_wallet/src/widgets/gradient_background.dart';
|
||||
import 'package:cake_wallet/utils/show_pop_up.dart';
|
||||
import 'package:cake_wallet/view_model/integrations/deuro_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
@@ -190,6 +192,24 @@ class DEuroSavingsPage extends BasePage {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (state is FailureState) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
if (!context.mounted) return;
|
||||
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext popupContext) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(popupContext).error,
|
||||
alertContent: state.error,
|
||||
buttonText: S.of(popupContext).ok,
|
||||
buttonAction: () => Navigator.of(popupContext).pop(),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
_isReactionsSet = true;
|
||||
|
||||
@@ -46,10 +46,8 @@ abstract class DEuroViewModelBase with Store {
|
||||
|
||||
@action
|
||||
Future<void> reloadSavingsUserData() async {
|
||||
final savingsBalanceRaw =
|
||||
ethereum!.getDEuroSavingsBalance(_appStore.wallet!);
|
||||
final accruedInterestRaw =
|
||||
ethereum!.getDEuroAccruedInterest(_appStore.wallet!);
|
||||
final savingsBalanceRaw = ethereum!.getDEuroSavingsBalance(_appStore.wallet!);
|
||||
final accruedInterestRaw = ethereum!.getDEuroAccruedInterest(_appStore.wallet!);
|
||||
|
||||
approvedTokens = await ethereum!.getDEuroSavingsApproved(_appStore.wallet!);
|
||||
|
||||
@@ -63,56 +61,73 @@ abstract class DEuroViewModelBase with Store {
|
||||
|
||||
@action
|
||||
Future<void> reloadInterestRate() async {
|
||||
final interestRateRaw =
|
||||
await ethereum!.getDEuroInterestRate(_appStore.wallet!);
|
||||
final interestRateRaw = await ethereum!.getDEuroInterestRate(_appStore.wallet!);
|
||||
|
||||
interestRate = (interestRateRaw / BigInt.from(10000)).toString();
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> prepareApproval() async {
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
approvalTransaction =
|
||||
await ethereum!.enableDEuroSaving(_appStore.wallet!, priority);
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
approvalTransaction = await ethereum!.enableDEuroSaving(_appStore.wallet!, priority);
|
||||
state = InitialExecutionState();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> prepareSavingsEdit(String amountRaw, bool isAdding) async {
|
||||
final amount = BigInt.from(num.parse(amountRaw) * pow(10, 18));
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
transaction = await (isAdding
|
||||
? ethereum!.addDEuroSaving(_appStore.wallet!, amount, priority)
|
||||
: ethereum!.removeDEuroSaving(_appStore.wallet!, amount, priority));
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
final amount = BigInt.from(num.parse(amountRaw) * pow(10, 18));
|
||||
final priority = _appStore.settingsStore.priority[WalletType.ethereum]!;
|
||||
transaction = await (isAdding
|
||||
? ethereum!.addDEuroSaving(_appStore.wallet!, amount, priority)
|
||||
: ethereum!.removeDEuroSaving(_appStore.wallet!, amount, priority));
|
||||
state = InitialExecutionState();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> prepareCollectInterest() =>
|
||||
prepareSavingsEdit(accruedInterest, false);
|
||||
Future<void> prepareCollectInterest() => prepareSavingsEdit(accruedInterest, false);
|
||||
|
||||
@action
|
||||
Future<void> commitTransaction() async {
|
||||
if (transaction != null) {
|
||||
state = TransactionCommitting();
|
||||
await transaction!.commit();
|
||||
transaction = null;
|
||||
reloadSavingsUserData();
|
||||
state = TransactionCommitted();
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
await transaction!.commit();
|
||||
transaction = null;
|
||||
reloadSavingsUserData();
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> commitApprovalTransaction() async {
|
||||
if (approvalTransaction != null) {
|
||||
state = TransactionCommitting();
|
||||
await approvalTransaction!.commit();
|
||||
approvalTransaction = null;
|
||||
reloadSavingsUserData();
|
||||
state = TransactionCommitted();
|
||||
try {
|
||||
state = TransactionCommitting();
|
||||
await approvalTransaction!.commit();
|
||||
approvalTransaction = null;
|
||||
reloadSavingsUserData();
|
||||
state = TransactionCommitted();
|
||||
} catch (e) {
|
||||
state = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void dismissTransaction() {
|
||||
transaction == null;
|
||||
transaction = null;
|
||||
approvalTransaction = null;
|
||||
state = InitialExecutionState();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user