Skip to content

Commit

Permalink
Merge pull request #502 from ardriveapp/PE-1571-ui-crashes-and-enters…
Browse files Browse the repository at this point in the history
…-an-infinite-loop-on-negative-blockheights

Fix: Handle negative numbers getting the current block height
  • Loading branch information
thiagocarvalhodev authored May 18, 2022
2 parents 2aabb76 + 34b2d03 commit 1c31388
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/blocs/sync/sync_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:moor/moor.dart';
import 'package:retry/retry.dart';

part 'sync_state.dart';

Expand Down Expand Up @@ -237,9 +238,16 @@ class SyncCubit extends Cubit<SyncState> {
return;
}

final currentBlockHeight = await retry(
() async => await getCurrentBlockHeight(), onRetry: (exception) {
print(
'Retrying for get the current block height on exception ${exception.toString()}',
);
});

_syncProgress = _syncProgress.copyWith(drivesCount: drives.length);

final currentBlockHeight = await arweave.getCurrentBlockHeight();
print('Current block height number $currentBlockHeight');

final driveSyncProcesses = drives.map((drive) => _syncDrive(
drive.id,
Expand Down Expand Up @@ -295,6 +303,16 @@ class SyncCubit extends Cubit<SyncState> {
}
}

Future<int> getCurrentBlockHeight() async {
final currentBlockHeight = await arweave.getCurrentBlockHeight();

if (currentBlockHeight < 0) {
throw Exception(
'The current block height $currentBlockHeight is negative. It should be equal or greater than 0.');
}
return currentBlockHeight;
}

Future<void> createGhosts({String? ownerAddress}) async {
//Finalize missing parent list
for (final ghostFolder in ghostFolders.values) {
Expand Down

0 comments on commit 1c31388

Please sign in to comment.