Skip to content
Snippets Groups Projects
Commit 6cf1b77d authored by vjrj's avatar vjrj
Browse files

Reset current gva node when not pending txs

parent e4dadb27
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,6 @@ import 'transaction.dart';
import 'transaction_state.dart';
import 'transaction_type.dart';
import 'transactions_bloc.dart';
import 'utxo_cubit.dart';
class MultiWalletTransactionCubit
extends HydratedCubit<MultiWalletTransactionState> {
......@@ -122,7 +121,7 @@ class MultiWalletTransactionCubit
String _getTxKey(Transaction t) => '${t.to.pubKey}-${t.comment}-${t.amount}';
Future<List<Transaction>> fetchTransactions(
NodeListCubit cubit, UtxoCubit utxoCubit, AppCubit appCubit,
NodeListCubit cubit, AppCubit appCubit,
{int retries = 5, int? pageSize, String? cursor, String? pubKey}) async {
pubKey = _defKey(pubKey);
final TransactionState currentState = _getStateOfWallet(pubKey);
......@@ -166,6 +165,8 @@ class MultiWalletTransactionCubit
TransactionState currentModifiedState = newState;
resetCurrentGvaNode(newState, cubit);
logger(
'Last received notification: ${currentModifiedState.latestReceivedNotification.toIso8601String()})}');
logger(
......@@ -220,6 +221,32 @@ class MultiWalletTransactionCubit
return <Transaction>[];
}
void resetCurrentGvaNode(TransactionState newState, NodeListCubit cubit) {
final List<Transaction> pendingTransactions = newState.pendingTransactions;
bool shouldResetGvaNode = pendingTransactions.isEmpty ||
pendingTransactions
.every((Transaction transaction) => transaction.isFailed);
if (!shouldResetGvaNode) {
final Transaction? oldestPendingTransaction = pendingTransactions
.isNotEmpty
? pendingTransactions.reduce(
(Transaction a, Transaction b) => a.time.isBefore(b.time) ? a : b)
: null;
if (oldestPendingTransaction != null &&
oldestPendingTransaction.time
.isBefore(DateTime.now().subtract(const Duration(hours: 1)))) {
shouldResetGvaNode = true;
}
}
if (shouldResetGvaNode) {
cubit.resetCurrentGvaNode();
}
}
TransactionState _checkPendingTx(
String? cursor, TransactionState newState, String myPubKey, Node node) {
// Check pending transactions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment