Skip to content

Commit

Permalink
chore: ⚡ Just refresh tx in transactions tab
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Jan 15, 2025
1 parent c000bca commit b1eea6b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 62 deletions.
72 changes: 16 additions & 56 deletions lib/service/app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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!);
}
Expand All @@ -469,32 +465,35 @@ 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,
);
}
}

// Decrypt secrets
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!);
}
break;
case RecentTransaction.transferOutput:
if (recentTransaction.from != null) {
if (recentTransaction.timestamp! >= mostRecentTimestamp) {
if (recentTransaction.timestamp! > mostRecentTimestamp) {
ownershipsAddresses.add(recentTransaction.from!);
}
recentTransactionLastAddresses.add(recentTransaction.from!);
Expand Down Expand Up @@ -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!] ?? [],
Expand All @@ -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!] ?? [],
Expand All @@ -551,45 +550,6 @@ class AppService {
}
}

// Get last transactions for all tx and contacts
final lastTransactionAddressesToSearch = [
...recentTransactionLastAddresses,
];

final lastAddressesMap = <String, Transaction>{};

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()}',
);
Expand All @@ -602,10 +562,10 @@ class AppService {
required List<Ownership> ownerships,
required RecentTransaction recentTransaction,
}) {
recentTransaction.decryptedSecret = List<String>.empty(growable: true);
if (ownerships.isEmpty) {
return recentTransaction;
}
recentTransaction.decryptedSecret = <String>[];
for (final ownership in ownerships) {
final authorizedPublicKey = ownership.authorizedPublicKeys.firstWhere(
(AuthorizedKey authKey) =>
Expand Down
16 changes: 11 additions & 5 deletions lib/ui/views/main/components/menu_widget_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion lib/ui/views/main/transactions_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b1eea6b

Please sign in to comment.