-
Notifications
You must be signed in to change notification settings - Fork 19
PE-8183: snapshots for extensions #2044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vilenarios
wants to merge
6
commits into
dev
Choose a base branch
from
PE-8183-snapshots-for-extensions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
818095c
fix: improve drive attach sync performance with snapshots and UI resp…
vilenarios fab53e3
feat:claude.md
vilenarios b3b324a
refactor: remove un-uses import PE-8183
fedellen e26a103
Merge branch 'dev' into PE-8183-snapshots-for-extensions
fedellen fe9162f
fix: handle ProfilePromptLogIn state for drive sharing links
vilenarios 7d27d3e
fix: fixes drive_attach_cubit_test.dart
vilenarios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
# CLAUDE.md | ||
|
||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
||
## Development Commands | ||
|
||
### Setup and Build | ||
```bash | ||
# Initial setup - install dependencies and generate code | ||
scr setup | ||
|
||
# Generate code (run after changing .drift files or GraphQL schemas) | ||
flutter pub run build_runner build --delete-conflicting-outputs | ||
|
||
# Watch for changes during development | ||
flutter packages pub run build_runner watch | ||
|
||
# Check Flutter version compliance | ||
scr check-flutter | ||
|
||
# Database schema validation | ||
scr check-db | ||
``` | ||
|
||
### Testing | ||
```bash | ||
# Run all tests (main app + all packages) | ||
scr test | ||
|
||
# Run main app tests only | ||
flutter test | ||
|
||
# Run tests for specific package | ||
cd packages/ardrive_ui && flutter test | ||
|
||
# Run specific test file | ||
flutter test test/blocs/upload_cubit_test.dart | ||
``` | ||
|
||
### Running the App | ||
```bash | ||
# Development environment (web) | ||
flutter run -d chrome --dart-define=environment=development | ||
|
||
# Production environment (web) | ||
flutter run -d chrome --dart-define=environment=production | ||
|
||
# Mobile development | ||
flutter run --flavor=development | ||
|
||
# Mobile production | ||
flutter run --flavor=production | ||
``` | ||
|
||
### Code Quality | ||
```bash | ||
# Analyze code | ||
flutter analyze | ||
|
||
# Format code | ||
dart format . | ||
|
||
# Lint check (via lefthook pre-commit) | ||
lefthook run pre-commit | ||
``` | ||
|
||
## Architecture Overview | ||
|
||
ArDrive is a Flutter web/mobile application for decentralized file storage on Arweave blockchain. | ||
|
||
### Core Architecture Patterns | ||
|
||
**State Management**: BLoC pattern with Cubits | ||
- Complex features (uploads, sync, file operations) use event-driven BLoCs | ||
- Simple UI state uses Cubits | ||
- Dependency injection via Provider | ||
|
||
**Database**: Drift ORM with SQL generation | ||
- Schema versioning with migrations in `drift_schemas/` (current: version 27) | ||
- Core entities: drives, files, folders, licenses, ARNS records, ANT records, network transactions | ||
- DAOs provide repository pattern for data access | ||
- Database resets for schema versions < 24 | ||
|
||
**Upload System**: Multi-strategy architecture | ||
- Direct Arweave uploads vs Turbo bundled uploads | ||
- Payment methods: AR tokens or Turbo credits | ||
- Upload handles abstract different upload patterns | ||
- Real-time progress tracking with cancellation | ||
|
||
### Key Components | ||
|
||
**Authentication**: Multi-wallet support (ArConnect, keyfile, Ethereum) | ||
**Encryption**: End-to-end encryption for private drives | ||
**ARNS Integration**: Decentralized naming system via `ario_sdk` | ||
**GraphQL**: Artemis-generated clients for Arweave gateway queries | ||
**Packages**: Modular local packages in `/packages/` directory: | ||
- `ardrive_ui` - UI Design Library with Storybook | ||
- `ardrive_crypto` - Cryptography utilities | ||
- `ardrive_uploader` - Upload functionality | ||
- `ardrive_utils` - Shared utilities | ||
- `ario_sdk` - ARNS integration | ||
- `arconnect` - Wallet connection | ||
- `pst` - Profit Sharing Token functionality | ||
- `ardrive_logger` - Logging utilities | ||
|
||
### File Structure | ||
|
||
- `lib/blocs/` - State management (BLoCs/Cubits) | ||
- `lib/models/` - Database models and DAOs | ||
- `lib/services/` - External integrations (Arweave, payments, auth) | ||
- `lib/pages/` - UI screens and routing | ||
- `lib/components/` - Reusable UI components | ||
- `packages/` - Local modular packages | ||
- `test/` - Unit and integration tests | ||
|
||
### Database Schema | ||
|
||
When modifying database schema: | ||
1. Update `.drift` files in `lib/models/tables/` or `lib/models/queries/` | ||
2. Run `flutter pub run build_runner build --delete-conflicting-outputs` | ||
3. Update migration logic in `lib/models/database/database.dart` if needed | ||
4. Run `scr check-db` to validate schema changes | ||
|
||
### Adding New Features | ||
|
||
1. Create BLoC/Cubit in `lib/blocs/` | ||
2. Add models/DAOs if database changes needed | ||
3. Create UI components in `lib/components/` or pages in `lib/pages/` | ||
4. Add tests in corresponding `test/` directories | ||
5. Update routing in `lib/pages/app_router_delegate.dart` if needed | ||
|
||
### Commit Message Format | ||
|
||
Use conventional commit prefixes (lowercase): | ||
- `fix:` - Bug fixes | ||
- `feat:` - New features | ||
- `perf:` - Performance improvements | ||
- `docs:` - Documentation changes | ||
- `style:` - Formatting changes | ||
- `refactor:` - Code refactoring | ||
- `test:` - Adding missing tests | ||
- `chore:` - Chore tasks | ||
|
||
Include detailed changes list after summary line if not self-explanatory. | ||
|
||
### Environment Configuration | ||
|
||
The app uses three environments (development, staging, production) with config files in `assets/config/`. Use `--dart-define=environment=<env>` to specify environment when running. | ||
|
||
### Code Generation | ||
|
||
The codebase uses several code generation tools: | ||
- **Artemis**: GraphQL client generation from schema in `lib/services/arweave/graphql/` | ||
- **Drift**: Database schema and DAO generation from `.drift` files | ||
- **JSON Serialization**: Model serialization via `json_annotation` | ||
|
||
Build configuration in `build.yaml` specifies output paths and options. | ||
|
||
### Key Dependencies | ||
|
||
- **Flutter SDK**: 3.19.6 (exact version required) | ||
- **Dart SDK**: >=3.2.0 <4.0.0 | ||
- **State Management**: flutter_bloc ^8.1.1 | ||
- **Database**: drift ^2.12.1 | ||
- **GraphQL**: artemis ^7.0.0-beta.13 | ||
- **Testing**: mocktail, bloc_test, golden tests | ||
- **Mobile**: Firebase integration (Crashlytics, Core) | ||
|
||
### Development Tools | ||
|
||
- **Lefthook**: Git hooks for pre-commit/pre-push validation | ||
- **Script Runner**: Access to custom scripts via `scr` command | ||
- **Flutter Lints**: Code quality enforcement | ||
- **Golden Tests**: UI regression testing support | ||
|
||
### Custom Gateway | ||
|
||
For testing with custom Arweave gateways, set `flutter.arweaveGatewayUrl` in browser localStorage: | ||
```js | ||
localStorage.setItem('flutter.arweaveGatewayUrl', '"https://my.custom.url"'); | ||
``` | ||
|
||
### Release Process | ||
|
||
- **Staging**: All changes to `dev` branch auto-deploy to staging.ardrive.io | ||
- **Production**: Merge `dev` to `master`, create GitHub release with `v*` tag pattern | ||
- **Preview Builds**: PRs to `dev` trigger shareable preview builds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,30 @@ class DriveAttachCubit extends Cubit<DriveAttachState> { | |
} | ||
} | ||
|
||
Future<bool> _checkForSnapshots(String driveId) async { | ||
try { | ||
final snapshotsStream = _arweave.getAllSnapshotsOfDrive( | ||
driveId, | ||
null, // No lastBlockHeight filter for checking | ||
ownerAddress: null, // Allow snapshots from any owner | ||
); | ||
|
||
final snapshots = await snapshotsStream.take(1).toList(); | ||
final hasSnapshots = snapshots.isNotEmpty; | ||
|
||
if (hasSnapshots) { | ||
logger.i('Drive $driveId has snapshots - will enable performance optimization'); | ||
} else { | ||
logger.d('Drive $driveId has no snapshots - will use standard sync'); | ||
} | ||
|
||
return hasSnapshots; | ||
} catch (e) { | ||
logger.w('Error checking for snapshots on drive $driveId: $e'); | ||
return false; | ||
} | ||
} | ||
|
||
void submit() async { | ||
final driveId = driveIdController.text; | ||
final driveName = driveNameController.text; | ||
|
@@ -158,15 +182,37 @@ class DriveAttachCubit extends Cubit<DriveAttachState> { | |
profileKey: _profileKey, | ||
); | ||
|
||
emit(DriveAttachSuccess()); | ||
|
||
// Check for snapshots to provide better user feedback | ||
final hasSnapshots = await _checkForSnapshots(driveId); | ||
|
||
// Don't emit success yet - go straight to syncing state | ||
|
||
/// Wait for the sync to finish before syncing the newly attached drive. | ||
await _syncBloc.waitCurrentSync(); | ||
|
||
/// Then, sync and select the newly attached drive. | ||
unawaited(_syncBloc | ||
.startSync() | ||
.then((value) => _drivesBloc.selectDrive(driveId))); | ||
/// Show syncing state while the drive syncs | ||
emit(DriveAttachSyncing(hasSnapshots: hasSnapshots)); | ||
fedellen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Start the sync in the background | ||
/// Don't await it so the user can close the modal if they want | ||
_syncBloc.syncSingleDrive(driveId).then((_) { | ||
if (!isClosed) { | ||
/// Select the drive after sync completes | ||
_drivesBloc.selectDrive(driveId); | ||
} | ||
}).catchError((err) { | ||
logger.e('Error during background sync of attached drive', err); | ||
}); | ||
|
||
// Give the UI time to show the syncing state before allowing the user to close | ||
await Future.delayed(const Duration(seconds: 2)); | ||
|
||
// Check if still in syncing state (user hasn't closed the modal) | ||
if (!isClosed && state is DriveAttachSyncing) { | ||
/// Emit success to indicate the attach is complete | ||
/// The sync continues in the background | ||
emit(DriveAttachSuccess()); | ||
} | ||
Comment on lines
+207
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems fishy here, wondering if is there a chance we leave the user stuck |
||
|
||
PlausibleEventTracker.trackAttachDrive( | ||
drivePrivacy: drivePrivacy, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.