diff --git a/lib/application/account/account_notifier.dart b/lib/application/account/account_notifier.dart index 7e1bb1f58..1c4363c2f 100644 --- a/lib/application/account/account_notifier.dart +++ b/lib/application/account/account_notifier.dart @@ -115,129 +115,131 @@ class AccountNotifier extends _$AccountNotifier { } Future updateBalance() async { - final account = await future; - if (account == null) return; - - var totalUSD = 0.0; + await _update((account) async { + var totalUSD = 0.0; - final balanceGetResponseMap = await ref - .read(appServiceProvider) - .getBalanceGetResponse([account.genesisAddress]); + final balanceGetResponseMap = await ref + .read(appServiceProvider) + .getBalanceGetResponse([account.genesisAddress]); - if (balanceGetResponseMap[account.genesisAddress] == null) { - return; - } + if (balanceGetResponseMap[account.genesisAddress] == null) { + return account; + } - final ucidsTokens = await ref.read( - aedappfm.UcidsTokensProviders.ucidsTokens( - environment: ref.read(environmentProvider), - ).future, - ); + final ucidsTokens = await ref.read( + aedappfm.UcidsTokensProviders.ucidsTokens( + environment: ref.read(environmentProvider), + ).future, + ); - final cryptoPrice = ref.read(aedappfm.CoinPriceProviders.coinPrices); + final cryptoPrice = ref.read(aedappfm.CoinPriceProviders.coinPrices); - final balanceGetResponse = balanceGetResponseMap[account.genesisAddress]!; - final ucoAmount = fromBigInt(balanceGetResponse.uco).toDouble(); - final accountBalance = AccountBalance( - nativeTokenName: AccountBalance.cryptoCurrencyLabel, - nativeTokenValue: ucoAmount, - ); + final balanceGetResponse = balanceGetResponseMap[account.genesisAddress]!; + final ucoAmount = fromBigInt(balanceGetResponse.uco).toDouble(); + final accountBalance = AccountBalance( + nativeTokenName: AccountBalance.cryptoCurrencyLabel, + nativeTokenValue: ucoAmount, + ); - if (balanceGetResponse.uco > 0) { - accountBalance.tokensFungiblesNb++; + if (balanceGetResponse.uco > 0) { + accountBalance.tokensFungiblesNb++; - final archethicOracleUCO = await ref.read( - aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.future, - ); - totalUSD = (Decimal.parse(totalUSD.toString()) + - Decimal.parse(ucoAmount.toString()) * - Decimal.parse(archethicOracleUCO.usd.toString())) - .toDouble(); - } + final archethicOracleUCO = await ref.read( + aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.future, + ); + totalUSD = (Decimal.parse(totalUSD.toString()) + + Decimal.parse(ucoAmount.toString()) * + Decimal.parse(archethicOracleUCO.usd.toString())) + .toDouble(); + } - for (final token in balanceGetResponse.token) { - if (token.tokenId != null) { - if (token.tokenId == 0) { - accountBalance.tokensFungiblesNb++; - - final ucidsToken = ucidsTokens[token.address]; - if (ucidsToken != null && ucidsToken != 0) { - final amountTokenUSD = - (Decimal.parse(fromBigInt(token.amount).toString()) * - Decimal.parse( - aedappfm.CoinPriceRepositoryImpl() - .getPriceFromUcid(ucidsToken, cryptoPrice) - .toString(), - )) - .toDouble(); - totalUSD = totalUSD + amountTokenUSD; + for (final token in balanceGetResponse.token) { + if (token.tokenId != null) { + if (token.tokenId == 0) { + accountBalance.tokensFungiblesNb++; + + final ucidsToken = ucidsTokens[token.address]; + if (ucidsToken != null && ucidsToken != 0) { + final amountTokenUSD = + (Decimal.parse(fromBigInt(token.amount).toString()) * + Decimal.parse( + aedappfm.CoinPriceRepositoryImpl() + .getPriceFromUcid(ucidsToken, cryptoPrice) + .toString(), + )) + .toDouble(); + totalUSD = totalUSD + amountTokenUSD; + } + } else { + accountBalance.nftNb++; } - } else { - accountBalance.nftNb++; } } - } - accountBalance.totalUSD = totalUSD; + accountBalance.totalUSD = totalUSD; - account.balance = accountBalance; - await updateAccount(); + return account.copyWith(balance: accountBalance); + }); } Future updateFungiblesTokens() async { - final account = await future; - if (account == null) { - return; - } - final appService = ref.read(appServiceProvider); - final poolsListRaw = await ref.read(DexPoolProviders.getPoolListRaw.future); - - account.accountTokens = await appService.getFungiblesTokensList( - account.genesisAddress, - poolsListRaw, - ); - await updateAccount(); + await _update((account) async { + final appService = ref.read(appServiceProvider); + final poolsListRaw = + await ref.read(DexPoolProviders.getPoolListRaw.future); + + return account.copyWith( + accountTokens: await appService.getFungiblesTokensList( + account.genesisAddress, + poolsListRaw, + ), + ); + }); } Future updateRecentTransactions() async { - final account = await future; - if (account == null) { - return; - } - final session = ref.read(sessionNotifierProvider).loggedIn!; - final appService = ref.read(appServiceProvider); - - account - ..recentTransactions = await appService.getAccountRecentTransactions( - account.genesisAddress, - account.name, - session.wallet.keychainSecuredInfos, - account.recentTransactions ?? [], - ) - ..lastLoadingTransactionInputs = DateTime.now().millisecondsSinceEpoch ~/ - Duration.millisecondsPerSecond; - await updateAccount(); + await _update((account) async { + final session = ref.read(sessionNotifierProvider).loggedIn!; + final appService = ref.read(appServiceProvider); + + return account.copyWith( + recentTransactions: await appService.getAccountRecentTransactions( + account.genesisAddress, + account.name, + session.wallet.keychainSecuredInfos, + account.recentTransactions ?? [], + ), + lastLoadingTransactionInputs: DateTime.now().millisecondsSinceEpoch ~/ + Duration.millisecondsPerSecond, + ); + }); } Future addCustomTokenAddress(String tokenAddress) async { - final account = await future; - if (account == null) { - return; - } - if (Address(address: tokenAddress).isValid() == false) return; - (account.customTokenAddressList ??= []).add(tokenAddress.toUpperCase()); - await updateAccount(); + await _update((account) async { + return account.copyWith( + customTokenAddressList: [ + ...account.customTokenAddressList ?? [], + tokenAddress.toUpperCase(), + ], + ); + }); } Future removeCustomTokenAddress(String tokenAddress) async { - final account = await future; - if (account == null) { - return; - } - if (Address(address: tokenAddress).isValid() == false) return; - (account.customTokenAddressList ??= []).remove(tokenAddress.toUpperCase()); - await updateAccount(); + await _update((account) async { + final customTokenAddressList = account.customTokenAddressList; + if (customTokenAddressList == null) return account; + + return account.copyWith( + customTokenAddressList: customTokenAddressList + .where( + (element) => element != tokenAddress.toUpperCase(), + ) + .toList(), + ); + }); } Future checkCustomTokenAddress(String tokenAddress) async { @@ -252,42 +254,42 @@ class AccountNotifier extends _$AccountNotifier { } Future updateNFT() async { - final account = await future; - if (account == null) { - return; - } - final session = ref.read(sessionNotifierProvider).loggedIn!; - final tokenInformation = await ref.read( - NFTProviders.getNFTList( - account.genesisAddress, - account.name, - session.wallet.keychainSecuredInfos, - ).future, - ); - - account - ..accountNFT = tokenInformation.$1 - ..accountNFTCollections = tokenInformation.$2; + await _update( + (account) async { + final session = ref.read(sessionNotifierProvider).loggedIn!; + final tokenInformation = await ref.read( + NFTProviders.getNFTList( + account.genesisAddress, + account.name, + session.wallet.keychainSecuredInfos, + ).future, + ); - await updateAccount(); + return account.copyWith( + accountNFT: tokenInformation.$1, + accountNFTCollections: tokenInformation.$2, + ); + }, + ); } Future clearRecentTransactionsFromCache() async { - final account = await future; - if (account == null) { - return; - } - - account.recentTransactions = []; - await updateAccount(); + await _update( + (account) => account.copyWith(recentTransactions: []), + ); } - Future updateAccount() async { - final account = await future; - if (account == null) { - return; - } + Future _update( + FutureOr Function(Account) doUpdate, + ) async { + await update( + (account) async { + if (account == null) return null; - await AccountHiveDatasource.instance().updateAccount(account); + final newState = await doUpdate(account); + await AccountHiveDatasource.instance().updateAccount(newState); + return newState; + }, + ); } } diff --git a/lib/application/account/account_notifier.g.dart b/lib/application/account/account_notifier.g.dart index 59baa3319..bba848c53 100644 --- a/lib/application/account/account_notifier.g.dart +++ b/lib/application/account/account_notifier.g.dart @@ -6,7 +6,7 @@ part of 'account_notifier.dart'; // RiverpodGenerator // ************************************************************************** -String _$accountNotifierHash() => r'e1fe68fac65b0f98a98bbe745d1608ff9e9cd990'; +String _$accountNotifierHash() => r'33410ce13c1065c8a2840153d20ff40456ac07cc'; /// Copied from Dart SDK class _SystemHash { diff --git a/lib/application/account/accounts_notifier.dart b/lib/application/account/accounts_notifier.dart index 8f7d0d84e..b3352ee6a 100644 --- a/lib/application/account/accounts_notifier.dart +++ b/lib/application/account/accounts_notifier.dart @@ -4,7 +4,6 @@ import 'dart:async'; import 'package:aewallet/application/account/account_notifier.dart'; import 'package:aewallet/application/session/session.dart'; -import 'package:aewallet/infrastructure/datasources/account.hive.dart'; import 'package:aewallet/infrastructure/repositories/local_account.dart'; import 'package:aewallet/model/data/account.dart'; import 'package:aewallet/util/account_formatters.dart'; @@ -16,7 +15,7 @@ part 'accounts_notifier.g.dart'; @riverpod class AccountsNotifier extends _$AccountsNotifier { @override - FutureOr> build() async { + FutureOr> build() async { final session = ref.watch(sessionNotifierProvider); if (session.isLoggedOut) { return []; @@ -55,16 +54,18 @@ class AccountsNotifier extends _$AccountsNotifier { return ref.read(accountNotifierProvider(accountName).notifier); } + // TODO(Chralu): check if this works Future clearRecentTransactionsFromCache() async { final accounts = await future; for (final account in accounts) { - account.recentTransactions = []; - await AccountHiveDatasource.instance().updateAccount(account); + await ref + .read(accountNotifierProvider(account.name).notifier) + .clearRecentTransactionsFromCache(); } } } -extension AccountsExt on List { +extension AccountsExt on Iterable { Account? get selectedAccount { for (final account in this) { if (account.selected == true) return account; @@ -91,7 +92,7 @@ extension AccountsExt on List { } } -extension FutureAccountsExt on Future> { +extension FutureAccountsExt on Future> { Future get selectedAccount async { return (await this).selectedAccount; } diff --git a/lib/application/account/accounts_notifier.g.dart b/lib/application/account/accounts_notifier.g.dart index f2380c8e3..e939ce1a9 100644 --- a/lib/application/account/accounts_notifier.g.dart +++ b/lib/application/account/accounts_notifier.g.dart @@ -6,12 +6,12 @@ part of 'accounts_notifier.dart'; // RiverpodGenerator // ************************************************************************** -String _$accountsNotifierHash() => r'83532736c884190fa4b4cb54a0ab4c43b0dcdd05'; +String _$accountsNotifierHash() => r'58f869b3689672b3bd919a0071e727e97feeeb67'; /// See also [AccountsNotifier]. @ProviderFor(AccountsNotifier) -final accountsNotifierProvider = - AutoDisposeAsyncNotifierProvider>.internal( +final accountsNotifierProvider = AutoDisposeAsyncNotifierProvider< + AccountsNotifier, Iterable>.internal( AccountsNotifier.new, name: r'accountsNotifierProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') @@ -21,6 +21,6 @@ final accountsNotifierProvider = allTransitiveDependencies: null, ); -typedef _$AccountsNotifier = AutoDisposeAsyncNotifier>; +typedef _$AccountsNotifier = AutoDisposeAsyncNotifier>; // 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/usecases/transaction/send_transaction.freezed.dart b/lib/domain/usecases/transaction/send_transaction.freezed.dart index 7f9ea7252..35d6036c1 100644 --- a/lib/domain/usecases/transaction/send_transaction.freezed.dart +++ b/lib/domain/usecases/transaction/send_transaction.freezed.dart @@ -42,6 +42,7 @@ abstract class $SendTransactionCommandCopyWith<$Res> { @useResult $Res call({Account senderAccount, Data data, String type, int version}); + $AccountCopyWith<$Res> get senderAccount; $DataCopyWith<$Res> get data; } @@ -86,6 +87,16 @@ class _$SendTransactionCommandCopyWithImpl<$Res, ) as $Val); } + /// Create a copy of SendTransactionCommand + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $AccountCopyWith<$Res> get senderAccount { + return $AccountCopyWith<$Res>(_value.senderAccount, (value) { + return _then(_value.copyWith(senderAccount: value) as $Val); + }); + } + /// Create a copy of SendTransactionCommand /// with the given fields replaced by the non-null parameter values. @override @@ -108,6 +119,8 @@ abstract class _$$SendTransactionCommandImplCopyWith<$Res> @useResult $Res call({Account senderAccount, Data data, String type, int version}); + @override + $AccountCopyWith<$Res> get senderAccount; @override $DataCopyWith<$Res> get data; } diff --git a/lib/infrastructure/datasources/account.hive.dart b/lib/infrastructure/datasources/account.hive.dart index 762ebcc9f..f3c3d7896 100644 --- a/lib/infrastructure/datasources/account.hive.dart +++ b/lib/infrastructure/datasources/account.hive.dart @@ -1,5 +1,4 @@ import 'package:aewallet/model/data/account.dart'; -import 'package:aewallet/model/data/account_balance.dart'; import 'package:aewallet/model/data/hive_app_wallet_dto.dart'; import 'package:hive/hive.dart'; @@ -47,44 +46,23 @@ class AccountHiveDatasource { return _writeAppWallet(appWallet); } - Future clearAccount() async { - final appWallet = await _readAppWallet(); - appWallet.appKeychain.accounts.clear(); - return _writeAppWallet(appWallet); - } - - Future changeAccount(String accountName) async { + Future selectAccount(String accountName) async { final appWallet = await _readAppWallet(); for (var i = 0; i < appWallet.appKeychain.accounts.length; i++) { - if (appWallet.appKeychain.accounts[i].name == accountName) { - appWallet.appKeychain.accounts[i].selected = true; - } else { - appWallet.appKeychain.accounts[i].selected = false; - } + final account = appWallet.appKeychain.accounts[i]; + final updatedAccount = account.copyWith( + selected: account.name == accountName, + ); + appWallet.appKeychain.accounts[i] = updatedAccount; } return _writeAppWallet(appWallet); } - Future updateAccountBalance( - Account selectedAccount, - AccountBalance balance, - ) async { - final appWallet = await _readAppWallet(); - final accounts = appWallet.appKeychain.accounts; - for (final account in accounts) { - if (selectedAccount.name == account.name) { - account.balance = balance; - await _writeAppWallet(appWallet); - return; - } - } - } - - Future updateAccount(Account selectedAccount) async { + Future updateAccount(Account updatedAccount) async { final appWallet = await _readAppWallet(); appWallet.appKeychain.accounts = appWallet.appKeychain.accounts.map( (account) { - if (account.name == selectedAccount.name) return selectedAccount; + if (account.name == updatedAccount.name) return updatedAccount; return account; }, ).toList(); diff --git a/lib/infrastructure/datasources/appdb.hive.dart b/lib/infrastructure/datasources/appdb.hive.dart index a66551d37..411337260 100644 --- a/lib/infrastructure/datasources/appdb.hive.dart +++ b/lib/infrastructure/datasources/appdb.hive.dart @@ -54,7 +54,7 @@ class DBHelper { ..registerAdapter(ContactAdapter()) ..registerAdapter(HiveAppWalletDTOAdapter()) ..registerAdapter(AccountBalanceAdapter()) - ..registerAdapter(AccountAdapter()) + ..registerAdapter(AccountImplAdapter()) ..registerAdapter(AppKeychainAdapter()) ..registerAdapter(RecentTransactionAdapter()) ..registerAdapter(AccountTokenAdapter()) diff --git a/lib/infrastructure/repositories/local_account.dart b/lib/infrastructure/repositories/local_account.dart index 249df219e..9caf243f2 100644 --- a/lib/infrastructure/repositories/local_account.dart +++ b/lib/infrastructure/repositories/local_account.dart @@ -37,6 +37,6 @@ class AccountLocalRepository implements AccountLocalRepositoryInterface { @override Future selectAccount(String name) async { - await _accountDatasource.changeAccount(name); + await _accountDatasource.selectAccount(name); } } diff --git a/lib/model/data/account.dart b/lib/model/data/account.dart index 316d8eb4b..1036a5780 100644 --- a/lib/model/data/account.dart +++ b/lib/model/data/account.dart @@ -6,6 +6,7 @@ import 'package:aewallet/model/data/nft_infos_off_chain.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:hive/hive.dart'; +part 'account.freezed.dart'; part 'account.g.dart'; class AccountConverter implements JsonConverter> { @@ -28,109 +29,57 @@ class AccountConverter implements JsonConverter> { } } -@HiveType(typeId: HiveTypeIds.account) - /// Next field available : 16 -class Account extends HiveObject { - Account({ - required this.name, - required this.genesisAddress, - this.lastLoadingTransactionInputs, - this.selected = false, - this.balance, - this.recentTransactions, - this.accountTokens, - this.accountNFT, - this.accountNFTCollections, - this.serviceType, - this.customTokenAddressList, - }); - - Account copyWith({ - String? name, - String? genesisAddress, - int? lastLoadingTransactionInputs, - bool? selected, +@freezed +class Account extends HiveObject with _$Account { + @HiveType(typeId: HiveTypeIds.account) + factory Account({ + /// Account name - Primary Key + @HiveField(0) required String name, + + /// Genesis Address + @HiveField(1) required String genesisAddress, + + /// Last loading of transaction inputs + @HiveField(2) int? lastLoadingTransactionInputs, + + /// Whether this is the currently selected account + @HiveField(3) bool? selected, + + /// Last address + + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21', + ) String? lastAddress, - String? serviceType, - AccountBalance? balance, - List? recentTransactions, - List? accountTokens, - List? accountNFT, - List? accountNFTCollections, - List? customTokenAddressList, - }) => - Account( - name: name ?? this.name, - genesisAddress: genesisAddress ?? this.genesisAddress, - lastLoadingTransactionInputs: - lastLoadingTransactionInputs ?? this.lastLoadingTransactionInputs, - selected: selected ?? this.selected, - serviceType: serviceType ?? this.serviceType, - balance: balance ?? this.balance, - recentTransactions: recentTransactions ?? this.recentTransactions, - accountTokens: accountTokens ?? this.accountTokens, - accountNFT: accountNFT ?? this.accountNFT, - accountNFTCollections: - accountNFTCollections ?? this.accountNFTCollections, - customTokenAddressList: - customTokenAddressList ?? this.customTokenAddressList, - ); - - /// Account name - Primary Key - @HiveField(0) - final String name; - - /// Genesis Address - @HiveField(1) - final String genesisAddress; - - /// Last loading of transaction inputs - @HiveField(2) - int? lastLoadingTransactionInputs; - - /// Whether this is the currently selected account - @HiveField(3) - bool? selected; - - /// Last address - - @HiveField(4) - @Deprecated( - 'Genesis address should be preferred instead of last address after AEIP21', - ) - String? lastAddress; - - /// Balance - @HiveField(5) - AccountBalance? balance; - - /// Recent transactions - @HiveField(6) - List? recentTransactions; - - /// Tokens - @HiveField(7) - List? accountTokens; - - /// NFT - @HiveField(8) - List? accountNFT; - - /// NFT Info Off Chain - @Deprecated('Thanks to hive, we should keep this unused property...') - @HiveField(10) - List? nftInfosOffChainList; - - /// Service Type - @HiveField(13) - String? serviceType; - - /// NFT Collections - @HiveField(14) - List? accountNFTCollections; - - /// Custom Token Addresses - @HiveField(15) - List? customTokenAddressList; + + /// Balance + @HiveField(5) AccountBalance? balance, + + /// Recent transactions + @HiveField(6) List? recentTransactions, + + /// Tokens + @HiveField(7) List? accountTokens, + + /// NFT + @HiveField(8) List? accountNFT, + + /// NFT Info Off Chain + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? nftInfosOffChainList, + + /// Service Type + @HiveField(13) String? serviceType, + + /// NFT Collections + @HiveField(14) List? accountNFTCollections, + + /// Custom Token Addresses + @HiveField(15) List? customTokenAddressList, + }) = _Account; + + Account._(); } diff --git a/lib/model/data/account.freezed.dart b/lib/model/data/account.freezed.dart new file mode 100644 index 000000000..c492aa3aa --- /dev/null +++ b/lib/model/data/account.freezed.dart @@ -0,0 +1,626 @@ +// 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 'account.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 _$Account { + /// Account name - Primary Key + @HiveField(0) + String get name => throw _privateConstructorUsedError; + + /// Genesis Address + @HiveField(1) + String get genesisAddress => throw _privateConstructorUsedError; + + /// Last loading of transaction inputs + @HiveField(2) + int? get lastLoadingTransactionInputs => throw _privateConstructorUsedError; + + /// Whether this is the currently selected account + @HiveField(3) + bool? get selected => throw _privateConstructorUsedError; + + /// Last address + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + String? get lastAddress => throw _privateConstructorUsedError; + + /// Balance + @HiveField(5) + AccountBalance? get balance => throw _privateConstructorUsedError; + + /// Recent transactions + @HiveField(6) + List? get recentTransactions => + throw _privateConstructorUsedError; + + /// Tokens + @HiveField(7) + List? get accountTokens => throw _privateConstructorUsedError; + + /// NFT + @HiveField(8) + List? get accountNFT => throw _privateConstructorUsedError; + + /// NFT Info Off Chain + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? get nftInfosOffChainList => + throw _privateConstructorUsedError; + + /// Service Type + @HiveField(13) + String? get serviceType => throw _privateConstructorUsedError; + + /// NFT Collections + @HiveField(14) + List? get accountNFTCollections => + throw _privateConstructorUsedError; + + /// Custom Token Addresses + @HiveField(15) + List? get customTokenAddressList => + throw _privateConstructorUsedError; + + /// Create a copy of Account + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $AccountCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AccountCopyWith<$Res> { + factory $AccountCopyWith(Account value, $Res Function(Account) then) = + _$AccountCopyWithImpl<$Res, Account>; + @useResult + $Res call( + {@HiveField(0) String name, + @HiveField(1) String genesisAddress, + @HiveField(2) int? lastLoadingTransactionInputs, + @HiveField(3) bool? selected, + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + String? lastAddress, + @HiveField(5) AccountBalance? balance, + @HiveField(6) List? recentTransactions, + @HiveField(7) List? accountTokens, + @HiveField(8) List? accountNFT, + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? nftInfosOffChainList, + @HiveField(13) String? serviceType, + @HiveField(14) List? accountNFTCollections, + @HiveField(15) List? customTokenAddressList}); +} + +/// @nodoc +class _$AccountCopyWithImpl<$Res, $Val extends Account> + implements $AccountCopyWith<$Res> { + _$AccountCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of Account + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? genesisAddress = null, + Object? lastLoadingTransactionInputs = freezed, + Object? selected = freezed, + Object? lastAddress = freezed, + Object? balance = freezed, + Object? recentTransactions = freezed, + Object? accountTokens = freezed, + Object? accountNFT = freezed, + Object? nftInfosOffChainList = freezed, + Object? serviceType = freezed, + Object? accountNFTCollections = freezed, + Object? customTokenAddressList = freezed, + }) { + return _then(_value.copyWith( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + genesisAddress: null == genesisAddress + ? _value.genesisAddress + : genesisAddress // ignore: cast_nullable_to_non_nullable + as String, + lastLoadingTransactionInputs: freezed == lastLoadingTransactionInputs + ? _value.lastLoadingTransactionInputs + : lastLoadingTransactionInputs // ignore: cast_nullable_to_non_nullable + as int?, + selected: freezed == selected + ? _value.selected + : selected // ignore: cast_nullable_to_non_nullable + as bool?, + lastAddress: freezed == lastAddress + ? _value.lastAddress + : lastAddress // ignore: cast_nullable_to_non_nullable + as String?, + balance: freezed == balance + ? _value.balance + : balance // ignore: cast_nullable_to_non_nullable + as AccountBalance?, + recentTransactions: freezed == recentTransactions + ? _value.recentTransactions + : recentTransactions // ignore: cast_nullable_to_non_nullable + as List?, + accountTokens: freezed == accountTokens + ? _value.accountTokens + : accountTokens // ignore: cast_nullable_to_non_nullable + as List?, + accountNFT: freezed == accountNFT + ? _value.accountNFT + : accountNFT // ignore: cast_nullable_to_non_nullable + as List?, + nftInfosOffChainList: freezed == nftInfosOffChainList + ? _value.nftInfosOffChainList + : nftInfosOffChainList // ignore: cast_nullable_to_non_nullable + as List?, + serviceType: freezed == serviceType + ? _value.serviceType + : serviceType // ignore: cast_nullable_to_non_nullable + as String?, + accountNFTCollections: freezed == accountNFTCollections + ? _value.accountNFTCollections + : accountNFTCollections // ignore: cast_nullable_to_non_nullable + as List?, + customTokenAddressList: freezed == customTokenAddressList + ? _value.customTokenAddressList + : customTokenAddressList // ignore: cast_nullable_to_non_nullable + as List?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$AccountImplCopyWith<$Res> implements $AccountCopyWith<$Res> { + factory _$$AccountImplCopyWith( + _$AccountImpl value, $Res Function(_$AccountImpl) then) = + __$$AccountImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@HiveField(0) String name, + @HiveField(1) String genesisAddress, + @HiveField(2) int? lastLoadingTransactionInputs, + @HiveField(3) bool? selected, + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + String? lastAddress, + @HiveField(5) AccountBalance? balance, + @HiveField(6) List? recentTransactions, + @HiveField(7) List? accountTokens, + @HiveField(8) List? accountNFT, + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? nftInfosOffChainList, + @HiveField(13) String? serviceType, + @HiveField(14) List? accountNFTCollections, + @HiveField(15) List? customTokenAddressList}); +} + +/// @nodoc +class __$$AccountImplCopyWithImpl<$Res> + extends _$AccountCopyWithImpl<$Res, _$AccountImpl> + implements _$$AccountImplCopyWith<$Res> { + __$$AccountImplCopyWithImpl( + _$AccountImpl _value, $Res Function(_$AccountImpl) _then) + : super(_value, _then); + + /// Create a copy of Account + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? genesisAddress = null, + Object? lastLoadingTransactionInputs = freezed, + Object? selected = freezed, + Object? lastAddress = freezed, + Object? balance = freezed, + Object? recentTransactions = freezed, + Object? accountTokens = freezed, + Object? accountNFT = freezed, + Object? nftInfosOffChainList = freezed, + Object? serviceType = freezed, + Object? accountNFTCollections = freezed, + Object? customTokenAddressList = freezed, + }) { + return _then(_$AccountImpl( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + genesisAddress: null == genesisAddress + ? _value.genesisAddress + : genesisAddress // ignore: cast_nullable_to_non_nullable + as String, + lastLoadingTransactionInputs: freezed == lastLoadingTransactionInputs + ? _value.lastLoadingTransactionInputs + : lastLoadingTransactionInputs // ignore: cast_nullable_to_non_nullable + as int?, + selected: freezed == selected + ? _value.selected + : selected // ignore: cast_nullable_to_non_nullable + as bool?, + lastAddress: freezed == lastAddress + ? _value.lastAddress + : lastAddress // ignore: cast_nullable_to_non_nullable + as String?, + balance: freezed == balance + ? _value.balance + : balance // ignore: cast_nullable_to_non_nullable + as AccountBalance?, + recentTransactions: freezed == recentTransactions + ? _value._recentTransactions + : recentTransactions // ignore: cast_nullable_to_non_nullable + as List?, + accountTokens: freezed == accountTokens + ? _value._accountTokens + : accountTokens // ignore: cast_nullable_to_non_nullable + as List?, + accountNFT: freezed == accountNFT + ? _value._accountNFT + : accountNFT // ignore: cast_nullable_to_non_nullable + as List?, + nftInfosOffChainList: freezed == nftInfosOffChainList + ? _value._nftInfosOffChainList + : nftInfosOffChainList // ignore: cast_nullable_to_non_nullable + as List?, + serviceType: freezed == serviceType + ? _value.serviceType + : serviceType // ignore: cast_nullable_to_non_nullable + as String?, + accountNFTCollections: freezed == accountNFTCollections + ? _value._accountNFTCollections + : accountNFTCollections // ignore: cast_nullable_to_non_nullable + as List?, + customTokenAddressList: freezed == customTokenAddressList + ? _value._customTokenAddressList + : customTokenAddressList // ignore: cast_nullable_to_non_nullable + as List?, + )); + } +} + +/// @nodoc + +@HiveType(typeId: HiveTypeIds.account) +class _$AccountImpl extends _Account { + _$AccountImpl( + {@HiveField(0) required this.name, + @HiveField(1) required this.genesisAddress, + @HiveField(2) this.lastLoadingTransactionInputs, + @HiveField(3) this.selected, + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + this.lastAddress, + @HiveField(5) this.balance, + @HiveField(6) final List? recentTransactions, + @HiveField(7) final List? accountTokens, + @HiveField(8) final List? accountNFT, + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + final List? nftInfosOffChainList, + @HiveField(13) this.serviceType, + @HiveField(14) final List? accountNFTCollections, + @HiveField(15) final List? customTokenAddressList}) + : _recentTransactions = recentTransactions, + _accountTokens = accountTokens, + _accountNFT = accountNFT, + _nftInfosOffChainList = nftInfosOffChainList, + _accountNFTCollections = accountNFTCollections, + _customTokenAddressList = customTokenAddressList, + super._(); + + /// Account name - Primary Key + @override + @HiveField(0) + final String name; + + /// Genesis Address + @override + @HiveField(1) + final String genesisAddress; + + /// Last loading of transaction inputs + @override + @HiveField(2) + final int? lastLoadingTransactionInputs; + + /// Whether this is the currently selected account + @override + @HiveField(3) + final bool? selected; + + /// Last address + @override + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + final String? lastAddress; + + /// Balance + @override + @HiveField(5) + final AccountBalance? balance; + + /// Recent transactions + final List? _recentTransactions; + + /// Recent transactions + @override + @HiveField(6) + List? get recentTransactions { + final value = _recentTransactions; + if (value == null) return null; + if (_recentTransactions is EqualUnmodifiableListView) + return _recentTransactions; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + /// Tokens + final List? _accountTokens; + + /// Tokens + @override + @HiveField(7) + List? get accountTokens { + final value = _accountTokens; + if (value == null) return null; + if (_accountTokens is EqualUnmodifiableListView) return _accountTokens; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + /// NFT + final List? _accountNFT; + + /// NFT + @override + @HiveField(8) + List? get accountNFT { + final value = _accountNFT; + if (value == null) return null; + if (_accountNFT is EqualUnmodifiableListView) return _accountNFT; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + /// NFT Info Off Chain + final List? _nftInfosOffChainList; + + /// NFT Info Off Chain + @override + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? get nftInfosOffChainList { + final value = _nftInfosOffChainList; + if (value == null) return null; + if (_nftInfosOffChainList is EqualUnmodifiableListView) + return _nftInfosOffChainList; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + /// Service Type + @override + @HiveField(13) + final String? serviceType; + + /// NFT Collections + final List? _accountNFTCollections; + + /// NFT Collections + @override + @HiveField(14) + List? get accountNFTCollections { + final value = _accountNFTCollections; + if (value == null) return null; + if (_accountNFTCollections is EqualUnmodifiableListView) + return _accountNFTCollections; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + /// Custom Token Addresses + final List? _customTokenAddressList; + + /// Custom Token Addresses + @override + @HiveField(15) + List? get customTokenAddressList { + final value = _customTokenAddressList; + if (value == null) return null; + if (_customTokenAddressList is EqualUnmodifiableListView) + return _customTokenAddressList; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + + @override + String toString() { + return 'Account(name: $name, genesisAddress: $genesisAddress, lastLoadingTransactionInputs: $lastLoadingTransactionInputs, selected: $selected, lastAddress: $lastAddress, balance: $balance, recentTransactions: $recentTransactions, accountTokens: $accountTokens, accountNFT: $accountNFT, nftInfosOffChainList: $nftInfosOffChainList, serviceType: $serviceType, accountNFTCollections: $accountNFTCollections, customTokenAddressList: $customTokenAddressList)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AccountImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.genesisAddress, genesisAddress) || + other.genesisAddress == genesisAddress) && + (identical(other.lastLoadingTransactionInputs, + lastLoadingTransactionInputs) || + other.lastLoadingTransactionInputs == + lastLoadingTransactionInputs) && + (identical(other.selected, selected) || + other.selected == selected) && + (identical(other.lastAddress, lastAddress) || + other.lastAddress == lastAddress) && + (identical(other.balance, balance) || other.balance == balance) && + const DeepCollectionEquality() + .equals(other._recentTransactions, _recentTransactions) && + const DeepCollectionEquality() + .equals(other._accountTokens, _accountTokens) && + const DeepCollectionEquality() + .equals(other._accountNFT, _accountNFT) && + const DeepCollectionEquality() + .equals(other._nftInfosOffChainList, _nftInfosOffChainList) && + (identical(other.serviceType, serviceType) || + other.serviceType == serviceType) && + const DeepCollectionEquality() + .equals(other._accountNFTCollections, _accountNFTCollections) && + const DeepCollectionEquality().equals( + other._customTokenAddressList, _customTokenAddressList)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + name, + genesisAddress, + lastLoadingTransactionInputs, + selected, + lastAddress, + balance, + const DeepCollectionEquality().hash(_recentTransactions), + const DeepCollectionEquality().hash(_accountTokens), + const DeepCollectionEquality().hash(_accountNFT), + const DeepCollectionEquality().hash(_nftInfosOffChainList), + serviceType, + const DeepCollectionEquality().hash(_accountNFTCollections), + const DeepCollectionEquality().hash(_customTokenAddressList)); + + /// Create a copy of Account + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$AccountImplCopyWith<_$AccountImpl> get copyWith => + __$$AccountImplCopyWithImpl<_$AccountImpl>(this, _$identity); +} + +abstract class _Account extends Account { + factory _Account( + {@HiveField(0) required final String name, + @HiveField(1) required final String genesisAddress, + @HiveField(2) final int? lastLoadingTransactionInputs, + @HiveField(3) final bool? selected, + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + final String? lastAddress, + @HiveField(5) final AccountBalance? balance, + @HiveField(6) final List? recentTransactions, + @HiveField(7) final List? accountTokens, + @HiveField(8) final List? accountNFT, + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + final List? nftInfosOffChainList, + @HiveField(13) final String? serviceType, + @HiveField(14) final List? accountNFTCollections, + @HiveField(15) + final List? customTokenAddressList}) = _$AccountImpl; + _Account._() : super._(); + + /// Account name - Primary Key + @override + @HiveField(0) + String get name; + + /// Genesis Address + @override + @HiveField(1) + String get genesisAddress; + + /// Last loading of transaction inputs + @override + @HiveField(2) + int? get lastLoadingTransactionInputs; + + /// Whether this is the currently selected account + @override + @HiveField(3) + bool? get selected; + + /// Last address + @override + @HiveField(4) + @Deprecated( + 'Genesis address should be preferred instead of last address after AEIP21') + String? get lastAddress; + + /// Balance + @override + @HiveField(5) + AccountBalance? get balance; + + /// Recent transactions + @override + @HiveField(6) + List? get recentTransactions; + + /// Tokens + @override + @HiveField(7) + List? get accountTokens; + + /// NFT + @override + @HiveField(8) + List? get accountNFT; + + /// NFT Info Off Chain + @override + @Deprecated('Thanks to hive, we should keep this unused property...') + @HiveField(10) + List? get nftInfosOffChainList; + + /// Service Type + @override + @HiveField(13) + String? get serviceType; + + /// NFT Collections + @override + @HiveField(14) + List? get accountNFTCollections; + + /// Custom Token Addresses + @override + @HiveField(15) + List? get customTokenAddressList; + + /// Create a copy of Account + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$AccountImplCopyWith<_$AccountImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/model/data/account.g.dart b/lib/model/data/account.g.dart index 4784c99e6..25fc00b26 100644 --- a/lib/model/data/account.g.dart +++ b/lib/model/data/account.g.dart @@ -6,35 +6,35 @@ part of 'account.dart'; // TypeAdapterGenerator // ************************************************************************** -class AccountAdapter extends TypeAdapter { +class AccountImplAdapter extends TypeAdapter<_$AccountImpl> { @override final int typeId = 1; @override - Account read(BinaryReader reader) { + _$AccountImpl read(BinaryReader reader) { final numOfFields = reader.readByte(); final fields = { for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), }; - return Account( + return _$AccountImpl( name: fields[0] as String, genesisAddress: fields[1] as String, lastLoadingTransactionInputs: fields[2] as int?, selected: fields[3] as bool?, + lastAddress: fields[4] as String?, balance: fields[5] as AccountBalance?, recentTransactions: (fields[6] as List?)?.cast(), accountTokens: (fields[7] as List?)?.cast(), accountNFT: (fields[8] as List?)?.cast(), - accountNFTCollections: (fields[14] as List?)?.cast(), + nftInfosOffChainList: (fields[10] as List?)?.cast(), serviceType: fields[13] as String?, + accountNFTCollections: (fields[14] as List?)?.cast(), customTokenAddressList: (fields[15] as List?)?.cast(), - ) - ..lastAddress = fields[4] as String? - ..nftInfosOffChainList = (fields[10] as List?)?.cast(); + ); } @override - void write(BinaryWriter writer, Account obj) { + void write(BinaryWriter writer, _$AccountImpl obj) { writer ..writeByte(13) ..writeByte(0) @@ -49,6 +49,8 @@ class AccountAdapter extends TypeAdapter { ..write(obj.lastAddress) ..writeByte(5) ..write(obj.balance) + ..writeByte(13) + ..write(obj.serviceType) ..writeByte(6) ..write(obj.recentTransactions) ..writeByte(7) @@ -57,8 +59,6 @@ class AccountAdapter extends TypeAdapter { ..write(obj.accountNFT) ..writeByte(10) ..write(obj.nftInfosOffChainList) - ..writeByte(13) - ..write(obj.serviceType) ..writeByte(14) ..write(obj.accountNFTCollections) ..writeByte(15) @@ -71,7 +71,7 @@ class AccountAdapter extends TypeAdapter { @override bool operator ==(Object other) => identical(this, other) || - other is AccountAdapter && + other is AccountImplAdapter && runtimeType == other.runtimeType && typeId == other.typeId; } diff --git a/lib/model/data/app_keychain.dart b/lib/model/data/app_keychain.dart index 03b56f279..58b8cb6ed 100644 --- a/lib/model/data/app_keychain.dart +++ b/lib/model/data/app_keychain.dart @@ -34,7 +34,7 @@ class AppKeychain extends HiveObject { // To manage the migration of https://github.com/archethic-foundation/archethic-wallet/pull/759 for (final account in accounts) { if (account.serviceType == 'archethicWallet') { - await AccountHiveDatasource.instance().changeAccount(account.name); + await AccountHiveDatasource.instance().selectAccount(account.name); return account; } } diff --git a/lib/ui/views/accounts/layouts/account_list.dart b/lib/ui/views/accounts/layouts/account_list.dart index 228aef275..c83090932 100644 --- a/lib/ui/views/accounts/layouts/account_list.dart +++ b/lib/ui/views/accounts/layouts/account_list.dart @@ -31,7 +31,8 @@ class AccountsListState extends ConsumerState (accounts) => accounts.valueOrNull?.selectedAccount, ), ); - final accountsList = ref.watch(accountsNotifierProvider).valueOrNull ?? []; + final accountsList = + (ref.watch(accountsNotifierProvider).valueOrNull ?? []).toList(); if (accountsList.isNotEmpty) { accountsList.sort( (a, b) => a.nameDisplayed.compareTo(b.nameDisplayed), diff --git a/lib/ui/views/main/bloc/providers.dart b/lib/ui/views/main/bloc/providers.dart index 7dfb22368..010c0b768 100644 --- a/lib/ui/views/main/bloc/providers.dart +++ b/lib/ui/views/main/bloc/providers.dart @@ -32,10 +32,10 @@ class HomePage extends _$HomePage { ..watch(verifiedTokensProvider) ..watch(DexTokensProviders.tokensFromAccount) ..watch(farmLockFormFarmLockProvider) - ..watch( - aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO, - ) - ..watch(aedappfm.CoinPriceProviders.coinPrices) + // ..watch( + // aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO, + // ) + // ..watch(aedappfm.CoinPriceProviders.coinPrices) ..listen( connectivityStatusProviders, (previous, next) async { @@ -60,17 +60,17 @@ class HomePage extends _$HomePage { } Future startSubscriptions() async { - await ref - .read( - aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.notifier, - ) - .startSubscription(); - - await ref - .read( - aedappfm.CoinPriceProviders.coinPrices.notifier, - ) - .startTimer(); + // await ref + // .read( + // aedappfm.ArchethicOracleUCOProviders.archethicOracleUCO.notifier, + // ) + // .startSubscription(); + + // await ref + // .read( + // aedappfm.CoinPriceProviders.coinPrices.notifier, + // ) + // .startTimer(); } Future stopSubscriptions() async { diff --git a/lib/ui/views/main/bloc/providers.g.dart b/lib/ui/views/main/bloc/providers.g.dart index 5285c5df8..4257be341 100644 --- a/lib/ui/views/main/bloc/providers.g.dart +++ b/lib/ui/views/main/bloc/providers.g.dart @@ -6,7 +6,7 @@ part of 'providers.dart'; // RiverpodGenerator // ************************************************************************** -String _$homePageHash() => r'b3a7e0d8b8465ba8f13decf492db4b8eeae87ec9'; +String _$homePageHash() => r'048f93f65373efbed56acfe689b166b9f0aeea4d'; /// Eagerly initializes providers (https://riverpod.dev/docs/essentials/eager_initialization). /// diff --git a/lib/ui/views/transfer/bloc/state.freezed.dart b/lib/ui/views/transfer/bloc/state.freezed.dart index f8ce65470..a46c722bd 100644 --- a/lib/ui/views/transfer/bloc/state.freezed.dart +++ b/lib/ui/views/transfer/bloc/state.freezed.dart @@ -795,6 +795,8 @@ abstract class _$$TransferDestinationContactImplCopyWith<$Res> { __$$TransferDestinationContactImplCopyWithImpl<$Res>; @useResult $Res call({@AccountConverter() Account account}); + + $AccountCopyWith<$Res> get account; } /// @nodoc @@ -821,6 +823,16 @@ class __$$TransferDestinationContactImplCopyWithImpl<$Res> as Account, )); } + + /// Create a copy of TransferRecipient + /// with the given fields replaced by the non-null parameter values. + @override + @pragma('vm:prefer-inline') + $AccountCopyWith<$Res> get account { + return $AccountCopyWith<$Res>(_value.account, (value) { + return _then(_value.copyWith(account: value)); + }); + } } /// @nodoc diff --git a/lib/ui/views/transfer/layouts/components/transfer_textfield_address.dart b/lib/ui/views/transfer/layouts/components/transfer_textfield_address.dart index 0e2c57693..048b39048 100644 --- a/lib/ui/views/transfer/layouts/components/transfer_textfield_address.dart +++ b/lib/ui/views/transfer/layouts/components/transfer_textfield_address.dart @@ -217,11 +217,12 @@ class _TransferTextFieldAddressState .read(accountsNotifierProvider.future) .selectedAccount; final filteredAccounts = accounts - ..removeWhere( - (element) => - element.format.toUpperCase() == - accountSelected?.format.toUpperCase(), - ); + .where( + (element) => + element.format.toUpperCase() != + accountSelected?.format.toUpperCase(), + ) + .toList(); final account = await AccountsDialog.selectSingleAccount( context: context, diff --git a/lib/util/keychain_util.dart b/lib/util/keychain_util.dart index 632f46578..9eb47bd1c 100644 --- a/lib/util/keychain_util.dart +++ b/lib/util/keychain_util.dart @@ -166,6 +166,11 @@ mixin KeychainServiceMixin { genesisAddressAccountList.add( uint8ListToHex(genesisAddress), ); + + final isSelected = selectedAccount != null && + selectedAccount.name == name && + serviceType == 'archethicWallet'; + final account = Account( lastLoadingTransactionInputs: DateTime.now().millisecondsSinceEpoch ~/ Duration.millisecondsPerSecond, @@ -175,16 +180,10 @@ mixin KeychainServiceMixin { nativeTokenName: 'UCO', nativeTokenValue: 0, ), - recentTransactions: [], + recentTransactions: const [], serviceType: serviceType, + selected: isSelected, ); - if (selectedAccount != null && - selectedAccount.name == name && - serviceType == 'archethicWallet') { - account.selected = true; - } else { - account.selected = false; - } accounts.add(account); }); @@ -237,7 +236,7 @@ mixin KeychainServiceMixin { } } - accounts[i].balance = accountBalance; + accounts[i] = accounts[i].copyWith(balance: accountBalance); } }