Skip to content

Commit

Permalink
fix: Attempet operation at least 3 times #2627
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Apr 26, 2024
1 parent 9737bea commit fae8e2d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/dashboard/connection/operation/cubit/operation_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,18 @@ class OperationCubit extends Cubit<OperationState> {
}
}

int operationAttemptCount = 0;

void resetOperationAttemptCount() {
operationAttemptCount = 0;
}

Future<void> sendOperataion(ConnectionBridgeType connectionBridgeType) async {
if (isClosed) return;
try {
emit(state.loading());
log.i('sendOperataion');
operationAttemptCount++;
log.i('sendOperataion attempt $operationAttemptCount');

final isInternetAvailable = await isConnected();
if (!isInternetAvailable) {
Expand Down Expand Up @@ -384,12 +391,20 @@ class OperationCubit extends Cubit<OperationState> {
);
unawaited(nftCubit.fetchFromZero());
unawaited(tokensCubit.fetchFromZero());
resetOperationAttemptCount();
} else {
throw ResponseMessage(
message: ResponseString.RESPONSE_STRING_OPERATION_FAILED,
);
}
} catch (e) {
if (operationAttemptCount < 3) {
await Future<void>.delayed(const Duration(milliseconds: 500));
await sendOperataion(connectionBridgeType);
return;
}
resetOperationAttemptCount();

log.e('sendOperataion , e: $e');
if (e is MessageHandler) {
emit(state.error(messageHandler: e));
Expand Down

0 comments on commit fae8e2d

Please sign in to comment.