From 74aef3b40bf979d05623595f294b74b6a0b57ee4 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Mon, 4 Nov 2024 17:55:47 +0100 Subject: [PATCH 01/11] feat: :sparkles: Add Custom tokens management --- lib/application/account/account_notifier.dart | 9 +- lib/application/account/providers.g.dart | 2 +- lib/application/aeswap/dex_token.g.dart | 4 + lib/application/tokens/tokens.dart | 24 +- lib/application/tokens/tokens.g.dart | 274 ++++++++++++++---- lib/domain/models/token_parser.dart | 107 +++++++ .../tokens/tokens.repository.dart | 11 +- .../tokens/tokens.repository.dart | 147 +++------- lib/l10n/intl_en.arb | 12 +- lib/l10n/intl_fr.arb | 12 +- lib/model/data/account.dart | 27 +- lib/model/data/account.g.dart | 7 +- lib/modules/aeswap/application/balance.g.dart | 4 + .../views/add_custom_token/bloc/provider.dart | 138 +++++++++ .../add_custom_token/bloc/provider.g.dart | 28 ++ lib/ui/views/add_custom_token/bloc/state.dart | 17 ++ .../add_custom_token/bloc/state.freezed.dart | 240 +++++++++++++++ .../layouts/add_custom_token_sheet.dart | 153 ++++++++++ .../add_custom_token_info_token.dart | 105 +++++++ .../add_custom_token_textfield_address.dart | 187 ++++++++++++ ...farm_lock_block_list_single_line_lock.dart | 1 - .../layouts/token_detail_sheet.dart | 64 ++++ lib/ui/views/tokens_list/bloc/provider.dart | 11 +- lib/ui/views/tokens_list/bloc/provider.g.dart | 72 ++--- .../components/custom_token_add_btn.dart | 68 +++++ .../layouts/tokens_list_sheet.dart | 66 ++++- .../components/transfer_tokens_list.dart | 22 +- lib/ui/widgets/balance/balance_infos.dart | 4 +- 28 files changed, 1562 insertions(+), 254 deletions(-) create mode 100644 lib/domain/models/token_parser.dart create mode 100644 lib/ui/views/add_custom_token/bloc/provider.dart create mode 100644 lib/ui/views/add_custom_token/bloc/provider.g.dart create mode 100644 lib/ui/views/add_custom_token/bloc/state.dart create mode 100644 lib/ui/views/add_custom_token/bloc/state.freezed.dart create mode 100644 lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart create mode 100644 lib/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart create mode 100644 lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart create mode 100644 lib/ui/views/tokens_list/layouts/components/custom_token_add_btn.dart diff --git a/lib/application/account/account_notifier.dart b/lib/application/account/account_notifier.dart index b436aa411..4ce4efb21 100644 --- a/lib/application/account/account_notifier.dart +++ b/lib/application/account/account_notifier.dart @@ -81,17 +81,10 @@ class _AccountNotifier extends _$AccountNotifier { 'End method refreshRecentTransactions for ${account.nameDisplayed}', ); - final accountSelected = ref - .read( - AccountProviders.accounts, - ) - .valueOrNull - ?.selectedAccount; - ref ..invalidate(userBalanceProvider) ..invalidate( - tokensListProvider(accountSelected!.genesisAddress), + tokensFromUserBalanceProvider, ); }, ]); diff --git a/lib/application/account/providers.g.dart b/lib/application/account/providers.g.dart index 01703af84..b8a4e9eca 100644 --- a/lib/application/account/providers.g.dart +++ b/lib/application/account/providers.g.dart @@ -381,7 +381,7 @@ class _AccountExistsNotifierProviderElement (origin as _AccountExistsNotifierProvider).accountName; } -String _$accountNotifierHash() => r'6933147f3a2c8322666d3776c0a3ae81c7a2f79a'; +String _$accountNotifierHash() => r'b66707462d0170e94fcdaa5568e52e5babfe26fb'; abstract class _$AccountNotifier extends BuildlessAsyncNotifier { late final String accountName; diff --git a/lib/application/aeswap/dex_token.g.dart b/lib/application/aeswap/dex_token.g.dart index ed5d2b63f..e2fd79cd3 100644 --- a/lib/application/aeswap/dex_token.g.dart +++ b/lib/application/aeswap/dex_token.g.dart @@ -789,7 +789,11 @@ class _GetRemoveAmountsProviderElement } String _$estimateLPTokenInFiatHash() => +<<<<<<< HEAD r'117d1b9fae927eca34724ab59d026abeaf3a6393'; +======= + r'4da34defbb60f367688c57c66b713d474f680f72'; +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// See also [_estimateLPTokenInFiat]. @ProviderFor(_estimateLPTokenInFiat) diff --git a/lib/application/tokens/tokens.dart b/lib/application/tokens/tokens.dart index 4b047afaa..c0eb0c203 100644 --- a/lib/application/tokens/tokens.dart +++ b/lib/application/tokens/tokens.dart @@ -1,5 +1,6 @@ import 'dart:developer'; +import 'package:aewallet/application/account/providers.dart'; import 'package:aewallet/application/aeswap/dex_token.dart'; import 'package:aewallet/application/api_service.dart'; import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; @@ -7,6 +8,7 @@ import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart'; import 'package:aewallet/modules/aeswap/application/session/provider.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; +import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -14,37 +16,47 @@ part 'tokens.g.dart'; @riverpod Future> tokensList( - Ref ref, - String userGenesisAddress, { + Ref ref, { bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, + bool withCustomToken = true, }) async { final apiService = ref.watch(apiServiceProvider); final environment = ref.watch(environmentProvider); final poolListRaw = await ref.watch(DexPoolProviders.getPoolListRaw.future); + final selectedAccount = + await ref.watch(AccountProviders.accounts.future).selectedAccount; + + if (selectedAccount == null) return []; - return TokensRepositoryImpl().getTokensList( - userGenesisAddress, + return TokensRepositoryImpl().getTokensFromUserBalance( + selectedAccount.genesisAddress, + selectedAccount.customTokenAddressList ?? [], apiService, poolListRaw, environment, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, + withCustomToken: withCustomToken, ); } @riverpod Future tokensTotalUSD( Ref ref, - String userGenesisAddress, ) async { var total = 0.0; const _logName = 'tokensTotalUSD'; + final selectedAccount = + await ref.watch(AccountProviders.accounts.future).selectedAccount; + + if (selectedAccount == null) return 0.0; + final tokensList = await ref.watch( - tokensListProvider(userGenesisAddress).future, + tokensFromUserBalanceProvider().future, ); for (final token in tokensList) { diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index c92418faf..4b65bc793 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -6,7 +6,12 @@ part of 'tokens.dart'; // RiverpodGenerator // ************************************************************************** +<<<<<<< HEAD String _$tokensListHash() => r'593e48ed9063457663e2e48b344aed4ca8bc7518'; +======= +String _$tokensFromAddressesHash() => + r'4cd16d00a6c3c466c3eefe8e60852b2791c7527b'; +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// Copied from Dart SDK class _SystemHash { @@ -29,39 +34,177 @@ class _SystemHash { } } -/// See also [tokensList]. -@ProviderFor(tokensList) -const tokensListProvider = TokensListFamily(); +/// See also [tokensFromAddresses]. +@ProviderFor(tokensFromAddresses) +const tokensFromAddressesProvider = TokensFromAddressesFamily(); -/// See also [tokensList]. -class TokensListFamily extends Family>> { - /// See also [tokensList]. - const TokensListFamily(); +/// See also [tokensFromAddresses]. +class TokensFromAddressesFamily + extends Family>> { + /// See also [tokensFromAddresses]. + const TokensFromAddressesFamily(); - /// See also [tokensList]. - TokensListProvider call( - String userGenesisAddress, { + /// See also [tokensFromAddresses]. + TokensFromAddressesProvider call( + List addresses, + ) { + return TokensFromAddressesProvider( + addresses, + ); + } + + @override + TokensFromAddressesProvider getProviderOverride( + covariant TokensFromAddressesProvider provider, + ) { + return call( + provider.addresses, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'tokensFromAddressesProvider'; +} + +/// See also [tokensFromAddresses]. +class TokensFromAddressesProvider + extends AutoDisposeFutureProvider> { + /// See also [tokensFromAddresses]. + TokensFromAddressesProvider( + List addresses, + ) : this._internal( + (ref) => tokensFromAddresses( + ref as TokensFromAddressesRef, + addresses, + ), + from: tokensFromAddressesProvider, + name: r'tokensFromAddressesProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$tokensFromAddressesHash, + dependencies: TokensFromAddressesFamily._dependencies, + allTransitiveDependencies: + TokensFromAddressesFamily._allTransitiveDependencies, + addresses: addresses, + ); + + TokensFromAddressesProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.addresses, + }) : super.internal(); + + final List addresses; + + @override + Override overrideWith( + FutureOr> Function( + TokensFromAddressesRef provider) + create, + ) { + return ProviderOverride( + origin: this, + override: TokensFromAddressesProvider._internal( + (ref) => create(ref as TokensFromAddressesRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + addresses: addresses, + ), + ); + } + + @override + AutoDisposeFutureProviderElement> + createElement() { + return _TokensFromAddressesProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is TokensFromAddressesProvider && other.addresses == addresses; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, addresses.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin TokensFromAddressesRef + on AutoDisposeFutureProviderRef> { + /// The parameter `addresses` of this provider. + List get addresses; +} + +class _TokensFromAddressesProviderElement + extends AutoDisposeFutureProviderElement> + with TokensFromAddressesRef { + _TokensFromAddressesProviderElement(super.provider); + + @override + List get addresses => + (origin as TokensFromAddressesProvider).addresses; +} + +String _$tokensFromUserBalanceHash() => + r'3a218ad12c5949939e3f275d32d1e1f27a2022cf'; + +/// See also [tokensFromUserBalance]. +@ProviderFor(tokensFromUserBalance) +const tokensFromUserBalanceProvider = TokensFromUserBalanceFamily(); + +/// See also [tokensFromUserBalance]. +class TokensFromUserBalanceFamily + extends Family>> { + /// See also [tokensFromUserBalance]. + const TokensFromUserBalanceFamily(); + + /// See also [tokensFromUserBalance]. + TokensFromUserBalanceProvider call({ bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, + bool withCustomToken = true, }) { - return TokensListProvider( - userGenesisAddress, + return TokensFromUserBalanceProvider( withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, + withCustomToken: withCustomToken, ); } @override - TokensListProvider getProviderOverride( - covariant TokensListProvider provider, + TokensFromUserBalanceProvider getProviderOverride( + covariant TokensFromUserBalanceProvider provider, ) { return call( - provider.userGenesisAddress, withVerified: provider.withVerified, withLPToken: provider.withLPToken, withNotVerified: provider.withNotVerified, + withCustomToken: provider.withCustomToken, ); } @@ -77,112 +220,118 @@ class TokensListFamily extends Family>> { _allTransitiveDependencies; @override - String? get name => r'tokensListProvider'; + String? get name => r'tokensFromUserBalanceProvider'; } -/// See also [tokensList]. -class TokensListProvider +/// See also [tokensFromUserBalance]. +class TokensFromUserBalanceProvider extends AutoDisposeFutureProvider> { - /// See also [tokensList]. - TokensListProvider( - String userGenesisAddress, { + /// See also [tokensFromUserBalance]. + TokensFromUserBalanceProvider({ bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, + bool withCustomToken = true, }) : this._internal( - (ref) => tokensList( - ref as TokensListRef, - userGenesisAddress, + (ref) => tokensFromUserBalance( + ref as TokensFromUserBalanceRef, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, + withCustomToken: withCustomToken, ), - from: tokensListProvider, - name: r'tokensListProvider', + from: tokensFromUserBalanceProvider, + name: r'tokensFromUserBalanceProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') ? null - : _$tokensListHash, - dependencies: TokensListFamily._dependencies, + : _$tokensFromUserBalanceHash, + dependencies: TokensFromUserBalanceFamily._dependencies, allTransitiveDependencies: - TokensListFamily._allTransitiveDependencies, - userGenesisAddress: userGenesisAddress, + TokensFromUserBalanceFamily._allTransitiveDependencies, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, + withCustomToken: withCustomToken, ); - TokensListProvider._internal( + TokensFromUserBalanceProvider._internal( super._createNotifier, { required super.name, required super.dependencies, required super.allTransitiveDependencies, required super.debugGetCreateSourceHash, required super.from, - required this.userGenesisAddress, required this.withVerified, required this.withLPToken, required this.withNotVerified, + required this.withCustomToken, }) : super.internal(); - final String userGenesisAddress; final bool withVerified; final bool withLPToken; final bool withNotVerified; + final bool withCustomToken; @override Override overrideWith( - FutureOr> Function(TokensListRef provider) create, + FutureOr> Function(TokensFromUserBalanceRef provider) + create, ) { return ProviderOverride( origin: this, - override: TokensListProvider._internal( - (ref) => create(ref as TokensListRef), + override: TokensFromUserBalanceProvider._internal( + (ref) => create(ref as TokensFromUserBalanceRef), from: from, name: null, dependencies: null, allTransitiveDependencies: null, debugGetCreateSourceHash: null, - userGenesisAddress: userGenesisAddress, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, + withCustomToken: withCustomToken, ), ); } @override AutoDisposeFutureProviderElement> createElement() { - return _TokensListProviderElement(this); + return _TokensFromUserBalanceProviderElement(this); } @override bool operator ==(Object other) { - return other is TokensListProvider && - other.userGenesisAddress == userGenesisAddress && + return other is TokensFromUserBalanceProvider && other.withVerified == withVerified && other.withLPToken == withLPToken && - other.withNotVerified == withNotVerified; + other.withNotVerified == withNotVerified && + other.withCustomToken == withCustomToken; } @override int get hashCode { var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, userGenesisAddress.hashCode); hash = _SystemHash.combine(hash, withVerified.hashCode); hash = _SystemHash.combine(hash, withLPToken.hashCode); hash = _SystemHash.combine(hash, withNotVerified.hashCode); + hash = _SystemHash.combine(hash, withCustomToken.hashCode); return _SystemHash.finish(hash); } } +<<<<<<< HEAD @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element mixin TokensListRef on AutoDisposeFutureProviderRef> { /// The parameter `userGenesisAddress` of this provider. String get userGenesisAddress; +======= +mixin TokensFromUserBalanceRef + on AutoDisposeFutureProviderRef> { +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// The parameter `withVerified` of this provider. bool get withVerified; @@ -191,30 +340,48 @@ mixin TokensListRef on AutoDisposeFutureProviderRef> { /// The parameter `withNotVerified` of this provider. bool get withNotVerified; + + /// The parameter `withCustomToken` of this provider. + bool get withCustomToken; } -class _TokensListProviderElement +class _TokensFromUserBalanceProviderElement extends AutoDisposeFutureProviderElement> - with TokensListRef { - _TokensListProviderElement(super.provider); + with TokensFromUserBalanceRef { + _TokensFromUserBalanceProviderElement(super.provider); @override - String get userGenesisAddress => - (origin as TokensListProvider).userGenesisAddress; + bool get withVerified => + (origin as TokensFromUserBalanceProvider).withVerified; @override - bool get withVerified => (origin as TokensListProvider).withVerified; + bool get withLPToken => (origin as TokensFromUserBalanceProvider).withLPToken; @override - bool get withLPToken => (origin as TokensListProvider).withLPToken; + bool get withNotVerified => + (origin as TokensFromUserBalanceProvider).withNotVerified; @override - bool get withNotVerified => (origin as TokensListProvider).withNotVerified; + bool get withCustomToken => + (origin as TokensFromUserBalanceProvider).withCustomToken; } +<<<<<<< HEAD String _$tokensTotalUSDHash() => r'a0f42e1ef21073d1ec7f627b48fde93b76205a7a'; +======= +String _$tokensTotalUSDHash() => r'98ac96ba39ca5f3b227f4d114c7556532a4d24dd'; +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// See also [tokensTotalUSD]. @ProviderFor(tokensTotalUSD) -const tokensTotalUSDProvider = TokensTotalUSDFamily(); - +final tokensTotalUSDProvider = AutoDisposeFutureProvider.internal( + tokensTotalUSD, + name: r'tokensTotalUSDProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$tokensTotalUSDHash, + dependencies: null, + allTransitiveDependencies: null, +); + +<<<<<<< HEAD /// See also [tokensTotalUSD]. class TokensTotalUSDFamily extends Family> { /// See also [tokensTotalUSD]. @@ -340,5 +507,8 @@ class _TokensTotalUSDProviderElement String get userGenesisAddress => (origin as TokensTotalUSDProvider).userGenesisAddress; } +======= +typedef TokensTotalUSDRef = AutoDisposeFutureProviderRef; +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) // ignore_for_file: type=lint // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/domain/models/token_parser.dart b/lib/domain/models/token_parser.dart new file mode 100644 index 000000000..4abd79872 --- /dev/null +++ b/lib/domain/models/token_parser.dart @@ -0,0 +1,107 @@ +import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; +import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; +import 'package:collection/collection.dart'; + +mixin TokenParser { + Future tokenModelToAETokenModel( + archethic.Token token, + List verifiedTokens, + List poolsListRaw, + aedappfm.Environment environment, + archethic.ApiService apiService, + ) async { + String? pairSymbolToken1; + String? pairSymbolToken2; + aedappfm.AEToken? defPairSymbolToken1; + aedappfm.AEToken? defPairSymbolToken2; + String? token1Address; + String? token2Address; + + final tokenSymbolSearch = []; + final isLPToken = + poolsListRaw.any((item) => item.lpTokenAddress == token.address); + token1Address = null; + token2Address = null; + if (isLPToken) { + final poolRaw = poolsListRaw.firstWhereOrNull( + (item) => item.lpTokenAddress == token.address!, + ); + if (poolRaw != null) { + token1Address = + poolRaw.concatenatedTokensAddresses.split('/')[0].toUpperCase(); + token2Address = + poolRaw.concatenatedTokensAddresses.split('/')[1].toUpperCase(); + if (token1Address != 'UCO') { + tokenSymbolSearch.add(token1Address); + } + if (token2Address != 'UCO') { + tokenSymbolSearch.add(token2Address); + } + + final tokensSymbolMap = + await TokensRepositoryImpl().getTokensFromAddresses( + tokenSymbolSearch, + apiService, + ); + pairSymbolToken1 = token1Address != 'UCO' + ? tokensSymbolMap[token1Address]!.symbol + : 'UCO'; + pairSymbolToken2 = token2Address != 'UCO' + ? tokensSymbolMap[token2Address]!.symbol + : 'UCO'; + + final futureToken1 = aedappfm.DefTokensRepositoryImpl().getDefToken( + environment, + token1Address, + ); + + final futureToken2 = aedappfm.DefTokensRepositoryImpl().getDefToken( + environment, + token2Address, + ); + + final results = await Future.wait([futureToken1, futureToken2]); + + defPairSymbolToken1 = results[0]; + defPairSymbolToken2 = results[1]; + } + } + + final defToken = await aedappfm.DefTokensRepositoryImpl() + .getDefToken(environment, token.address!.toUpperCase()); + + return aedappfm.AEToken( + name: defToken?.name ?? '', + address: token.address!.toUpperCase(), + icon: defToken?.icon, + ucid: defToken?.ucid, + supply: archethic.fromBigInt(token.supply).toDouble(), + isLpToken: pairSymbolToken1 != null && pairSymbolToken2 != null, + symbol: pairSymbolToken1 != null && pairSymbolToken2 != null + ? 'LP Token' + : token.symbol!, + lpTokenPair: pairSymbolToken1 != null && pairSymbolToken2 != null + ? aedappfm.AETokenPair( + token1: aedappfm.AEToken( + symbol: pairSymbolToken1, + address: token1Address, + name: defPairSymbolToken1?.name ?? '', + icon: defPairSymbolToken1?.icon, + ucid: defPairSymbolToken1?.ucid, + ), + token2: aedappfm.AEToken( + symbol: pairSymbolToken2, + address: token2Address, + name: defPairSymbolToken2?.name ?? '', + icon: defPairSymbolToken2?.icon, + ucid: defPairSymbolToken2?.ucid, + ), + ) + : null, + isVerified: verifiedTokens.contains(token.address!.toUpperCase()), + ); + } +} diff --git a/lib/domain/repositories/tokens/tokens.repository.dart b/lib/domain/repositories/tokens/tokens.repository.dart index 7e2ddee60..8cb2d8e61 100644 --- a/lib/domain/repositories/tokens/tokens.repository.dart +++ b/lib/domain/repositories/tokens/tokens.repository.dart @@ -1,20 +1,23 @@ import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; -import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; abstract class TokensRepository { - Future> getToken( + Future> getTokensFromAddresses( List addresses, archethic.ApiService apiService, ); - Future> getTokensList( + Future> getTokensFromUserBalance( String userGenesisAddress, + List userTokenLocalAddresses, archethic.ApiService apiService, List poolsListRaw, - Environment environment, { + aedappfm.Environment environment, { bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, + bool withCustomToken = true, }); } diff --git a/lib/infrastructure/repositories/tokens/tokens.repository.dart b/lib/infrastructure/repositories/tokens/tokens.repository.dart index 30d14a73b..7dfc89d03 100644 --- a/lib/infrastructure/repositories/tokens/tokens.repository.dart +++ b/lib/infrastructure/repositories/tokens/tokens.repository.dart @@ -1,16 +1,15 @@ +import 'package:aewallet/domain/models/token_parser.dart'; import 'package:aewallet/domain/repositories/tokens/tokens.repository.dart'; import 'package:aewallet/infrastructure/datasources/tokens_list.hive.dart'; import 'package:aewallet/infrastructure/datasources/wallet_token_dto.hive.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; -import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'; import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; -import 'package:collection/collection.dart'; -class TokensRepositoryImpl implements TokensRepository { +class TokensRepositoryImpl with TokenParser implements TokensRepository { @override - Future> getToken( + Future> getTokensFromAddresses( List addresses, archethic.ApiService apiService, ) async { @@ -47,11 +46,11 @@ class TokensRepositoryImpl implements TokensRepository { final getTokens = await Future.wait(futures); for (final Map getToken in getTokens) { - tokenMap.addAll(getToken); - getToken.forEach((key, value) async { - value = value.copyWith(address: key); - await tokensListDatasource.setToken(value.toHive()); + if (value.type == 'fungible') { + value = value.copyWith(address: key); + await tokensListDatasource.setToken(value.toHive()); + } }); } @@ -59,16 +58,18 @@ class TokensRepositoryImpl implements TokensRepository { } @override - Future> getTokensList( + Future> getTokensFromUserBalance( String userGenesisAddress, + List userTokenLocalAddresses, archethic.ApiService apiService, List poolsListRaw, - Environment environment, { + aedappfm.Environment environment, { bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, + bool withCustomToken = true, }) async { - final tokensList = []; + final tokensList = []; final balanceMap = await apiService.fetchBalance([userGenesisAddress]); if (balanceMap[userGenesisAddress] == null) { return tokensList; @@ -77,7 +78,7 @@ class TokensRepositoryImpl implements TokensRepository { final defUCOToken = await aedappfm.DefTokensRepositoryImpl() .getDefToken(environment, 'UCO'); tokensList.add( - ucoToken.copyWith( + aedappfm.ucoToken.copyWith( name: defUCOToken?.name ?? '', isVerified: true, icon: defUCOToken?.icon, @@ -88,17 +89,21 @@ class TokensRepositoryImpl implements TokensRepository { ), ); } + final tokenAddressList = []; + if (userTokenLocalAddresses.isNotEmpty && withCustomToken) { + tokenAddressList.addAll(userTokenLocalAddresses); + } if (balanceMap[userGenesisAddress]!.token.isNotEmpty) { - final tokenAddressList = []; for (final tokenBalance in balanceMap[userGenesisAddress]!.token) { if (tokenBalance.address != null) { tokenAddressList.add(tokenBalance.address!); } } + } - // Search token Information - final tokenMap = await getToken( + if (tokenAddressList.isNotEmpty) { + final tokenMap = await getTokensFromAddresses( tokenAddressList.toSet().toList(), apiService, ); @@ -109,112 +114,30 @@ class TokensRepositoryImpl implements TokensRepository { ).getVerifiedTokens(); for (final tokenBalance in balanceMap[userGenesisAddress]!.token) { - String? pairSymbolToken1; - String? pairSymbolToken2; - AEToken? defPairSymbolToken1; - AEToken? defPairSymbolToken2; - String? token1Address; - String? token2Address; - var token = tokenMap[tokenBalance.address]; + final token = tokenMap[tokenBalance.address]; if (token != null && token.type == 'fungible') { - token = token.copyWith(address: tokenBalance.address); - final tokenSymbolSearch = []; - final isLPToken = - poolsListRaw.any((item) => item.lpTokenAddress == token!.address); - token1Address = null; - token2Address = null; - if (isLPToken) { - final poolRaw = poolsListRaw.firstWhereOrNull( - (item) => item.lpTokenAddress == token!.address!, - ); - if (poolRaw != null) { - token1Address = poolRaw.concatenatedTokensAddresses - .split('/')[0] - .toUpperCase(); - token2Address = poolRaw.concatenatedTokensAddresses - .split('/')[1] - .toUpperCase(); - if (token1Address != 'UCO') { - tokenSymbolSearch.add(token1Address); - } - if (token2Address != 'UCO') { - tokenSymbolSearch.add(token2Address); - } - - final tokensSymbolMap = await getToken( - tokenSymbolSearch, - apiService, - ); - pairSymbolToken1 = token1Address != 'UCO' - ? tokensSymbolMap[token1Address]!.symbol! - : 'UCO'; - pairSymbolToken2 = token2Address != 'UCO' - ? tokensSymbolMap[token2Address]!.symbol! - : 'UCO'; - - final futureToken1 = - aedappfm.DefTokensRepositoryImpl().getDefToken( - environment, - token1Address, - ); - - final futureToken2 = - aedappfm.DefTokensRepositoryImpl().getDefToken( - environment, - token2Address, - ); - - final results = await Future.wait([futureToken1, futureToken2]); - - defPairSymbolToken1 = results[0]; - defPairSymbolToken2 = results[1]; - } - } - - final defToken = await aedappfm.DefTokensRepositoryImpl() - .getDefToken(environment, token.address!.toUpperCase()); - - final aeToken = AEToken( - name: defToken?.name ?? '', - address: token.address!.toUpperCase(), + var aeToken = await tokenModelToAETokenModel( + token, + verifiedTokens, + poolsListRaw, + environment, + apiService, + ); + aeToken = aeToken.copyWith( balance: archethic.fromBigInt(tokenBalance.amount).toDouble(), - icon: defToken?.icon, - ucid: defToken?.ucid, - supply: archethic.fromBigInt(token.supply).toDouble(), - isLpToken: pairSymbolToken1 != null && pairSymbolToken2 != null, - symbol: pairSymbolToken1 != null && pairSymbolToken2 != null - ? 'LP Token' - : token.symbol!, - lpTokenPair: pairSymbolToken1 != null && pairSymbolToken2 != null - ? aedappfm.AETokenPair( - token1: AEToken( - symbol: pairSymbolToken1, - address: token1Address, - name: defPairSymbolToken1?.name ?? '', - icon: defPairSymbolToken1?.icon, - ucid: defPairSymbolToken1?.ucid, - ), - token2: AEToken( - symbol: pairSymbolToken2, - address: token2Address, - name: defPairSymbolToken2?.name ?? '', - icon: defPairSymbolToken2?.icon, - ucid: defPairSymbolToken2?.ucid, - ), - ) - : null, - isVerified: verifiedTokens.contains(token.address!.toUpperCase()), ); - if (aeToken.isLpToken && withLPToken || - aeToken.isVerified && withVerified || - aeToken.isVerified == false && withNotVerified) { + if (aeToken.isVerified && withVerified || + aeToken.isLpToken && withLPToken || + withCustomToken && + userTokenLocalAddresses + .contains(aeToken.address!.toUpperCase()) || + !aeToken.isVerified && withNotVerified) { tokensList.add(aeToken); } } } } - return tokensList; } } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 978767dce..e2929956d 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -749,5 +749,15 @@ "logsDesc": "If you encounter any problems, you can copy and send the information below to the Archethic support team.\nEnsure that no sensitive or private information that could affect the security of your funds is shared.", "logsCopied": "Logs copied", "getSomeHelp": "Get some help", - "rpcSignTransactionsProcessing": "Processing transactions signature request" + "rpcSignTransactionsProcessing": "Processing transactions signature request", + "customTokenAddTextFieldLabel": "Token address", + "customTokenAddTitle": "Add custom token", + "customTokenAddDesc": "You can add custom tokens to your wallet using their contract address. Once added, you can view the balance of these tokens and send them directly from your wallet.\nAt any time, you can remove a token’s display from the token detail screen.\nPlease note that adding tokens is specific to your current user account and this wallet instance, so these tokens will not be visible from other accounts or synchronized with your other wallet installations.", + "customTokenAddressAlreadyExistsInAccount": "You already have this token in your wallet.", + "customTokenAddressNotValid": "This address is not a valid token.", + "hideBtn": "Hide", + "hideTokenConfirmationTitle": "Hide this token in my wallet", + "hideTokenConfirmationDesc": "Are you sure you want to hide this token in your wallet?\nYou can display it again anytime by going to the Account tab and clicking '+ token'.", + "customTokenAddSelectionTokenTitle": "Select a token\nwith a balance in your account", + "customTokenAddBalance": "Your balance" } \ No newline at end of file diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 7ce837134..313df3e93 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -729,5 +729,15 @@ "logsDesc": "Si vous rencontrez des problèmes, vous pouvez copier et envoyer les informations ci-dessous à l'équipe support d'Archethic.\nVeillez à ce qu'aucune information sensible ou privée qui pourrait affecter la sécurité de vos fonds ne soit partagée.", "logsCopied": "Informations copiées", "getSomeHelp": "Contactez nous", - "rpcSignTransactionsProcessing": "Traitement de la demande de signature" + "rpcSignTransactionsProcessing": "Traitement de la demande de signature", + "customTokenAddTextFieldLabel": "Adresse du jeton", + "customTokenAddTitle": "Ajout de jeton personnalisé", + "customTokenAddDesc": "Vous pouvez ajouter des tokens personnalisés à votre portefeuille via leur adresse de contrat. Une fois ajoutés, vous pourrez consulter le solde de ces tokens et les envoyer directement depuis votre portefeuille.\nÀ tout moment, il est possible de retirer l'affichage d'un token depuis l'écran de détail du token.\nVeuillez noter que l'ajout de tokens est spécifique à votre compte utilisateur actuel et à cette instance de votre portefeuille, donc ces tokens ne seront pas visibles depuis d'autres comptes ni synchronisés avec vos autres installations du portefeuille.", + "customTokenAddressAlreadyExistsInAccount": "Vous avez déjà ce token dans votre wallet.", + "customTokenAddressNotValid": "Cette adresse ne correspond pas à un token.", + "hideBtn": "Masquer", + "hideTokenConfirmationTitle": "Masquer ce token dans mon portefeuille", + "hideTokenConfirmationDesc": "Êtes-vous sûr(e) de vouloir masquer ce token dans votre wallet ? Vous pourrez le réafficher à tout moment en accédant à l'onglet Compte et en cliquant sur '+ jeton'.", + "customTokenAddSelectionTokenTitle": "Sélectionner un token\navec un solde dans votre compte", + "customTokenAddBalance": "Votre solde" } \ No newline at end of file diff --git a/lib/model/data/account.dart b/lib/model/data/account.dart index 06d7627e6..8196ca8d6 100644 --- a/lib/model/data/account.dart +++ b/lib/model/data/account.dart @@ -21,7 +21,7 @@ part 'account.g.dart'; @HiveType(typeId: HiveTypeIds.account) -/// Next field available : 15 +/// Next field available : 16 class Account extends HiveObject with KeychainServiceMixin { Account({ required this.name, @@ -37,6 +37,7 @@ class Account extends HiveObject with KeychainServiceMixin { this.nftInfosOffChainList, this.nftCategoryList, this.serviceType, + this.customTokenAddressList, }); String get nameDisplayed => _getShortName(name); @@ -69,6 +70,7 @@ class Account extends HiveObject with KeychainServiceMixin { List? accountNFTCollections, List? nftInfosOffChainList, List? nftCategoryList, + List? customTokenAddressList, }) => Account( name: name ?? this.name, @@ -86,6 +88,8 @@ class Account extends HiveObject with KeychainServiceMixin { accountNFTCollections ?? this.accountNFTCollections, nftInfosOffChainList: nftInfosOffChainList ?? this.nftInfosOffChainList, nftCategoryList: nftCategoryList ?? this.nftCategoryList, + customTokenAddressList: + customTokenAddressList ?? this.customTokenAddressList, ); /// Account name - Primary Key @@ -140,6 +144,10 @@ class Account extends HiveObject with KeychainServiceMixin { @HiveField(14) List? accountNFTCollections; + /// Custom Token Addresses + @HiveField(15) + List? customTokenAddressList; + Future updateLastAddress( AddressService addressService, ) async { @@ -380,6 +388,23 @@ class Account extends HiveObject with KeychainServiceMixin { recentTransactions = []; await updateAccount(); } + + Future addCustomTokenAddress(String tokenAddress) async { + if (Address(address: tokenAddress).isValid() == false) return; + (customTokenAddressList ??= []).add(tokenAddress.toUpperCase()); + await updateAccount(); + } + + Future removeCustomTokenAddress(String tokenAddress) async { + if (Address(address: tokenAddress).isValid() == false) return; + (customTokenAddressList ??= []).remove(tokenAddress.toUpperCase()); + await updateAccount(); + } + + bool checkCustomTokenAddress(String tokenAddress) { + if (Address(address: tokenAddress).isValid() == false) return false; + return (customTokenAddressList ?? []).contains(tokenAddress.toUpperCase()); + } } mixin KeychainServiceMixin { diff --git a/lib/model/data/account.g.dart b/lib/model/data/account.g.dart index f1cd03e70..babd57df4 100644 --- a/lib/model/data/account.g.dart +++ b/lib/model/data/account.g.dart @@ -30,13 +30,14 @@ class AccountAdapter extends TypeAdapter { nftInfosOffChainList: (fields[10] as List?)?.cast(), nftCategoryList: (fields[11] as List?)?.cast(), serviceType: fields[13] as String?, + customTokenAddressList: (fields[15] as List?)?.cast(), ); } @override void write(BinaryWriter writer, Account obj) { writer - ..writeByte(13) + ..writeByte(14) ..writeByte(0) ..write(obj.name) ..writeByte(1) @@ -62,7 +63,9 @@ class AccountAdapter extends TypeAdapter { ..writeByte(13) ..write(obj.serviceType) ..writeByte(14) - ..write(obj.accountNFTCollections); + ..write(obj.accountNFTCollections) + ..writeByte(15) + ..write(obj.customTokenAddressList); } @override diff --git a/lib/modules/aeswap/application/balance.g.dart b/lib/modules/aeswap/application/balance.g.dart index 812975058..13b0cb255 100644 --- a/lib/modules/aeswap/application/balance.g.dart +++ b/lib/modules/aeswap/application/balance.g.dart @@ -177,7 +177,11 @@ class _AddressBalanceProviderElement } String _$addressBalanceTotalFiatHash() => +<<<<<<< HEAD r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; +======= + r'39f9c8fc5cd22a8b4ae2c923013783f59c219326'; +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// See also [addressBalanceTotalFiat]. @ProviderFor(addressBalanceTotalFiat) diff --git a/lib/ui/views/add_custom_token/bloc/provider.dart b/lib/ui/views/add_custom_token/bloc/provider.dart new file mode 100644 index 000000000..274547d34 --- /dev/null +++ b/lib/ui/views/add_custom_token/bloc/provider.dart @@ -0,0 +1,138 @@ +import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/application/api_service.dart'; +import 'package:aewallet/application/tokens/tokens.dart'; +import 'package:aewallet/domain/models/token_parser.dart'; +import 'package:aewallet/modules/aeswap/application/balance.dart'; +import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart'; +import 'package:aewallet/modules/aeswap/application/session/provider.dart'; +import 'package:aewallet/modules/aeswap/application/verified_tokens.dart'; +import 'package:aewallet/ui/views/add_custom_token/bloc/state.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:archethic_lib_dart/archethic_lib_dart.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +part 'provider.g.dart'; + +@riverpod +class AddCustomTokenFormNotifier extends _$AddCustomTokenFormNotifier + with TokenParser { + AddCustomTokenFormNotifier(); + + @override + AddCustomTokenFormState build() => const AddCustomTokenFormState(); + + Future setTokenAddress( + AppLocalizations appLocalizations, + String tokenAddress, + ) async { + state = state.copyWith( + tokenAddress: tokenAddress, + token: null, + errorText: '', + ); + if (Address(address: state.tokenAddress).isValid()) { + final tokenResult = + await ref.read(tokensFromAddressesProvider([tokenAddress]).future); + if (tokenResult[tokenAddress] != null) { + final userTokenBalance = await ref.read( + getBalanceProvider( + tokenAddress, + ).future, + ); + final poolsListRaw = + await ref.watch(DexPoolProviders.getPoolListRaw.future); + + final apiService = ref.read(apiServiceProvider); + final verifiedTokens = await ref + .read(verifiedTokensRepositoryProvider) + .getVerifiedTokens(); + final environment = ref.read(environmentProvider); + + final aeToken = await tokenModelToAETokenModel( + tokenResult[tokenAddress]!, + verifiedTokens, + poolsListRaw, + environment, + apiService, + ); + + setToken(aeToken); + state = state.copyWith( + userTokenBalance: userTokenBalance, + ); + } else { + setError( + appLocalizations.customTokenAddressNotValid, + ); + } + } + } + + void setError( + String errorText, + ) { + state = state.copyWith( + errorText: errorText, + ); + } + + void setToken( + aedappfm.AEToken token, + ) { + state = state.copyWith( + token: token, + ); + } + + Future control(WidgetRef ref, AppLocalizations appLocalizations) async { + if (Address(address: state.tokenAddress).isValid() == false) { + setError(appLocalizations.invalidAddress); + return false; + } + + final tokenResult = await ref + .read(tokensFromAddressesProvider([state.tokenAddress]).future); + if (tokenResult[state.tokenAddress] == null) { + setError( + appLocalizations.customTokenAddressNotValid, + ); + return false; + } + + final accountSelected = ref + .read( + AccountProviders.accounts, + ) + .valueOrNull + ?.selectedAccount; + if (accountSelected != null && + accountSelected.customTokenAddressList != null && + accountSelected.checkCustomTokenAddress(state.tokenAddress)) { + setError(appLocalizations.customTokenAddressAlreadyExistsInAccount); + return false; + } + + return true; + } + + Future addCustomToken( + WidgetRef ref, + AppLocalizations appLocalizations, + ) async { + if (await control(ref, appLocalizations) == false) { + return false; + } + + final accountSelected = ref + .read( + AccountProviders.accounts, + ) + .valueOrNull + ?.selectedAccount; + await accountSelected!.addCustomTokenAddress(state.tokenAddress); + return true; + } +} diff --git a/lib/ui/views/add_custom_token/bloc/provider.g.dart b/lib/ui/views/add_custom_token/bloc/provider.g.dart new file mode 100644 index 000000000..f441ed643 --- /dev/null +++ b/lib/ui/views/add_custom_token/bloc/provider.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$addCustomTokenFormNotifierHash() => + r'bed5461223b7090b5dbb444712be793f51e556e2'; + +/// See also [AddCustomTokenFormNotifier]. +@ProviderFor(AddCustomTokenFormNotifier) +final addCustomTokenFormNotifierProvider = AutoDisposeNotifierProvider< + AddCustomTokenFormNotifier, AddCustomTokenFormState>.internal( + AddCustomTokenFormNotifier.new, + name: r'addCustomTokenFormNotifierProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$addCustomTokenFormNotifierHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$AddCustomTokenFormNotifier + = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/ui/views/add_custom_token/bloc/state.dart b/lib/ui/views/add_custom_token/bloc/state.dart new file mode 100644 index 000000000..94083488d --- /dev/null +++ b/lib/ui/views/add_custom_token/bloc/state.dart @@ -0,0 +1,17 @@ +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'state.freezed.dart'; + +@freezed +class AddCustomTokenFormState with _$AddCustomTokenFormState { + const factory AddCustomTokenFormState({ + @Default('') String tokenAddress, + @Default('') String errorText, + AEToken? token, + @Default(0) double userTokenBalance, + }) = _AddCustomTokenFormState; + const AddCustomTokenFormState._(); + + bool get isControlsOk => errorText == '' && token != null; +} diff --git a/lib/ui/views/add_custom_token/bloc/state.freezed.dart b/lib/ui/views/add_custom_token/bloc/state.freezed.dart new file mode 100644 index 000000000..3862ee19f --- /dev/null +++ b/lib/ui/views/add_custom_token/bloc/state.freezed.dart @@ -0,0 +1,240 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'state.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +/// @nodoc +mixin _$AddCustomTokenFormState { + String get tokenAddress => throw _privateConstructorUsedError; + String get errorText => throw _privateConstructorUsedError; + AEToken? get token => throw _privateConstructorUsedError; + double get userTokenBalance => throw _privateConstructorUsedError; + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $AddCustomTokenFormStateCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AddCustomTokenFormStateCopyWith<$Res> { + factory $AddCustomTokenFormStateCopyWith(AddCustomTokenFormState value, + $Res Function(AddCustomTokenFormState) then) = + _$AddCustomTokenFormStateCopyWithImpl<$Res, AddCustomTokenFormState>; + @useResult + $Res call( + {String tokenAddress, + String errorText, + AEToken? token, + double userTokenBalance}); + + $AETokenCopyWith<$Res>? get token; +} + +/// @nodoc +class _$AddCustomTokenFormStateCopyWithImpl<$Res, + $Val extends AddCustomTokenFormState> + implements $AddCustomTokenFormStateCopyWith<$Res> { + _$AddCustomTokenFormStateCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? tokenAddress = null, + Object? errorText = null, + Object? token = freezed, + Object? userTokenBalance = null, + }) { + return _then(_value.copyWith( + tokenAddress: null == tokenAddress + ? _value.tokenAddress + : tokenAddress // ignore: cast_nullable_to_non_nullable + as String, + errorText: null == errorText + ? _value.errorText + : errorText // ignore: cast_nullable_to_non_nullable + as String, + token: freezed == token + ? _value.token + : token // ignore: cast_nullable_to_non_nullable + as AEToken?, + userTokenBalance: null == userTokenBalance + ? _value.userTokenBalance + : userTokenBalance // ignore: cast_nullable_to_non_nullable + as double, + ) as $Val); + } + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $AETokenCopyWith<$Res>? get token { + if (_value.token == null) { + return null; + } + + return $AETokenCopyWith<$Res>(_value.token!, (value) { + return _then(_value.copyWith(token: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$AddCustomTokenFormStateImplCopyWith<$Res> + implements $AddCustomTokenFormStateCopyWith<$Res> { + factory _$$AddCustomTokenFormStateImplCopyWith( + _$AddCustomTokenFormStateImpl value, + $Res Function(_$AddCustomTokenFormStateImpl) then) = + __$$AddCustomTokenFormStateImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String tokenAddress, + String errorText, + AEToken? token, + double userTokenBalance}); + + @override + $AETokenCopyWith<$Res>? get token; +} + +/// @nodoc +class __$$AddCustomTokenFormStateImplCopyWithImpl<$Res> + extends _$AddCustomTokenFormStateCopyWithImpl<$Res, + _$AddCustomTokenFormStateImpl> + implements _$$AddCustomTokenFormStateImplCopyWith<$Res> { + __$$AddCustomTokenFormStateImplCopyWithImpl( + _$AddCustomTokenFormStateImpl _value, + $Res Function(_$AddCustomTokenFormStateImpl) _then) + : super(_value, _then); + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? tokenAddress = null, + Object? errorText = null, + Object? token = freezed, + Object? userTokenBalance = null, + }) { + return _then(_$AddCustomTokenFormStateImpl( + tokenAddress: null == tokenAddress + ? _value.tokenAddress + : tokenAddress // ignore: cast_nullable_to_non_nullable + as String, + errorText: null == errorText + ? _value.errorText + : errorText // ignore: cast_nullable_to_non_nullable + as String, + token: freezed == token + ? _value.token + : token // ignore: cast_nullable_to_non_nullable + as AEToken?, + userTokenBalance: null == userTokenBalance + ? _value.userTokenBalance + : userTokenBalance // ignore: cast_nullable_to_non_nullable + as double, + )); + } +} + +/// @nodoc + +class _$AddCustomTokenFormStateImpl extends _AddCustomTokenFormState { + const _$AddCustomTokenFormStateImpl( + {this.tokenAddress = '', + this.errorText = '', + this.token, + this.userTokenBalance = 0}) + : super._(); + + @override + @JsonKey() + final String tokenAddress; + @override + @JsonKey() + final String errorText; + @override + final AEToken? token; + @override + @JsonKey() + final double userTokenBalance; + + @override + String toString() { + return 'AddCustomTokenFormState(tokenAddress: $tokenAddress, errorText: $errorText, token: $token, userTokenBalance: $userTokenBalance)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AddCustomTokenFormStateImpl && + (identical(other.tokenAddress, tokenAddress) || + other.tokenAddress == tokenAddress) && + (identical(other.errorText, errorText) || + other.errorText == errorText) && + (identical(other.token, token) || other.token == token) && + (identical(other.userTokenBalance, userTokenBalance) || + other.userTokenBalance == userTokenBalance)); + } + + @override + int get hashCode => Object.hash( + runtimeType, tokenAddress, errorText, token, userTokenBalance); + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$AddCustomTokenFormStateImplCopyWith<_$AddCustomTokenFormStateImpl> + get copyWith => __$$AddCustomTokenFormStateImplCopyWithImpl< + _$AddCustomTokenFormStateImpl>(this, _$identity); +} + +abstract class _AddCustomTokenFormState extends AddCustomTokenFormState { + const factory _AddCustomTokenFormState( + {final String tokenAddress, + final String errorText, + final AEToken? token, + final double userTokenBalance}) = _$AddCustomTokenFormStateImpl; + const _AddCustomTokenFormState._() : super._(); + + @override + String get tokenAddress; + @override + String get errorText; + @override + AEToken? get token; + @override + double get userTokenBalance; + + /// Create a copy of AddCustomTokenFormState + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$AddCustomTokenFormStateImplCopyWith<_$AddCustomTokenFormStateImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart b/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart new file mode 100644 index 000000000..36ff2d9ad --- /dev/null +++ b/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart @@ -0,0 +1,153 @@ +/// SPDX-License-Identifier: AGPL-3.0-or-later +import 'dart:async'; +import 'dart:ui'; + +import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart'; +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; +import 'package:aewallet/ui/themes/archethic_theme.dart'; +import 'package:aewallet/ui/themes/styles.dart'; +import 'package:aewallet/ui/util/dimens.dart'; +import 'package:aewallet/ui/util/ui_util.dart'; +import 'package:aewallet/ui/views/add_custom_token/bloc/provider.dart'; +import 'package:aewallet/ui/views/add_custom_token/bloc/state.dart'; +import 'package:aewallet/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart'; +import 'package:aewallet/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart'; +import 'package:aewallet/ui/widgets/components/app_button_tiny.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:go_router/go_router.dart'; + +class AddCustomTokenSheet extends ConsumerWidget { + const AddCustomTokenSheet({ + super.key, + }); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final addCustomTokenForm = ref.watch(addCustomTokenFormNotifierProvider); + ref.listen( + addCustomTokenFormNotifierProvider, + (_, addCustomToken) { + if (addCustomToken.isControlsOk || addCustomToken.errorText == '') { + return; + } + + UIUtil.showSnackbar( + addCustomToken.errorText, + context, + ref, + ArchethicTheme.text, + ArchethicTheme.snackBarShadow, + duration: const Duration(seconds: 5), + ); + + ref.read(addCustomTokenFormNotifierProvider.notifier).setError( + '', + ); + }, + ); + + final localizations = AppLocalizations.of(context)!; + return Stack( + children: [ + ClipRRect( + child: ScrollConfiguration( + behavior: ScrollConfiguration.of(context).copyWith( + dragDevices: { + PointerDeviceKind.touch, + PointerDeviceKind.mouse, + PointerDeviceKind.trackpad, + }, + ), + child: Padding( + padding: const EdgeInsets.only( + left: 20, + right: 20, + bottom: 20, + top: 40, + ), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + localizations.customTokenAddTitle, + style: ArchethicThemeStyles.textStyleSize16W600Primary, + ), + const SizedBox( + height: 30, + ), + const AddCustomTokenTextFieldAddress(), + const Padding( + padding: EdgeInsets.symmetric(vertical: 20), + child: AddCustomTokenInfoToken(), + ), + Text( + localizations.customTokenAddDesc, + style: AppTextStyles.bodyMedium(context), + ), + const SizedBox( + height: 100, + ), + ], + ), + ), + ), + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: Padding( + padding: EdgeInsets.only( + bottom: MediaQuery.of(context).padding.bottom + 20, + ), + child: Row( + children: [ + AppButtonTinyConnectivity( + localizations.cancel, + Dimens.buttonBottomDimens, + key: const Key('cancel'), + onPressed: () { + context.pop(); + }, + ), + AppButtonTinyConnectivity( + localizations.confirm, + disabled: !addCustomTokenForm.isControlsOk, + Dimens.buttonBottomDimens, + key: const Key('confirm'), + onPressed: () async { + final result = await ref + .read(addCustomTokenFormNotifierProvider.notifier) + .addCustomToken(ref, localizations); + if (result) { + final poolListRaw = await ref + .read(DexPoolProviders.getPoolListRaw.future); + + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshBalance(), + ); + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshFungibleTokens(poolListRaw), + ); + + context.pop(); + } + }, + ), + ], + ), + ), + ), + ], + ); + } +} diff --git a/lib/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart new file mode 100644 index 000000000..24e94220d --- /dev/null +++ b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_info_token.dart @@ -0,0 +1,105 @@ +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; +import 'package:aewallet/modules/aeswap/ui/views/util/components/format_address_link_copy_big_icon.dart'; +import 'package:aewallet/ui/views/add_custom_token/bloc/provider.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:gradient_borders/box_borders/gradient_box_border.dart'; + +class AddCustomTokenInfoToken extends ConsumerWidget { + const AddCustomTokenInfoToken({ + super.key, + }); + + @override + Widget build(BuildContext context, WidgetRef ref) { + final addCustomToken = ref.watch(addCustomTokenFormNotifierProvider); + if (addCustomToken.token == null) { + return const SizedBox( + height: 100, + ); + } + + return Container( + height: 100, + padding: const EdgeInsets.all(10), + alignment: Alignment.centerLeft, + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + aedappfm.AppThemeBase.sheetBackgroundTertiary.withOpacity(0.4), + aedappfm.AppThemeBase.sheetBackgroundTertiary, + ], + stops: const [0, 1], + ), + border: GradientBoxBorder( + gradient: LinearGradient( + colors: [ + aedappfm.AppThemeBase.sheetBorderTertiary.withOpacity(0.4), + aedappfm.AppThemeBase.sheetBorderTertiary, + ], + stops: const [0, 1], + ), + ), + borderRadius: BorderRadius.circular(10), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + width: 10, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (addCustomToken.token!.isLpToken) + SizedBox( + height: 50, + child: FormatAddressLinkCopyBigIcon( + header: + '${addCustomToken.token!.lpTokenPair!.token1.symbol.reduceSymbol()}/${addCustomToken.token!.lpTokenPair!.token2.symbol.reduceSymbol()}', + address: addCustomToken.token!.address!, + reduceAddress: true, + fontSize: AppTextStyles.bodyMedium(context).fontSize!, + ), + ) + else + SizedBox( + height: 50, + child: FormatAddressLinkCopyBigIcon( + header: addCustomToken.token!.symbol, + address: addCustomToken.token!.address!, + reduceAddress: true, + fontSize: AppTextStyles.bodyMedium(context).fontSize!, + ), + ), + ], + ), + ), + Row( + children: [ + Text( + '${AppLocalizations.of(context)!.customTokenAddBalance}: ', + style: AppTextStyles.bodyMedium(context), + ), + if (addCustomToken.token!.isLpToken) + Text( + '${addCustomToken.userTokenBalance.formatNumber(precision: addCustomToken.userTokenBalance > 1 ? 4 : 8)} ${addCustomToken.userTokenBalance > 1 ? AppLocalizations.of(context)!.lpTokens : AppLocalizations.of(context)!.lpToken}', + style: AppTextStyles.bodyMediumSecondaryColor(context), + ) + else + Text( + '${addCustomToken.userTokenBalance.formatNumber(precision: addCustomToken.userTokenBalance > 1 ? 4 : 8)} ${addCustomToken.token!.symbol.reduceSymbol()}', + style: AppTextStyles.bodyMediumSecondaryColor(context), + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart new file mode 100644 index 000000000..9dc52f0e2 --- /dev/null +++ b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart @@ -0,0 +1,187 @@ +import 'package:aewallet/ui/themes/archethic_theme.dart'; +import 'package:aewallet/ui/themes/styles.dart'; +import 'package:aewallet/ui/views/add_custom_token/bloc/provider.dart'; +import 'package:aewallet/ui/views/transfer/layouts/components/transfer_tokens_list.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_animate/flutter_animate.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:material_symbols_icons/symbols.dart'; +import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; + +class AddCustomTokenTextFieldAddress extends ConsumerStatefulWidget { + const AddCustomTokenTextFieldAddress({ + super.key, + }); + + @override + ConsumerState createState() => + _AddCustomTokenTextFieldAddressState(); +} + +class _AddCustomTokenTextFieldAddressState + extends ConsumerState { + late TextEditingController addressController; + late FocusNode addressFocusNode; + + @override + void initState() { + super.initState(); + addressFocusNode = FocusNode(); + addressController = TextEditingController(); + } + + @override + void dispose() { + addressFocusNode.dispose(); + addressController.dispose(); + super.dispose(); + } + + @override + Widget build( + BuildContext context, + ) { + final addCustomTokenFormNotifier = + ref.watch(addCustomTokenFormNotifierProvider.notifier); + final localizations = AppLocalizations.of(context)!; + + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 5), + child: Text( + AppLocalizations.of(context)!.customTokenAddTextFieldLabel, + ), + ), + SizedBox( + width: MediaQuery.of(context).size.width, + child: Row( + children: [ + Expanded( + child: DecoratedBox( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + ), + child: Row( + children: [ + Expanded( + child: DecoratedBox( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + 10, + ), + border: Border.all( + color: Theme.of(context) + .colorScheme + .primaryContainer, + width: 0.5, + ), + gradient: + ArchethicTheme.gradientInputFormBackground, + ), + child: TextField( + style: const TextStyle( + fontSize: 14, + ), + autocorrect: false, + textAlignVertical: TextAlignVertical.center, + maxLines: 2, + maxLength: 68, + controller: addressController, + onChanged: (text) async { + await addCustomTokenFormNotifier.setTokenAddress( + AppLocalizations.of(context)!, + text, + ); + }, + focusNode: addressFocusNode, + textInputAction: TextInputAction.next, + keyboardType: TextInputType.text, + inputFormatters: [ + LengthLimitingTextInputFormatter( + 68, + ), + ], + decoration: const InputDecoration( + border: InputBorder.none, + contentPadding: EdgeInsets.all(10), + ), + ), + ), + ), + aedappfm.TextFieldButton( + icon: Symbols.data_loss_prevention, + onPressed: () async { + final tokenSelected = + await showCupertinoModalBottomSheet( + context: context, + builder: (BuildContext context) { + return FractionallySizedBox( + heightFactor: 1, + child: Scaffold( + backgroundColor: aedappfm + .AppThemeBase.sheetBackground + .withOpacity(0.2), + body: Container( + width: MediaQuery.sizeOf(context).width, + padding: const EdgeInsets.symmetric( + horizontal: 15, + ), + child: Column( + children: [ + Padding( + padding: + const EdgeInsets.only(top: 15), + child: Text( + localizations + .customTokenAddSelectionTokenTitle, + style: ArchethicThemeStyles + .textStyleSize16W600Primary, + textAlign: TextAlign.center, + ), + ), + const TransferTokensList( + withVerified: false, + withLPToken: true, + withNotVerified: true, + withCustomToken: false, + ), + ], + ), + ), + ), + ); + }, + ) as aedappfm.AEToken; + if (tokenSelected.address != null) { + addressController.text = tokenSelected.address!; + await ref + .read( + addCustomTokenFormNotifierProvider.notifier, + ) + .setTokenAddress( + localizations, + tokenSelected.address!, + ); + } + }, + ), + ], + ), + ), + ), + ], + ), + ), + ], + ) + .animate() + .fade(duration: const Duration(milliseconds: 200)) + .scale(duration: const Duration(milliseconds: 200)); + } +} diff --git a/lib/ui/views/aeswap_earn/layouts/components/farm_lock_block_list_single_line_lock.dart b/lib/ui/views/aeswap_earn/layouts/components/farm_lock_block_list_single_line_lock.dart index 974b8e1ce..1e56eadb4 100644 --- a/lib/ui/views/aeswap_earn/layouts/components/farm_lock_block_list_single_line_lock.dart +++ b/lib/ui/views/aeswap_earn/layouts/components/farm_lock_block_list_single_line_lock.dart @@ -1,4 +1,3 @@ -import 'dart:ui'; import 'package:aewallet/modules/aeswap/domain/models/dex_farm_lock.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_farm_lock_user_infos.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_pool.dart'; diff --git a/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart b/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart index d1e9423a9..aa756a497 100644 --- a/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart +++ b/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart @@ -1,4 +1,9 @@ +import 'dart:async'; + +import 'package:aewallet/application/account/providers.dart'; import 'package:aewallet/application/price_history/providers.dart'; +import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart'; +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/address_formatters.dart'; @@ -9,6 +14,7 @@ import 'package:aewallet/ui/views/tokens_detail/layouts/components/token_detail_ import 'package:aewallet/ui/views/tokens_detail/layouts/components/token_detail_info.dart'; import 'package:aewallet/ui/views/tokens_detail/layouts/components/token_detail_menu.dart'; import 'package:aewallet/ui/widgets/balance/balance_infos.dart'; +import 'package:aewallet/ui/widgets/components/dialog.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton.dart'; import 'package:aewallet/ui/widgets/components/sheet_skeleton_interface.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' @@ -117,6 +123,64 @@ class TokenDetailSheet extends ConsumerWidget context.pop(); }, ), + widgetRight: aeToken.isVerified + ? null + : Padding( + padding: const EdgeInsets.only(top: 13, right: 15), + child: InkWell( + child: Column( + children: [ + const Icon( + Symbols.hide_source, + size: 20, + weight: IconSize.weightM, + opticalSize: IconSize.opticalSizeM, + grade: IconSize.gradeM, + ), + Text( + localizations.hideBtn, + style: AppTextStyles.bodySmall(context), + ), + ], + ), + onTap: () async { + await AppDialogs.showConfirmDialog( + context, + ref, + localizations.hideTokenConfirmationTitle, + localizations.hideTokenConfirmationDesc, + localizations.yes, + () async { + final accountSelected = ref.read( + AccountProviders.accounts.select( + (accounts) => accounts.valueOrNull?.selectedAccount, + ), + ); + if (accountSelected != null && aeToken.address != null) { + await accountSelected + .removeCustomTokenAddress(aeToken.address!); + + final poolListRaw = await ref + .read(DexPoolProviders.getPoolListRaw.future); + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshBalance(), + ); + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshFungibleTokens(poolListRaw), + ); + } + context.pop(); + }, + ); + }, + ), + ), ); } diff --git a/lib/ui/views/tokens_list/bloc/provider.dart b/lib/ui/views/tokens_list/bloc/provider.dart index 9f8e154b4..a4ab99aeb 100644 --- a/lib/ui/views/tokens_list/bloc/provider.dart +++ b/lib/ui/views/tokens_list/bloc/provider.dart @@ -7,8 +7,8 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'provider.g.dart'; @riverpod -Future> _tokens( - _TokensRef ref, { +Future> tokens( + TokensRef ref, { String searchCriteria = '', bool withVerified = true, bool withLPToken = true, @@ -23,8 +23,7 @@ Future> _tokens( if (selectedAccount == null) return []; final tokensList = await ref.watch( - TokensListProvider( - selectedAccount.genesisAddress, + tokensFromUserBalanceProvider( withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, @@ -61,7 +60,3 @@ Future> _tokens( return sortedTokens; }, ); - -class TokensListFormProvider { - static const tokens = _tokensProvider; -} diff --git a/lib/ui/views/tokens_list/bloc/provider.g.dart b/lib/ui/views/tokens_list/bloc/provider.g.dart index 715cc1c44..3bd739f44 100644 --- a/lib/ui/views/tokens_list/bloc/provider.g.dart +++ b/lib/ui/views/tokens_list/bloc/provider.g.dart @@ -6,7 +6,7 @@ part of 'provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$tokensHash() => r'dfa67751dda19dc2e149611ed148260fc5f373c2'; +String _$tokensHash() => r'd2db0355eb2b61faa66737441a25e6049591c9f6'; /// Copied from Dart SDK class _SystemHash { @@ -29,23 +29,23 @@ class _SystemHash { } } -/// See also [_tokens]. -@ProviderFor(_tokens) -const _tokensProvider = _TokensFamily(); +/// See also [tokens]. +@ProviderFor(tokens) +const tokensProvider = TokensFamily(); -/// See also [_tokens]. -class _TokensFamily extends Family>> { - /// See also [_tokens]. - const _TokensFamily(); +/// See also [tokens]. +class TokensFamily extends Family>> { + /// See also [tokens]. + const TokensFamily(); - /// See also [_tokens]. - _TokensProvider call({ + /// See also [tokens]. + TokensProvider call({ String searchCriteria = '', bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, }) { - return _TokensProvider( + return TokensProvider( searchCriteria: searchCriteria, withVerified: withVerified, withLPToken: withLPToken, @@ -54,8 +54,8 @@ class _TokensFamily extends Family>> { } @override - _TokensProvider getProviderOverride( - covariant _TokensProvider provider, + TokensProvider getProviderOverride( + covariant TokensProvider provider, ) { return call( searchCriteria: provider.searchCriteria, @@ -77,40 +77,40 @@ class _TokensFamily extends Family>> { _allTransitiveDependencies; @override - String? get name => r'_tokensProvider'; + String? get name => r'tokensProvider'; } -/// See also [_tokens]. -class _TokensProvider extends AutoDisposeFutureProvider> { - /// See also [_tokens]. - _TokensProvider({ +/// See also [tokens]. +class TokensProvider extends AutoDisposeFutureProvider> { + /// See also [tokens]. + TokensProvider({ String searchCriteria = '', bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, }) : this._internal( - (ref) => _tokens( - ref as _TokensRef, + (ref) => tokens( + ref as TokensRef, searchCriteria: searchCriteria, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, ), - from: _tokensProvider, - name: r'_tokensProvider', + from: tokensProvider, + name: r'tokensProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') ? null : _$tokensHash, - dependencies: _TokensFamily._dependencies, - allTransitiveDependencies: _TokensFamily._allTransitiveDependencies, + dependencies: TokensFamily._dependencies, + allTransitiveDependencies: TokensFamily._allTransitiveDependencies, searchCriteria: searchCriteria, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, ); - _TokensProvider._internal( + TokensProvider._internal( super._createNotifier, { required super.name, required super.dependencies, @@ -130,12 +130,12 @@ class _TokensProvider extends AutoDisposeFutureProvider> { @override Override overrideWith( - FutureOr> Function(_TokensRef provider) create, + FutureOr> Function(TokensRef provider) create, ) { return ProviderOverride( origin: this, - override: _TokensProvider._internal( - (ref) => create(ref as _TokensRef), + override: TokensProvider._internal( + (ref) => create(ref as TokensRef), from: from, name: null, dependencies: null, @@ -156,7 +156,7 @@ class _TokensProvider extends AutoDisposeFutureProvider> { @override bool operator ==(Object other) { - return other is _TokensProvider && + return other is TokensProvider && other.searchCriteria == searchCriteria && other.withVerified == withVerified && other.withLPToken == withLPToken && @@ -175,9 +175,13 @@ class _TokensProvider extends AutoDisposeFutureProvider> { } } +<<<<<<< HEAD @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element mixin _TokensRef on AutoDisposeFutureProviderRef> { +======= +mixin TokensRef on AutoDisposeFutureProviderRef> { +>>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// The parameter `searchCriteria` of this provider. String get searchCriteria; @@ -192,17 +196,17 @@ mixin _TokensRef on AutoDisposeFutureProviderRef> { } class _TokensProviderElement - extends AutoDisposeFutureProviderElement> with _TokensRef { + extends AutoDisposeFutureProviderElement> with TokensRef { _TokensProviderElement(super.provider); @override - String get searchCriteria => (origin as _TokensProvider).searchCriteria; + String get searchCriteria => (origin as TokensProvider).searchCriteria; @override - bool get withVerified => (origin as _TokensProvider).withVerified; + bool get withVerified => (origin as TokensProvider).withVerified; @override - bool get withLPToken => (origin as _TokensProvider).withLPToken; + bool get withLPToken => (origin as TokensProvider).withLPToken; @override - bool get withNotVerified => (origin as _TokensProvider).withNotVerified; + bool get withNotVerified => (origin as TokensProvider).withNotVerified; } // ignore_for_file: type=lint // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/ui/views/tokens_list/layouts/components/custom_token_add_btn.dart b/lib/ui/views/tokens_list/layouts/components/custom_token_add_btn.dart new file mode 100644 index 000000000..04814afc2 --- /dev/null +++ b/lib/ui/views/tokens_list/layouts/components/custom_token_add_btn.dart @@ -0,0 +1,68 @@ +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; +import 'package:aewallet/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:material_symbols_icons/symbols.dart'; +import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; + +class CustomTokenAddBtn extends ConsumerWidget { + const CustomTokenAddBtn({ + super.key, + }); + + @override + Widget build(BuildContext context, WidgetRef ref) { + return Padding( + padding: const EdgeInsets.only(left: 10, right: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + InkWell( + onTap: () async { + await CupertinoScaffold.showCupertinoModalBottomSheet( + context: context, + builder: (BuildContext context) { + return FractionallySizedBox( + heightFactor: 1, + child: Scaffold( + backgroundColor: aedappfm.AppThemeBase.sheetBackground + .withOpacity(0.2), + body: const AddCustomTokenSheet(), + ), + ); + }, + ); + }, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), + alignment: Alignment.center, + decoration: BoxDecoration( + gradient: aedappfm.AppThemeBase.gradientBtn, + borderRadius: BorderRadius.circular(20), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + const Icon( + Symbols.add, + color: Colors.white, + size: 17, + ), + const SizedBox(width: 5), + Text( + AppLocalizations.of(context)!.token, + style: AppTextStyles.bodyMedium(context), + ), + const SizedBox(width: 5), + ], + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart b/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart index 37150af53..c29fb0fc7 100644 --- a/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart +++ b/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart @@ -1,9 +1,11 @@ import 'package:aewallet/domain/repositories/features_flags.dart'; +import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/formatters.dart'; import 'package:aewallet/ui/views/tokens_detail/layouts/token_detail_sheet.dart'; import 'package:aewallet/ui/views/tokens_list/bloc/provider.dart'; +import 'package:aewallet/ui/views/tokens_list/layouts/components/custom_token_add_btn.dart'; import 'package:aewallet/ui/views/tokens_list/layouts/components/token_add_btn.dart'; import 'package:aewallet/ui/views/tokens_list/layouts/components/token_detail.dart'; import 'package:flutter/material.dart'; @@ -25,6 +27,35 @@ class TokensListState extends ConsumerState @override bool get wantKeepAlive => true; String searchCriteria = ''; + late FocusNode _focusNode; + double _searchFieldWidth = 150; + + @override + void initState() { + super.initState(); + _focusNode = FocusNode(); + _focusNode.addListener(_handleFocusChange); + } + + @override + void dispose() { + _focusNode + ..removeListener(_handleFocusChange) + ..dispose(); + super.dispose(); + } + + void _handleFocusChange() { + if (_focusNode.hasFocus) { + setState(() { + _searchFieldWidth = MediaQuery.of(context).size.width * 0.9; + }); + } else { + setState(() { + _searchFieldWidth = 150; + }); + } + } @override Widget build(BuildContext context) { @@ -32,42 +63,51 @@ class TokensListState extends ConsumerState final tokens = ref .watch( - TokensListFormProvider.tokens( + tokensProvider( searchCriteria: searchCriteria, + withLPToken: false, + withNotVerified: false, ), ) .valueOrNull; final localizations = AppLocalizations.of(context)!; return Column( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.center, + Stack( + alignment: Alignment.centerLeft, children: [ - Expanded( - child: Align( - alignment: Alignment.topCenter, + const Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + if (FeatureFlags.tokenFungibleCreationFeature) TokenAddBtn(), + CustomTokenAddBtn(), + ], + ), + SizedBox( + height: 48, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + width: _searchFieldWidth, child: TextFormField( + focusNode: _focusNode, textAlignVertical: TextAlignVertical.center, decoration: InputDecoration( contentPadding: EdgeInsets.zero, prefixIcon: Icon( Symbols.search, color: ArchethicTheme.text, - size: 18, + size: 20, weight: IconSize.weightM, opticalSize: IconSize.opticalSizeM, grade: IconSize.gradeM, ), - suffixIcon: const SizedBox( - width: 26, - ), border: const OutlineInputBorder( borderRadius: BorderRadius.all( Radius.circular(90), ), borderSide: BorderSide.none, ), - hintStyle: ArchethicThemeStyles.textStyleSize12W100Primary, + hintStyle: AppTextStyles.bodyMedium(context), filled: true, hintText: localizations.searchField, ), @@ -85,10 +125,12 @@ class TokensListState extends ConsumerState }, ); }, + onTapOutside: (event) { + FocusManager.instance.primaryFocus?.unfocus(); + }, ), ), ), - if (FeatureFlags.tokenFungibleCreationFeature) const TokenAddBtn(), ], ), if (tokens != null) diff --git a/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart b/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart index a7c2fb268..9fd0d2f42 100644 --- a/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart +++ b/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:aewallet/application/account/providers.dart'; import 'package:aewallet/application/tokens/tokens.dart'; import 'package:aewallet/ui/views/transfer/layouts/components/transfer_token_detail.dart'; import 'package:flutter/material.dart'; @@ -8,9 +7,18 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; class TransferTokensList extends ConsumerStatefulWidget { const TransferTokensList({ + this.withVerified = true, + this.withNotVerified = false, + this.withLPToken = false, + this.withCustomToken = true, super.key, }); + final bool withVerified; + final bool withNotVerified; + final bool withLPToken; + final bool withCustomToken; + @override ConsumerState createState() => TransferTokensListState(); } @@ -24,14 +32,12 @@ class TransferTokensListState extends ConsumerState Widget build(BuildContext context) { super.build(context); - final selectedAccount = ref.watch( - AccountProviders.accounts.select( - (accounts) => accounts.valueOrNull?.selectedAccount, - ), - ); final tokensListAsync = ref.watch( - TokensListProvider( - selectedAccount!.genesisAddress, + tokensFromUserBalanceProvider( + withVerified: widget.withVerified, + withNotVerified: widget.withNotVerified, + withLPToken: widget.withLPToken, + withCustomToken: widget.withCustomToken, ), ); diff --git a/lib/ui/widgets/balance/balance_infos.dart b/lib/ui/widgets/balance/balance_infos.dart index e8ac6b977..9df77f62a 100644 --- a/lib/ui/widgets/balance/balance_infos.dart +++ b/lib/ui/widgets/balance/balance_infos.dart @@ -61,9 +61,7 @@ class _BalanceTotalUSDShowed extends ConsumerWidget { children: [ FutureBuilder( future: ref.watch( - TokensTotalUSDProvider( - accountSelected.genesisAddress, - ).future, + tokensTotalUSDProvider.future, ), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { From 15b325b04c7189fc47e81ffeabb786ddf7b4074c Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 08:49:12 +0100 Subject: [PATCH 02/11] chore: :arrow_up: Upgrade riverpod --- lib/application/aeswap/dex_token.g.dart | 4 ++ lib/application/dapps.dart | 1 + lib/application/dapps.g.dart | 4 ++ lib/application/tokens/tokens.dart | 68 +++++++++++++++---- lib/application/tokens/tokens.g.dart | 22 +++++- lib/l10n/intl_en.arb | 2 +- lib/l10n/intl_fr.arb | 2 +- lib/modules/aeswap/application/balance.g.dart | 4 ++ .../add_custom_token/bloc/provider.g.dart | 2 +- lib/ui/views/tokens_list/bloc/provider.dart | 3 +- lib/ui/views/tokens_list/bloc/provider.g.dart | 7 +- lib/util/riverpod_debounce.dart | 4 +- pubspec.yaml | 8 +-- 13 files changed, 105 insertions(+), 26 deletions(-) diff --git a/lib/application/aeswap/dex_token.g.dart b/lib/application/aeswap/dex_token.g.dart index e2fd79cd3..92c8c336d 100644 --- a/lib/application/aeswap/dex_token.g.dart +++ b/lib/application/aeswap/dex_token.g.dart @@ -789,11 +789,15 @@ class _GetRemoveAmountsProviderElement } String _$estimateLPTokenInFiatHash() => +<<<<<<< HEAD <<<<<<< HEAD r'117d1b9fae927eca34724ab59d026abeaf3a6393'; ======= r'4da34defbb60f367688c57c66b713d474f680f72'; >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) +======= + r'117d1b9fae927eca34724ab59d026abeaf3a6393'; +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// See also [_estimateLPTokenInFiat]. @ProviderFor(_estimateLPTokenInFiat) diff --git a/lib/application/dapps.dart b/lib/application/dapps.dart index a16a4fcd5..7d2e10127 100644 --- a/lib/application/dapps.dart +++ b/lib/application/dapps.dart @@ -17,6 +17,7 @@ DAppsRepositoryImpl _dAppsRepository( @riverpod Future _getDApp( Ref ref, + AvailableNetworks network, String code, ) async { final apiService = ref.watch(apiServiceProvider); diff --git a/lib/application/dapps.g.dart b/lib/application/dapps.g.dart index f0ab0bdbe..c09fa03e6 100644 --- a/lib/application/dapps.g.dart +++ b/lib/application/dapps.g.dart @@ -24,7 +24,11 @@ final _dAppsRepositoryProvider = @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _DAppsRepositoryRef = AutoDisposeProviderRef; +<<<<<<< HEAD String _$getDAppHash() => r'e708424d60dbef17da84a12ed02a67dd493a28a2'; +======= +String _$getDAppHash() => r'70f3139f239d37e2aaf093b1007b668aeab29d90'; +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// Copied from Dart SDK class _SystemHash { diff --git a/lib/application/tokens/tokens.dart b/lib/application/tokens/tokens.dart index c0eb0c203..e5a26e253 100644 --- a/lib/application/tokens/tokens.dart +++ b/lib/application/tokens/tokens.dart @@ -6,6 +6,7 @@ import 'package:aewallet/application/api_service.dart'; import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; import 'package:aewallet/modules/aeswap/application/pool/dex_pool.dart'; import 'package:aewallet/modules/aeswap/application/session/provider.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; @@ -15,8 +16,32 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'tokens.g.dart'; @riverpod -Future> tokensList( +TokensRepositoryImpl tokensRepositoryImpl( + Ref ref, +) => + TokensRepositoryImpl(); + +@riverpod +Future> tokensFromAddresses( + Ref ref, + List addresses, +) async { + final apiService = ref.watch(apiServiceProvider); + + return ref + .watch( + tokensRepositoryImplProvider, + ) + .getTokensFromAddresses( + addresses, + apiService, + ); +} + +@riverpod +Future> tokensFromUserBalance( Ref ref, { + bool withUCO = true, bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, @@ -31,17 +56,28 @@ Future> tokensList( if (selectedAccount == null) return []; - return TokensRepositoryImpl().getTokensFromUserBalance( - selectedAccount.genesisAddress, - selectedAccount.customTokenAddressList ?? [], - apiService, - poolListRaw, - environment, - withVerified: withVerified, - withLPToken: withLPToken, - withNotVerified: withNotVerified, - withCustomToken: withCustomToken, - ); + final tokensRepository = ref.watch(tokensRepositoryImplProvider); + final defTokensRepository = + ref.watch(aedappfm.defTokensRepositoryImplProvider); + + return ref + .watch( + tokensRepositoryImplProvider, + ) + .getTokensFromUserBalance( + selectedAccount.genesisAddress, + selectedAccount.customTokenAddressList ?? [], + apiService, + poolListRaw, + environment, + withUCO: withUCO, + withVerified: withVerified, + withLPToken: withLPToken, + withNotVerified: withNotVerified, + withCustomToken: withCustomToken, + defTokensRepository, + tokensRepository, + ); } @riverpod @@ -56,7 +92,11 @@ Future tokensTotalUSD( if (selectedAccount == null) return 0.0; final tokensList = await ref.watch( - tokensFromUserBalanceProvider().future, + tokensFromUserBalanceProvider( + withLPToken: false, + withNotVerified: false, + withVerified: false, + ).future, ); for (final token in tokensList) { @@ -75,7 +115,7 @@ Future tokensTotalUSD( ) : (await ref.watch( DexTokensProviders.estimateTokenInFiat( - token.address != null ? token.address! : 'UCO', + token.address != null ? token.address! : kUCOAddress, ).future, ) * token.balance); diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index 4b65bc793..ecef1b1d8 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -10,8 +10,12 @@ part of 'tokens.dart'; String _$tokensListHash() => r'593e48ed9063457663e2e48b344aed4ca8bc7518'; ======= String _$tokensFromAddressesHash() => +<<<<<<< HEAD r'4cd16d00a6c3c466c3eefe8e60852b2791c7527b'; >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) +======= + r'dfc16b82d33ff918a59411a80e8a0d3719259f92'; +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// Copied from Dart SDK class _SystemHash { @@ -152,6 +156,8 @@ class TokensFromAddressesProvider } } +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element mixin TokensFromAddressesRef on AutoDisposeFutureProviderRef> { /// The parameter `addresses` of this provider. @@ -169,7 +175,7 @@ class _TokensFromAddressesProviderElement } String _$tokensFromUserBalanceHash() => - r'3a218ad12c5949939e3f275d32d1e1f27a2022cf'; + r'935d3476bfdb54548c70492dede7f9c08a3a7338'; /// See also [tokensFromUserBalance]. @ProviderFor(tokensFromUserBalance) @@ -321,6 +327,7 @@ class TokensFromUserBalanceProvider } } +<<<<<<< HEAD <<<<<<< HEAD @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element @@ -329,6 +336,10 @@ mixin TokensListRef on AutoDisposeFutureProviderRef> { String get userGenesisAddress; ======= +======= +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) mixin TokensFromUserBalanceRef on AutoDisposeFutureProviderRef> { >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) @@ -363,11 +374,15 @@ class _TokensFromUserBalanceProviderElement (origin as TokensFromUserBalanceProvider).withCustomToken; } +<<<<<<< HEAD <<<<<<< HEAD String _$tokensTotalUSDHash() => r'a0f42e1ef21073d1ec7f627b48fde93b76205a7a'; ======= String _$tokensTotalUSDHash() => r'98ac96ba39ca5f3b227f4d114c7556532a4d24dd'; >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) +======= +String _$tokensTotalUSDHash() => r'39ec8250b31cdf374fe272bd8b3077dd8efb6476'; +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// See also [tokensTotalUSD]. @ProviderFor(tokensTotalUSD) @@ -381,6 +396,7 @@ final tokensTotalUSDProvider = AutoDisposeFutureProvider.internal( allTransitiveDependencies: null, ); +<<<<<<< HEAD <<<<<<< HEAD /// See also [tokensTotalUSD]. class TokensTotalUSDFamily extends Family> { @@ -508,6 +524,10 @@ class _TokensTotalUSDProviderElement (origin as TokensTotalUSDProvider).userGenesisAddress; } ======= +======= +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) typedef TokensTotalUSDRef = AutoDisposeFutureProviderRef; >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) // ignore_for_file: type=lint diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index e2929956d..c9dd63a86 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -756,7 +756,7 @@ "customTokenAddressAlreadyExistsInAccount": "You already have this token in your wallet.", "customTokenAddressNotValid": "This address is not a valid token.", "hideBtn": "Hide", - "hideTokenConfirmationTitle": "Hide this token in my wallet", + "hideTokenConfirmationTitle": "Hide this token?", "hideTokenConfirmationDesc": "Are you sure you want to hide this token in your wallet?\nYou can display it again anytime by going to the Account tab and clicking '+ token'.", "customTokenAddSelectionTokenTitle": "Select a token\nwith a balance in your account", "customTokenAddBalance": "Your balance" diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 313df3e93..bf8af52a6 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -736,7 +736,7 @@ "customTokenAddressAlreadyExistsInAccount": "Vous avez déjà ce token dans votre wallet.", "customTokenAddressNotValid": "Cette adresse ne correspond pas à un token.", "hideBtn": "Masquer", - "hideTokenConfirmationTitle": "Masquer ce token dans mon portefeuille", + "hideTokenConfirmationTitle": "Masquer ce token ?", "hideTokenConfirmationDesc": "Êtes-vous sûr(e) de vouloir masquer ce token dans votre wallet ? Vous pourrez le réafficher à tout moment en accédant à l'onglet Compte et en cliquant sur '+ jeton'.", "customTokenAddSelectionTokenTitle": "Sélectionner un token\navec un solde dans votre compte", "customTokenAddBalance": "Votre solde" diff --git a/lib/modules/aeswap/application/balance.g.dart b/lib/modules/aeswap/application/balance.g.dart index 13b0cb255..a677c05e5 100644 --- a/lib/modules/aeswap/application/balance.g.dart +++ b/lib/modules/aeswap/application/balance.g.dart @@ -177,11 +177,15 @@ class _AddressBalanceProviderElement } String _$addressBalanceTotalFiatHash() => +<<<<<<< HEAD <<<<<<< HEAD r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; ======= r'39f9c8fc5cd22a8b4ae2c923013783f59c219326'; >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) +======= + r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// See also [addressBalanceTotalFiat]. @ProviderFor(addressBalanceTotalFiat) diff --git a/lib/ui/views/add_custom_token/bloc/provider.g.dart b/lib/ui/views/add_custom_token/bloc/provider.g.dart index f441ed643..3fba6296a 100644 --- a/lib/ui/views/add_custom_token/bloc/provider.g.dart +++ b/lib/ui/views/add_custom_token/bloc/provider.g.dart @@ -25,4 +25,4 @@ final addCustomTokenFormNotifierProvider = AutoDisposeNotifierProvider< typedef _$AddCustomTokenFormNotifier = AutoDisposeNotifier; // ignore_for_file: type=lint -// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/ui/views/tokens_list/bloc/provider.dart b/lib/ui/views/tokens_list/bloc/provider.dart index a4ab99aeb..227cc469b 100644 --- a/lib/ui/views/tokens_list/bloc/provider.dart +++ b/lib/ui/views/tokens_list/bloc/provider.dart @@ -2,13 +2,14 @@ import 'package:aewallet/application/account/providers.dart'; import 'package:aewallet/application/tokens/tokens.dart'; import 'package:aewallet/util/riverpod_debounce.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'provider.g.dart'; @riverpod Future> tokens( - TokensRef ref, { + Ref ref, { String searchCriteria = '', bool withVerified = true, bool withLPToken = true, diff --git a/lib/ui/views/tokens_list/bloc/provider.g.dart b/lib/ui/views/tokens_list/bloc/provider.g.dart index 3bd739f44..287c386f8 100644 --- a/lib/ui/views/tokens_list/bloc/provider.g.dart +++ b/lib/ui/views/tokens_list/bloc/provider.g.dart @@ -6,7 +6,7 @@ part of 'provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$tokensHash() => r'd2db0355eb2b61faa66737441a25e6049591c9f6'; +String _$tokensHash() => r'7d7863f8ea3451e67500a6aea50ee4fffa0305a4'; /// Copied from Dart SDK class _SystemHash { @@ -175,11 +175,16 @@ class TokensProvider extends AutoDisposeFutureProvider> { } } +<<<<<<< HEAD <<<<<<< HEAD @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element mixin _TokensRef on AutoDisposeFutureProviderRef> { ======= +======= +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +>>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) mixin TokensRef on AutoDisposeFutureProviderRef> { >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// The parameter `searchCriteria` of this provider. diff --git a/lib/util/riverpod_debounce.dart b/lib/util/riverpod_debounce.dart index b404927a4..a351e4666 100644 --- a/lib/util/riverpod_debounce.dart +++ b/lib/util/riverpod_debounce.dart @@ -1,7 +1,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; -extension FutureRefDebounce on Ref> { - Future debounce({ +extension FutureRefDebounce on Ref { + Future debounce({ bool shouldDebounce = true, Duration delay = const Duration(milliseconds: 500), required Future Function() build, diff --git a/pubspec.yaml b/pubspec.yaml index ad6cf69a0..3e8581801 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -129,7 +129,7 @@ dependencies: flutter_native_splash: ^2.3.10 # State management - flutter_riverpod: ^2.5.1 + flutter_riverpod: ^2.6.1 # Flutter Secure Storage provides API to store data in secure storage. Keychain is used in iOS, KeyStore based solution is used in Android flutter_secure_storage: ^9.0.0 @@ -231,7 +231,7 @@ dependencies: quiver: ^3.2.1 # A package exposing annotations for riverpod_generator - riverpod_annotation: ^2.3.5 + riverpod_annotation: ^2.6.1 # RxDart is an implementation of the popular reactiveX api for asynchronous programming, leveraging the native Dart Streams api. rxdart: ^0.27.7 @@ -292,8 +292,8 @@ dev_dependencies: # Simple yet powerful Flutter-native UI testing framework eliminating limitations of flutter_test, integration_test, and flutter_driver. #patrol: ^3.5.2 # A code generator for Riverpod. This both simplifies the syntax empowers it, such as allowing stateful hot-reload. - riverpod_generator: ^2.3.11 - riverpod_lint: ^2.3.10 + riverpod_generator: ^2.6.1 + riverpod_lint: ^2.4.0 msix_config: display_name: Archethic Wallet From f2721e312f2c7ffaea3ca1d20b3740224a4bc595 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 09:56:21 +0100 Subject: [PATCH 03/11] fix: :bug: Bugs fixing --- lib/application/aeswap/dex_token.dart | 7 ++--- lib/application/aeswap/dex_token.g.dart | 2 +- lib/application/tokens/tokens.g.dart | 21 ++++++++++++++- .../tokens/tokens.repository.dart | 27 ++++++++++++++----- .../repositories/dex_token.repository.dart | 1 + .../infrastructure/dex_token.repository.dart | 25 ++++------------- .../add_custom_token_textfield_address.dart | 4 +-- lib/ui/views/main/account_tab.dart | 1 + .../layouts/token_detail_sheet.dart | 2 +- .../components/transfer_tokens_list.dart | 3 +++ 10 files changed, 58 insertions(+), 35 deletions(-) diff --git a/lib/application/aeswap/dex_token.dart b/lib/application/aeswap/dex_token.dart index e01c44c74..4fcdf25f4 100644 --- a/lib/application/aeswap/dex_token.dart +++ b/lib/application/aeswap/dex_token.dart @@ -40,9 +40,10 @@ Future> _tokensFromAccount( return const []; } - return ref - .watch(_dexTokenRepositoryProvider) - .getTokensFromAccount(accountSelected.genesisAddress); + return ref.watch(_dexTokenRepositoryProvider).getTokensFromAccount( + accountSelected.genesisAddress, + accountSelected.customTokenAddressList ?? [], + ); } @riverpod diff --git a/lib/application/aeswap/dex_token.g.dart b/lib/application/aeswap/dex_token.g.dart index 92c8c336d..549bf297f 100644 --- a/lib/application/aeswap/dex_token.g.dart +++ b/lib/application/aeswap/dex_token.g.dart @@ -179,7 +179,7 @@ class _GetTokenFromAddressProviderElement dynamic get address => (origin as _GetTokenFromAddressProvider).address; } -String _$tokensFromAccountHash() => r'5569df982bfeec1ae0830584cc20954eccc43fbc'; +String _$tokensFromAccountHash() => r'1c72386cb1da228839f679494a627d6e051fbf68'; /// See also [_tokensFromAccount]. @ProviderFor(_tokensFromAccount) diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index ecef1b1d8..9dce6d3d3 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -175,7 +175,7 @@ class _TokensFromAddressesProviderElement } String _$tokensFromUserBalanceHash() => - r'935d3476bfdb54548c70492dede7f9c08a3a7338'; + r'00dbb0c3c334cf38533f0e7d50ba90a95f24803e'; /// See also [tokensFromUserBalance]. @ProviderFor(tokensFromUserBalance) @@ -189,12 +189,14 @@ class TokensFromUserBalanceFamily /// See also [tokensFromUserBalance]. TokensFromUserBalanceProvider call({ + bool withUCO = true, bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, bool withCustomToken = true, }) { return TokensFromUserBalanceProvider( + withUCO: withUCO, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, @@ -207,6 +209,7 @@ class TokensFromUserBalanceFamily covariant TokensFromUserBalanceProvider provider, ) { return call( + withUCO: provider.withUCO, withVerified: provider.withVerified, withLPToken: provider.withLPToken, withNotVerified: provider.withNotVerified, @@ -234,6 +237,7 @@ class TokensFromUserBalanceProvider extends AutoDisposeFutureProvider> { /// See also [tokensFromUserBalance]. TokensFromUserBalanceProvider({ + bool withUCO = true, bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, @@ -241,6 +245,7 @@ class TokensFromUserBalanceProvider }) : this._internal( (ref) => tokensFromUserBalance( ref as TokensFromUserBalanceRef, + withUCO: withUCO, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, @@ -255,6 +260,7 @@ class TokensFromUserBalanceProvider dependencies: TokensFromUserBalanceFamily._dependencies, allTransitiveDependencies: TokensFromUserBalanceFamily._allTransitiveDependencies, + withUCO: withUCO, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, @@ -268,12 +274,14 @@ class TokensFromUserBalanceProvider required super.allTransitiveDependencies, required super.debugGetCreateSourceHash, required super.from, + required this.withUCO, required this.withVerified, required this.withLPToken, required this.withNotVerified, required this.withCustomToken, }) : super.internal(); + final bool withUCO; final bool withVerified; final bool withLPToken; final bool withNotVerified; @@ -293,6 +301,7 @@ class TokensFromUserBalanceProvider dependencies: null, allTransitiveDependencies: null, debugGetCreateSourceHash: null, + withUCO: withUCO, withVerified: withVerified, withLPToken: withLPToken, withNotVerified: withNotVerified, @@ -309,6 +318,7 @@ class TokensFromUserBalanceProvider @override bool operator ==(Object other) { return other is TokensFromUserBalanceProvider && + other.withUCO == withUCO && other.withVerified == withVerified && other.withLPToken == withLPToken && other.withNotVerified == withNotVerified && @@ -318,6 +328,7 @@ class TokensFromUserBalanceProvider @override int get hashCode { var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, withUCO.hashCode); hash = _SystemHash.combine(hash, withVerified.hashCode); hash = _SystemHash.combine(hash, withLPToken.hashCode); hash = _SystemHash.combine(hash, withNotVerified.hashCode); @@ -342,7 +353,13 @@ mixin TokensListRef on AutoDisposeFutureProviderRef> { >>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) mixin TokensFromUserBalanceRef on AutoDisposeFutureProviderRef> { +<<<<<<< HEAD >>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) +======= + /// The parameter `withUCO` of this provider. + bool get withUCO; + +>>>>>>> c07b6392 (fix: :bug: Bugs fixing) /// The parameter `withVerified` of this provider. bool get withVerified; @@ -361,6 +378,8 @@ class _TokensFromUserBalanceProviderElement with TokensFromUserBalanceRef { _TokensFromUserBalanceProviderElement(super.provider); + @override + bool get withUCO => (origin as TokensFromUserBalanceProvider).withUCO; @override bool get withVerified => (origin as TokensFromUserBalanceProvider).withVerified; diff --git a/lib/infrastructure/repositories/tokens/tokens.repository.dart b/lib/infrastructure/repositories/tokens/tokens.repository.dart index 7dfc89d03..d499ca683 100644 --- a/lib/infrastructure/repositories/tokens/tokens.repository.dart +++ b/lib/infrastructure/repositories/tokens/tokens.repository.dart @@ -64,6 +64,7 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { archethic.ApiService apiService, List poolsListRaw, aedappfm.Environment environment, { + bool withUCO = true, bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, @@ -74,7 +75,7 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { if (balanceMap[userGenesisAddress] == null) { return tokensList; } - if (withVerified) { + if (withUCO) { final defUCOToken = await aedappfm.DefTokensRepositoryImpl() .getDefToken(environment, 'UCO'); tokensList.add( @@ -113,9 +114,13 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { environment: environment, ).getVerifiedTokens(); - for (final tokenBalance in balanceMap[userGenesisAddress]!.token) { - final token = tokenMap[tokenBalance.address]; - if (token != null && token.type == 'fungible') { + final tokenBalances = balanceMap[userGenesisAddress]!.token; + + for (final entry in tokenMap.entries) { + final key = entry.key; + final token = entry.value; + + if (token.type == 'fungible') { var aeToken = await tokenModelToAETokenModel( token, verifiedTokens, @@ -123,16 +128,24 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { environment, apiService, ); + + final matchingBalances = tokenBalances.where( + (element) => element.address?.toUpperCase() == key.toUpperCase(), + ); + final tokenBalanceAmount = matchingBalances.isNotEmpty + ? archethic.fromBigInt(matchingBalances.first.amount).toDouble() + : 0.0; + aeToken = aeToken.copyWith( - balance: archethic.fromBigInt(tokenBalance.amount).toDouble(), + balance: tokenBalanceAmount, ); if (aeToken.isVerified && withVerified || + !aeToken.isVerified && withNotVerified || aeToken.isLpToken && withLPToken || withCustomToken && userTokenLocalAddresses - .contains(aeToken.address!.toUpperCase()) || - !aeToken.isVerified && withNotVerified) { + .contains(aeToken.address!.toUpperCase())) { tokensList.add(aeToken); } } diff --git a/lib/modules/aeswap/domain/repositories/dex_token.repository.dart b/lib/modules/aeswap/domain/repositories/dex_token.repository.dart index f999ee9c6..82d1bd137 100644 --- a/lib/modules/aeswap/domain/repositories/dex_token.repository.dart +++ b/lib/modules/aeswap/domain/repositories/dex_token.repository.dart @@ -10,6 +10,7 @@ abstract class DexTokenRepository { Future> getTokensFromAccount( String accountAddress, + List userTokenLocalAddresses, ); Future> getLocalTokensDescriptions( diff --git a/lib/modules/aeswap/infrastructure/dex_token.repository.dart b/lib/modules/aeswap/infrastructure/dex_token.repository.dart index 1249d3664..c6c7933e2 100644 --- a/lib/modules/aeswap/infrastructure/dex_token.repository.dart +++ b/lib/modules/aeswap/infrastructure/dex_token.repository.dart @@ -51,22 +51,16 @@ class DexTokenRepositoryImpl with ModelParser implements DexTokenRepository { @override Future> getTokensFromAccount( String accountAddress, + List userTokenLocalAddresses, ) async { - final balanceMap = await apiService.fetchBalance([accountAddress]); - final balance = balanceMap[accountAddress]; - if (balance == null) { - return []; - } final dexTokens = []; final tokenAddressList = []; - for (final token in balance.token) { - if (token.tokenId == 0) tokenAddressList.add(token.address!); + for (final tokenAddress in userTokenLocalAddresses) { + tokenAddressList.add(tokenAddress); } - final dexTokenUCO = DexToken.uco( - balance: archethic.fromBigInt(balance.uco).toDouble(), - ); + final dexTokenUCO = DexToken.uco(); dexTokens.add(dexTokenUCO); final tokenMap = await apiService.getToken( @@ -105,16 +99,7 @@ class DexTokenRepositoryImpl with ModelParser implements DexTokenRepository { final _token = value.copyWith(address: key); - var balanceAmount = 0.0; - for (final tokenBalance in balance.token) { - if (tokenBalance.address!.toUpperCase() == - _token.address!.toUpperCase()) { - balanceAmount = archethic.fromBigInt(tokenBalance.amount).toDouble(); - break; - } - } - - var dexToken = tokenSDKToModel(_token, balanceAmount); + var dexToken = tokenSDKToModel(_token, 0); if (token1Address != null && token2Address != null) { dexToken = dexToken.copyWith( diff --git a/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart index 9dc52f0e2..71df72f30 100644 --- a/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart +++ b/lib/ui/views/add_custom_token/layouts/components/add_custom_token_textfield_address.dart @@ -90,7 +90,7 @@ class _AddCustomTokenTextFieldAddressState ), autocorrect: false, textAlignVertical: TextAlignVertical.center, - maxLines: 2, + maxLines: 3, maxLength: 68, controller: addressController, onChanged: (text) async { @@ -146,7 +146,7 @@ class _AddCustomTokenTextFieldAddressState ), ), const TransferTokensList( - withVerified: false, + withUCO: false, withLPToken: true, withNotVerified: true, withCustomToken: false, diff --git a/lib/ui/views/main/account_tab.dart b/lib/ui/views/main/account_tab.dart index 791ecafa2..f37dc22ff 100644 --- a/lib/ui/views/main/account_tab.dart +++ b/lib/ui/views/main/account_tab.dart @@ -112,6 +112,7 @@ class AccountTab extends ConsumerWidget { ), const Icon( Symbols.content_copy, + color: Colors.white, weight: IconSize.weightM, opticalSize: IconSize.opticalSizeM, grade: IconSize.gradeM, diff --git a/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart b/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart index aa756a497..be0aa508e 100644 --- a/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart +++ b/lib/ui/views/tokens_detail/layouts/token_detail_sheet.dart @@ -123,7 +123,7 @@ class TokenDetailSheet extends ConsumerWidget context.pop(); }, ), - widgetRight: aeToken.isVerified + widgetRight: aeToken.isUCO ? null : Padding( padding: const EdgeInsets.only(top: 13, right: 15), diff --git a/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart b/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart index 9fd0d2f42..b6f0010b0 100644 --- a/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart +++ b/lib/ui/views/transfer/layouts/components/transfer_tokens_list.dart @@ -7,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; class TransferTokensList extends ConsumerStatefulWidget { const TransferTokensList({ + this.withUCO = true, this.withVerified = true, this.withNotVerified = false, this.withLPToken = false, @@ -14,6 +15,7 @@ class TransferTokensList extends ConsumerStatefulWidget { super.key, }); + final bool withUCO; final bool withVerified; final bool withNotVerified; final bool withLPToken; @@ -34,6 +36,7 @@ class TransferTokensListState extends ConsumerState final tokensListAsync = ref.watch( tokensFromUserBalanceProvider( + withUCO: widget.withUCO, withVerified: widget.withVerified, withNotVerified: widget.withNotVerified, withLPToken: widget.withLPToken, From 53835d89eeabf7051dfb35128864b401064796c2 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 10:23:06 +0100 Subject: [PATCH 04/11] fix: :bug: Bug fixing --- lib/application/tokens/tokens.g.dart | 4 ++++ lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index 9dce6d3d3..1f65a218d 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -393,6 +393,7 @@ class _TokensFromUserBalanceProviderElement (origin as TokensFromUserBalanceProvider).withCustomToken; } +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD String _$tokensTotalUSDHash() => r'a0f42e1ef21073d1ec7f627b48fde93b76205a7a'; @@ -402,6 +403,9 @@ String _$tokensTotalUSDHash() => r'98ac96ba39ca5f3b227f4d114c7556532a4d24dd'; ======= String _$tokensTotalUSDHash() => r'39ec8250b31cdf374fe272bd8b3077dd8efb6476'; >>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) +======= +String _$tokensTotalUSDHash() => r'f3e1d13475c67a72664e0fdb557b296f134fc9ad'; +>>>>>>> d4305dd0 (fix: :bug: Bug fixing) /// See also [tokensTotalUSD]. @ProviderFor(tokensTotalUSD) diff --git a/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart b/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart index c29fb0fc7..460ca17b4 100644 --- a/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart +++ b/lib/ui/views/tokens_list/layouts/tokens_list_sheet.dart @@ -65,6 +65,7 @@ class TokensListState extends ConsumerState .watch( tokensProvider( searchCriteria: searchCriteria, + withVerified: false, withLPToken: false, withNotVerified: false, ), From 7da5f64b6cc56f991d6a7d2b9984c00dfcef0459 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 11:46:42 +0100 Subject: [PATCH 05/11] chore: :recycle: Use provider to use TokensRepositoryImpl --- lib/application/tokens/tokens.g.dart | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index 1f65a218d..85e18c14a 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -6,6 +6,7 @@ part of 'tokens.dart'; // RiverpodGenerator // ************************************************************************** +<<<<<<< HEAD <<<<<<< HEAD String _$tokensListHash() => r'593e48ed9063457663e2e48b344aed4ca8bc7518'; ======= @@ -16,6 +17,29 @@ String _$tokensFromAddressesHash() => ======= r'dfc16b82d33ff918a59411a80e8a0d3719259f92'; >>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) +======= +String _$tokensRepositoryImplHash() => + r'6d0639fff11793ccb691c0bdb8aa86b99078ee47'; + +/// See also [tokensRepositoryImpl]. +@ProviderFor(tokensRepositoryImpl) +final tokensRepositoryImplProvider = + AutoDisposeProvider.internal( + tokensRepositoryImpl, + name: r'tokensRepositoryImplProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$tokensRepositoryImplHash, + dependencies: null, + allTransitiveDependencies: null, +); + +@Deprecated('Will be removed in 3.0. Use Ref instead') +// ignore: unused_element +typedef TokensRepositoryImplRef = AutoDisposeProviderRef; +String _$tokensFromAddressesHash() => + r'3eb854cf86092bf7599a28a546924b3a2eb3bf14'; +>>>>>>> d48d1eb3 (chore: :recycle: Use provider to use TokensRepositoryImpl) /// Copied from Dart SDK class _SystemHash { @@ -175,7 +199,7 @@ class _TokensFromAddressesProviderElement } String _$tokensFromUserBalanceHash() => - r'00dbb0c3c334cf38533f0e7d50ba90a95f24803e'; + r'8541eb1a96eca49d68d5e757fb375a953c7176c7'; /// See also [tokensFromUserBalance]. @ProviderFor(tokensFromUserBalance) From 44c7d0f4a42e923467917537add99ba4a93d7945 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 11:52:04 +0100 Subject: [PATCH 06/11] chore: :recycle: Fix code from PR review --- .../views/add_custom_token/bloc/provider.dart | 2 +- .../add_custom_token/bloc/provider.g.dart | 2 +- .../layouts/add_custom_token_sheet.dart | 35 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/ui/views/add_custom_token/bloc/provider.dart b/lib/ui/views/add_custom_token/bloc/provider.dart index 274547d34..5053c8248 100644 --- a/lib/ui/views/add_custom_token/bloc/provider.dart +++ b/lib/ui/views/add_custom_token/bloc/provider.dart @@ -43,7 +43,7 @@ class AddCustomTokenFormNotifier extends _$AddCustomTokenFormNotifier ).future, ); final poolsListRaw = - await ref.watch(DexPoolProviders.getPoolListRaw.future); + await ref.read(DexPoolProviders.getPoolListRaw.future); final apiService = ref.read(apiServiceProvider); final verifiedTokens = await ref diff --git a/lib/ui/views/add_custom_token/bloc/provider.g.dart b/lib/ui/views/add_custom_token/bloc/provider.g.dart index 3fba6296a..92fd34296 100644 --- a/lib/ui/views/add_custom_token/bloc/provider.g.dart +++ b/lib/ui/views/add_custom_token/bloc/provider.g.dart @@ -7,7 +7,7 @@ part of 'provider.dart'; // ************************************************************************** String _$addCustomTokenFormNotifierHash() => - r'bed5461223b7090b5dbb444712be793f51e556e2'; + r'371269f8e2baa6caddf2e73f9b0269bbdc1199e8'; /// See also [AddCustomTokenFormNotifier]. @ProviderFor(AddCustomTokenFormNotifier) diff --git a/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart b/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart index 36ff2d9ad..23468cb10 100644 --- a/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart +++ b/lib/ui/views/add_custom_token/layouts/add_custom_token_sheet.dart @@ -122,25 +122,26 @@ class AddCustomTokenSheet extends ConsumerWidget { final result = await ref .read(addCustomTokenFormNotifierProvider.notifier) .addCustomToken(ref, localizations); - if (result) { - final poolListRaw = await ref - .read(DexPoolProviders.getPoolListRaw.future); - unawaited( - (await ref - .read(AccountProviders.accounts.notifier) - .selectedAccountNotifier) - ?.refreshBalance(), - ); - unawaited( - (await ref - .read(AccountProviders.accounts.notifier) - .selectedAccountNotifier) - ?.refreshFungibleTokens(poolListRaw), - ); + if (!result) return; - context.pop(); - } + final poolListRaw = + await ref.read(DexPoolProviders.getPoolListRaw.future); + + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshBalance(), + ); + unawaited( + (await ref + .read(AccountProviders.accounts.notifier) + .selectedAccountNotifier) + ?.refreshFungibleTokens(poolListRaw), + ); + + context.pop(); }, ), ], From 88c6cc3c058c3299326bac33c74297f817b8280f Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 16:02:04 +0100 Subject: [PATCH 07/11] chore: :recycle: Use constants --- lib/application/tokens/tokens.g.dart | 4 +++ lib/domain/models/token_parser.dart | 13 +++---- .../tokens/tokens.repository.dart | 5 +-- lib/modules/aeswap/application/balance.dart | 4 +-- lib/modules/aeswap/application/balance.g.dart | 4 +++ .../aeswap/domain/models/dex_token.dart | 9 ++++- .../infrastructure/dex_token.repository.dart | 3 +- .../views/util/components/dex_token_icon.dart | 3 +- lib/service/app_service.dart | 11 +++--- .../farm_lock_claim_confirm_infos.dart | 3 +- .../farm_lock_claim_confirm_sheet.dart | 3 +- .../aeswap_farm_lock_deposit/bloc/state.dart | 3 +- .../farm_lock_deposit_confirm_sheet.dart | 3 +- .../bloc/provider.dart | 3 +- .../bloc/provider.g.dart | 2 +- .../farm_lock_level_up_confirm_sheet.dart | 3 +- .../farm_lock_withdraw_confirm_infos.dart | 3 +- .../farm_lock_withdraw_confirm_sheet.dart | 3 +- .../aeswap_liquidity_add/bloc/provider.dart | 10 +++--- .../aeswap_liquidity_add/bloc/provider.g.dart | 2 +- .../liquidity_add_confirm_sheet.dart | 3 +- .../components/liquidity_add_form_sheet.dart | 4 +-- .../bloc/provider.dart | 4 +-- .../bloc/provider.g.dart | 2 +- .../liquidity_remove_confirm_sheet.dart | 3 +- lib/ui/views/aeswap_swap/bloc/provider.dart | 16 ++++----- lib/ui/views/aeswap_swap/bloc/provider.g.dart | 2 +- .../components/swap_confirm_sheet.dart | 3 +- .../layouts/components/swap_icon_refresh.dart | 3 +- .../views/aeswap_swap/layouts/swap_tab.dart | 4 +-- .../token_selection_common_bases.dart | 2 +- .../layouts/components/token_single.dart | 7 ++-- .../layouts/components/token_detail_info.dart | 5 +-- .../layouts/components/token_detail_menu.dart | 3 +- .../layouts/components/token_detail.dart | 5 +-- .../components/transfer_textfield_amount.dart | 2 +- .../transfer/layouts/transfer_sheet.dart | 1 + pubspec.lock | 35 +++++++++++++++++++ 38 files changed, 135 insertions(+), 63 deletions(-) diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index 85e18c14a..7998c2357 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -420,6 +420,7 @@ class _TokensFromUserBalanceProviderElement <<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD +<<<<<<< HEAD String _$tokensTotalUSDHash() => r'a0f42e1ef21073d1ec7f627b48fde93b76205a7a'; ======= String _$tokensTotalUSDHash() => r'98ac96ba39ca5f3b227f4d114c7556532a4d24dd'; @@ -430,6 +431,9 @@ String _$tokensTotalUSDHash() => r'39ec8250b31cdf374fe272bd8b3077dd8efb6476'; ======= String _$tokensTotalUSDHash() => r'f3e1d13475c67a72664e0fdb557b296f134fc9ad'; >>>>>>> d4305dd0 (fix: :bug: Bug fixing) +======= +String _$tokensTotalUSDHash() => r'4cd1d9dfe1e4a3c828254a2be2461ee032318cc0'; +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) /// See also [tokensTotalUSD]. @ProviderFor(tokensTotalUSD) diff --git a/lib/domain/models/token_parser.dart b/lib/domain/models/token_parser.dart index 4abd79872..29532813f 100644 --- a/lib/domain/models/token_parser.dart +++ b/lib/domain/models/token_parser.dart @@ -1,4 +1,5 @@ import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; @@ -34,10 +35,10 @@ mixin TokenParser { poolRaw.concatenatedTokensAddresses.split('/')[0].toUpperCase(); token2Address = poolRaw.concatenatedTokensAddresses.split('/')[1].toUpperCase(); - if (token1Address != 'UCO') { + if (token1Address != kUCOAddress) { tokenSymbolSearch.add(token1Address); } - if (token2Address != 'UCO') { + if (token2Address != kUCOAddress) { tokenSymbolSearch.add(token2Address); } @@ -46,12 +47,12 @@ mixin TokenParser { tokenSymbolSearch, apiService, ); - pairSymbolToken1 = token1Address != 'UCO' + pairSymbolToken1 = token1Address != kUCOAddress ? tokensSymbolMap[token1Address]!.symbol - : 'UCO'; - pairSymbolToken2 = token2Address != 'UCO' + : kUCOAddress; + pairSymbolToken2 = token2Address != kUCOAddress ? tokensSymbolMap[token2Address]!.symbol - : 'UCO'; + : kUCOAddress; final futureToken1 = aedappfm.DefTokensRepositoryImpl().getDefToken( environment, diff --git a/lib/infrastructure/repositories/tokens/tokens.repository.dart b/lib/infrastructure/repositories/tokens/tokens.repository.dart index d499ca683..2422133f6 100644 --- a/lib/infrastructure/repositories/tokens/tokens.repository.dart +++ b/lib/infrastructure/repositories/tokens/tokens.repository.dart @@ -2,6 +2,7 @@ import 'package:aewallet/domain/models/token_parser.dart'; import 'package:aewallet/domain/repositories/tokens/tokens.repository.dart'; import 'package:aewallet/infrastructure/datasources/tokens_list.hive.dart'; import 'package:aewallet/infrastructure/datasources/wallet_token_dto.hive.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; @@ -47,7 +48,7 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { final getTokens = await Future.wait(futures); for (final Map getToken in getTokens) { getToken.forEach((key, value) async { - if (value.type == 'fungible') { + if (value.type == tokenFungibleType) { value = value.copyWith(address: key); await tokensListDatasource.setToken(value.toHive()); } @@ -77,7 +78,7 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { } if (withUCO) { final defUCOToken = await aedappfm.DefTokensRepositoryImpl() - .getDefToken(environment, 'UCO'); + .getDefToken(environment, kUCOAddress); tokensList.add( aedappfm.ucoToken.copyWith( name: defUCOToken?.name ?? '', diff --git a/lib/modules/aeswap/application/balance.dart b/lib/modules/aeswap/application/balance.dart index 6e3f219aa..0f077cbd6 100644 --- a/lib/modules/aeswap/application/balance.dart +++ b/lib/modules/aeswap/application/balance.dart @@ -72,8 +72,8 @@ Future addressBalanceTotalFiat( await balanceAsync.when( data: (balance) async { if (balance.uco > 0) { - final fiatValueUCO = await ref - .watch(DexTokensProviders.estimateTokenInFiat('UCO').future); + final fiatValueUCO = await ref.watch( + DexTokensProviders.estimateTokenInFiat(kUCOAddress).future); total = (Decimal.parse('${archethic.fromBigInt(balance.uco)}') * Decimal.parse(fiatValueUCO.toString())) .toDouble(); diff --git a/lib/modules/aeswap/application/balance.g.dart b/lib/modules/aeswap/application/balance.g.dart index a677c05e5..786cdada2 100644 --- a/lib/modules/aeswap/application/balance.g.dart +++ b/lib/modules/aeswap/application/balance.g.dart @@ -178,6 +178,7 @@ class _AddressBalanceProviderElement String _$addressBalanceTotalFiatHash() => <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; ======= @@ -186,6 +187,9 @@ String _$addressBalanceTotalFiatHash() => ======= r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; >>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) +======= + r'b5193d8603fbd36ea7e7f676a624a0137ad43fde'; +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) /// See also [addressBalanceTotalFiat]. @ProviderFor(addressBalanceTotalFiat) diff --git a/lib/modules/aeswap/domain/models/dex_token.dart b/lib/modules/aeswap/domain/models/dex_token.dart index 6b4cdd48a..1c4ce49cd 100644 --- a/lib/modules/aeswap/domain/models/dex_token.dart +++ b/lib/modules/aeswap/domain/models/dex_token.dart @@ -28,7 +28,7 @@ class DexToken with _$DexToken { DexToken( name: 'Universal Coin', symbol: 'UCO', - address: 'UCO', + address: kUCOAddress, icon: 'Archethic.svg', isVerified: true, balance: balance ?? 0, @@ -44,8 +44,15 @@ class DexToken with _$DexToken { } const kUCOAddress = 'UCO'; +const tokenFungibleType = 'fungible'; +const tokenNonFungibleType = 'non-fungible'; extension DexTokenAddressExtension on String { bool get isUCO => this == kUCOAddress; bool get isNotUCO => !isUCO; } + +extension TokenExtension on String { + bool get isFungible => this == tokenFungibleType; + bool get isNonFungible => this == tokenNonFungibleType; +} diff --git a/lib/modules/aeswap/infrastructure/dex_token.repository.dart b/lib/modules/aeswap/infrastructure/dex_token.repository.dart index c6c7933e2..6bafa9e40 100644 --- a/lib/modules/aeswap/infrastructure/dex_token.repository.dart +++ b/lib/modules/aeswap/infrastructure/dex_token.repository.dart @@ -33,7 +33,8 @@ class DexTokenRepositoryImpl with ModelParser implements DexTokenRepository { [address], request: 'name, symbol, type', ); - if (tokenMap[address] != null && tokenMap[address]!.type == 'fungible') { + if (tokenMap[address] != null && + tokenMap[address]!.type == tokenFungibleType) { token = tokenSDKToModel(tokenMap[address]!, 0); token = token.copyWith(address: address); await tokensListDatasource.setToken( diff --git a/lib/modules/aeswap/ui/views/util/components/dex_token_icon.dart b/lib/modules/aeswap/ui/views/util/components/dex_token_icon.dart index 42b506b63..cc2df1f84 100644 --- a/lib/modules/aeswap/ui/views/util/components/dex_token_icon.dart +++ b/lib/modules/aeswap/ui/views/util/components/dex_token_icon.dart @@ -1,5 +1,6 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/application/aeswap/dex_token.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; @@ -18,7 +19,7 @@ class DexTokenIcon extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final tokenIcon = ref.watch( DexTokensProviders.getTokenIcon( - tokenAddress.isEmpty ? 'UCO' : tokenAddress, + tokenAddress.isEmpty ? kUCOAddress : tokenAddress, ), ); return tokenIcon.map( diff --git a/lib/service/app_service.dart b/lib/service/app_service.dart index c36f20267..7d4213453 100644 --- a/lib/service/app_service.dart +++ b/lib/service/app_service.dart @@ -15,6 +15,7 @@ import 'package:aewallet/model/data/account_token.dart'; import 'package:aewallet/model/data/contact.dart'; import 'package:aewallet/model/keychain_service_keypair.dart'; import 'package:aewallet/model/transaction_infos.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; import 'package:aewallet/util/keychain_util.dart'; import 'package:aewallet/util/number_util.dart'; @@ -753,7 +754,7 @@ class AppService { String? pairSymbolToken2; String? token1Address; String? token2Address; - if (token != null && token.type == 'fungible') { + if (token != null && token.type == tokenFungibleType) { var pairSymbolToken = ''; token1Address = null; token2Address = null; @@ -772,12 +773,12 @@ class AppService { final tokensSymbolMap = await getToken( tokenSymbolSearch, ); - pairSymbolToken1 = token1Address != 'UCO' + pairSymbolToken1 = token1Address != kUCOAddress ? tokensSymbolMap[token1Address]!.symbol! - : 'UCO'; - pairSymbolToken2 = token2Address != 'UCO' + : kUCOAddress; + pairSymbolToken2 = token2Address != kUCOAddress ? tokensSymbolMap[token2Address]!.symbol! - : 'UCO'; + : kUCOAddress; pairSymbolToken = '$pairSymbolToken1/$pairSymbolToken2'; } diff --git a/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_infos.dart b/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_infos.dart index b4b55effe..36c1df814 100644 --- a/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_infos.dart +++ b/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_infos.dart @@ -1,4 +1,5 @@ import 'package:aewallet/modules/aeswap/application/balance.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/dex_token_balance.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/fiat_value.dart'; @@ -108,7 +109,7 @@ class FarmLockClaimConfirmInfos extends ConsumerWidget { future: ref.watch( getBalanceProvider( farmLockClaim.rewardToken!.isUCO - ? 'UCO' + ? kUCOAddress : farmLockClaim.rewardToken!.address, ).future, ), diff --git a/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_sheet.dart b/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_sheet.dart index 1acbbaeb6..1806fc9df 100644 --- a/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_sheet.dart +++ b/lib/ui/views/aeswap_farm_lock_claim/layouts/components/farm_lock_claim_confirm_sheet.dart @@ -1,5 +1,6 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; @@ -151,7 +152,7 @@ class FarmLockClaimConfirmSheetState Text( AmountFormatters.standardSmallValue( farmLockClaim.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_farm_lock_deposit/bloc/state.dart b/lib/ui/views/aeswap_farm_lock_deposit/bloc/state.dart index 9f0e6de82..814602736 100644 --- a/lib/ui/views/aeswap_farm_lock_deposit/bloc/state.dart +++ b/lib/ui/views/aeswap_farm_lock_deposit/bloc/state.dart @@ -2,6 +2,7 @@ import 'package:aewallet/modules/aeswap/domain/models/dex_farm_lock.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_pool.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/farm_lock_duration_type.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'; import 'package:archethic_lib_dart/archethic_lib_dart.dart'; @@ -37,5 +38,5 @@ class FarmLockDepositFormState with _$FarmLockDepositFormState { bool get isControlsOk => failure == null && amount > 0; String? get lpTokenAddress => - pool?.lpToken.isUCO == true ? 'UCO' : pool?.lpToken.address; + pool?.lpToken.isUCO == true ? kUCOAddress : pool?.lpToken.address; } diff --git a/lib/ui/views/aeswap_farm_lock_deposit/layouts/components/farm_lock_deposit_confirm_sheet.dart b/lib/ui/views/aeswap_farm_lock_deposit/layouts/components/farm_lock_deposit_confirm_sheet.dart index d678d1d54..803851666 100644 --- a/lib/ui/views/aeswap_farm_lock_deposit/layouts/components/farm_lock_deposit_confirm_sheet.dart +++ b/lib/ui/views/aeswap_farm_lock_deposit/layouts/components/farm_lock_deposit_confirm_sheet.dart @@ -1,4 +1,5 @@ import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/consent_uri.dart'; @@ -210,7 +211,7 @@ class FarmLockDepositConfirmSheetState Text( AmountFormatters.standardSmallValue( farmLockDeposit.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.dart b/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.dart index 42ab4cd57..dbcd05812 100644 --- a/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.dart +++ b/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.dart @@ -3,6 +3,7 @@ import 'package:aewallet/application/aeswap/usecases.dart'; import 'package:aewallet/modules/aeswap/application/balance.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_farm_lock.dart'; import 'package:aewallet/modules/aeswap/domain/models/dex_pool.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/farm_lock_duration_type.dart'; import 'package:aewallet/modules/aeswap/util/browser_util_desktop.dart'; import 'package:aewallet/ui/views/aeswap_earn/bloc/provider.dart'; @@ -26,7 +27,7 @@ class FarmLockLevelUpFormNotifier extends _$FarmLockLevelUpFormNotifier { Future initBalances() async { final lpTokenBalance = await ref.read( getBalanceProvider( - state.pool!.lpToken.isUCO ? 'UCO' : state.pool!.lpToken.address, + state.pool!.lpToken.isUCO ? kUCOAddress : state.pool!.lpToken.address, ).future, ); state = state.copyWith(lpTokenBalance: lpTokenBalance); diff --git a/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.g.dart b/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.g.dart index 1e173d8f1..c5fc6dcba 100644 --- a/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.g.dart +++ b/lib/ui/views/aeswap_farm_lock_level_up/bloc/provider.g.dart @@ -7,7 +7,7 @@ part of 'provider.dart'; // ************************************************************************** String _$farmLockLevelUpFormNotifierHash() => - r'17c12bac574d83d4a0551b44bd840e51f8342739'; + r'e3dc1f345c81987a234fd1522c72354774e69acd'; /// See also [FarmLockLevelUpFormNotifier]. @ProviderFor(FarmLockLevelUpFormNotifier) diff --git a/lib/ui/views/aeswap_farm_lock_level_up/layouts/components/farm_lock_level_up_confirm_sheet.dart b/lib/ui/views/aeswap_farm_lock_level_up/layouts/components/farm_lock_level_up_confirm_sheet.dart index 59cc3cc1c..17f0ef2e4 100644 --- a/lib/ui/views/aeswap_farm_lock_level_up/layouts/components/farm_lock_level_up_confirm_sheet.dart +++ b/lib/ui/views/aeswap_farm_lock_level_up/layouts/components/farm_lock_level_up_confirm_sheet.dart @@ -1,5 +1,6 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/consent_uri.dart'; @@ -209,7 +210,7 @@ class FarmLockLevelUpConfirmSheetState Text( AmountFormatters.standardSmallValue( farmLockLevelUp.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_infos.dart b/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_infos.dart index f1db79b73..adb1dcfa6 100755 --- a/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_infos.dart +++ b/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_infos.dart @@ -1,4 +1,5 @@ import 'package:aewallet/modules/aeswap/application/balance.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/dex_token_balance.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/fiat_value.dart'; @@ -99,7 +100,7 @@ class FarmLockWithdrawConfirmInfos extends ConsumerWidget { future: ref.watch( getBalanceProvider( farmLockWithdraw.lpToken!.isUCO - ? 'UCO' + ? kUCOAddress : farmLockWithdraw.lpToken!.address, ).future, ), diff --git a/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_sheet.dart b/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_sheet.dart index d2a321f5b..7bd0ab5be 100644 --- a/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_sheet.dart +++ b/lib/ui/views/aeswap_farm_lock_withdraw/layouts/components/farm_lock_withdraw_confirm_sheet.dart @@ -1,5 +1,6 @@ /// SPDX-License-Identifier: AGPL-3.0-or-later import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; @@ -151,7 +152,7 @@ class FarmLockWithdrawConfirmSheetState Text( AmountFormatters.standardSmallValue( farmLockWithdraw.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_liquidity_add/bloc/provider.dart b/lib/ui/views/aeswap_liquidity_add/bloc/provider.dart index 3a329409f..1f80279b0 100644 --- a/lib/ui/views/aeswap_liquidity_add/bloc/provider.dart +++ b/lib/ui/views/aeswap_liquidity_add/bloc/provider.dart @@ -39,14 +39,14 @@ class LiquidityAddFormNotifier extends _$LiquidityAddFormNotifier { Future initBalances() async { final token1Balance = await ref.read( getBalanceProvider( - state.token1!.isUCO ? 'UCO' : state.token1!.address, + state.token1!.isUCO ? kUCOAddress : state.token1!.address, ).future, ); state = state.copyWith(token1Balance: token1Balance); final token2Balance = await ref.read( getBalanceProvider( - state.token2!.isUCO ? 'UCO' : state.token2!.address, + state.token2!.isUCO ? kUCOAddress : state.token2!.address, ).future, ); state = state.copyWith(token2Balance: token2Balance); @@ -64,7 +64,7 @@ class LiquidityAddFormNotifier extends _$LiquidityAddFormNotifier { final equivalentAmounResult = await PoolFactoryRepositoryImpl(state.pool!.poolAddress, apiService) .getEquivalentAmount( - state.token1!.isUCO ? 'UCO' : state.token1!.address, + state.token1!.isUCO ? kUCOAddress : state.token1!.address, 1, ); var ratio = 0.0; @@ -213,7 +213,7 @@ class LiquidityAddFormNotifier extends _$LiquidityAddFormNotifier { calculationInProgress: true, ); final equivalentAmount = await _calculateEquivalentAmount( - state.token1!.isUCO ? 'UCO' : state.token1!.address, + state.token1!.isUCO ? kUCOAddress : state.token1!.address, state.token1Amount, ); state = state.copyWith( @@ -226,7 +226,7 @@ class LiquidityAddFormNotifier extends _$LiquidityAddFormNotifier { calculationInProgress: true, ); final equivalentAmount = await _calculateEquivalentAmount( - state.token2!.isUCO ? 'UCO' : state.token2!.address, + state.token2!.isUCO ? kUCOAddress : state.token2!.address, state.token2Amount, ); state = state.copyWith( diff --git a/lib/ui/views/aeswap_liquidity_add/bloc/provider.g.dart b/lib/ui/views/aeswap_liquidity_add/bloc/provider.g.dart index e7317bd60..5e80102b8 100644 --- a/lib/ui/views/aeswap_liquidity_add/bloc/provider.g.dart +++ b/lib/ui/views/aeswap_liquidity_add/bloc/provider.g.dart @@ -7,7 +7,7 @@ part of 'provider.dart'; // ************************************************************************** String _$liquidityAddFormNotifierHash() => - r'85bfbe561e5dfe3b89a0afb865137e2bb2415b65'; + r'be1e9e77b31f4a71ffb32e6134c877353e0eacbf'; /// See also [LiquidityAddFormNotifier]. @ProviderFor(LiquidityAddFormNotifier) diff --git a/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_confirm_sheet.dart b/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_confirm_sheet.dart index 5d86d9bf8..c58a109cc 100644 --- a/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_confirm_sheet.dart +++ b/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_confirm_sheet.dart @@ -1,4 +1,5 @@ import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; @@ -148,7 +149,7 @@ class LiquidityAddConfirmFormSheetState Text( AmountFormatters.standardSmallValue( liquidityAdd.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_form_sheet.dart b/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_form_sheet.dart index 8b4bdb1f8..dd1715df4 100644 --- a/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_form_sheet.dart +++ b/lib/ui/views/aeswap_liquidity_add/layouts/components/liquidity_add_form_sheet.dart @@ -176,7 +176,7 @@ class LiquidityAddFormSheet extends ConsumerWidget children: [ DexTokenIcon( tokenAddress: liquidityAdd.token1!.address.isUCO - ? 'UCO' + ? kUCOAddress : liquidityAdd.token1!.address, ), Padding( @@ -223,7 +223,7 @@ class LiquidityAddFormSheet extends ConsumerWidget children: [ DexTokenIcon( tokenAddress: liquidityAdd.token2!.address.isUCO - ? 'UCO' + ? kUCOAddress : liquidityAdd.token2!.address, ), Padding( diff --git a/lib/ui/views/aeswap_liquidity_remove/bloc/provider.dart b/lib/ui/views/aeswap_liquidity_remove/bloc/provider.dart index 44e908587..2618c9446 100644 --- a/lib/ui/views/aeswap_liquidity_remove/bloc/provider.dart +++ b/lib/ui/views/aeswap_liquidity_remove/bloc/provider.dart @@ -177,13 +177,13 @@ class LiquidityRemoveFormNotifier extends _$LiquidityRemoveFormNotifier { ); final balanceToken1 = await ref.read( getBalanceProvider( - state.token1!.isUCO ? 'UCO' : state.token1!.address, + state.token1!.isUCO ? kUCOAddress : state.token1!.address, ).future, ); state = state.copyWith(token1Balance: balanceToken1); final balanceToken2 = await ref.read( getBalanceProvider( - state.token2!.isUCO ? 'UCO' : state.token2!.address, + state.token2!.isUCO ? kUCOAddress : state.token2!.address, ).future, ); state = state.copyWith( diff --git a/lib/ui/views/aeswap_liquidity_remove/bloc/provider.g.dart b/lib/ui/views/aeswap_liquidity_remove/bloc/provider.g.dart index 6453bb445..0c86064d2 100644 --- a/lib/ui/views/aeswap_liquidity_remove/bloc/provider.g.dart +++ b/lib/ui/views/aeswap_liquidity_remove/bloc/provider.g.dart @@ -7,7 +7,7 @@ part of 'provider.dart'; // ************************************************************************** String _$liquidityRemoveFormNotifierHash() => - r'7cdeac48f3a3d72edc1e480b803bca238491f5e1'; + r'75869b87bc39a8e04d04da78aadb490cd6b6f925'; /// See also [LiquidityRemoveFormNotifier]. @ProviderFor(LiquidityRemoveFormNotifier) diff --git a/lib/ui/views/aeswap_liquidity_remove/layouts/components/liquidity_remove_confirm_sheet.dart b/lib/ui/views/aeswap_liquidity_remove/layouts/components/liquidity_remove_confirm_sheet.dart index 6b8e99234..cce7f737d 100644 --- a/lib/ui/views/aeswap_liquidity_remove/layouts/components/liquidity_remove_confirm_sheet.dart +++ b/lib/ui/views/aeswap_liquidity_remove/layouts/components/liquidity_remove_confirm_sheet.dart @@ -1,4 +1,5 @@ import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; @@ -152,7 +153,7 @@ class LiquidityRemoveConfirmFormSheetState Text( AmountFormatters.standardSmallValue( liquidityRemove.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_swap/bloc/provider.dart b/lib/ui/views/aeswap_swap/bloc/provider.dart index 7193b6be9..35216ab61 100644 --- a/lib/ui/views/aeswap_swap/bloc/provider.dart +++ b/lib/ui/views/aeswap_swap/bloc/provider.dart @@ -118,8 +118,8 @@ class SwapFormNotifier extends _$SwapFormNotifier ), ); final poolInfosResult = await routerFactory.getPoolAddresses( - state.tokenToSwap!.isUCO ? 'UCO' : state.tokenToSwap!.address, - state.tokenSwapped!.isUCO ? 'UCO' : state.tokenSwapped!.address, + state.tokenToSwap!.isUCO ? kUCOAddress : state.tokenToSwap!.address, + state.tokenSwapped!.isUCO ? kUCOAddress : state.tokenSwapped!.address, ); await poolInfosResult.map( success: (success) async { @@ -343,7 +343,7 @@ class SwapFormNotifier extends _$SwapFormNotifier calculationInProgress: true, ); swapInfos = await calculateSwapInfos( - state.tokenToSwap!.isUCO ? 'UCO' : state.tokenToSwap!.address, + state.tokenToSwap!.isUCO ? kUCOAddress : state.tokenToSwap!.address, state.tokenToSwapAmount, true, ); @@ -370,7 +370,7 @@ class SwapFormNotifier extends _$SwapFormNotifier calculationInProgress: true, ); swapInfos = await calculateSwapInfos( - state.tokenSwapped!.isUCO ? 'UCO' : state.tokenSwapped!.address, + state.tokenSwapped!.isUCO ? kUCOAddress : state.tokenSwapped!.address, state.tokenSwappedAmount, false, ); @@ -391,7 +391,7 @@ class SwapFormNotifier extends _$SwapFormNotifier ); if (state.tokenToSwap != null) { swapInfos = await calculateSwapInfos( - state.tokenToSwap!.isUCO ? 'UCO' : state.tokenToSwap!.address, + state.tokenToSwap!.isUCO ? kUCOAddress : state.tokenToSwap!.address, state.tokenToSwapAmount, true, ); @@ -547,8 +547,8 @@ class SwapFormNotifier extends _$SwapFormNotifier ), ); final poolInfosResult = await routerFactory.getPoolAddresses( - state.tokenToSwap!.isUCO ? 'UCO' : state.tokenToSwap!.address, - state.tokenSwapped!.isUCO ? 'UCO' : state.tokenSwapped!.address, + state.tokenToSwap!.isUCO ? kUCOAddress : state.tokenToSwap!.address, + state.tokenSwapped!.isUCO ? kUCOAddress : state.tokenSwapped!.address, ); await poolInfosResult.map( success: (success) async { @@ -643,7 +643,7 @@ class SwapFormNotifier extends _$SwapFormNotifier return; } final swapInfos = await calculateSwapInfos( - state.tokenToSwap!.isUCO ? 'UCO' : state.tokenToSwap!.address, + state.tokenToSwap!.isUCO ? kUCOAddress : state.tokenToSwap!.address, state.tokenToSwapAmount, true, ); diff --git a/lib/ui/views/aeswap_swap/bloc/provider.g.dart b/lib/ui/views/aeswap_swap/bloc/provider.g.dart index 84e284747..b467ade42 100644 --- a/lib/ui/views/aeswap_swap/bloc/provider.g.dart +++ b/lib/ui/views/aeswap_swap/bloc/provider.g.dart @@ -42,7 +42,7 @@ final tokenSwappedBalanceProvider = AutoDisposeFutureProvider.internal( @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef TokenSwappedBalanceRef = AutoDisposeFutureProviderRef; -String _$swapFormNotifierHash() => r'40cbafe8ef97e62afe196e6c565baea18d19f2a9'; +String _$swapFormNotifierHash() => r'ac434094b894b4e632fa4ae94e14c96c5efa7c11'; /// See also [SwapFormNotifier]. @ProviderFor(SwapFormNotifier) diff --git a/lib/ui/views/aeswap_swap/layouts/components/swap_confirm_sheet.dart b/lib/ui/views/aeswap_swap/layouts/components/swap_confirm_sheet.dart index 6f684eddd..91d6cfdf9 100644 --- a/lib/ui/views/aeswap_swap/layouts/components/swap_confirm_sheet.dart +++ b/lib/ui/views/aeswap_swap/layouts/components/swap_confirm_sheet.dart @@ -1,4 +1,5 @@ import 'package:aewallet/application/account/providers.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/components/failure_message.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; @@ -145,7 +146,7 @@ class SwapConfirmFormSheetState extends ConsumerState Text( AmountFormatters.standardSmallValue( swap.feesEstimatedUCO, - 'UCO', + kUCOAddress, decimal: 3, ), style: AppTextStyles.bodyMedium(context), diff --git a/lib/ui/views/aeswap_swap/layouts/components/swap_icon_refresh.dart b/lib/ui/views/aeswap_swap/layouts/components/swap_icon_refresh.dart index 9e31907ea..1f14b06ee 100644 --- a/lib/ui/views/aeswap_swap/layouts/components/swap_icon_refresh.dart +++ b/lib/ui/views/aeswap_swap/layouts/components/swap_icon_refresh.dart @@ -1,3 +1,4 @@ +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/util/ui_util.dart'; import 'package:aewallet/ui/views/aeswap_swap/bloc/provider.dart'; @@ -53,7 +54,7 @@ class _SwapTokenIconRefreshState extends ConsumerState { if (swap.tokenToSwap != null && swap.tokenSwapped != null) { await swapNotifier.calculateSwapInfos( - swap.tokenToSwap!.isUCO ? 'UCO' : swap.tokenToSwap!.address, + swap.tokenToSwap!.isUCO ? kUCOAddress : swap.tokenToSwap!.address, swap.tokenToSwapAmount, true, ); diff --git a/lib/ui/views/aeswap_swap/layouts/swap_tab.dart b/lib/ui/views/aeswap_swap/layouts/swap_tab.dart index 33c0e50ef..8834256e6 100644 --- a/lib/ui/views/aeswap_swap/layouts/swap_tab.dart +++ b/lib/ui/views/aeswap_swap/layouts/swap_tab.dart @@ -46,7 +46,7 @@ class SwapTabState extends ConsumerState { if (params['from'] != null) { DexToken? _tokenToSwap; - if (params['from'] != 'UCO') { + if (params['from'] != kUCOAddress) { _tokenToSwap = await ref.read( DexTokensProviders.getTokenFromAddress(params['from']).future, ); @@ -62,7 +62,7 @@ class SwapTabState extends ConsumerState { if (params['to'] != null) { DexToken? _tokenSwapped; - if (params['to'] != 'UCO') { + if (params['to'] != kUCOAddress) { _tokenSwapped = await ref.read( DexTokensProviders.getTokenFromAddress(params['to']).future, ); diff --git a/lib/ui/views/token_selection/layouts/components/token_selection_common_bases.dart b/lib/ui/views/token_selection/layouts/components/token_selection_common_bases.dart index 7aed2ee7d..7c345a3ba 100644 --- a/lib/ui/views/token_selection/layouts/components/token_selection_common_bases.dart +++ b/lib/ui/views/token_selection/layouts/components/token_selection_common_bases.dart @@ -115,7 +115,7 @@ class _TokenSelector extends StatelessWidget { Padding( padding: const EdgeInsets.only(top: 2), child: VerifiedTokenIcon( - address: token.isUCO ? 'UCO' : token.address, + address: token.isUCO ? kUCOAddress : token.address, iconSize: 12, ), ), diff --git a/lib/ui/views/token_selection/layouts/components/token_single.dart b/lib/ui/views/token_selection/layouts/components/token_single.dart index ef702da8f..56b1f0d80 100644 --- a/lib/ui/views/token_selection/layouts/components/token_single.dart +++ b/lib/ui/views/token_selection/layouts/components/token_single.dart @@ -107,16 +107,17 @@ class SingleTokenState extends State Padding( padding: const EdgeInsets.only(top: 2), child: VerifiedTokenIcon( - address: widget.token.isUCO ? 'UCO' : widget.token.address, + address: + widget.token.isUCO ? kUCOAddress : widget.token.address, iconSize: 12, ), ), if (widget.token.isLpToken && widget.token.lpTokenPair != null) Tooltip( message: - '${AppLocalizations.of(context)!.tokenSelectionSingleTokenLPTooltip} ${widget.token.lpTokenPair!.token1.isUCO ? 'UCO' : widget.token.lpTokenPair!.token1.symbol}/${widget.token.lpTokenPair!.token2.isUCO ? 'UCO' : widget.token.lpTokenPair!.token2.symbol}', + '${AppLocalizations.of(context)!.tokenSelectionSingleTokenLPTooltip} ${widget.token.lpTokenPair!.token1.isUCO ? kUCOAddress : widget.token.lpTokenPair!.token1.symbol}/${widget.token.lpTokenPair!.token2.isUCO ? kUCOAddress : widget.token.lpTokenPair!.token2.symbol}', child: Text( - '${AppLocalizations.of(context)!.tokenSelectionSingleTokenLPTooltip} ${widget.token.lpTokenPair!.token1.isUCO ? 'UCO' : widget.token.lpTokenPair!.token1.symbol.reduceSymbol()}/${widget.token.lpTokenPair!.token2.isUCO ? 'UCO' : widget.token.lpTokenPair!.token2.symbol.reduceSymbol()}', + '${AppLocalizations.of(context)!.tokenSelectionSingleTokenLPTooltip} ${widget.token.lpTokenPair!.token1.isUCO ? kUCOAddress : widget.token.lpTokenPair!.token1.symbol.reduceSymbol()}/${widget.token.lpTokenPair!.token2.isUCO ? kUCOAddress : widget.token.lpTokenPair!.token2.symbol.reduceSymbol()}', style: AppTextStyles.bodyLarge(context), ), ), diff --git a/lib/ui/views/tokens_detail/layouts/components/token_detail_info.dart b/lib/ui/views/tokens_detail/layouts/components/token_detail_info.dart index daae0a6c1..fb791863c 100644 --- a/lib/ui/views/tokens_detail/layouts/components/token_detail_info.dart +++ b/lib/ui/views/tokens_detail/layouts/components/token_detail_info.dart @@ -1,5 +1,6 @@ import 'package:aewallet/application/aeswap/dex_token.dart'; import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/widgets/tokens/verified_token_icon.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' @@ -84,7 +85,7 @@ class TokenDetailInfo extends ConsumerWidget { padding: const EdgeInsets.only(left: 5), child: VerifiedTokenIcon( address: aeToken.lpTokenPair!.token1.isUCO - ? 'UCO' + ? kUCOAddress : aeToken.lpTokenPair!.token1.address!, ), ), @@ -131,7 +132,7 @@ class TokenDetailInfo extends ConsumerWidget { padding: const EdgeInsets.only(left: 5), child: VerifiedTokenIcon( address: aeToken.lpTokenPair!.token2.isUCO - ? 'UCO' + ? kUCOAddress : aeToken.lpTokenPair!.token2.address!, ), ), diff --git a/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart b/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart index e8c012d50..1a5244478 100644 --- a/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart +++ b/lib/ui/views/tokens_detail/layouts/components/token_detail_menu.dart @@ -1,6 +1,7 @@ import 'package:aewallet/application/account/providers.dart'; import 'package:aewallet/application/connectivity_status.dart'; import 'package:aewallet/application/settings/settings.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/ui/views/aeswap_earn/bloc/provider.dart'; import 'package:aewallet/ui/views/aeswap_swap/layouts/swap_tab.dart'; import 'package:aewallet/ui/views/main/bloc/providers.dart'; @@ -129,7 +130,7 @@ class TokenDetailMenu extends ConsumerWidget { icon: aedappfm.Iconsax.arrange_circle_2, onTap: () async { final params = { - 'from': aeToken.isUCO ? 'UCO' : aeToken.address, + 'from': aeToken.isUCO ? kUCOAddress : aeToken.address, }; ref.read(swapParametersProvider.notifier).state = params; diff --git a/lib/ui/views/tokens_list/layouts/components/token_detail.dart b/lib/ui/views/tokens_list/layouts/components/token_detail.dart index 244db2e2e..dc2aeaabb 100644 --- a/lib/ui/views/tokens_list/layouts/components/token_detail.dart +++ b/lib/ui/views/tokens_list/layouts/components/token_detail.dart @@ -4,6 +4,7 @@ import 'package:aewallet/application/price_history/providers.dart'; import 'package:aewallet/application/settings/primary_currency.dart'; import 'package:aewallet/application/settings/settings.dart'; import 'package:aewallet/model/primary_currency.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/modules/aeswap/ui/views/util/app_styles.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; @@ -278,7 +279,7 @@ class _TokenDetailState extends ConsumerState { .lpTokenPair! .token1 .isUCO - ? 'UCO' + ? kUCOAddress : widget .aeToken .lpTokenPair! @@ -315,7 +316,7 @@ class _TokenDetailState extends ConsumerState { .lpTokenPair! .token2 .isUCO - ? 'UCO' + ? kUCOAddress : widget .aeToken .lpTokenPair! diff --git a/lib/ui/views/transfer/layouts/components/transfer_textfield_amount.dart b/lib/ui/views/transfer/layouts/components/transfer_textfield_amount.dart index 65fc6abf9..3df8592da 100644 --- a/lib/ui/views/transfer/layouts/components/transfer_textfield_amount.dart +++ b/lib/ui/views/transfer/layouts/components/transfer_textfield_amount.dart @@ -244,7 +244,7 @@ class _TransferTextFieldAmountState ), VerifiedTokenIcon( address: transfer.aeToken!.isUCO - ? 'UCO' + ? kUCOAddress : transfer.aeToken!.address!, ), ], diff --git a/lib/ui/views/transfer/layouts/transfer_sheet.dart b/lib/ui/views/transfer/layouts/transfer_sheet.dart index e29b6bbac..1a302af52 100755 --- a/lib/ui/views/transfer/layouts/transfer_sheet.dart +++ b/lib/ui/views/transfer/layouts/transfer_sheet.dart @@ -8,6 +8,7 @@ import 'package:aewallet/model/available_currency.dart'; import 'package:aewallet/model/data/account_token.dart'; import 'package:aewallet/model/data/contact.dart'; import 'package:aewallet/model/primary_currency.dart'; +import 'package:aewallet/modules/aeswap/domain/models/dex_token.dart'; import 'package:aewallet/ui/themes/archethic_theme.dart'; import 'package:aewallet/ui/themes/styles.dart'; import 'package:aewallet/ui/util/amount_formatters.dart'; diff --git a/pubspec.lock b/pubspec.lock index d4b2adeec..23a3a8006 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -65,11 +65,18 @@ packages: archethic_dapp_framework_flutter: dependency: "direct main" description: +<<<<<<< HEAD path: "." ref: upgrade_web_socket resolved-ref: "85b213ea35218561314596204aa5ea9f3f1b520b" url: "https://github.com/archethic-foundation/archethic-dapp-framework-flutter.git" source: git +======= + name: archethic_dapp_framework_flutter + sha256: bd1a4014b115132d8967198b6ec52b011fa515ec32ab27a04110c6f10cd0f697 + url: "https://pub.dev" + source: hosted +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) version: "3.2.2" archethic_lib_dart: dependency: transitive @@ -839,10 +846,17 @@ packages: dependency: "direct main" description: name: flutter_svg +<<<<<<< HEAD sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471" url: "https://pub.dev" source: hosted version: "2.0.15" +======= + sha256: "2ca230f2ef6e31151769f4a03ec806b94f0554ff02ea1a40bb0d531ac150f035" + url: "https://pub.dev" + source: hosted + version: "2.0.12" +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) flutter_test: dependency: "direct dev" description: flutter @@ -2095,10 +2109,17 @@ packages: dependency: transitive description: name: vector_graphics +<<<<<<< HEAD sha256: "27d5fefe86fb9aace4a9f8375b56b3c292b64d8c04510df230f849850d912cb7" url: "https://pub.dev" source: hosted version: "1.1.15" +======= + sha256: "0b9149c6ddb013818075b072b9ddc1b89a5122fff1275d4648d297086b46c4f0" + url: "https://pub.dev" + source: hosted + version: "1.1.12" +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) vector_graphics_codec: dependency: transitive description: @@ -2111,10 +2132,17 @@ packages: dependency: transitive description: name: vector_graphics_compiler +<<<<<<< HEAD sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad" url: "https://pub.dev" source: hosted version: "1.1.16" +======= + sha256: f3b9b6e4591c11394d4be4806c63e72d3a41778547b2c1e2a8a04fadcfd7d173 + url: "https://pub.dev" + source: hosted + version: "1.1.12" +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) vector_math: dependency: transitive description: @@ -2199,10 +2227,17 @@ packages: dependency: transitive description: name: webview_flutter_wkwebview +<<<<<<< HEAD sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb url: "https://pub.dev" source: hosted version: "3.16.3" +======= + sha256: f14ee08021772fed913da8daebcfdeb46be457081e521e93e9918fe6cd1ce9e8 + url: "https://pub.dev" + source: hosted + version: "3.16.1" +>>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) win32: dependency: transitive description: From 908b8bdd220b7ebcd4cfe651c991b64b78ca5b7d Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 5 Nov 2024 22:49:18 +0100 Subject: [PATCH 08/11] test: :construction: tokenModelToAETokenModel TU --- test/tokenModelToAETokenModel_test.dart | 320 ++++++++++++++++++++++++ 1 file changed, 320 insertions(+) create mode 100644 test/tokenModelToAETokenModel_test.dart diff --git a/test/tokenModelToAETokenModel_test.dart b/test/tokenModelToAETokenModel_test.dart new file mode 100644 index 000000000..a068bd0c1 --- /dev/null +++ b/test/tokenModelToAETokenModel_test.dart @@ -0,0 +1,320 @@ +import 'package:aewallet/domain/models/token_parser.dart'; +import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; +import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as aedappfm; +import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; + +class MockTokensRepositoryImpl extends Mock implements TokensRepositoryImpl {} + +class MockDefTokensRepositoryImpl extends Mock + implements aedappfm.DefTokensRepositoryImpl {} + +class MockApiService extends Mock implements archethic.ApiService {} + +class _TokenParserImpl with TokenParser {} + +void main() { + group('TokenParser - tokenModelToAETokenModel', () { + late TokenParser tokenParser; + late MockTokensRepositoryImpl mockTokensRepository; + late MockDefTokensRepositoryImpl mockDefTokensRepository; + late MockApiService mockApiService; + late aedappfm.Environment environment; + + setUp(() { + mockTokensRepository = MockTokensRepositoryImpl(); + mockDefTokensRepository = MockDefTokensRepositoryImpl(); + mockApiService = MockApiService(); + environment = aedappfm.Environment.testnet; + tokenParser = _TokenParserImpl(); + }); + + test('Convert UCO to AEToken', () async { + final token = archethic.Token( + address: 'UCO', + symbol: 'UCO', + supply: archethic.toBigInt(1000000), + ); + final verifiedTokens = [ + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ]; + final poolsListRaw = [ + const GetPoolListResponse( + concatenatedTokensAddresses: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', + address: + '0000818EF23676779DAE1C97072BB99A3E0DD1C31BAD3787422798DBE3F777F74A43', + lpTokenAddress: + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', + ), + const GetPoolListResponse( + concatenatedTokensAddresses: + 'UCO/0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + address: + '0000DD19DD796959B72998536F67814DCCABE156FF647E0E63E43395203908963767', + lpTokenAddress: + '0000A4CAB2362A97002EE0A6DD2013BEC3AF02C4D8C392712CFBC38F3E4809B9314C', + ), + ]; + + when(mockDefTokensRepository.getDefToken(environment, 'UCO')) + .thenAnswer((_) async { + return const aedappfm.AEToken( + address: 'UCO', + name: 'Universal Coin', + symbol: 'UCO', + ucid: 6887, + icon: 'Archethic.svg', + ); + }); + + when( + mockDefTokensRepository.getDefToken( + environment, + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + name: 'Wrapped Ether', + symbol: 'aeETH', + ucid: 1027, + icon: 'Ethereum.svg', + ), + ); + + when( + mockDefTokensRepository.getDefToken( + environment, + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + name: 'Wrapped BNB', + symbol: 'aeBNB', + ucid: 1839, + icon: 'BNB.svg', + ), + ); + + final result = await tokenParser.tokenModelToAETokenModel( + token, + verifiedTokens, + poolsListRaw, + environment, + mockApiService, + ); + + expect(result.name, 'Universal Coin'); + expect(result.address, 'UCO'); + expect(result.symbol, 'UCO'); + expect(result.isLpToken, false); + expect(result.isVerified, false); + expect(result.isUCO, true); + expect(result.ucid, 6887); + expect(result.lpTokenPair, isNull); + }); + + test('Convert token to AEToken', () async { + final token = archethic.Token( + address: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + symbol: 'aeETH', + type: 'fungible', + supply: archethic.toBigInt(1000000), + ); + final verifiedTokens = [ + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ]; + final poolsListRaw = [ + const GetPoolListResponse( + concatenatedTokensAddresses: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', + address: + '0000818EF23676779DAE1C97072BB99A3E0DD1C31BAD3787422798DBE3F777F74A43', + lpTokenAddress: + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', + ), + const GetPoolListResponse( + concatenatedTokensAddresses: + 'UCO/0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + address: + '0000DD19DD796959B72998536F67814DCCABE156FF647E0E63E43395203908963767', + lpTokenAddress: + '0000A4CAB2362A97002EE0A6DD2013BEC3AF02C4D8C392712CFBC38F3E4809B9314C', + ), + ]; + + when(mockDefTokensRepository.getDefToken(environment, 'UCO')).thenAnswer( + (_) async => const aedappfm.AEToken( + address: 'UCO', + name: 'Universal Coin', + symbol: 'UCO', + ucid: 6887, + icon: 'Archethic.svg', + ), + ); + + when( + mockDefTokensRepository.getDefToken( + environment, + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + name: 'Wrapped Ether', + symbol: 'aeETH', + ucid: 1027, + icon: 'Ethereum.svg', + ), + ); + + when( + mockDefTokensRepository.getDefToken( + environment, + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + name: 'Wrapped BNB', + symbol: 'aeBNB', + ucid: 1839, + icon: 'BNB.svg', + ), + ); + + final result = await tokenParser.tokenModelToAETokenModel( + token, + verifiedTokens, + poolsListRaw, + environment, + mockApiService, + ); + + expect(result.name, 'Wrapped Ether'); + expect( + result.address, + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ); + expect(result.symbol, 'aeETH'); + expect(result.isLpToken, false); + expect(result.isVerified, true); + expect(result.isUCO, false); + expect(result.ucid, 1027); + expect(result.lpTokenPair, isNull); + }); + + test('Convert LP token to AEToken', () async { + final token = archethic.Token( + address: + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', + supply: archethic.toBigInt(500000), + ); + final verifiedTokens = [ + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ]; + final poolsListRaw = [ + const GetPoolListResponse( + concatenatedTokensAddresses: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', + address: + '0000818EF23676779DAE1C97072BB99A3E0DD1C31BAD3787422798DBE3F777F74A43', + lpTokenAddress: + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', + ), + const GetPoolListResponse( + concatenatedTokensAddresses: + 'UCO/0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + address: + '0000DD19DD796959B72998536F67814DCCABE156FF647E0E63E43395203908963767', + lpTokenAddress: + '0000A4CAB2362A97002EE0A6DD2013BEC3AF02C4D8C392712CFBC38F3E4809B9314C', + ), + ]; + + final addresses = [ + 'UCO', + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF' + ]; + + when( + mockTokensRepository.getTokensFromAddresses(addresses, mockApiService), + ).thenAnswer( + (_) async => { + 'UCO': const archethic.Token(symbol: 'UCO'), + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF': + const archethic.Token(symbol: 'aeETH'), + }, + ); + when(mockDefTokensRepository.getDefToken(environment, 'UCO')).thenAnswer( + (_) async => const aedappfm.AEToken( + address: 'UCO', + name: 'Universal Coin', + symbol: 'UCO', + ucid: 6887, + icon: 'Archethic.svg', + ), + ); + + when( + mockDefTokensRepository.getDefToken( + environment, + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + name: 'Wrapped Ether', + symbol: 'aeETH', + ucid: 1027, + icon: 'Ethereum.svg', + ), + ); + + when( + mockDefTokensRepository.getDefToken( + environment, + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + ), + ).thenAnswer( + (_) async => const aedappfm.AEToken( + address: + '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', + name: 'Wrapped BNB', + symbol: 'aeBNB', + ucid: 1839, + icon: 'BNB.svg', + ), + ); + + final result = await tokenParser.tokenModelToAETokenModel( + token, + verifiedTokens, + poolsListRaw, + environment, + mockApiService, + ); + + expect(result.symbol, 'aeETH'); + expect(result.isLpToken, true); + expect(result.isVerified, false); + expect(result.isUCO, false); + expect(result.ucid, isNull); + expect(result.lpTokenPair, isNotNull); + }); + }); +} From 30d931d5dd9884b59fb2baa2a35ffcd05b065b27 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Wed, 6 Nov 2024 10:28:45 +0100 Subject: [PATCH 09/11] test: :bug: Fix mokito use --- ...nModel_test.dart => tokenParser_test.dart} | 26 +- test/tokenParser_test.mocks.dart | 930 ++++++++++++++++++ 2 files changed, 946 insertions(+), 10 deletions(-) rename test/{tokenModelToAETokenModel_test.dart => tokenParser_test.dart} (94%) create mode 100644 test/tokenParser_test.mocks.dart diff --git a/test/tokenModelToAETokenModel_test.dart b/test/tokenParser_test.dart similarity index 94% rename from test/tokenModelToAETokenModel_test.dart rename to test/tokenParser_test.dart index a068bd0c1..5d0bf48ad 100644 --- a/test/tokenModelToAETokenModel_test.dart +++ b/test/tokenParser_test.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'package:aewallet/domain/models/token_parser.dart'; import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; @@ -5,18 +6,24 @@ import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutte as aedappfm; import 'package:archethic_lib_dart/archethic_lib_dart.dart' as archethic; import 'package:flutter_test/flutter_test.dart'; +import 'package:hive/hive.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -class MockTokensRepositoryImpl extends Mock implements TokensRepositoryImpl {} - -class MockDefTokensRepositoryImpl extends Mock - implements aedappfm.DefTokensRepositoryImpl {} - -class MockApiService extends Mock implements archethic.ApiService {} +@GenerateNiceMocks( + [ + MockSpec(), + MockSpec(), + MockSpec(), + ], +) +import 'tokenParser_test.mocks.dart'; class _TokenParserImpl with TokenParser {} void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + group('TokenParser - tokenModelToAETokenModel', () { late TokenParser tokenParser; late MockTokensRepositoryImpl mockTokensRepository; @@ -25,6 +32,7 @@ void main() { late aedappfm.Environment environment; setUp(() { + Hive.init('${Directory.current.path}/test/tmp_data'); mockTokensRepository = MockTokensRepositoryImpl(); mockDefTokensRepository = MockDefTokensRepositoryImpl(); mockApiService = MockApiService(); @@ -246,16 +254,14 @@ void main() { ]; final addresses = [ - 'UCO', - '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF' + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', ]; when( mockTokensRepository.getTokensFromAddresses(addresses, mockApiService), ).thenAnswer( (_) async => { - 'UCO': const archethic.Token(symbol: 'UCO'), - '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF': + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4': const archethic.Token(symbol: 'aeETH'), }, ); diff --git a/test/tokenParser_test.mocks.dart b/test/tokenParser_test.mocks.dart new file mode 100644 index 000000000..2d9d56f3a --- /dev/null +++ b/test/tokenParser_test.mocks.dart @@ -0,0 +1,930 @@ +// Mocks generated by Mockito 5.4.4 from annotations +// in aewallet/test/tokenParser_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i10; +import 'dart:typed_data' as _i18; + +import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart' + as _i23; +import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart' + as _i24; +import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' + as _i9; +import 'package:archethic_dapp_framework_flutter/src/domain/models/ae_token.dart' + as _i8; +import 'package:archethic_dapp_framework_flutter/src/domain/models/environment.dart' + as _i11; +import 'package:archethic_lib_dart/archethic_lib_dart.dart' as _i12; +import 'package:archethic_lib_dart/src/model/address.dart' as _i6; +import 'package:archethic_lib_dart/src/model/balance.dart' as _i14; +import 'package:archethic_lib_dart/src/model/blockchain_version.dart' as _i7; +import 'package:archethic_lib_dart/src/model/endpoint.dart' as _i20; +import 'package:archethic_lib_dart/src/model/keychain.dart' as _i5; +import 'package:archethic_lib_dart/src/model/node.dart' as _i15; +import 'package:archethic_lib_dart/src/model/ownership.dart' as _i17; +import 'package:archethic_lib_dart/src/model/smart_contracts/sc_call_function_request.dart' + as _i21; +import 'package:archethic_lib_dart/src/model/token.dart' as _i19; +import 'package:archethic_lib_dart/src/model/transaction.dart' as _i4; +import 'package:archethic_lib_dart/src/model/transaction_fee.dart' as _i3; +import 'package:archethic_lib_dart/src/model/transaction_input.dart' as _i16; +import 'package:archethic_lib_dart/src/model/transaction_status.dart' as _i2; +import 'package:graphql/client.dart' as _i22; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i13; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeTransactionStatus_0 extends _i1.SmartFake + implements _i2.TransactionStatus { + _FakeTransactionStatus_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeTransactionFee_1 extends _i1.SmartFake + implements _i3.TransactionFee { + _FakeTransactionFee_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeTransaction_2 extends _i1.SmartFake implements _i4.Transaction { + _FakeTransaction_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeKeychain_3 extends _i1.SmartFake implements _i5.Keychain { + _FakeKeychain_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeAddress_4 extends _i1.SmartFake implements _i6.Address { + _FakeAddress_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeObject_5 extends _i1.SmartFake implements Object { + _FakeObject_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeBlockchainVersionModel_6 extends _i1.SmartFake + implements _i7.BlockchainVersionModel { + _FakeBlockchainVersionModel_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeAEToken_7 extends _i1.SmartFake implements _i8.AEToken { + _FakeAEToken_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [DefTokensRepositoryImpl]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockDefTokensRepositoryImpl extends _i1.Mock + implements _i9.DefTokensRepositoryImpl { + @override + _i10.Future<_i8.AEToken?> getDefToken( + _i11.Environment? environment, + String? address, + ) => + (super.noSuchMethod( + Invocation.method( + #getDefToken, + [ + environment, + address, + ], + ), + returnValue: _i10.Future<_i8.AEToken?>.value(), + returnValueForMissingStub: _i10.Future<_i8.AEToken?>.value(), + ) as _i10.Future<_i8.AEToken?>); +} + +/// A class which mocks [ApiService]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockApiService extends _i1.Mock implements _i12.ApiService { + @override + String get endpoint => (super.noSuchMethod( + Invocation.getter(#endpoint), + returnValue: _i13.dummyValue( + this, + Invocation.getter(#endpoint), + ), + returnValueForMissingStub: _i13.dummyValue( + this, + Invocation.getter(#endpoint), + ), + ) as String); + + @override + _i10.Future<_i2.TransactionStatus> sendTx(_i4.Transaction? transaction) => + (super.noSuchMethod( + Invocation.method( + #sendTx, + [transaction], + ), + returnValue: + _i10.Future<_i2.TransactionStatus>.value(_FakeTransactionStatus_0( + this, + Invocation.method( + #sendTx, + [transaction], + ), + )), + returnValueForMissingStub: + _i10.Future<_i2.TransactionStatus>.value(_FakeTransactionStatus_0( + this, + Invocation.method( + #sendTx, + [transaction], + ), + )), + ) as _i10.Future<_i2.TransactionStatus>); + + @override + _i10.Future> getLastTransaction( + List? addresses, { + String? request = + r' address, balance { token { address, amount }, uco }, chainLength, crossValidationStamps { nodePublicKey, signature }, data { content, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey } secret } ledger { uco { transfers { amount, to } }, token { transfers { amount, to, tokenAddress, tokenId } } } recipients, actionRecipients { action address args } } inputs { amount, from, tokenAddress, spent, tokenId, timestamp, type, }, originSignature, previousAddress, previousPublicKey, previousSignature, type, validationStamp { proofOfIntegrity, proofOfWork, signature, timestamp, ledgerOperations { fee, unspentOutputs { state } } }, version', + }) => + (super.noSuchMethod( + Invocation.method( + #getLastTransaction, + [addresses], + {#request: request}, + ), + returnValue: _i10.Future>.value( + {}), + returnValueForMissingStub: + _i10.Future>.value( + {}), + ) as _i10.Future>); + + @override + _i10.Future> getTransactionIndex(List? addresses) => + (super.noSuchMethod( + Invocation.method( + #getTransactionIndex, + [addresses], + ), + returnValue: _i10.Future>.value({}), + returnValueForMissingStub: + _i10.Future>.value({}), + ) as _i10.Future>); + + @override + _i10.Future getStorageNoncePublicKey() => (super.noSuchMethod( + Invocation.method( + #getStorageNoncePublicKey, + [], + ), + returnValue: _i10.Future.value(_i13.dummyValue( + this, + Invocation.method( + #getStorageNoncePublicKey, + [], + ), + )), + returnValueForMissingStub: + _i10.Future.value(_i13.dummyValue( + this, + Invocation.method( + #getStorageNoncePublicKey, + [], + ), + )), + ) as _i10.Future); + + @override + _i10.Future> fetchBalance( + List? addresses, { + String? request = r' token { address, amount, tokenId }, uco ', + }) => + (super.noSuchMethod( + Invocation.method( + #fetchBalance, + [addresses], + {#request: request}, + ), + returnValue: _i10.Future>.value( + {}), + returnValueForMissingStub: _i10.Future>.value( + {}), + ) as _i10.Future>); + + @override + _i10.Future> getTransactionContent( + Map? addresses) => + (super.noSuchMethod( + Invocation.method( + #getTransactionContent, + [addresses], + ), + returnValue: _i10.Future>.value({}), + returnValueForMissingStub: + _i10.Future>.value({}), + ) as _i10.Future>); + + @override + _i10.Future>> getTransactionChain( + Map? addresses, { + String? request = + r' address, balance { token { address, amount }, uco }, chainLength, crossValidationStamps { nodePublicKey, signature }, data { content, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey } secret } ledger { uco { transfers { amount, to } }, token { transfers { amount, to, tokenAddress, tokenId } } } recipients, actionRecipients { action address args } } inputs { amount, from, tokenAddress, spent, tokenId, timestamp, type, }, originSignature, previousAddress, previousPublicKey, previousSignature, type, validationStamp { proofOfIntegrity, proofOfWork, signature, timestamp, ledgerOperations { fee, unspentOutputs { state } } }, version', + bool? orderAsc = true, + int? fromCriteria, + }) => + (super.noSuchMethod( + Invocation.method( + #getTransactionChain, + [addresses], + { + #request: request, + #orderAsc: orderAsc, + #fromCriteria: fromCriteria, + }, + ), + returnValue: _i10.Future>>.value( + >{}), + returnValueForMissingStub: + _i10.Future>>.value( + >{}), + ) as _i10.Future>>); + + @override + _i10.Future> getNodeList() => (super.noSuchMethod( + Invocation.method( + #getNodeList, + [], + ), + returnValue: _i10.Future>.value(<_i15.Node>[]), + returnValueForMissingStub: + _i10.Future>.value(<_i15.Node>[]), + ) as _i10.Future>); + + @override + _i10.Future> networkTransactions( + String? type, + int? page, { + String? request = + r' address, balance { token { address, amount }, uco }, chainLength, crossValidationStamps { nodePublicKey, signature }, data { content, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey } secret } ledger { uco { transfers { amount, to } }, token { transfers { amount, to, tokenAddress, tokenId } } } recipients, actionRecipients { action address args } } inputs { amount, from, tokenAddress, spent, tokenId, timestamp, type, }, originSignature, previousAddress, previousPublicKey, previousSignature, type, validationStamp { proofOfIntegrity, proofOfWork, signature, timestamp, ledgerOperations { fee, unspentOutputs { state } } }, version', + }) => + (super.noSuchMethod( + Invocation.method( + #networkTransactions, + [ + type, + page, + ], + {#request: request}, + ), + returnValue: + _i10.Future>.value(<_i4.Transaction>[]), + returnValueForMissingStub: + _i10.Future>.value(<_i4.Transaction>[]), + ) as _i10.Future>); + + @override + _i10.Future>> getTransactionInputs( + List? addresses, { + String? request = + r'amount, from, tokenAddress, spent, tokenId, timestamp, type', + int? limit = 0, + int? pagingOffset = 0, + }) => + (super.noSuchMethod( + Invocation.method( + #getTransactionInputs, + [addresses], + { + #request: request, + #limit: limit, + #pagingOffset: pagingOffset, + }, + ), + returnValue: + _i10.Future>>.value( + >{}), + returnValueForMissingStub: + _i10.Future>>.value( + >{}), + ) as _i10.Future>>); + + @override + _i10.Future> getTransaction( + List? addresses, { + String? request = + r' address, balance { token { address, amount }, uco }, chainLength, crossValidationStamps { nodePublicKey, signature }, data { content, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey } secret } ledger { uco { transfers { amount, to } }, token { transfers { amount, to, tokenAddress, tokenId } } } recipients, actionRecipients { action address args } } inputs { amount, from, tokenAddress, spent, tokenId, timestamp, type, }, originSignature, previousAddress, previousPublicKey, previousSignature, type, validationStamp { proofOfIntegrity, proofOfWork, signature, timestamp, ledgerOperations { fee, unspentOutputs { state } } }, version', + }) => + (super.noSuchMethod( + Invocation.method( + #getTransaction, + [addresses], + {#request: request}, + ), + returnValue: _i10.Future>.value( + {}), + returnValueForMissingStub: + _i10.Future>.value( + {}), + ) as _i10.Future>); + + @override + _i10.Future<_i3.TransactionFee> getTransactionFee( + _i4.Transaction? transaction) => + (super.noSuchMethod( + Invocation.method( + #getTransactionFee, + [transaction], + ), + returnValue: + _i10.Future<_i3.TransactionFee>.value(_FakeTransactionFee_1( + this, + Invocation.method( + #getTransactionFee, + [transaction], + ), + )), + returnValueForMissingStub: + _i10.Future<_i3.TransactionFee>.value(_FakeTransactionFee_1( + this, + Invocation.method( + #getTransactionFee, + [transaction], + ), + )), + ) as _i10.Future<_i3.TransactionFee>); + + @override + _i10.Future>> getTransactionOwnerships( + List? addresses) => + (super.noSuchMethod( + Invocation.method( + #getTransactionOwnerships, + [addresses], + ), + returnValue: _i10.Future>>.value( + >{}), + returnValueForMissingStub: + _i10.Future>>.value( + >{}), + ) as _i10.Future>>); + + @override + _i4.Transaction newKeychainTransaction( + String? seed, + List? authorizedPublicKeys, + _i18.Uint8List? originPrivateKey, + int? blockchainTxVersion, { + String? serviceName, + String? derivationPath, + }) => + (super.noSuchMethod( + Invocation.method( + #newKeychainTransaction, + [ + seed, + authorizedPublicKeys, + originPrivateKey, + blockchainTxVersion, + ], + { + #serviceName: serviceName, + #derivationPath: derivationPath, + }, + ), + returnValue: _FakeTransaction_2( + this, + Invocation.method( + #newKeychainTransaction, + [ + seed, + authorizedPublicKeys, + originPrivateKey, + blockchainTxVersion, + ], + { + #serviceName: serviceName, + #derivationPath: derivationPath, + }, + ), + ), + returnValueForMissingStub: _FakeTransaction_2( + this, + Invocation.method( + #newKeychainTransaction, + [ + seed, + authorizedPublicKeys, + originPrivateKey, + blockchainTxVersion, + ], + { + #serviceName: serviceName, + #derivationPath: derivationPath, + }, + ), + ), + ) as _i4.Transaction); + + @override + _i4.Transaction newAccessKeychainTransaction( + String? seed, + _i18.Uint8List? keychainAddress, + _i18.Uint8List? originPrivateKey, + int? blockchainTxVersion, + ) => + (super.noSuchMethod( + Invocation.method( + #newAccessKeychainTransaction, + [ + seed, + keychainAddress, + originPrivateKey, + blockchainTxVersion, + ], + ), + returnValue: _FakeTransaction_2( + this, + Invocation.method( + #newAccessKeychainTransaction, + [ + seed, + keychainAddress, + originPrivateKey, + blockchainTxVersion, + ], + ), + ), + returnValueForMissingStub: _FakeTransaction_2( + this, + Invocation.method( + #newAccessKeychainTransaction, + [ + seed, + keychainAddress, + originPrivateKey, + blockchainTxVersion, + ], + ), + ), + ) as _i4.Transaction); + + @override + _i10.Future<_i5.Keychain> getKeychain(String? seed) => (super.noSuchMethod( + Invocation.method( + #getKeychain, + [seed], + ), + returnValue: _i10.Future<_i5.Keychain>.value(_FakeKeychain_3( + this, + Invocation.method( + #getKeychain, + [seed], + ), + )), + returnValueForMissingStub: + _i10.Future<_i5.Keychain>.value(_FakeKeychain_3( + this, + Invocation.method( + #getKeychain, + [seed], + ), + )), + ) as _i10.Future<_i5.Keychain>); + + @override + String getOriginKey() => (super.noSuchMethod( + Invocation.method( + #getOriginKey, + [], + ), + returnValue: _i13.dummyValue( + this, + Invocation.method( + #getOriginKey, + [], + ), + ), + returnValueForMissingStub: _i13.dummyValue( + this, + Invocation.method( + #getOriginKey, + [], + ), + ), + ) as String); + + @override + _i10.Future addOriginKey({ + String? originPublicKey, + String? certificate, + }) => + (super.noSuchMethod( + Invocation.method( + #addOriginKey, + [], + { + #originPublicKey: originPublicKey, + #certificate: certificate, + }, + ), + returnValue: _i10.Future.value(_i13.dummyValue( + this, + Invocation.method( + #addOriginKey, + [], + { + #originPublicKey: originPublicKey, + #certificate: certificate, + }, + ), + )), + returnValueForMissingStub: + _i10.Future.value(_i13.dummyValue( + this, + Invocation.method( + #addOriginKey, + [], + { + #originPublicKey: originPublicKey, + #certificate: certificate, + }, + ), + )), + ) as _i10.Future); + + @override + _i10.Future> getToken( + List? addresses, { + String? request = + r'genesis, name, id, supply, symbol, type, properties, decimals, collection, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey }, secret }', + }) => + (super.noSuchMethod( + Invocation.method( + #getToken, + [addresses], + {#request: request}, + ), + returnValue: + _i10.Future>.value({}), + returnValueForMissingStub: + _i10.Future>.value({}), + ) as _i10.Future>); + + @override + _i10.Future> getNearestEndpoints() => (super.noSuchMethod( + Invocation.method( + #getNearestEndpoints, + [], + ), + returnValue: _i10.Future>.value(<_i20.Endpoint>[]), + returnValueForMissingStub: + _i10.Future>.value(<_i20.Endpoint>[]), + ) as _i10.Future>); + + @override + _i10.Future<_i6.Address> getGenesisAddress(String? address) => + (super.noSuchMethod( + Invocation.method( + #getGenesisAddress, + [address], + ), + returnValue: _i10.Future<_i6.Address>.value(_FakeAddress_4( + this, + Invocation.method( + #getGenesisAddress, + [address], + ), + )), + returnValueForMissingStub: + _i10.Future<_i6.Address>.value(_FakeAddress_4( + this, + Invocation.method( + #getGenesisAddress, + [address], + ), + )), + ) as _i10.Future<_i6.Address>); + + @override + _i10.Future> callSCFunctionMulti( + {required List<_i21.SCCallFunctionRequest>? jsonRPCRequests}) => + (super.noSuchMethod( + Invocation.method( + #callSCFunctionMulti, + [], + {#jsonRPCRequests: jsonRPCRequests}, + ), + returnValue: _i10.Future>.value([]), + returnValueForMissingStub: + _i10.Future>.value([]), + ) as _i10.Future>); + + @override + _i10.Future callSCFunction({ + required _i21.SCCallFunctionRequest? jsonRPCRequest, + bool? resultMap = false, + }) => + (super.noSuchMethod( + Invocation.method( + #callSCFunction, + [], + { + #jsonRPCRequest: jsonRPCRequest, + #resultMap: resultMap, + }, + ), + returnValue: _i10.Future.value(_FakeObject_5( + this, + Invocation.method( + #callSCFunction, + [], + { + #jsonRPCRequest: jsonRPCRequest, + #resultMap: resultMap, + }, + ), + )), + returnValueForMissingStub: _i10.Future.value(_FakeObject_5( + this, + Invocation.method( + #callSCFunction, + [], + { + #jsonRPCRequest: jsonRPCRequest, + #resultMap: resultMap, + }, + ), + )), + ) as _i10.Future); + + @override + _i10.Future<_i7.BlockchainVersionModel> getBlockchainVersion() => + (super.noSuchMethod( + Invocation.method( + #getBlockchainVersion, + [], + ), + returnValue: _i10.Future<_i7.BlockchainVersionModel>.value( + _FakeBlockchainVersionModel_6( + this, + Invocation.method( + #getBlockchainVersion, + [], + ), + )), + returnValueForMissingStub: + _i10.Future<_i7.BlockchainVersionModel>.value( + _FakeBlockchainVersionModel_6( + this, + Invocation.method( + #getBlockchainVersion, + [], + ), + )), + ) as _i10.Future<_i7.BlockchainVersionModel>); + + @override + void manageLinkException(_i22.QueryResult? result) => + super.noSuchMethod( + Invocation.method( + #manageLinkException, + [result], + ), + returnValueForMissingStub: null, + ); + + @override + String setJsonRPCRequest( + String? method, + Object? params, { + int? id = 1, + }) => + (super.noSuchMethod( + Invocation.method( + #setJsonRPCRequest, + [ + method, + params, + ], + {#id: id}, + ), + returnValue: _i13.dummyValue( + this, + Invocation.method( + #setJsonRPCRequest, + [ + method, + params, + ], + {#id: id}, + ), + ), + returnValueForMissingStub: _i13.dummyValue( + this, + Invocation.method( + #setJsonRPCRequest, + [ + method, + params, + ], + {#id: id}, + ), + ), + ) as String); + + @override + dynamic getJsonRPCResult(String? body) => super.noSuchMethod( + Invocation.method( + #getJsonRPCResult, + [body], + ), + returnValueForMissingStub: null, + ); + + @override + String getJsonRPCResultString(String? body) => (super.noSuchMethod( + Invocation.method( + #getJsonRPCResultString, + [body], + ), + returnValue: _i13.dummyValue( + this, + Invocation.method( + #getJsonRPCResultString, + [body], + ), + ), + returnValueForMissingStub: _i13.dummyValue( + this, + Invocation.method( + #getJsonRPCResultString, + [body], + ), + ), + ) as String); +} + +/// A class which mocks [TokensRepositoryImpl]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTokensRepositoryImpl extends _i1.Mock + implements _i23.TokensRepositoryImpl { + @override + _i10.Future> getTokensFromAddresses( + List? addresses, + _i12.ApiService? apiService, + ) => + (super.noSuchMethod( + Invocation.method( + #getTokensFromAddresses, + [ + addresses, + apiService, + ], + ), + returnValue: + _i10.Future>.value({}), + returnValueForMissingStub: + _i10.Future>.value({}), + ) as _i10.Future>); + + @override + _i10.Future> getTokensFromUserBalance( + String? userGenesisAddress, + List? userTokenLocalAddresses, + _i12.ApiService? apiService, + List<_i24.GetPoolListResponse>? poolsListRaw, + _i11.Environment? environment, { + bool? withUCO = true, + bool? withVerified = true, + bool? withLPToken = true, + bool? withNotVerified = true, + bool? withCustomToken = true, + }) => + (super.noSuchMethod( + Invocation.method( + #getTokensFromUserBalance, + [ + userGenesisAddress, + userTokenLocalAddresses, + apiService, + poolsListRaw, + environment, + ], + { + #withUCO: withUCO, + #withVerified: withVerified, + #withLPToken: withLPToken, + #withNotVerified: withNotVerified, + #withCustomToken: withCustomToken, + }, + ), + returnValue: _i10.Future>.value(<_i8.AEToken>[]), + returnValueForMissingStub: + _i10.Future>.value(<_i8.AEToken>[]), + ) as _i10.Future>); + + @override + _i10.Future<_i8.AEToken> tokenModelToAETokenModel( + _i19.Token? token, + List? verifiedTokens, + List<_i24.GetPoolListResponse>? poolsListRaw, + _i11.Environment? environment, + _i12.ApiService? apiService, + ) => + (super.noSuchMethod( + Invocation.method( + #tokenModelToAETokenModel, + [ + token, + verifiedTokens, + poolsListRaw, + environment, + apiService, + ], + ), + returnValue: _i10.Future<_i8.AEToken>.value(_FakeAEToken_7( + this, + Invocation.method( + #tokenModelToAETokenModel, + [ + token, + verifiedTokens, + poolsListRaw, + environment, + apiService, + ], + ), + )), + returnValueForMissingStub: + _i10.Future<_i8.AEToken>.value(_FakeAEToken_7( + this, + Invocation.method( + #tokenModelToAETokenModel, + [ + token, + verifiedTokens, + poolsListRaw, + environment, + apiService, + ], + ), + )), + ) as _i10.Future<_i8.AEToken>); +} From 15d9b7f4d53ebc77b0ade0410617b25079457844 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Fri, 8 Nov 2024 15:27:07 +0100 Subject: [PATCH 10/11] chore: Use providers to get implementations --- lib/application/tokens/tokens.g.dart | 2 +- lib/domain/models/token_parser.dart | 15 +- .../tokens/tokens.repository.dart | 5 +- .../tokens/tokens.repository.dart | 10 +- lib/modules/aeswap/application/balance.dart | 3 +- .../views/add_custom_token/bloc/provider.dart | 5 + .../add_custom_token/bloc/provider.g.dart | 2 +- pubspec.lock | 6 +- pubspec.yaml | 1 + test/tokenParser_test.dart | 190 ++++-------------- test/tokenParser_test.mocks.dart | 14 +- 11 files changed, 89 insertions(+), 164 deletions(-) diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index 7998c2357..c87be17f7 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -199,7 +199,7 @@ class _TokensFromAddressesProviderElement } String _$tokensFromUserBalanceHash() => - r'8541eb1a96eca49d68d5e757fb375a953c7176c7'; + r'65295bf500c0c6e9682ed073e1e342a741289f05'; /// See also [tokensFromUserBalance]. @ProviderFor(tokensFromUserBalance) diff --git a/lib/domain/models/token_parser.dart b/lib/domain/models/token_parser.dart index 29532813f..3d8014467 100644 --- a/lib/domain/models/token_parser.dart +++ b/lib/domain/models/token_parser.dart @@ -13,6 +13,8 @@ mixin TokenParser { List poolsListRaw, aedappfm.Environment environment, archethic.ApiService apiService, + aedappfm.DefTokensRepositoryImpl defTokensRepository, + TokensRepositoryImpl tokensRepository, ) async { String? pairSymbolToken1; String? pairSymbolToken2; @@ -42,8 +44,7 @@ mixin TokenParser { tokenSymbolSearch.add(token2Address); } - final tokensSymbolMap = - await TokensRepositoryImpl().getTokensFromAddresses( + final tokensSymbolMap = await tokensRepository.getTokensFromAddresses( tokenSymbolSearch, apiService, ); @@ -54,12 +55,12 @@ mixin TokenParser { ? tokensSymbolMap[token2Address]!.symbol : kUCOAddress; - final futureToken1 = aedappfm.DefTokensRepositoryImpl().getDefToken( + final futureToken1 = defTokensRepository.getDefToken( environment, token1Address, ); - final futureToken2 = aedappfm.DefTokensRepositoryImpl().getDefToken( + final futureToken2 = defTokensRepository.getDefToken( environment, token2Address, ); @@ -71,8 +72,10 @@ mixin TokenParser { } } - final defToken = await aedappfm.DefTokensRepositoryImpl() - .getDefToken(environment, token.address!.toUpperCase()); + final defToken = await defTokensRepository.getDefToken( + environment, + token.address!.toUpperCase(), + ); return aedappfm.AEToken( name: defToken?.name ?? '', diff --git a/lib/domain/repositories/tokens/tokens.repository.dart b/lib/domain/repositories/tokens/tokens.repository.dart index 8cb2d8e61..dccfe5647 100644 --- a/lib/domain/repositories/tokens/tokens.repository.dart +++ b/lib/domain/repositories/tokens/tokens.repository.dart @@ -1,3 +1,4 @@ +import 'package:aewallet/infrastructure/repositories/tokens/tokens.repository.dart'; import 'package:aewallet/modules/aeswap/domain/models/util/get_pool_list_response.dart'; import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart' as aedappfm; @@ -14,7 +15,9 @@ abstract class TokensRepository { List userTokenLocalAddresses, archethic.ApiService apiService, List poolsListRaw, - aedappfm.Environment environment, { + aedappfm.Environment environment, + aedappfm.DefTokensRepositoryImpl defTokensRepositoryImpl, + TokensRepositoryImpl tokensRepositoryImpl, { bool withVerified = true, bool withLPToken = true, bool withNotVerified = true, diff --git a/lib/infrastructure/repositories/tokens/tokens.repository.dart b/lib/infrastructure/repositories/tokens/tokens.repository.dart index 2422133f6..3950bf73d 100644 --- a/lib/infrastructure/repositories/tokens/tokens.repository.dart +++ b/lib/infrastructure/repositories/tokens/tokens.repository.dart @@ -64,7 +64,9 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { List userTokenLocalAddresses, archethic.ApiService apiService, List poolsListRaw, - aedappfm.Environment environment, { + aedappfm.Environment environment, + aedappfm.DefTokensRepositoryImpl defTokensRepositoryImpl, + TokensRepositoryImpl tokensRepositoryImpl, { bool withUCO = true, bool withVerified = true, bool withLPToken = true, @@ -77,8 +79,8 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { return tokensList; } if (withUCO) { - final defUCOToken = await aedappfm.DefTokensRepositoryImpl() - .getDefToken(environment, kUCOAddress); + final defUCOToken = + await defTokensRepositoryImpl.getDefToken(environment, kUCOAddress); tokensList.add( aedappfm.ucoToken.copyWith( name: defUCOToken?.name ?? '', @@ -128,6 +130,8 @@ class TokensRepositoryImpl with TokenParser implements TokensRepository { poolsListRaw, environment, apiService, + defTokensRepositoryImpl, + tokensRepositoryImpl, ); final matchingBalances = tokenBalances.where( diff --git a/lib/modules/aeswap/application/balance.dart b/lib/modules/aeswap/application/balance.dart index 0f077cbd6..417ed4af5 100644 --- a/lib/modules/aeswap/application/balance.dart +++ b/lib/modules/aeswap/application/balance.dart @@ -73,7 +73,8 @@ Future addressBalanceTotalFiat( data: (balance) async { if (balance.uco > 0) { final fiatValueUCO = await ref.watch( - DexTokensProviders.estimateTokenInFiat(kUCOAddress).future); + DexTokensProviders.estimateTokenInFiat(kUCOAddress).future, + ); total = (Decimal.parse('${archethic.fromBigInt(balance.uco)}') * Decimal.parse(fiatValueUCO.toString())) .toDouble(); diff --git a/lib/ui/views/add_custom_token/bloc/provider.dart b/lib/ui/views/add_custom_token/bloc/provider.dart index 5053c8248..de4592056 100644 --- a/lib/ui/views/add_custom_token/bloc/provider.dart +++ b/lib/ui/views/add_custom_token/bloc/provider.dart @@ -50,6 +50,9 @@ class AddCustomTokenFormNotifier extends _$AddCustomTokenFormNotifier .read(verifiedTokensRepositoryProvider) .getVerifiedTokens(); final environment = ref.read(environmentProvider); + final tokensRepositoryImpl = ref.read(tokensRepositoryImplProvider); + final defTokensRepositoryImpl = + ref.read(aedappfm.defTokensRepositoryImplProvider); final aeToken = await tokenModelToAETokenModel( tokenResult[tokenAddress]!, @@ -57,6 +60,8 @@ class AddCustomTokenFormNotifier extends _$AddCustomTokenFormNotifier poolsListRaw, environment, apiService, + defTokensRepositoryImpl, + tokensRepositoryImpl, ); setToken(aeToken); diff --git a/lib/ui/views/add_custom_token/bloc/provider.g.dart b/lib/ui/views/add_custom_token/bloc/provider.g.dart index 92fd34296..d3000055e 100644 --- a/lib/ui/views/add_custom_token/bloc/provider.g.dart +++ b/lib/ui/views/add_custom_token/bloc/provider.g.dart @@ -7,7 +7,7 @@ part of 'provider.dart'; // ************************************************************************** String _$addCustomTokenFormNotifierHash() => - r'371269f8e2baa6caddf2e73f9b0269bbdc1199e8'; + r'292d4b87e13f34c2c640f0dd81ad60ac7eaada44'; /// See also [AddCustomTokenFormNotifier]. @ProviderFor(AddCustomTokenFormNotifier) diff --git a/pubspec.lock b/pubspec.lock index 23a3a8006..69ee9a8d1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -73,11 +73,15 @@ packages: source: git ======= name: archethic_dapp_framework_flutter - sha256: bd1a4014b115132d8967198b6ec52b011fa515ec32ab27a04110c6f10cd0f697 + sha256: "8b2d67eb30c92e85b54883ac0e86fa0e96d0a6a886e8967a0d12203a6c7c9f80" url: "https://pub.dev" source: hosted +<<<<<<< HEAD >>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) version: "3.2.2" +======= + version: "3.2.4" +>>>>>>> bbe2bcd0 (chore: Use providers to get implementations) archethic_lib_dart: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3e8581801..c3e7c289d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: git: url: https://github.com/archethic-foundation/archethic-dapp-framework-flutter.git ref: upgrade_web_socket + # archethic_dapp_framework_flutter: # path: ../../packages/archethic-dapp-framework-flutter diff --git a/test/tokenParser_test.dart b/test/tokenParser_test.dart index 5d0bf48ad..d7d066837 100644 --- a/test/tokenParser_test.dart +++ b/test/tokenParser_test.dart @@ -30,6 +30,8 @@ void main() { late MockDefTokensRepositoryImpl mockDefTokensRepository; late MockApiService mockApiService; late aedappfm.Environment environment; + late List verifiedTokens; + late List poolsListRaw; setUp(() { Hive.init('${Directory.current.path}/test/tmp_data'); @@ -38,19 +40,12 @@ void main() { mockApiService = MockApiService(); environment = aedappfm.Environment.testnet; tokenParser = _TokenParserImpl(); - }); - test('Convert UCO to AEToken', () async { - final token = archethic.Token( - address: 'UCO', - symbol: 'UCO', - supply: archethic.toBigInt(1000000), - ); - final verifiedTokens = [ + verifiedTokens = [ '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', ]; - final poolsListRaw = [ + poolsListRaw = [ const GetPoolListResponse( concatenatedTokensAddresses: '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', @@ -69,16 +64,15 @@ void main() { ), ]; - when(mockDefTokensRepository.getDefToken(environment, 'UCO')) - .thenAnswer((_) async { - return const aedappfm.AEToken( + when(mockDefTokensRepository.getDefToken(environment, 'UCO')).thenAnswer( + (_) async => const aedappfm.AEToken( address: 'UCO', name: 'Universal Coin', symbol: 'UCO', ucid: 6887, icon: 'Archethic.svg', - ); - }); + ), + ); when( mockDefTokensRepository.getDefToken( @@ -111,6 +105,14 @@ void main() { icon: 'BNB.svg', ), ); + }); + + test('Convert UCO to AEToken', () async { + final token = archethic.Token( + address: 'UCO', + symbol: 'UCO', + supply: archethic.toBigInt(1000000), + ); final result = await tokenParser.tokenModelToAETokenModel( token, @@ -118,6 +120,8 @@ void main() { poolsListRaw, environment, mockApiService, + mockDefTokensRepository, + mockTokensRepository, ); expect(result.name, 'Universal Coin'); @@ -138,70 +142,6 @@ void main() { type: 'fungible', supply: archethic.toBigInt(1000000), ); - final verifiedTokens = [ - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - ]; - final poolsListRaw = [ - const GetPoolListResponse( - concatenatedTokensAddresses: - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', - address: - '0000818EF23676779DAE1C97072BB99A3E0DD1C31BAD3787422798DBE3F777F74A43', - lpTokenAddress: - '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', - ), - const GetPoolListResponse( - concatenatedTokensAddresses: - 'UCO/0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - address: - '0000DD19DD796959B72998536F67814DCCABE156FF647E0E63E43395203908963767', - lpTokenAddress: - '0000A4CAB2362A97002EE0A6DD2013BEC3AF02C4D8C392712CFBC38F3E4809B9314C', - ), - ]; - - when(mockDefTokensRepository.getDefToken(environment, 'UCO')).thenAnswer( - (_) async => const aedappfm.AEToken( - address: 'UCO', - name: 'Universal Coin', - symbol: 'UCO', - ucid: 6887, - icon: 'Archethic.svg', - ), - ); - - when( - mockDefTokensRepository.getDefToken( - environment, - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - ), - ).thenAnswer( - (_) async => const aedappfm.AEToken( - address: - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - name: 'Wrapped Ether', - symbol: 'aeETH', - ucid: 1027, - icon: 'Ethereum.svg', - ), - ); - - when( - mockDefTokensRepository.getDefToken( - environment, - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - ), - ).thenAnswer( - (_) async => const aedappfm.AEToken( - address: - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - name: 'Wrapped BNB', - symbol: 'aeBNB', - ucid: 1839, - icon: 'BNB.svg', - ), - ); final result = await tokenParser.tokenModelToAETokenModel( token, @@ -209,6 +149,8 @@ void main() { poolsListRaw, environment, mockApiService, + mockDefTokensRepository, + mockTokensRepository, ); expect(result.name, 'Wrapped Ether'); @@ -230,97 +172,47 @@ void main() { '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', supply: archethic.toBigInt(500000), ); - final verifiedTokens = [ - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - ]; - final poolsListRaw = [ - const GetPoolListResponse( - concatenatedTokensAddresses: - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4/UCO', - address: - '0000818EF23676779DAE1C97072BB99A3E0DD1C31BAD3787422798DBE3F777F74A43', - lpTokenAddress: - '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', - ), - const GetPoolListResponse( - concatenatedTokensAddresses: - 'UCO/0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - address: - '0000DD19DD796959B72998536F67814DCCABE156FF647E0E63E43395203908963767', - lpTokenAddress: - '0000A4CAB2362A97002EE0A6DD2013BEC3AF02C4D8C392712CFBC38F3E4809B9314C', - ), - ]; - - final addresses = [ - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - ]; - when( - mockTokensRepository.getTokensFromAddresses(addresses, mockApiService), + mockTokensRepository.getTokensFromAddresses( + argThat( + equals([ + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ]), + ), + any, + ), ).thenAnswer( (_) async => { '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4': const archethic.Token(symbol: 'aeETH'), }, ); - when(mockDefTokensRepository.getDefToken(environment, 'UCO')).thenAnswer( - (_) async => const aedappfm.AEToken( - address: 'UCO', - name: 'Universal Coin', - symbol: 'UCO', - ucid: 6887, - icon: 'Archethic.svg', - ), - ); - - when( - mockDefTokensRepository.getDefToken( - environment, - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - ), - ).thenAnswer( - (_) async => const aedappfm.AEToken( - address: - '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', - name: 'Wrapped Ether', - symbol: 'aeETH', - ucid: 1027, - icon: 'Ethereum.svg', - ), - ); - - when( - mockDefTokensRepository.getDefToken( - environment, - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - ), - ).thenAnswer( - (_) async => const aedappfm.AEToken( - address: - '0000288BF6F0E12457B125DC54D2DFA4EB010BE3073CF02E10FB79B696180F55B827', - name: 'Wrapped BNB', - symbol: 'aeBNB', - ucid: 1839, - icon: 'BNB.svg', - ), - ); - final result = await tokenParser.tokenModelToAETokenModel( token, verifiedTokens, poolsListRaw, environment, mockApiService, + mockDefTokensRepository, + mockTokensRepository, ); - expect(result.symbol, 'aeETH'); + expect(result.symbol, 'LP Token'); + expect( + result.address, + '00006394EF24DFDC6FDFC3642FDC83827591A485704BB997221C0B9F313A468BDEAF', + ); + expect(result.supply, 500000); expect(result.isLpToken, true); expect(result.isVerified, false); expect(result.isUCO, false); expect(result.ucid, isNull); expect(result.lpTokenPair, isNotNull); + expect( + result.lpTokenPair!.token1.address, + '00003DF600E329199BF3EE8FBE2B8223413D70BCDD97E15089E6A74D94DE3F1173B4', + ); + expect(result.lpTokenPair!.token2.address, 'UCO'); }); }); } diff --git a/test/tokenParser_test.mocks.dart b/test/tokenParser_test.mocks.dart index 2d9d56f3a..a1d52fcb9 100644 --- a/test/tokenParser_test.mocks.dart +++ b/test/tokenParser_test.mocks.dart @@ -850,7 +850,9 @@ class MockTokensRepositoryImpl extends _i1.Mock List? userTokenLocalAddresses, _i12.ApiService? apiService, List<_i24.GetPoolListResponse>? poolsListRaw, - _i11.Environment? environment, { + _i11.Environment? environment, + _i9.DefTokensRepositoryImpl? defTokensRepositoryImpl, + _i23.TokensRepositoryImpl? tokensRepositoryImpl, { bool? withUCO = true, bool? withVerified = true, bool? withLPToken = true, @@ -866,6 +868,8 @@ class MockTokensRepositoryImpl extends _i1.Mock apiService, poolsListRaw, environment, + defTokensRepositoryImpl, + tokensRepositoryImpl, ], { #withUCO: withUCO, @@ -887,6 +891,8 @@ class MockTokensRepositoryImpl extends _i1.Mock List<_i24.GetPoolListResponse>? poolsListRaw, _i11.Environment? environment, _i12.ApiService? apiService, + _i9.DefTokensRepositoryImpl? defTokensRepository, + _i23.TokensRepositoryImpl? tokensRepository, ) => (super.noSuchMethod( Invocation.method( @@ -897,6 +903,8 @@ class MockTokensRepositoryImpl extends _i1.Mock poolsListRaw, environment, apiService, + defTokensRepository, + tokensRepository, ], ), returnValue: _i10.Future<_i8.AEToken>.value(_FakeAEToken_7( @@ -909,6 +917,8 @@ class MockTokensRepositoryImpl extends _i1.Mock poolsListRaw, environment, apiService, + defTokensRepository, + tokensRepository, ], ), )), @@ -923,6 +933,8 @@ class MockTokensRepositoryImpl extends _i1.Mock poolsListRaw, environment, apiService, + defTokensRepository, + tokensRepository, ], ), )), From 151df4b96e9479ca68d22ad333fc2c1da19331f5 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Tue, 10 Dec 2024 17:53:39 +0100 Subject: [PATCH 11/11] chore: :bug: Fixes following rebase (WIP) --- lib/application/aeswap/dex_token.g.dart | 8 - lib/application/dapps.dart | 1 - lib/application/dapps.g.dart | 4 - lib/application/tokens/tokens.g.dart | 175 ------------------ lib/modules/aeswap/application/balance.g.dart | 12 -- lib/ui/views/main/account_tab.dart | 1 - lib/ui/views/tokens_list/bloc/provider.g.dart | 9 - pubspec.lock | 103 ++++------- 8 files changed, 32 insertions(+), 281 deletions(-) diff --git a/lib/application/aeswap/dex_token.g.dart b/lib/application/aeswap/dex_token.g.dart index 549bf297f..a70fcfd29 100644 --- a/lib/application/aeswap/dex_token.g.dart +++ b/lib/application/aeswap/dex_token.g.dart @@ -789,15 +789,7 @@ class _GetRemoveAmountsProviderElement } String _$estimateLPTokenInFiatHash() => -<<<<<<< HEAD -<<<<<<< HEAD r'117d1b9fae927eca34724ab59d026abeaf3a6393'; -======= - r'4da34defbb60f367688c57c66b713d474f680f72'; ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) -======= - r'117d1b9fae927eca34724ab59d026abeaf3a6393'; ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// See also [_estimateLPTokenInFiat]. @ProviderFor(_estimateLPTokenInFiat) diff --git a/lib/application/dapps.dart b/lib/application/dapps.dart index 7d2e10127..a16a4fcd5 100644 --- a/lib/application/dapps.dart +++ b/lib/application/dapps.dart @@ -17,7 +17,6 @@ DAppsRepositoryImpl _dAppsRepository( @riverpod Future _getDApp( Ref ref, - AvailableNetworks network, String code, ) async { final apiService = ref.watch(apiServiceProvider); diff --git a/lib/application/dapps.g.dart b/lib/application/dapps.g.dart index c09fa03e6..f0ab0bdbe 100644 --- a/lib/application/dapps.g.dart +++ b/lib/application/dapps.g.dart @@ -24,11 +24,7 @@ final _dAppsRepositoryProvider = @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element typedef _DAppsRepositoryRef = AutoDisposeProviderRef; -<<<<<<< HEAD String _$getDAppHash() => r'e708424d60dbef17da84a12ed02a67dd493a28a2'; -======= -String _$getDAppHash() => r'70f3139f239d37e2aaf093b1007b668aeab29d90'; ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) /// Copied from Dart SDK class _SystemHash { diff --git a/lib/application/tokens/tokens.g.dart b/lib/application/tokens/tokens.g.dart index c87be17f7..2f2c05706 100644 --- a/lib/application/tokens/tokens.g.dart +++ b/lib/application/tokens/tokens.g.dart @@ -6,18 +6,6 @@ part of 'tokens.dart'; // RiverpodGenerator // ************************************************************************** -<<<<<<< HEAD -<<<<<<< HEAD -String _$tokensListHash() => r'593e48ed9063457663e2e48b344aed4ca8bc7518'; -======= -String _$tokensFromAddressesHash() => -<<<<<<< HEAD - r'4cd16d00a6c3c466c3eefe8e60852b2791c7527b'; ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) -======= - r'dfc16b82d33ff918a59411a80e8a0d3719259f92'; ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) -======= String _$tokensRepositoryImplHash() => r'6d0639fff11793ccb691c0bdb8aa86b99078ee47'; @@ -39,7 +27,6 @@ final tokensRepositoryImplProvider = typedef TokensRepositoryImplRef = AutoDisposeProviderRef; String _$tokensFromAddressesHash() => r'3eb854cf86092bf7599a28a546924b3a2eb3bf14'; ->>>>>>> d48d1eb3 (chore: :recycle: Use provider to use TokensRepositoryImpl) /// Copied from Dart SDK class _SystemHash { @@ -362,28 +349,13 @@ class TokensFromUserBalanceProvider } } -<<<<<<< HEAD -<<<<<<< HEAD -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element -mixin TokensListRef on AutoDisposeFutureProviderRef> { - /// The parameter `userGenesisAddress` of this provider. - String get userGenesisAddress; - -======= -======= @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) mixin TokensFromUserBalanceRef on AutoDisposeFutureProviderRef> { -<<<<<<< HEAD ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) -======= /// The parameter `withUCO` of this provider. bool get withUCO; ->>>>>>> c07b6392 (fix: :bug: Bugs fixing) /// The parameter `withVerified` of this provider. bool get withVerified; @@ -417,23 +389,7 @@ class _TokensFromUserBalanceProviderElement (origin as TokensFromUserBalanceProvider).withCustomToken; } -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD -String _$tokensTotalUSDHash() => r'a0f42e1ef21073d1ec7f627b48fde93b76205a7a'; -======= -String _$tokensTotalUSDHash() => r'98ac96ba39ca5f3b227f4d114c7556532a4d24dd'; ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) -======= -String _$tokensTotalUSDHash() => r'39ec8250b31cdf374fe272bd8b3077dd8efb6476'; ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) -======= -String _$tokensTotalUSDHash() => r'f3e1d13475c67a72664e0fdb557b296f134fc9ad'; ->>>>>>> d4305dd0 (fix: :bug: Bug fixing) -======= String _$tokensTotalUSDHash() => r'4cd1d9dfe1e4a3c828254a2be2461ee032318cc0'; ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) /// See also [tokensTotalUSD]. @ProviderFor(tokensTotalUSD) @@ -447,139 +403,8 @@ final tokensTotalUSDProvider = AutoDisposeFutureProvider.internal( allTransitiveDependencies: null, ); -<<<<<<< HEAD -<<<<<<< HEAD -/// See also [tokensTotalUSD]. -class TokensTotalUSDFamily extends Family> { - /// See also [tokensTotalUSD]. - const TokensTotalUSDFamily(); - - /// See also [tokensTotalUSD]. - TokensTotalUSDProvider call( - String userGenesisAddress, - ) { - return TokensTotalUSDProvider( - userGenesisAddress, - ); - } - - @override - TokensTotalUSDProvider getProviderOverride( - covariant TokensTotalUSDProvider provider, - ) { - return call( - provider.userGenesisAddress, - ); - } - - static const Iterable? _dependencies = null; - - @override - Iterable? get dependencies => _dependencies; - - static const Iterable? _allTransitiveDependencies = null; - - @override - Iterable? get allTransitiveDependencies => - _allTransitiveDependencies; - - @override - String? get name => r'tokensTotalUSDProvider'; -} - -/// See also [tokensTotalUSD]. -class TokensTotalUSDProvider extends AutoDisposeFutureProvider { - /// See also [tokensTotalUSD]. - TokensTotalUSDProvider( - String userGenesisAddress, - ) : this._internal( - (ref) => tokensTotalUSD( - ref as TokensTotalUSDRef, - userGenesisAddress, - ), - from: tokensTotalUSDProvider, - name: r'tokensTotalUSDProvider', - debugGetCreateSourceHash: - const bool.fromEnvironment('dart.vm.product') - ? null - : _$tokensTotalUSDHash, - dependencies: TokensTotalUSDFamily._dependencies, - allTransitiveDependencies: - TokensTotalUSDFamily._allTransitiveDependencies, - userGenesisAddress: userGenesisAddress, - ); - - TokensTotalUSDProvider._internal( - super._createNotifier, { - required super.name, - required super.dependencies, - required super.allTransitiveDependencies, - required super.debugGetCreateSourceHash, - required super.from, - required this.userGenesisAddress, - }) : super.internal(); - - final String userGenesisAddress; - - @override - Override overrideWith( - FutureOr Function(TokensTotalUSDRef provider) create, - ) { - return ProviderOverride( - origin: this, - override: TokensTotalUSDProvider._internal( - (ref) => create(ref as TokensTotalUSDRef), - from: from, - name: null, - dependencies: null, - allTransitiveDependencies: null, - debugGetCreateSourceHash: null, - userGenesisAddress: userGenesisAddress, - ), - ); - } - - @override - AutoDisposeFutureProviderElement createElement() { - return _TokensTotalUSDProviderElement(this); - } - - @override - bool operator ==(Object other) { - return other is TokensTotalUSDProvider && - other.userGenesisAddress == userGenesisAddress; - } - - @override - int get hashCode { - var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, userGenesisAddress.hashCode); - - return _SystemHash.finish(hash); - } -} - -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element -mixin TokensTotalUSDRef on AutoDisposeFutureProviderRef { - /// The parameter `userGenesisAddress` of this provider. - String get userGenesisAddress; -} - -class _TokensTotalUSDProviderElement - extends AutoDisposeFutureProviderElement with TokensTotalUSDRef { - _TokensTotalUSDProviderElement(super.provider); - - @override - String get userGenesisAddress => - (origin as TokensTotalUSDProvider).userGenesisAddress; -} -======= -======= @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) typedef TokensTotalUSDRef = AutoDisposeFutureProviderRef; ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) // ignore_for_file: type=lint // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/modules/aeswap/application/balance.g.dart b/lib/modules/aeswap/application/balance.g.dart index 786cdada2..e5c76825a 100644 --- a/lib/modules/aeswap/application/balance.g.dart +++ b/lib/modules/aeswap/application/balance.g.dart @@ -177,19 +177,7 @@ class _AddressBalanceProviderElement } String _$addressBalanceTotalFiatHash() => -<<<<<<< HEAD -<<<<<<< HEAD -<<<<<<< HEAD - r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; -======= - r'39f9c8fc5cd22a8b4ae2c923013783f59c219326'; ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) -======= - r'7a2802ee8f75deea0f6ed01238eaa91e54986faa'; ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) -======= r'b5193d8603fbd36ea7e7f676a624a0137ad43fde'; ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) /// See also [addressBalanceTotalFiat]. @ProviderFor(addressBalanceTotalFiat) diff --git a/lib/ui/views/main/account_tab.dart b/lib/ui/views/main/account_tab.dart index f37dc22ff..a84600fb4 100644 --- a/lib/ui/views/main/account_tab.dart +++ b/lib/ui/views/main/account_tab.dart @@ -117,7 +117,6 @@ class AccountTab extends ConsumerWidget { opticalSize: IconSize.opticalSizeM, grade: IconSize.gradeM, size: 16, - color: Colors.white, ), ], ), diff --git a/lib/ui/views/tokens_list/bloc/provider.g.dart b/lib/ui/views/tokens_list/bloc/provider.g.dart index 287c386f8..f5af9c823 100644 --- a/lib/ui/views/tokens_list/bloc/provider.g.dart +++ b/lib/ui/views/tokens_list/bloc/provider.g.dart @@ -175,18 +175,9 @@ class TokensProvider extends AutoDisposeFutureProvider> { } } -<<<<<<< HEAD -<<<<<<< HEAD @Deprecated('Will be removed in 3.0. Use Ref instead') // ignore: unused_element -mixin _TokensRef on AutoDisposeFutureProviderRef> { -======= -======= -@Deprecated('Will be removed in 3.0. Use Ref instead') -// ignore: unused_element ->>>>>>> 97bbb94a (chore: :arrow_up: Upgrade riverpod) mixin TokensRef on AutoDisposeFutureProviderRef> { ->>>>>>> 0fc830d6 (feat: :sparkles: Add Custom tokens management) /// The parameter `searchCriteria` of this provider. String get searchCriteria; diff --git a/pubspec.lock b/pubspec.lock index 69ee9a8d1..2cbd7d2bc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -65,23 +65,12 @@ packages: archethic_dapp_framework_flutter: dependency: "direct main" description: -<<<<<<< HEAD path: "." ref: upgrade_web_socket resolved-ref: "85b213ea35218561314596204aa5ea9f3f1b520b" url: "https://github.com/archethic-foundation/archethic-dapp-framework-flutter.git" source: git -======= - name: archethic_dapp_framework_flutter - sha256: "8b2d67eb30c92e85b54883ac0e86fa0e96d0a6a886e8967a0d12203a6c7c9f80" - url: "https://pub.dev" - source: hosted -<<<<<<< HEAD ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) version: "3.2.2" -======= - version: "3.2.4" ->>>>>>> bbe2bcd0 (chore: Use providers to get implementations) archethic_lib_dart: dependency: transitive description: @@ -645,18 +634,18 @@ packages: dependency: "direct main" description: name: flutter_inappwebview - sha256: "4289afd4fe1eda87f9d370a027b69de12033a796580c45857287ed76123e589f" + sha256: a8f5c9dd300a8cc7fde7bb902ae57febe95e9269424e4d08d5a1a56214e1e6ff url: "https://pub.dev" source: hosted - version: "6.2.0-beta.1" + version: "6.2.0-beta.2" flutter_inappwebview_android: dependency: transitive description: name: flutter_inappwebview_android - sha256: "14662920d8edd620aac0196bf52094d1197ed7a2ac30b6036fb002da0facfc1a" + sha256: "2427e89d9c7b00cc756f800932d7ab8f3272d3fbc71544e1aedb3dbc17dae074" url: "https://pub.dev" source: hosted - version: "1.2.0-beta.1" + version: "1.2.0-beta.2" flutter_inappwebview_internal_annotations: dependency: transitive description: @@ -669,42 +658,42 @@ packages: dependency: transitive description: name: flutter_inappwebview_ios - sha256: f242a910701e9b9fa2c9ffc543417536f5461ee168fb8f2255b5ed9a3eaa05f5 + sha256: "7ff65d7408e453f9a4ff38f74673aeec8cae824cba8276b4b77350262bfe356a" url: "https://pub.dev" source: hosted - version: "1.2.0-beta.1" + version: "1.2.0-beta.2" flutter_inappwebview_macos: dependency: transitive description: name: flutter_inappwebview_macos - sha256: da15186360896df817423a760072c6ccd818a28574451924a43b0e6acc7097c1 + sha256: be8b8ab0100c94ec9fc079a4d48b2bc8dd1a8b4c2647da34f1d3dae93cd5f88a url: "https://pub.dev" source: hosted - version: "1.2.0-beta.1" + version: "1.2.0-beta.2" flutter_inappwebview_platform_interface: dependency: transitive description: name: flutter_inappwebview_platform_interface - sha256: a83de41eabef0853e567aff32891bf43fb42ab7af7f065ee551d7384e192fe93 + sha256: "2c99bf767900ba029d825bc6f494d30169ee83cdaa038d86e85fe70571d0a655" url: "https://pub.dev" source: hosted - version: "1.4.0-beta.1" + version: "1.4.0-beta.2" flutter_inappwebview_web: dependency: transitive description: name: flutter_inappwebview_web - sha256: bc62e5718aec1c59677b5d76a3a62098a8da2668701d033e1d68f13db43f7922 + sha256: "6c4bb61ea9d52e51d79ea23da27c928d0430873c04ad380df39c1ef442b11f4e" url: "https://pub.dev" source: hosted - version: "1.2.0-beta.1" + version: "1.2.0-beta.2" flutter_inappwebview_windows: dependency: transitive description: name: flutter_inappwebview_windows - sha256: "6550a2507daad1003e78a2ba554b96dc2339e2307ac03a6cc2c254b5d1aebbf6" + sha256: "0ff241f814b7caff63b9632cf858b6d3d9c35758040620a9745e5f6e9dd94d74" url: "https://pub.dev" source: hosted - version: "0.7.0-beta.1" + version: "0.7.0-beta.2" flutter_jailbreak_detection: dependency: "direct main" description: @@ -850,17 +839,10 @@ packages: dependency: "direct main" description: name: flutter_svg -<<<<<<< HEAD - sha256: "936d9c1c010d3e234d1672574636f3352b4941ca3decaddd3cafaeb9ad49c471" + sha256: "54900a1a1243f3c4a5506d853a2b5c2dbc38d5f27e52a52618a8054401431123" url: "https://pub.dev" source: hosted - version: "2.0.15" -======= - sha256: "2ca230f2ef6e31151769f4a03ec806b94f0554ff02ea1a40bb0d531ac150f035" - url: "https://pub.dev" - source: hosted - version: "2.0.12" ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) + version: "2.0.16" flutter_test: dependency: "direct dev" description: flutter @@ -1092,10 +1074,10 @@ packages: dependency: transitive description: name: image_picker_android - sha256: "8faba09ba361d4b246dc0a17cb4289b3324c2b9f6db7b3d457ee69106a86bd32" + sha256: fa8141602fde3f7e2f81dbf043613eb44dfa325fa0bcf93c0f142c9f7a2c193e url: "https://pub.dev" source: hosted - version: "0.8.12+17" + version: "0.8.12+18" image_picker_for_web: dependency: transitive description: @@ -1164,10 +1146,10 @@ packages: dependency: transitive description: name: io - sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" js: dependency: "direct main" description: @@ -1340,10 +1322,10 @@ packages: dependency: "direct main" description: name: material_symbols_icons - sha256: "1dea2aef1c83434f832f14341a5ffa1254e76b68e4d90333f95f8a2643bf1024" + sha256: "64404f47f8e0a9d20478468e5decef867a688660bad7173adcd20418d7f892c9" url: "https://pub.dev" source: hosted - version: "4.2799.0" + version: "4.2801.0" meta: dependency: transitive description: @@ -1516,18 +1498,18 @@ packages: dependency: transitive description: name: path_provider_android - sha256: "8c4967f8b7cb46dc914e178daa29813d83ae502e0529d7b0478330616a691ef7" + sha256: "4adf4fd5423ec60a29506c76581bc05854c55e3a0b72d35bb28d661c9686edf2" url: "https://pub.dev" source: hosted - version: "2.2.14" + version: "2.2.15" path_provider_foundation: dependency: transitive description: name: path_provider_foundation - sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 + sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.1" path_provider_linux: dependency: transitive description: @@ -2049,10 +2031,10 @@ packages: dependency: transitive description: name: url_launcher_ios - sha256: e43b677296fadce447e987a2f519dcf5f6d1e527dc35d01ffab4fff5b8a7063e + sha256: "16a513b6c12bb419304e72ea0ae2ab4fed569920d1c7cb850263fe3acc824626" url: "https://pub.dev" source: hosted - version: "6.3.1" + version: "6.3.2" url_launcher_linux: dependency: transitive description: @@ -2065,10 +2047,10 @@ packages: dependency: transitive description: name: url_launcher_macos - sha256: "769549c999acdb42b8bcfa7c43d72bf79a382ca7441ab18a808e101149daf672" + sha256: "17ba2000b847f334f16626a574c702b196723af2a289e7a93ffcb79acff855c2" url: "https://pub.dev" source: hosted - version: "3.2.1" + version: "3.2.2" url_launcher_platform_interface: dependency: transitive description: @@ -2113,17 +2095,10 @@ packages: dependency: transitive description: name: vector_graphics -<<<<<<< HEAD sha256: "27d5fefe86fb9aace4a9f8375b56b3c292b64d8c04510df230f849850d912cb7" url: "https://pub.dev" source: hosted version: "1.1.15" -======= - sha256: "0b9149c6ddb013818075b072b9ddc1b89a5122fff1275d4648d297086b46c4f0" - url: "https://pub.dev" - source: hosted - version: "1.1.12" ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) vector_graphics_codec: dependency: transitive description: @@ -2136,17 +2111,10 @@ packages: dependency: transitive description: name: vector_graphics_compiler -<<<<<<< HEAD sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad" url: "https://pub.dev" source: hosted version: "1.1.16" -======= - sha256: f3b9b6e4591c11394d4be4806c63e72d3a41778547b2c1e2a8a04fadcfd7d173 - url: "https://pub.dev" - source: hosted - version: "1.1.12" ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) vector_math: dependency: transitive description: @@ -2231,25 +2199,18 @@ packages: dependency: transitive description: name: webview_flutter_wkwebview -<<<<<<< HEAD sha256: b7e92f129482460951d96ef9a46b49db34bd2e1621685de26e9eaafd9674e7eb url: "https://pub.dev" source: hosted version: "3.16.3" -======= - sha256: f14ee08021772fed913da8daebcfdeb46be457081e521e93e9918fe6cd1ce9e8 - url: "https://pub.dev" - source: hosted - version: "3.16.1" ->>>>>>> 4d0cd1d9 (chore: :recycle: Use constants) win32: dependency: transitive description: name: win32 - sha256: "84ba388638ed7a8cb3445a320c8273136ab2631cd5f2c57888335504ddab1bc2" + sha256: "8b338d4486ab3fbc0ba0db9f9b4f5239b6697fcee427939a40e720cbb9ee0a69" url: "https://pub.dev" source: hosted - version: "5.8.0" + version: "5.9.0" win32_registry: dependency: transitive description: