From b1eea6b3aa49cc14c0b240580003db48a1812212 Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Wed, 15 Jan 2025 14:50:51 +0100 Subject: [PATCH] chore: :zap: Just refresh tx in transactions tab --- lib/service/app_service.dart | 72 +++++-------------- .../main/components/menu_widget_wallet.dart | 16 +++-- lib/ui/views/main/transactions_tab.dart | 9 ++- 3 files changed, 35 insertions(+), 62 deletions(-) diff --git a/lib/service/app_service.dart b/lib/service/app_service.dart index b3400b8fe..32c47f889 100644 --- a/lib/service/app_service.dart +++ b/lib/service/app_service.dart @@ -388,11 +388,6 @@ class AppService { element.address!.toUpperCase() == addressToSearch.toUpperCase(), )) { _logger.info('addressToSearch exists in local -> break'); - recentTransactions = await _buildRecentTransactionFromTransaction( - recentTransactions, - addressToSearch, - mostRecentTimestamp, - ); break; } @@ -452,6 +447,7 @@ class AppService { for (final recentTransaction in recentTransactions) { if (recentTransaction.tokenAddress != null && recentTransaction.tokenAddress!.isNotEmpty && + recentTransaction.tokenInformation == null && recentTransaction.timestamp! >= mostRecentTimestamp) { tokensAddresses.add(recentTransaction.tokenAddress!); } @@ -469,16 +465,19 @@ class AppService { // Get token Information if (recentTransaction.tokenAddress != null && recentTransaction.tokenAddress!.isNotEmpty && + recentTransaction.tokenInformation == null && recentTransaction.timestamp! >= mostRecentTimestamp) { final token = tokensAddressMap[recentTransaction.tokenAddress]; if (token != null) { - recentTransaction.tokenInformation = TokenInformation( - address: token.address, - name: token.name, - supply: fromBigInt(token.supply).toDouble(), - symbol: token.symbol, - type: token.type, - ); + recentTransaction + ..tokenAddress = token.address + ..tokenInformation = TokenInformation( + address: token.address, + name: token.name, + supply: fromBigInt(token.supply).toDouble(), + symbol: token.symbol, + type: token.type, + ); } } @@ -486,7 +485,7 @@ class AppService { switch (recentTransaction.typeTx) { case RecentTransaction.transferInput: if (recentTransaction.from != null) { - if (recentTransaction.timestamp! >= mostRecentTimestamp) { + if (recentTransaction.timestamp! > mostRecentTimestamp) { ownershipsAddresses.add(recentTransaction.from!); } recentTransactionLastAddresses.add(recentTransaction.from!); @@ -494,7 +493,7 @@ class AppService { break; case RecentTransaction.transferOutput: if (recentTransaction.from != null) { - if (recentTransaction.timestamp! >= mostRecentTimestamp) { + if (recentTransaction.timestamp! > mostRecentTimestamp) { ownershipsAddresses.add(recentTransaction.from!); } recentTransactionLastAddresses.add(recentTransaction.from!); @@ -530,7 +529,7 @@ class AppService { switch (recentTransaction.typeTx) { case RecentTransaction.transferInput: if (recentTransaction.from != null && - recentTransaction.timestamp! >= mostRecentTimestamp) { + recentTransaction.timestamp! > mostRecentTimestamp) { recentTransaction = _decryptedSecret( keypair: keychainServiceKeyPair!, ownerships: ownershipsMap[recentTransaction.from!] ?? [], @@ -540,7 +539,7 @@ class AppService { break; case RecentTransaction.transferOutput: if (recentTransaction.address != null && - recentTransaction.timestamp! >= mostRecentTimestamp) { + recentTransaction.timestamp! > mostRecentTimestamp) { recentTransaction = _decryptedSecret( keypair: keychainServiceKeyPair!, ownerships: ownershipsMap[recentTransaction.address!] ?? [], @@ -551,45 +550,6 @@ class AppService { } } - // Get last transactions for all tx and contacts - final lastTransactionAddressesToSearch = [ - ...recentTransactionLastAddresses, - ]; - - final lastAddressesMap = {}; - - final getLastTransactions = await lastTransactionAddressesToSearch - .toSet() - .map( - (lastTransactionAddressToSearch) => Task( - name: - 'GetAccountRecentTransactions - lastTransactionAddressToSearch: $lastTransactionAddressToSearch', - logger: _logger, - action: () => apiService.getLastTransaction( - [lastTransactionAddressToSearch], - request: 'address', - ), - ), - ) - .autoRetry() - .batch(); - for (final getLastTransaction in getLastTransactions) { - lastAddressesMap.addAll(getLastTransaction); - } - - // We complete map with last address not found because no tx in the chain - for (final lastTransactionAddressToSearch - in lastTransactionAddressesToSearch) { - if (lastAddressesMap[lastTransactionAddressToSearch] == null) { - lastAddressesMap[lastTransactionAddressToSearch] = Transaction( - type: '', - data: Transaction.initData(), - address: - Address(address: lastTransactionAddressToSearch.toUpperCase()), - ); - } - } - _logger.info( '>> END getRecentTransactions : ${DateTime.now()}', ); @@ -602,10 +562,10 @@ class AppService { required List ownerships, required RecentTransaction recentTransaction, }) { - recentTransaction.decryptedSecret = List.empty(growable: true); if (ownerships.isEmpty) { return recentTransaction; } + recentTransaction.decryptedSecret = []; for (final ownership in ownerships) { final authorizedPublicKey = ownership.authorizedPublicKeys.firstWhere( (AuthorizedKey authKey) => diff --git a/lib/ui/views/main/components/menu_widget_wallet.dart b/lib/ui/views/main/components/menu_widget_wallet.dart index 8a15ffae7..b4167d871 100644 --- a/lib/ui/views/main/components/menu_widget_wallet.dart +++ b/lib/ui/views/main/components/menu_widget_wallet.dart @@ -20,7 +20,9 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; import 'package:url_launcher/url_launcher.dart'; class MenuWidgetWallet extends ConsumerWidget { - const MenuWidgetWallet({super.key}); + const MenuWidgetWallet({super.key, this.refreshFunction}); + + final Function()? refreshFunction; @override Widget build(BuildContext context, WidgetRef ref) { @@ -129,10 +131,14 @@ class MenuWidgetWallet extends ConsumerWidget { return; } - await (await ref - .read(accountsNotifierProvider.notifier) - .selectedAccountNotifier) - ?.refreshAll(); + if (refreshFunction == null) { + await (await ref + .read(accountsNotifierProvider.notifier) + .selectedAccountNotifier) + ?.refreshAll(); + } else { + refreshFunction!(); + } }, ) .animate() diff --git a/lib/ui/views/main/transactions_tab.dart b/lib/ui/views/main/transactions_tab.dart index 31cc0ad81..3450c445a 100644 --- a/lib/ui/views/main/transactions_tab.dart +++ b/lib/ui/views/main/transactions_tab.dart @@ -126,7 +126,14 @@ class _TransactionsList extends ConsumerWidget { const SizedBox( height: 10, ), - const MenuWidgetWallet(), + MenuWidgetWallet( + refreshFunction: () async { + await (await ref + .read(accountsNotifierProvider.notifier) + .selectedAccountNotifier) + ?.refreshRecentTransactions(); + }, + ), if (recentTransactions.isEmpty) Padding( padding: const EdgeInsets.only(top: 20),