Skip to content

Commit

Permalink
chore:
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 15, 2025
1 parent 6dfddb0 commit c997c17
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 284 deletions.
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/610.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version 4.5.0

- Fix bugs
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
6 changes: 4 additions & 2 deletions lib/application/market_price.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ 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
46 changes: 14 additions & 32 deletions lib/domain/usecases/transaction/send_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,29 +112,13 @@ class SendTransactionUseCase
final AppWallet wallet;
final ApiService apiService;
final NetworksSetting networkSettings;

@override
Future<Result<TransactionConfirmation, TransactionError>> run(
SendTransactionCommand command, {
UseCaseProgressListener? onProgress,
}) async {
final _logger = Logger('SendTransactionUseCase');

final operationCompleter =
Completer<Result<TransactionConfirmation, TransactionError>>();

void _fail(TransactionError error) {
operationCompleter.complete(
Result.failure(error),
);
}

final transactionSender = ArchethicTransactionSender(
phoenixHttpEndpoint: networkSettings.getPhoenixHttpLink(),
websocketEndpoint: networkSettings.getWebsocketUri(),
apiService: apiService,
);

final transaction = await command.toArchethicTransaction(
wallet: wallet,
apiService: apiService,
Expand All @@ -147,8 +131,9 @@ class SendTransactionUseCase
}

try {
// ignore: cascade_invocations
await transactionSender.send(
final confirmation = await ArchethicTransactionSender(
apiService: apiService,
).send(
transaction: transaction,
onConfirmation: (confirmation) async {
onProgress?.call(
Expand All @@ -157,25 +142,22 @@ class SendTransactionUseCase
progress: confirmation.nbConfirmations,
),
);
if (confirmation.isFullyConfirmed) {
_logger.info('Final confirmation received : $confirmation');
operationCompleter.complete(
Result.success(confirmation),
);
return;
}

_logger.info('Confirmation received : $confirmation');
},
onError: (error) async {
_logger.severe('Transaction error received', error);
_fail(error);
},
);
if (confirmation == null) {
return const Result.failure(TransactionError.userRejected());
}

_logger.info('Final confirmation received : $confirmation');
return Result.success(confirmation);
} on TransactionError catch (error) {
_logger.severe('Transaction error received', error);
return Result.failure(error);
} catch (e) {
_fail(const TransactionError.other());
_logger.severe('Transaction error received', e);
return const Result.failure(TransactionError.other());
}

return operationCompleter.future;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import 'package:aewallet/service/app_service.dart';
import 'package:aewallet/util/keychain_util.dart';
import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic;

const blockchainTxVersion = 3;

class ArchethicTransactionRepository
implements TransactionRemoteRepositoryInterface {
ArchethicTransactionRepository({
Expand Down Expand Up @@ -115,10 +117,6 @@ class ArchethicTransactionRepository

final index = indexMap[transfer.transactionLastAddress] ?? 0;

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

var tokenTransferList = <archethic.TokenTransfer>[];
var ucoTransferList = <archethic.UCOTransfer>[];

Expand Down Expand Up @@ -178,10 +176,6 @@ class ArchethicTransactionRepository

final index = indexMap[token.transactionLastAddress] ?? 0;

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

return AddTokenTransactionBuilder.build(
tokenName: token.name,
tokenSymbol: token.symbol,
Expand Down Expand Up @@ -278,8 +272,6 @@ class ArchethicTransactionRepository
required TransactionErrorHandler onError,
}) async {
final transactionSender = archethic.ArchethicTransactionSender(
phoenixHttpEndpoint: phoenixHttpEndpoint,
websocketEndpoint: websocketEndpoint,
apiService: apiService,
);

Expand All @@ -290,10 +282,6 @@ class ArchethicTransactionRepository
transactionSender,
transactionConfirmation,
),
onError: (error) => onError(
transactionSender,
error,
),
);
}

Expand All @@ -305,8 +293,6 @@ class ArchethicTransactionRepository
required TransactionErrorHandler onError,
}) async {
final transactionSender = archethic.ArchethicTransactionSender(
phoenixHttpEndpoint: phoenixHttpEndpoint,
websocketEndpoint: websocketEndpoint,
apiService: apiService,
);

Expand All @@ -317,10 +303,6 @@ class ArchethicTransactionRepository
transactionSender,
transactionConfirmation,
),
onError: (error) => onError(
transactionSender,
error,
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
// ignore_for_file: avoid_redundant_argument_values

import 'dart:convert';
import 'dart:math';
import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic;
import 'package:flutter/foundation.dart';

const blockchainTxVersion = 3;

extension KeychainTransactionBuilder on archethic.Transaction {
/// Builds a creation of keychain Transaction
static Future<archethic.Transaction> build({
Expand All @@ -26,10 +30,6 @@ extension KeychainTransactionBuilder on archethic.Transaction {
),
);

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final keychainTransaction = archethic.Transaction(
type: 'keychain',
version: blockchainTxVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:archethic_wallet_client/archethic_wallet_client.dart' as awc;
class RPCSignTransactionsCommandHandler extends RPCCommandHandler<
awc.SignTransactionRequest, awc.SignTransactionsResult> {
RPCSignTransactionsCommandHandler() : super();

@override
RPCCommand<awc.SignTransactionRequest> commandToModel(
awc.Request dto,
Expand All @@ -16,15 +15,14 @@ class RPCSignTransactionsCommandHandler extends RPCCommandHandler<
<awc.SignTransactionRequestData>[];
final transactions = dto.payload['transactions'];
for (final Map<String, dynamic> transaction in transactions) {
final tx = archethic.Transaction.fromJson(transaction);
final tx = archethic.Transaction.fromNodeRPC(transaction);
final rpcSignTransactionCommandData = awc.SignTransactionRequestData(
data: tx.data!,
version: tx.version,
type: tx.type!,
);
rpcSignTransactionCommandDataList.add(rpcSignTransactionCommandData);
}

return RPCCommand(
origin: dto.origin.toModel,
data: awc.SignTransactionRequest(
Expand Down
53 changes: 4 additions & 49 deletions lib/modules/aeswap/application/contracts/archethic_contract.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
// ignore_for_file: avoid_redundant_argument_values

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
Expand All @@ -13,6 +15,8 @@ import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutte
import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic;
import 'package:decimal/decimal.dart';

const blockchainTxVersion = 3;

class ArchethicContract with aedappfm.TransactionMixin {
const ArchethicContract({
required this.apiService,
Expand Down Expand Up @@ -99,9 +103,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
publicKey: storageNoncePublicKey,
);

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);
final originPrivateKey = apiService.getOriginKey();

final transactionPool = archethic.Transaction(
Expand Down Expand Up @@ -135,9 +136,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
transactionPool,
apiService,
);
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transactionTransfer = archethic.Transaction(
type: 'transfer',
Expand Down Expand Up @@ -192,10 +190,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
final token2minAmount =
Decimal.parse('$token2AmountSorted') * slippagePourcent.toDecimal();

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transactionAdd = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand Down Expand Up @@ -308,10 +302,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
final token2minAmount =
Decimal.parse('$token2AmountSorted') * slippagePourcent.toDecimal();

final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transactionLiquidity = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand Down Expand Up @@ -363,9 +353,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
return aedappfm.Result.guard(() async {
const burnAddress =
'00000000000000000000000000000000000000000000000000000000000000000000';
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transactionLiquidity = archethic.Transaction(
type: 'transfer',
Expand Down Expand Up @@ -423,10 +410,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
double outputAmount,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final minToReceive = (Decimal.parse(outputAmount.toString()) *
(Decimal.parse('100') - Decimal.parse(slippage.toString())) /
Decimal.parse('100'))
Expand Down Expand Up @@ -468,10 +451,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
double amount,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand All @@ -498,10 +477,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
double amount,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand All @@ -525,10 +500,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
String level,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand Down Expand Up @@ -566,10 +537,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
String level,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand Down Expand Up @@ -597,10 +564,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
String farmGenesisAddress,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand All @@ -622,10 +585,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
String depositId,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand All @@ -649,10 +608,6 @@ class ArchethicContract with aedappfm.TransactionMixin {
String depositId,
) async {
return aedappfm.Result.guard(() async {
final blockchainTxVersion = int.parse(
(await apiService.getBlockchainVersion()).version.transaction,
);

final transaction = archethic.Transaction(
type: 'transfer',
version: blockchainTxVersion,
Expand Down
Loading

0 comments on commit c997c17

Please sign in to comment.