Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Libdart compatibility #1184

Merged
merged 10 commits into from
Dec 17, 2024
1 change: 1 addition & 0 deletions l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-localization-file: localizations.dart
untranslated-messages-file: untranslated_messages.txt
8 changes: 4 additions & 4 deletions lib/application/aeswap/dex_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ Future<double> _estimateTokenInFiat(
String tokenAddress,
) async {
if (tokenAddress.isUCO) {
return ref.watch(
aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO
.select((value) => value.usd),
);
return (await ref.watch(
aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.future,
))
.usd;
} else {
final environment = ref.watch(environmentProvider);
return await ref.watch(
Expand Down
2 changes: 1 addition & 1 deletion lib/application/aeswap/dex_token.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/application/market_price.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ Future<MarketPrice> _currencyMarketPrice(
Future<MarketPrice> _selectedCurrencyMarketPrice(
Ref ref,
) async {
final archethicOracleUCO =
ref.watch(aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO);
final archethicOracleUCO = await ref.watch(
aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.future,
);
return MarketPrice(
amount: archethicOracleUCO.usd,
lastLoading: archethicOracleUCO.timestamp,
Expand Down
2 changes: 1 addition & 1 deletion lib/application/market_price.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 8 additions & 12 deletions lib/domain/repositories/transaction_remote.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import 'package:aewallet/model/data/account.dart';
import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic;

typedef TransactionConfirmationHandler = Future<void> Function(
archethic.TransactionSenderInterface sender,
archethic.TransactionConfirmation confirmation,
);
typedef TransactionErrorHandler = Future<void> Function(
archethic.TransactionSenderInterface sender,
archethic.TransactionError error,
);

Expand All @@ -22,11 +20,16 @@ abstract class TransactionRemoteRepositoryInterface {

Future<Result<double, Failure>> calculateFees(Transaction transaction);

Future<void> send({
Future<archethic.TransactionConfirmation?> send({
required Transaction transaction,
Duration timeout = const Duration(seconds: 10),
required TransactionConfirmationHandler onConfirmation,
required TransactionErrorHandler onError,
TransactionConfirmationHandler? onConfirmation,
});

Future<archethic.TransactionConfirmation?> sendSignedRaw({
required archethic.Transaction transaction,
Duration timeout = const Duration(seconds: 10),
TransactionConfirmationHandler? onConfirmation,
});

Future<archethic.Transaction> buildTransactionRaw(
Expand All @@ -36,13 +39,6 @@ abstract class TransactionRemoteRepositoryInterface {
String serviceName,
);

Future<void> sendSignedRaw({
required archethic.Transaction transactionSignedRaw,
Duration timeout = const Duration(seconds: 10),
required TransactionConfirmationHandler onConfirmation,
required TransactionErrorHandler onError,
});

Future<String?> getLastTransactionAddress({
required String genesisAddress,
});
Expand Down
15 changes: 0 additions & 15 deletions lib/domain/repositories/transaction_validation_ratios.dart

This file was deleted.

101 changes: 45 additions & 56 deletions lib/domain/usecases/aeswap/add_liquidity.usecase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import 'dart:async';

import 'package:aewallet/domain/repositories/transaction_remote.dart';
import 'package:aewallet/domain/repositories/transaction_validation_ratios.dart';
import 'package:aewallet/model/blockchain/keychain_secured_infos.dart';
import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/modules/aeswap/application/contracts/archethic_contract.dart';
Expand Down Expand Up @@ -95,67 +94,57 @@ class AddLiquidityCase with aedappfm.TransactionMixin {

liquidityAddNotifier.setTransactionAddLiquidity(transationSignedRaw);

await transactionRepository.sendSignedRaw(
transactionSignedRaw: transationSignedRaw,
onConfirmation: (sender, confirmation) async {
if (archethic.TransactionConfirmation.isEnoughConfirmations(
confirmation.nbConfirmations,
confirmation.maxConfirmations,
TransactionValidationRatios.addLiquidity,
)) {
sender.close();
final confirmation = await transactionRepository.sendSignedRaw(
transaction: transationSignedRaw,
);

liquidityAddNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setLiquidityAddOk(true);
if (confirmation == null) return;
liquidityAddNotifier
..setResumeProcess(false)
..setLiquidityAddOk(true);

notificationService.start(
operationId,
DexNotification.addLiquidity(
txAddress: transationSignedRaw.address!.address,
),
);
notificationService.start(
operationId,
DexNotification.addLiquidity(
txAddress: transationSignedRaw.address!.address,
),
);

final amount = await aedappfm.PeriodicFuture.periodic<double>(
() => getAmountFromTxInput(
transationSignedRaw.address!.address!,
lpToken.address,
apiService,
),
sleepDuration: const Duration(seconds: 3),
until: (amount) => amount > 0,
timeout: const Duration(minutes: 1),
);
final amount = await aedappfm.PeriodicFuture.periodic<double>(
() => getAmountFromTxInput(
transationSignedRaw.address!.address!,
lpToken.address,
apiService,
),
sleepDuration: const Duration(seconds: 3),
until: (amount) => amount > 0,
timeout: const Duration(minutes: 1),
);

liquidityAddNotifier.setFinalAmount(amount);
liquidityAddNotifier.setFinalAmount(amount);

notificationService.succeed(
operationId,
DexNotification.addLiquidity(
txAddress: transationSignedRaw.address!.address,
lpToken: lpToken,
amount: amount,
),
);
}
},
onError: (sender, error) async {
notificationService.failed(
operationId,
aedappfm.Failure.fromError(error.messageLabel),
);
liquidityAddNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setLiquidityAddOk(false)
..setFailure(
aedappfm.Failure.other(
cause: error.messageLabel.capitalize(),
),
);
},
notificationService.succeed(
operationId,
DexNotification.addLiquidity(
txAddress: transationSignedRaw.address!.address,
lpToken: lpToken,
amount: amount,
),
);
} on archethic.TransactionError catch (error) {
notificationService.failed(
operationId,
aedappfm.Failure.fromError(error.messageLabel),
);
liquidityAddNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setLiquidityAddOk(false)
..setFailure(
aedappfm.Failure.other(
cause: error.messageLabel.capitalize(),
),
);
} catch (e) {
liquidityAddNotifier
..setResumeProcess(false)
Expand Down
126 changes: 58 additions & 68 deletions lib/domain/usecases/aeswap/claim_farm_lock.usecase.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:async';

import 'package:aewallet/domain/repositories/transaction_remote.dart';
import 'package:aewallet/domain/repositories/transaction_validation_ratios.dart';
import 'package:aewallet/model/blockchain/keychain_secured_infos.dart';
import 'package:aewallet/model/data/account.dart';
import 'package:aewallet/modules/aeswap/application/contracts/archethic_contract.dart';
Expand Down Expand Up @@ -91,78 +91,68 @@ class ClaimFarmLockCase with aedappfm.TransactionMixin {
transationSignedRaw,
);

await transactionRepository.sendSignedRaw(
transactionSignedRaw: transationSignedRaw,
onConfirmation: (sender, confirmation) async {
if (archethic.TransactionConfirmation.isEnoughConfirmations(
confirmation.nbConfirmations,
confirmation.maxConfirmations,
TransactionValidationRatios.claimFarmLock,
)) {
sender.close();

farmClaimLockNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setFarmLockClaimOk(true);

notificationService.start(
operationId,
DexNotification.claimFarmLock(
txAddress: transationSignedRaw.address!.address,
),
);
final confirmation = await transactionRepository.sendSignedRaw(
transaction: transationSignedRaw,
);

await aedappfm.PeriodicFuture.periodic<bool>(
() => isSCCallExecuted(
apiService,
farmGenesisAddress,
transationSignedRaw.address!.address!,
),
sleepDuration: const Duration(seconds: 3),
until: (depositOk) => depositOk == true,
timeout: const Duration(minutes: 1),
);
if (confirmation == null) return;
farmClaimLockNotifier
..setResumeProcess(false)
..setFarmLockClaimOk(true);

final amount = await aedappfm.PeriodicFuture.periodic<double>(
() => getAmountFromTxInput(
transationSignedRaw.address!.address!,
rewardToken.address,
apiService,
),
sleepDuration: const Duration(seconds: 3),
until: (amount) => amount > 0,
timeout: const Duration(minutes: 1),
);
notificationService.start(
operationId,
DexNotification.claimFarmLock(
txAddress: transationSignedRaw.address!.address,
),
);

farmClaimLockNotifier.setFinalAmount(amount);
await aedappfm.PeriodicFuture.periodic<bool>(
() => isSCCallExecuted(
apiService,
farmGenesisAddress,
transationSignedRaw.address!.address!,
),
sleepDuration: const Duration(seconds: 3),
until: (depositOk) => depositOk == true,
timeout: const Duration(minutes: 1),
);

notificationService.succeed(
operationId,
DexNotification.claimFarmLock(
txAddress: transationSignedRaw.address!.address,
amount: amount,
rewardToken: rewardToken,
),
);
}
},
onError: (sender, error) async {
notificationService.failed(
operationId,
aedappfm.Failure.fromError(error.messageLabel),
);
farmClaimLockNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setFarmLockClaimOk(false)
..setFailure(
aedappfm.Failure.other(
cause: error.messageLabel.capitalize(),
),
);
},
final amount = await aedappfm.PeriodicFuture.periodic<double>(
() => getAmountFromTxInput(
transationSignedRaw.address!.address!,
rewardToken.address,
apiService,
),
sleepDuration: const Duration(seconds: 3),
until: (amount) => amount > 0,
timeout: const Duration(minutes: 1),
);

farmClaimLockNotifier.setFinalAmount(amount);

notificationService.succeed(
operationId,
DexNotification.claimFarmLock(
txAddress: transationSignedRaw.address!.address,
amount: amount,
rewardToken: rewardToken,
),
);
} on archethic.TransactionError catch (error) {
notificationService.failed(
operationId,
aedappfm.Failure.fromError(error.messageLabel),
);
farmClaimLockNotifier
..setResumeProcess(false)
..setProcessInProgress(false)
..setFarmLockClaimOk(false)
..setFailure(
aedappfm.Failure.other(
cause: error.messageLabel.capitalize(),
),
);
} catch (e) {
farmClaimLockNotifier
..setResumeProcess(false)
Expand Down
Loading
Loading