diff --git a/lib/blocs/upload/upload_cubit.dart b/lib/blocs/upload/upload_cubit.dart index 61ce3c5054..9725014cba 100644 --- a/lib/blocs/upload/upload_cubit.dart +++ b/lib/blocs/upload/upload_cubit.dart @@ -150,7 +150,7 @@ class UploadCubit extends Cubit { fileId: manifestModels[i].existingManifestFileId, ) .getSingle(); - + await _createManifestCubit.prepareManifestTx( manifestName: manifestFileEntry.name, folderId: manifestFileEntry.parentFolderId, @@ -886,6 +886,10 @@ class UploadCubit extends Cubit { if (state is UploadReady) { emit((state as UploadReady).copyWith(arnsRecords: value)); } + }).catchError((e) { + logger.e( + 'Error getting ant records for wallet. Proceeding with the upload...', + e); }); _files @@ -1032,9 +1036,14 @@ class UploadCubit extends Cubit { } if (manifestFileEntries.isNotEmpty) { - // load arns names - await _arnsRepository - .getAntRecordsForWallet(_auth.currentUser.walletAddress); + try { + await _arnsRepository + .getAntRecordsForWallet(_auth.currentUser.walletAddress); + } catch (e) { + logger.e( + 'Error getting ant records for wallet. Proceeding with the upload...', + e); + } } emit( diff --git a/lib/main.dart b/lib/main.dart index 0fe72a818a..1b75627f74 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -75,6 +75,7 @@ late ConfigService configService; late ArweaveService arweave; late TurboUploadService _turboUpload; late PaymentService _turboPayment; +late Database db; void main() async { await runZonedGuarded(() async { @@ -129,11 +130,14 @@ Future _initializeServices() async { final config = configService.config; + db = Database(); + arweave = ArweaveService( Arweave( gatewayUrl: Uri.parse(config.defaultArweaveGatewayForDataRequest.url), ), ArDriveCrypto(), + db.driveDao, configService, ); _turboUpload = config.useTurboUpload @@ -395,7 +399,7 @@ class AppState extends State { ), ), ), - RepositoryProvider(create: (_) => Database()), + RepositoryProvider(create: (_) => db), RepositoryProvider( create: (context) => context.read().profileDao), RepositoryProvider( diff --git a/lib/services/arweave/arweave_service.dart b/lib/services/arweave/arweave_service.dart index 0c1ff7f729..92ae0ee0d5 100644 --- a/lib/services/arweave/arweave_service.dart +++ b/lib/services/arweave/arweave_service.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:ardrive/core/crypto/crypto.dart'; import 'package:ardrive/entities/entities.dart'; +import 'package:ardrive/models/daos/drive_dao/drive_dao.dart'; import 'package:ardrive/services/arweave/arweave_service_exception.dart'; import 'package:ardrive/services/arweave/error/gateway_error.dart'; import 'package:ardrive/services/arweave/get_segmented_transaction_from_drive_strategy.dart'; @@ -42,12 +43,13 @@ const kMaxNumberOfTransactionsPerPage = 100; class ArweaveService { Arweave client; final ArDriveCrypto _crypto; - + final DriveDao _driveDao; final ArtemisClient _gql; ArweaveService( this.client, this._crypto, + this._driveDao, ConfigService configService, { ArtemisClient? artemisClient, }) : _gql = artemisClient ?? @@ -588,15 +590,24 @@ class ArweaveService { continue; } - final driveKey = - driveTx.getTag(EntityTag.drivePrivacy) == DrivePrivacyTag.private - ? await _crypto.deriveDriveKey( - wallet, - driveTx.getTag(EntityTag.driveId)!, - password, - ) - : null; + SecretKey? driveKey; + + if (driveTx.getTag(EntityTag.drivePrivacy) == DrivePrivacyTag.private) { + driveKey = await _driveDao.getDriveKeyFromMemory( + driveTx.getTag(EntityTag.driveId)!, + ); + + driveKey ??= await _crypto.deriveDriveKey( + wallet, + driveTx.getTag(EntityTag.driveId)!, + password, + ); + _driveDao.putDriveKeyInMemory( + driveID: driveTx.getTag(EntityTag.driveId)!, + driveKey: driveKey, + ); + } try { final drive = await DriveEntity.fromTransaction( driveTx,