Skip to content

feat: add Flutter Web WASM support with OPFS interop extensions#176

Merged
CharlVS merged 13 commits intodevfrom
add/flutter-web-wasm
Aug 5, 2025
Merged

feat: add Flutter Web WASM support with OPFS interop extensions#176
CharlVS merged 13 commits intodevfrom
add/flutter-web-wasm

Conversation

@CharlVS
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS commented Aug 5, 2025

Summary

This PR adds comprehensive Flutter Web WASM support to the Komodo DeFi SDK Flutter framework, implementing OPFS (Origin Private File System) interop extensions while also addressing several critical issues including API rate limiting and type safety improvements.

What's Changed

🚀 Major Features

  • Flutter Web WASM Support: Complete implementation of WASM-compatible web operations with OPFS storage
  • OPFS Integration: New Origin Private File System interop extensions for missing FileSystemDirectoryHandle methods (.values(), .keys(), .entries())
  • Modern JS Interop: Migration from legacy dart:html/dart:js to dart:js_interop and package:web
  • Dragon Logs Integration: Added dragon_logs to komodo_defi_sdk example with export functionality

🔧 Critical Fixes

  • GitHub API Authentication: Added token support across all components to resolve rate limiting (60 → 5,000 requests/hour)
  • WASM Type Safety: Fixed Dart WASM type errors in JS interop operations
  • Build Configuration: Updated KDF binaries and resolved build step issues

📦 Technical Implementation

OPFS Interop Extensions (opfs_interop.dart)

  • Custom JSAsyncIterator type definitions for proper JavaScript interop
  • FileSystemDirectoryHandle extensions providing missing browser API methods
  • Stream-based async iteration over directory contents with proper type safety
  • Cross-compilation compatibility (JavaScript ↔ WebAssembly)

WASM-Compatible Storage (web_log_storage_wasm.dart)

  • Unified web storage implementation for both JS and WASM targets
  • Origin Private File System integration for secure file operations
  • Maintains full API compatibility with existing implementations

GitHub API Improvements

  • CoinConfigProvider now supports GitHub authentication tokens
  • Build transformer includes debug logging for API requests
  • Wallet CLI automatically uses GITHUB_API_PUBLIC_READONLY_TOKEN environment variable
  • Rate limit handling with proper error reporting

Packages Modified

Package Changes
dragon_logs BREAKING: WASM support, OPFS storage, modern JS interop
komodo_defi_framework WASM operations fixes, build config updates
komodo_coin_updates GitHub authentication, rate limit handling
komodo_defi_sdk Example app integration with dragon_logs
komodo_wallet_build_transformer GitHub auth debugging, lint fixes
komodo_wallet_cli Auto GitHub token detection

Breaking Changes

⚠️ dragon_logs v1.2.0+1:

  • Removed file_system_access_api and js dependencies
  • Requires Dart SDK >=3.7.0 for extension types support
  • WebLogStorage class replaced with WebLogStorageWasm
  • WASM compilation uses OPFS-only storage (API remains compatible)

Migration Guide

For dragon_logs users:

  1. Update to Dart SDK >=3.7.0
  2. No code changes required - API remains fully compatible
  3. Direct WebLogStorage imports should be replaced with WebLogStorageWasm
  4. WASM builds automatically use OPFS storage

For build processes:

  1. Set GITHUB_API_PUBLIC_READONLY_TOKEN environment variable to avoid rate limits
  2. Update Flutter version constraints to >=3.29.0 <3.36.0

Browser Support

Supports all modern browsers with File System API:

  • Chrome/Chromium 86+
  • Firefox 111+
  • Safari 15.2+
  • Edge 86+

Testing & Validation

  • ✅ Static analysis passes (dart analyze)
  • ✅ WASM compilation compatibility verified
  • ✅ JavaScript fallback compatibility confirmed
  • ✅ OPFS interop extensions fully functional
  • ✅ GitHub API authentication prevents rate limiting
  • ✅ Cross-platform file operations work correctly
  • ✅ Example app successfully integrates dragon_logs

Related Issues

  • Resolves: Rate limit exceeded errors during build process
  • Enables: Flutter Web WASM compilation support
  • Fixes: Type safety issues in WASM JS interop operations
  • Improves: Build reliability with authenticated GitHub requests

Type of Change: ✨ New Feature + 🐛 Bug Fixes
Breaking Change: ⚠️ Yes (dragon_logs only, with migration path)
Documentation Updated: ✅ Yes

CharlVS and others added 3 commits August 1, 2025 15:50
…ository first before cex repository (#167)

* fix(market-data-manager): default to KomodoPriceRepository

Binance CexRepository supports a limited number of symbols and no longer lists KMD price history after the delisting

* refactor(market-data-manager): deduplicate and clarify intent

* refactor(review): remove zero check and add log statements

also simplify the priceIfKnown function
Switch KDF to `dev` to allow usage of unreleased changes (particularly related to fees/priorities)
Copilot AI review requested due to automatic review settings August 5, 2025 19:28
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Aug 5, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add/flutter-web-wasm

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds OPFS (Origin Private File System) interop extensions for Flutter web and consolidates web storage implementations in the dragon_logs package by migrating from legacy web APIs to modern standards.

  • Implements OPFS JavaScript interop extensions with proper async iterator support for WASM compatibility
  • Consolidates web storage by removing the legacy WebLogStorage class and using WebLogStorageWasm for all web builds
  • Updates dependencies to use modern web APIs (package:web instead of dart:html and dart:js)

Reviewed Changes

Copilot reviewed 13 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/dragon_logs/lib/src/storage/opfs_interop.dart New OPFS JavaScript interop extensions providing missing async iterator methods
packages/dragon_logs/lib/src/storage/web_log_storage_wasm.dart New unified WASM-compatible web storage implementation using modern JS interop
packages/dragon_logs/lib/src/storage/web_log_storage.dart Removed legacy web storage implementation
packages/dragon_logs/lib/src/storage/platform_instance/log_storage_web_platform.dart Updated to use consolidated WebLogStorageWasm implementation
packages/dragon_logs/pubspec.yaml Updated dependencies and version, removed legacy packages
packages/komodo_defi_types/lib/src/utils/mnemonic_validator.dart Enhanced BIP39 mnemonic validation with proper checksum verification
packages/komodo_defi_sdk/lib/src/market_data/market_data_manager.dart Added fallback logic between Komodo and CEX price repositories

Comment thread packages/dragon_logs/lib/src/storage/web_log_storage_wasm.dart Outdated
Comment thread packages/dragon_logs/lib/src/storage/opfs_interop.dart Outdated
Comment thread packages/komodo_defi_types/lib/src/utils/mnemonic_validator.dart
Comment thread packages/komodo_defi_types/lib/src/utils/mnemonic_validator.dart
@CharlVS CharlVS changed the title feat(dragon_logs): add OPFS interop extensions and consolidate web storage implementations feat: add Flutter Web WASM support with OPFS interop extensions Aug 5, 2025
This commit implements comprehensive Flutter Web WASM support by:

- Adding opfs_interop.dart with FileSystemDirectoryHandle extensions for values(), keys(), and entries() methods
- Implementing JSAsyncIterator type definitions for proper JavaScript interop
- Creating WebLogStorageWasm implementation compatible with both JS and WASM targets
- Consolidating platform implementations to use unified WASM-compatible storage
- Removing redundant WebLogStorage in favor of cross-compatible implementation
- Updating platform configuration files for seamless WASM integration

The implementation provides backwards compatibility with JavaScript compilation while
enabling full WASM support through browser File System APIs that work consistently
across both compilation targets.

BREAKING CHANGE: WebLogStorage class has been removed in favor of WebLogStorageWasm
@CharlVS CharlVS force-pushed the add/flutter-web-wasm branch from 3a1e088 to 77ff4b2 Compare August 5, 2025 19:30
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Aug 5, 2025

Visit the preview URL for this PR (updated for commit 2b09291):

https://komodo-defi-sdk--pr176-add-flutter-web-wasm-7cn7n15g.web.app

(expires Tue, 12 Aug 2025 23:00:17 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 7f9f5ac39928f333b6e8fcefb7138575e24ed347

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Add GitHub authentication token support across all components that make
GitHub API requests to resolve rate limiting issues during builds.

Changes:
- feat(coin-updates): add githubToken parameter to CoinConfigProvider
- feat(coin-updates): support GitHub auth in CoinConfigRepository.withDefaults
- fix(build-transformer): add debug logging for GitHub API authentication
- fix(wallet-cli): auto-use GITHUB_API_PUBLIC_READONLY_TOKEN env variable
- style(build-transformer): fix lint issues with cascade operations

The CoinConfigProvider was making unauthenticated GitHub API requests,
contributing to rate limit errors. All GitHub API clients now properly
use the GITHUB_API_PUBLIC_READONLY_TOKEN environment variable when
available, increasing rate limits from 60 to 5,000 requests per hour.

Fixes: Rate limit exceeded errors during build process
@CharlVS CharlVS force-pushed the add/flutter-web-wasm branch from cc7db0d to 5c27d5a Compare August 5, 2025 22:44
CharlVS added 2 commits August 6, 2025 00:52
Roll KDF to the latest `dev` to ensure we are using the latest revision of all unreleased features.
@CharlVS CharlVS merged commit 62b919f into dev Aug 5, 2025
6 of 8 checks passed
@CharlVS CharlVS deleted the add/flutter-web-wasm branch August 5, 2025 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants