From 20fad15c9e72218bdcc2d646059b56aad0880fb8 Mon Sep 17 00:00:00 2001 From: thiagocarvalhodev Date: Wed, 18 May 2022 16:18:40 -0300 Subject: [PATCH 1/2] fix(wrong block height at sync) Handle negative numbers from the arweave gateway response for getting the block height --- lib/blocs/sync/sync_cubit.dart | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/blocs/sync/sync_cubit.dart b/lib/blocs/sync/sync_cubit.dart index 5fa0cf5e8a..afbcbe110c 100644 --- a/lib/blocs/sync/sync_cubit.dart +++ b/lib/blocs/sync/sync_cubit.dart @@ -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'; @@ -237,9 +238,16 @@ class SyncCubit extends Cubit { 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, @@ -295,6 +303,16 @@ class SyncCubit extends Cubit { } } + Future getCurrentBlockHeight() async { + final currentBlockHeight = await arweave.getCurrentBlockHeight(); + + if (currentBlockHeight < 0) { + throw Exception( + 'The current block height is negative. It should be equal or greater than 0.'); + } + return currentBlockHeight; + } + Future createGhosts({String? ownerAddress}) async { //Finalize missing parent list for (final ghostFolder in ghostFolders.values) { From 34b2d03f0c57253231052eb8de1c2afc062cc61a Mon Sep 17 00:00:00 2001 From: thiagocarvalhodev Date: Wed, 18 May 2022 16:38:10 -0300 Subject: [PATCH 2/2] refactor(sync ui crash) Add the current block on log --- lib/blocs/sync/sync_cubit.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blocs/sync/sync_cubit.dart b/lib/blocs/sync/sync_cubit.dart index afbcbe110c..e8e5acfb1f 100644 --- a/lib/blocs/sync/sync_cubit.dart +++ b/lib/blocs/sync/sync_cubit.dart @@ -308,7 +308,7 @@ class SyncCubit extends Cubit { if (currentBlockHeight < 0) { throw Exception( - 'The current block height is negative. It should be equal or greater than 0.'); + 'The current block height $currentBlockHeight is negative. It should be equal or greater than 0.'); } return currentBlockHeight; }