feat(zhtlc): add desktop zcash params downloader#228
feat(zhtlc): add desktop zcash params downloader#228takenagain merged 6 commits intobugfix/zhltc-activation-fixesfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds Zcash parameter download capability with models, services, platform-specific downloaders (web/windows/unix), and a factory. Introduces a ZHTLC configuration dialog integrating automatic parameter downloads. Expands SDK exports, adjusts activation flow, adds disposal in KDF local executable, updates macOS deployment target, tweaks build/analyzer configs, and adds Hive registration and tests. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Widget as LoggedInViewWidget
participant Handler as ZhtlcConfigDialogHandler
participant Factory as ZcashParamsDownloaderFactory
participant Downloader as ZcashParamsDownloader
participant Service as DownloadService
participant FS as FileSystem
User->>Widget: Configure ZHTLC
Widget->>Handler: handleZhtlcConfigDialog(context, asset)
Handler->>Factory: create()
Factory-->>Handler: Downloader
Handler->>Downloader: areParamsAvailable()
alt Params missing and platform supports download
Handler->>Downloader: downloadParams()
par Progress
Downloader-->>Handler: downloadProgress events
and Transfer
Downloader->>Service: downloadMissingFiles(...)
Service->>FS: ensure dirs / write files / hash
Service-->>Downloader: success/failure
end
Downloader-->>Handler: DownloadResult
alt success
Handler->>Handler: prefill path for dialog
else failure/cancel
Handler->>Handler: fallback to manual dialog
end
else Params available or web
Handler->>Handler: open config dialog
end
Handler-->>Widget: ZhtlcUserConfig?
opt Config provided
Widget->>SDK: saveZhtlcConfig(assetId, config)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Visit the preview URL for this PR (updated for commit 1cdf6aa): https://komodo-playground--pr228-feat-zcash-params-do-w9ze5g8c.web.app (expires Thu, 02 Oct 2025 15:34:08 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 2bfedd77fdea45b25ba7c784416e81f177aa5c47 |
|
Visit the preview URL for this PR (updated for commit 1cdf6aa): https://kdf-sdk--pr228-feat-zcash-params-do-uqew78vb.web.app (expires Thu, 02 Oct 2025 15:34:05 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 9c1b6e6c010cf0b965c455ba7a69c4aedafa8a1d |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull Request Overview
This PR introduces desktop ZCash parameters downloader functionality to streamline ZHTLC setup for users. The implementation provides platform-aware parameter download with progress reporting, validation, and cancellation support.
- Adds comprehensive ZCash parameters download functionality with factory pattern for cross-platform support
- Integrates automatic parameter download into ZHTLC configuration flow in the example app
- Updates minimum macOS version to 10.15 and adds necessary dependencies for cryptographic operations
Reviewed Changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/komodo_defi_sdk/lib/src/zcash_params/ | Core ZCash parameters download implementation with platform-specific downloaders |
| packages/komodo_defi_sdk/test/zcash_params/ | Comprehensive test suite covering models, services, and platform implementations |
| packages/komodo_defi_sdk/example/lib/widgets/instance_manager/zhtlc_config_dialog.dart | Enhanced ZHTLC configuration dialog with automatic parameter download |
| packages/komodo_defi_sdk/pubspec.yaml | Added crypto, freezed, and json serialization dependencies |
Comments suppressed due to low confidence (1)
packages/komodo_defi_sdk/lib/src/zcash_params/services/zcash_params_download_service.dart:1
- This appears to be unrelated code that was accidentally modified. The log message references 'KDF' and 'coins' which don't belong in the ZCash parameters download service. This should be reverted.
import 'dart:async';
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 12
🧹 Nitpick comments (15)
packages/komodo_defi_framework/lib/src/operations/kdf_operations_local_executable.dart (1)
259-272: Don’t null_processon timeout; kill as fallback and only clear after terminationIf the 10s timeout hits, the process may still be running but
_processis nulled, causingkdfMainStatus()to misreport. Kill as fallback and null-out only after termination.Apply this diff:
- if (_process != null && _process!.pid != 0) { - await _process?.exitCode.timeout( - const Duration(seconds: 10), - onTimeout: () { - _logCallback('KDF Process did not terminate in time.'); - stopStatus = StopStatus.errorStopping; - return -1; // not used - }, - ); - } - - _process = null; + final process = _process; + if (process != null && process.pid != 0) { + var exited = true; + final code = await process.exitCode.timeout( + const Duration(seconds: 10), + onTimeout: () { + exited = false; + _logCallback('KDF process did not terminate in time. Sending kill().'); + stopStatus = StopStatus.errorStopping; + return -1; + }, + ); + if (!exited) { + // Ensure termination then proceed. + process.kill(); + await process.exitCode.catchError((_) {}); + } + } + _process = null; _logCallback('KDF process cleanup complete');packages/komodo_defi_sdk/example/lib/widgets/instance_manager/logged_in_view_widget.dart (1)
219-224: Guard against exceptions from dialog handler.Wrap the await in try/catch and surface an error to the user; prevents silent failures.
- final config = - await ZhtlcConfigDialogHandler.handleZhtlcConfigDialog( - context, - asset, - ); + final config = await (() async { + try { + return await ZhtlcConfigDialogHandler.handleZhtlcConfigDialog( + context, + asset, + ); + } catch (e) { + if (!mounted) return null; + _showError('Failed to open ZHTLC configuration: $e'); + return null; + } + })();packages/komodo_defi_sdk/test/zcash_params/platform_implementations/windows_zcash_params_downloader_test.dart (2)
327-333: Await stream completion to avoid flakes.Use expectLater with await when asserting emitsDone.
- expect(stream, emitsDone); + await expectLater(stream, emitsDone);
46-58: Deterministic APPDATA testing via injectable environment.Consider injecting an environment provider into the downloader so tests can simulate presence/absence of APPDATA without relying on host.
packages/komodo_defi_sdk/test/zcash_params/services/zcash_params_download_service_test.dart (1)
641-647: Prefer idempotent dispose; assert single closeDisposing twice should not close the client twice. Make service
dispose()idempotent and adjust the test.test('can be called multiple times safely', () { service.dispose(); service.dispose(); - verify(() => mockHttpClient.close()).called(2); + verify(() => mockHttpClient.close()).called(1); });packages/komodo_defi_sdk/test/zcash_params/zcash_params_downloader_factory_test.dart (4)
39-57: Dispose created downloaders to avoid leaking resources in testsDispose instances created in the loop.
test('creates correct downloader for each platform type', () { for (final platform in ZcashParamsPlatform.values) { final downloader = ZcashParamsDownloaderFactory.createForPlatform( platform, ); switch (platform) { case ZcashParamsPlatform.web: expect(downloader, isA<WebZcashParamsDownloader>()); break; case ZcashParamsPlatform.windows: expect(downloader, isA<WindowsZcashParamsDownloader>()); break; case ZcashParamsPlatform.unix: expect(downloader, isA<UnixZcashParamsDownloader>()); break; } + downloader.dispose(); } });
59-69: Dispose both instances after assertionsPrevents dangling controllers/clients during tests.
test('creates different instances for multiple calls', () { final downloader1 = ZcashParamsDownloaderFactory.createForPlatform( ZcashParamsPlatform.web, ); final downloader2 = ZcashParamsDownloaderFactory.createForPlatform( ZcashParamsPlatform.web, ); expect(downloader1, isNot(same(downloader2))); expect(downloader1.runtimeType, equals(downloader2.runtimeType)); + downloader1.dispose(); + downloader2.dispose(); });
189-205: Also dispose instances in integration loopSmall hygiene improvement.
test('created downloaders have expected interfaces', () async { for (final platform in ZcashParamsPlatform.values) { final downloader = ZcashParamsDownloaderFactory.createForPlatform( platform, ); // Verify all downloaders implement the expected interface expect(downloader.downloadParams, isA<Function>()); expect(downloader.getParamsPath, isA<Function>()); expect(downloader.areParamsAvailable, isA<Function>()); expect(downloader.downloadProgress, isA<Stream>()); expect(downloader.cancelDownload, isA<Function>()); expect(downloader.validateParams, isA<Function>()); expect(downloader.clearParams, isA<Function>()); + downloader.dispose(); } });
146-163: Clean up created instances in edge-case testConsider disposing created downloaders at the end of the test to avoid leaks.
packages/komodo_defi_sdk/lib/src/zcash_params/platforms/unix_zcash_params_downloader.dart (2)
115-128: Gracefully handle missing HOME environment variableThrowing a StateError may crash flows that just want a boolean. Consider returning failure from callers or providing a configurable override/hint.
Option A: catch in callers like
areParamsAvailableand return false.Option B: allow injecting a custom base directory via config/constructor for environments without HOME.
130-142: Avoid redundant null-check
getParamsPathnever returns null (throws instead on error). Either let the error bubble or catch and return false; the current null-check is dead code.packages/komodo_defi_sdk/example/lib/widgets/instance_manager/zhtlc_config_dialog.dart (2)
401-403: Dispose TextEditingControllers after dialog closesPrevents minor leaks in debug/profile modes.
- return result; + // Dispose controllers + zcashPathController.dispose(); + blocksPerIterController.dispose(); + intervalMsController.dispose(); + syncValueController.dispose(); + return result;
47-80: Optional: avoid reattaching.then/.catchErroron rebuildsAttaching inside the builder can register multiple listeners if the dialog rebuilds. Wrap this in a one-time init or move the listener outside the builder.
packages/komodo_defi_sdk/lib/src/zcash_params/services/zcash_params_download_service.dart (2)
310-318: Add a timeout to HEAD request to avoid hanging on slow/unresponsive hosts.- final response = await _httpClient.head(Uri.parse(url)); + final response = await _httpClient + .head(Uri.parse(url)) + .timeout(const Duration(seconds: 15));
372-419: Optional: log when HEAD unsupported to reduce noise on 405.Some origins return 405 for HEAD; consider downgrading to fine or hinting fallback in the warning to avoid alarming logs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (21)
packages/komodo_defi_framework/lib/src/operations/kdf_operations_local_executable.dart(6 hunks)packages/komodo_defi_sdk/build.yaml(1 hunks)packages/komodo_defi_sdk/example/lib/widgets/instance_manager/logged_in_view_widget.dart(2 hunks)packages/komodo_defi_sdk/example/lib/widgets/instance_manager/zhtlc_config_dialog.dart(1 hunks)packages/komodo_defi_sdk/lib/src/activation_config/hive_adapters.g.dart(1 hunks)packages/komodo_defi_sdk/lib/src/activation_config/hive_registrar.g.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/_zcash_params_index.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/models/zcash_params_config.freezed.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/models/zcash_params_config.g.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/platforms/unix_zcash_params_downloader.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/platforms/web_zcash_params_downloader.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/platforms/windows_zcash_params_downloader.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/services/zcash_params_download_service.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader.dart(1 hunks)packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader_factory.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/models/download_progress_test.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/models/zcash_params_config_test.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/platform_implementations/web_zcash_params_downloader_test.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/platform_implementations/windows_zcash_params_downloader_test.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/services/zcash_params_download_service_test.dart(1 hunks)packages/komodo_defi_sdk/test/zcash_params/zcash_params_downloader_factory_test.dart(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/komodo_defi_sdk/test/zcash_params/models/download_progress_test.dart
- packages/komodo_defi_sdk/lib/src/zcash_params/_zcash_params_index.dart
- packages/komodo_defi_sdk/lib/src/zcash_params/models/zcash_params_config.g.dart
- packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader.dart
🔇 Additional comments (18)
packages/komodo_defi_sdk/build.yaml (1)
3-5: Globs cover the expanded source surface.Including
lib/**and broadening the generator target tolib/src/**.dartaligns the build config with the newly introduced code. Looks good.Also applies to: 10-10
packages/komodo_defi_sdk/lib/src/activation_config/hive_registrar.g.dart (1)
8-18: Registrar extension wired correctly.Centralizing the adapter registration for both
HiveInterfaceandIsolatedHiveInterfacekeeps the bootstrapping consistent. Nicely done.packages/komodo_defi_framework/lib/src/operations/kdf_operations_local_executable.dart (4)
20-22: LGTM: sensible default for executable finderUsing a fallback
KdfExecutableFinderwith the provided log callback is correct.
75-77: LGTM: robust executable path resolutionClean null-check around
findExecutable()and use of.absolute.path.
117-119: LGTM: argument passing and environment separationMoving the large coins list into a temp file and passing the remaining args as JSON keeps CLI size bounded.
195-197: CensoredJsonMap covers RPC creds and common secrets; no leaks detected Verifiedcensored()redacts keys includinguserpass,rpc_password,wallet_password, etc. Add any newly introduced sensitive fields (e.g. file paths) to thesensitivelist in security_utils.dart if needed.packages/komodo_defi_sdk/lib/src/zcash_params/models/zcash_params_config.freezed.dart (1)
499-506: Defaults now match source (primary/backup URL order).The generated defaults align with zcash_params_config.dart (primary=komodoplatform, backup=z.cash). This resolves the earlier mismatch.
Consider re-running codegen to ensure no other drift:
#!/bin/bash flutter pub run build_runner build --delete-conflicting-outputs rg -nP "const _ZcashParamsConfig\\(" -npackages/komodo_defi_sdk/example/lib/widgets/instance_manager/logged_in_view_widget.dart (1)
9-9: Good extraction of dialog flow into handler.Centralizing ZHTLC config logic via ZhtlcConfigDialogHandler improves cohesion.
packages/komodo_defi_sdk/test/zcash_params/platform_implementations/web_zcash_params_downloader_test.dart (1)
200-206: Await stream close to avoid race.Use await expectLater for emitsDone. This prevents flaky failures.
- // Stream should be closed after dispose - expect(stream, emitsDone); + // Stream should be closed after dispose + await expectLater(stream, emitsDone);packages/komodo_defi_sdk/test/zcash_params/services/zcash_params_download_service_test.dart (2)
306-315: Align mock to service: addexistsSync()stub for hash validation
validateFileHashmay rely onexistsSync(). Add the sync stub to ensure determinism.File fileFactory(String path) { final file = MockFile(); - when(() => file.exists()).thenAnswer((_) async => true); + when(() => file.exists()).thenAnswer((_) async => true); + when(() => file.existsSync()).thenReturn(true); when(() => file.path).thenReturn(path); when( () => file.openRead(), ).thenAnswer((_) => Stream.fromIterable([testData])); return file; }Please confirm which existence check the service uses (
existsvsexistsSync) and standardize tests accordingly.
58-152: Inconsistent use ofexists()vsexistsSync()across testsSeveral tests stub only one of these; if the service calls the other, tests will be flaky or fail. Recommend stubbing both consistently in file-related tests.
packages/komodo_defi_sdk/lib/src/zcash_params/platforms/web_zcash_params_downloader.dart (1)
19-23: LGTMSimple, deterministic web implementation aligns with tests and factory behavior.
packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader_factory.dart (3)
127-133: LGTM: safe acquire/cleanup pattern.Creating a downloader, awaiting getParamsPath, and disposing in finally is correct.
1-9: Blocking: Unconditional IO imports break Flutter Web; split via conditional exports.This file imports dart:io and IO-only implementations/services, which makes any web build fail even if branches are guarded at runtime. Use conditional exports to keep IO code out of the web compilation unit.
Preferred fix (replace this file’s contents with conditional exports) and add two platform-specific factory files:
-// Current contents (imports + factory + enum/extension) +// Facade using conditional exports to avoid pulling IO into web builds. +export 'zcash_params_downloader_factory_stub.dart' + if (dart.library.html) 'zcash_params_downloader_factory_web.dart' + if (dart.library.io) 'zcash_params_downloader_factory_io.dart';New files (add these):
// packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader_factory_io.dart import 'dart:io'; import 'package:komodo_defi_sdk/src/zcash_params/models/zcash_params_config.dart'; import 'package:komodo_defi_sdk/src/zcash_params/platforms/unix_zcash_params_downloader.dart'; import 'package:komodo_defi_sdk/src/zcash_params/platforms/windows_zcash_params_downloader.dart'; import 'package:komodo_defi_sdk/src/zcash_params/services/zcash_params_download_service.dart'; import 'package:komodo_defi_sdk/src/zcash_params/zcash_params_downloader.dart'; enum ZcashParamsPlatform { web, windows, unix } extension ZcashParamsPlatformExtension on ZcashParamsPlatform { String get displayName => switch (this) { ZcashParamsPlatform.web => 'Web', ZcashParamsPlatform.windows => 'Windows', ZcashParamsPlatform.unix => 'Unix/Linux' }; bool get requiresDownload => this != ZcashParamsPlatform.web; String? get defaultDirectoryName => switch (this) { ZcashParamsPlatform.windows => 'ZcashParams', _ => null }; } class ZcashParamsDownloaderFactory { const ZcashParamsDownloaderFactory._(); static ZcashParamsDownloader create({ ZcashParamsDownloadService? downloadService, ZcashParamsConfig? config, bool enableHashValidation = true, }) { if (Platform.isWindows) { return WindowsZcashParamsDownloader( downloadService: downloadService, config: config, enableHashValidation: enableHashValidation, ); } return UnixZcashParamsDownloader( downloadService: downloadService, config: config, enableHashValidation: enableHashValidation, ); } static ZcashParamsDownloader createForPlatform( ZcashParamsPlatform platformType, { ZcashParamsDownloadService? downloadService, ZcashParamsConfig? config, bool enableHashValidation = true, }) => switch (platformType) { ZcashParamsPlatform.windows => WindowsZcashParamsDownloader( downloadService: downloadService, config: config, enableHashValidation: enableHashValidation, ), ZcashParamsPlatform.unix => UnixZcashParamsDownloader( downloadService: downloadService, config: config, enableHashValidation: enableHashValidation, ), ZcashParamsPlatform.web => throw ArgumentError('Web uses no-op downloader') }; static ZcashParamsPlatform detectPlatform() => Platform.isWindows ? ZcashParamsPlatform.windows : ZcashParamsPlatform.unix; static bool get requiresDownload => true; static Future<String?> getDefaultParamsPath() async { final d = create(); try { return await d.getParamsPath(); } finally { d.dispose(); } } }// packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader_factory_web.dart import 'package:komodo_defi_sdk/src/zcash_params/platforms/web_zcash_params_downloader.dart'; import 'package:komodo_defi_sdk/src/zcash_params/zcash_params_downloader.dart'; import 'package:komodo_defi_sdk/src/zcash_params/models/zcash_params_config.dart'; enum ZcashParamsPlatform { web, windows, unix } extension ZcashParamsPlatformExtension on ZcashParamsPlatform { String get displayName => switch (this) { ZcashParamsPlatform.web => 'Web', ZcashParamsPlatform.windows => 'Windows', ZcashParamsPlatform.unix => 'Unix/Linux' }; bool get requiresDownload => false; String? get defaultDirectoryName => null; } class ZcashParamsDownloaderFactory { const ZcashParamsDownloaderFactory._(); static ZcashParamsDownloader create({ ZcashParamsConfig? config, bool enableHashValidation = true, // ignored on web dynamic downloadService, // ignored on web }) => WebZcashParamsDownloader(config: config); static ZcashParamsDownloader createForPlatform( ZcashParamsPlatform platformType, { ZcashParamsConfig? config, bool enableHashValidation = true, dynamic downloadService, }) => WebZcashParamsDownloader(config: config); static ZcashParamsPlatform detectPlatform() => ZcashParamsPlatform.web; static bool get requiresDownload => false; static Future<String?> getDefaultParamsPath() async => null; }// packages/komodo_defi_sdk/lib/src/zcash_params/zcash_params_downloader_factory_stub.dart export 'zcash_params_downloader_factory_web.dart';This resolves web compilation errors and keeps IO-only code out of web builds.
46-60: Avoid Platform.isWindows in cross-platform library; use Flutter’s TargetPlatform (or conditional exports).Even if you remove dart:io import, importing IO-only implementations in this file still breaks web. If you must keep this file, at least switch to Flutter platform detection:
- if (Platform.isWindows) { + if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) { return WindowsZcashParamsDownloader( downloadService: downloadService, config: config, enableHashValidation: enableHashValidation, ); }Note: Conditional exports (previous comment) are the proper fix.
packages/komodo_defi_sdk/lib/src/zcash_params/services/zcash_params_download_service.dart (1)
467-592: Good: robust stream/sink cleanup and partial-file deletion.The finally block reliably closes the IOSink, deletes partial files on failure, and cancels the response stream. This resolves Windows file-locking and retry issues.
packages/komodo_defi_sdk/lib/src/zcash_params/platforms/windows_zcash_params_downloader.dart (2)
51-106: Wrap body in try/catch/finally to always reset state and surface failures.If ensureDirectoryExists() throws (it rethrows), _isDownloading remains true, blocking subsequent calls. Wrap the body and always reset flags.
@override Future<DownloadResult> downloadParams() async { if (_isDownloading) { return const DownloadResult.failure( error: 'Download already in progress', ); } _isDownloading = true; _isCancelled = false; - - final paramsPath = await getParamsPath(); - if (paramsPath == null) { - _isDownloading = false; - _isCancelled = false; - return const DownloadResult.failure( - error: 'Unable to determine parameters path', - ); - } - - // Create directory if it doesn't exist - await _downloadService.ensureDirectoryExists(paramsPath, _directoryFactory); - - // Check which files need to be downloaded - final missingFiles = await _downloadService.getMissingFiles( - paramsPath, - _fileFactory, - config, - ); - - if (missingFiles.isEmpty) { - _isDownloading = false; - _isCancelled = false; - return DownloadResult.success(paramsPath: paramsPath); - } - - // Download missing files - final downloadSuccess = await _downloadService.downloadMissingFiles( - paramsPath, - missingFiles, - _progressController, - () => _isCancelled, - config, - ); - - _isDownloading = false; - _isCancelled = false; - - if (!downloadSuccess) { - return const DownloadResult.failure( - error: 'Failed to download one or more parameter files', - ); - } - - return DownloadResult.success(paramsPath: paramsPath); + try { + final paramsPath = await getParamsPath(); + if (paramsPath == null) { + return const DownloadResult.failure( + error: 'Unable to determine parameters path', + ); + } + + await _downloadService.ensureDirectoryExists( + paramsPath, + _directoryFactory, + ); + + final missingFiles = await _downloadService.getMissingFiles( + paramsPath, + _fileFactory, + config, + ); + + if (missingFiles.isEmpty) { + return DownloadResult.success(paramsPath: paramsPath); + } + + final downloadSuccess = await _downloadService.downloadMissingFiles( + paramsPath, + missingFiles, + _progressController, + () => _isCancelled, + config, + ); + + if (!downloadSuccess) { + return const DownloadResult.failure( + error: 'Failed to download one or more parameter files', + ); + } + return DownloadResult.success(paramsPath: paramsPath); + } catch (e) { + return DownloadResult.failure(error: 'Download failed: $e'); + } finally { + _isDownloading = false; + _isCancelled = false; + } }
108-115: Also treat empty APPDATA as missing.- final appData = Platform.environment['APPDATA']; - if (appData == null) { + final appData = Platform.environment['APPDATA']; + if (appData == null || appData.isEmpty) { return null; }
0d6b12c
into
bugfix/zhltc-activation-fixes
* Enhance ZHTLC activation with improved config parsing and RPC methods Co-authored-by: charl <charl@vanstaden.info> * feat(zhtlc): integrate ZHTLC types and task RPCs per KDF API * dragon_logs: remove tracked ignored files and add .gitignore files * Integrate and verify ZHTLC in komodo_defi_sdk (#196) * Refactor ZHTLC activation strategy with stream-based task handling Co-authored-by: charl <charl@vanstaden.info> * Refactor activation steps to use strongly-typed ActivationStep enum Co-authored-by: charl <charl@vanstaden.info> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> * chore: run code generators * chore(git): delete previously tracked igored files * Fix ERC20 and ZHTLC activation params serialization and method calls (#212) Co-authored-by: Cursor Agent <cursoragent@cursor.com> * fix: misc fixes * docs(activation): add activation params refactoring plan Clean base/subclass separation, canonical serialization + encoder strategy, user configuration + persistence, BLoC timeout, SDK integration via AssetId extension and resolveActivationParams, and migration steps. No backwards compatibility required. * docs(sdk): activation refactoring v2 * feat(activation,zhtlc,sdk,rpc)!: extract ZHTLC fields to ZhtlcActivationParams; add ActivationConfigService; unify priv_key_policy serialization; normalize toRpcParams; formatting fixes * Checkpoint before follow-up message Co-authored-by: charl <charl@vanstaden.info> * Fix: Remove unused import statement Co-authored-by: charl <charl@vanstaden.info> * feat: Add support for electrum_servers in Zhtlc activation Co-authored-by: charl <charl@vanstaden.info> * feat: initialize Firebase hosting for SDK example and playground - Add Firebase hosting configuration for packages/komodo_defi_sdk/example - Configure to use kdf-sdk hosting site on komodo-defi-sdk project - Set up hosting target mapping - Add Firebase hosting configuration for playground - Configure to use default hosting site on komodo-playground project - Update GitHub Actions workflows to use target parameter for SDK example - Update .gitignore to allow Firebase config files in example and playground * fix: update z-coin activation strategy and example UI - Update zhtlc_activation_strategy for improved activation handling - Add activation config service enhancements - Update logged_in_view_widget with improved UI for instance management - Export additional SDK functionality in public API * docs(firebase): reorganize Firebase deployment scripts and documentation - Move Firebase scripts to .github/scripts/firebase/ directory - Rename scripts for clarity: - setup-firebase-secrets.sh → setup-github-secrets.sh - verify-firebase-secrets.sh → verify-github-secrets.sh - Move documentation to docs/firebase/ directory - Rename documentation file to firebase-deployment-setup.md - Update script paths in documentation - Add README for scripts directory * fix: remove global singleton registration of ActivationConfigService - Remove global GetIt.I registration to prevent conflicts between multiple SDK instances - Pass ActivationConfigService through constructor chain instead of global resolution - Update ZhtlcActivationStrategy to accept service via constructor - Update ActivationStrategyFactory and ActivationManager to propagate the service - Prevent memory leaks and use-after-dispose issues when SDK instances are disposed This ensures each SDK instance maintains its own isolated ActivationConfigService, fixing issues where only the first SDK's service would be globally registered. * fix(activation): register ActivationConfigService during bootstrap - Ensure service is available before ActivationManager to fix ZHTLC/Z-coin activation flow\n- Remove duplicate registration from KomodoDefiSdk.init\n- Example: use instance sdk instead of context.read for ZHTLC prompt * docs(tech-debt): add Activation & ZHTLC tech-debt report and refine sections * feat(komodo_defi_sdk): add HiveActivationConfigRepository and integrate in activation flow; update bootstrap, activation service, and example widget * fix: resolve external logging callback flaws and memory leak - Fix native callback memory leak by disposing _kdfOperations in KomodoDefiFramework - Remove debug-only conditional logging in bootstrap.dart - Fix potential double subscription in komodo_defi_sdk.dart - Add comprehensive error handling to log stream listeners - Replace empty catch blocks with proper error handling - Add safe logging helpers to prevent callback exceptions from crashing - Ensure log streams continue operating even after callback errors * refactor(withdrawals): inject LegacyWithdrawalManager and use for Tendermint flows - add _legacyManager constructor param and field - delegate Tendermint preview/withdraw to injected manager - minor formatting and watch() simplifications * fix(kdf-ops): use conditional imports for platform-specific imports i.e. dart:ffi * fix(activation-params): include other RPC server keys * fix(activation-config-repository): register adapter type * feat(zhtlc): add desktop zcash params downloader (#228) * feat(sdk): add zhltc params file downloader * feat(sdk-example): integrate zcash downloader for desktop * chore: remove groth from default params download list * test(komodo-defi-sdk): fix failing zcash unit tests * refactor: clean up imports, tests, and dialog date conversion * feat(zhtlc): add mobile config params downloader * feat(zhtlc): web lightwallet server URLs workaround * fix(zhtlc): align orderbook RPC with KDF schema, and add id pagination support (#229) * feat(zhtlc-tx): add from_id pagination support from RPC docs * fix(orderbook-v2): use v2 fields and types * fix(source-address-field): use consistent text theme to fix visibility * fix(order-address): change address data to optional for shielded ops * fix(json-utils): convert int to string in traverse as it's lossless * test(sdk): fix missing type in zcash mock classes * fix(address-select-input): use consistent text theme to fix visibility * feat(zhtlc): estimate activation percentage based on block height (#230) * feat(zhtlc): estimate activation percentage based on block height * refactor(review): remove unnecessary casts, states, and configurable polling * fix(config-transform): only replace lightwalletservers if wss is not empty * Fix ZHTLC activation issues and improve resilience Co-authored-by: charl <charl@vanstaden.info> --------- Co-authored-by: Charl (Nitride) <77973576+CharlVS@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: charl <charl@vanstaden.info>
Summary by CodeRabbit