diff --git a/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab.dart b/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab.dart index 6ac082dc5..caa3ccec0 100644 --- a/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab.dart +++ b/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab.dart @@ -33,9 +33,8 @@ class AccountAssetsTab extends StatelessWidget { create: (_) => AccountAssetTabCubit( account, isFirstEntering, - inject(), + inject(), inject(), - inject(), ), child: BlocBuilder( builder: (context, state) { diff --git a/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab_cubit.dart b/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab_cubit.dart index ecf38e8c7..6f6cc3739 100644 --- a/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab_cubit.dart +++ b/lib/feature/wallet/widgets/account_asset_tab/account_asset_tab_cubit.dart @@ -18,9 +18,8 @@ class AccountAssetTabCubit extends Cubit { KeyAccount account, // ignore: avoid_positional_boolean_parameters this.isFirstEntering, - this.nekotonRepository, + this.tokenWalletsService, this.assetsService, - this.balanceStorage, ) : tonWallet = account.account.tonWallet, super( AccountAssetTabState.accounts(account.account.tonWallet, null, 0), @@ -33,53 +32,41 @@ class AccountAssetTabCubit extends Cubit { AccountAssetTabState.accounts(tonWallet, _contracts, _contractCount), ); }); - if (isFirstEntering) { - _allContractsSubscription = assetsService - .allAvailableContractsForAccount(account.address) - .listen((value) async { - final assets = []; - for (final asset in value.$1) { - try { - final wallet = await nekotonRepository.subscribeToken( - owner: tonWallet.address, - rootTokenContract: asset.address, - ); - if (wallet.wallet?.moneyBalance != null && - wallet.wallet?.moneyBalance.amount != Fixed.zero) { - assets.add(asset); - } - } finally { - nekotonRepository.unsubscribeToken( - tonWallet.address, - asset.address, - ); - } - } - _contractCount = assets.length; - emit( - AccountAssetTabState.accounts(tonWallet, _contracts, _contractCount), - ); - }); + if (isFirstEntering || true) { + _searchSubscription = tokenWalletsService + .searchTokenWalletsForAddress(tonWallet.address) + .reduce((previous, element) => [...previous, ...element]) + .asStream() + .listen( + (value) { + _contractCount = value.length; + emit( + AccountAssetTabState.accounts( + tonWallet, + _contracts, + _contractCount, + ), + ); + }, + ); } } final AssetsService assetsService; - final BalanceStorageService balanceStorage; - final NekotonRepository nekotonRepository; + final TokenWalletsService tokenWalletsService; final TonWalletAsset tonWallet; final bool isFirstEntering; late List? _contracts; int? _contractCount; late StreamSubscription> _contractsSubscription; - StreamSubscription<(List, List)>? - _allContractsSubscription; + StreamSubscription? _searchSubscription; @override - Future close() { - _contractsSubscription.cancel(); - _allContractsSubscription?.cancel(); + Future close() async { + await _contractsSubscription.cancel(); + await _searchSubscription?.cancel(); return super.close(); }