Skip to content
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

feat: adding error display feature #436

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

Hoossayn
Copy link

@Hoossayn Hoossayn commented Jan 9, 2025

Demo video

https://www.loom.com/share/5f8e866cb9974befab37875340837c0c

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new WalletKitError class for improved error handling.
    • Enhanced account addition process with more robust error management.
    • Added a new error handler initialization in the application.
  • Bug Fixes

    • Improved error handling in wallet account creation workflow.
    • Added user-friendly error notifications during account addition.
  • Chores

    • Updated .gitignore to exclude .build/ and .swiftpm/ directories.
    • Updated environment variables for Flutter configuration, reflecting new SDK paths and version increments.
    • Modified plugin registration in the project for consistency.
    • Incremented build version from 0.0.1 to 0.0.3.

Copy link

docs-page bot commented Jan 9, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/focustree/starknet.dart~436

Documentation is deployed and generated using docs.page.

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces several changes across the wallet application's codebase, focusing on error handling and project configuration. The modifications include updating the .gitignore file with new build-related entries, enhancing error management in the wallet state management, introducing a new WalletKitError class, and improving error handling in the wallet list widget. Additionally, environment variables related to the Flutter SDK paths and build configurations have been updated. These changes aim to provide more robust error handling and better project structure for the wallet application.

Changes

File Change Summary
examples/wallet_app/.gitignore Added .build/ and .swiftpm/ to ignore build-related directories
packages/secure_store/lib/src/password_store.dart Removed error handling in getSecret method, simplifying decryption process
packages/wallet_kit/lib/errors/index.dart Added export for wallet_kit_error.dart
packages/wallet_kit/lib/errors/wallet_kit_error.dart Introduced new WalletKitErrorHandler and WalletKitError classes for error management
packages/wallet_kit/lib/wallet_state/wallet_provider.dart Updated addAccount method to be asynchronous and improve error handling
packages/wallet_kit/lib/widgets/wallet_list.dart Modified onPressed callback to decouple account addition from navigation
examples/wallet_app/lib/main.dart Added initialization for WalletKitErrorHandler in the app's build method
melos_monorepo.iml Added exclusions for .dart_tool, .pub, and build directories
packages/wallet_kit/ios/Flutter/Generated.xcconfig Updated FLUTTER_ROOT, FLUTTER_APPLICATION_PATH, FLUTTER_BUILD_NAME, and FLUTTER_BUILD_NUMBER
packages/wallet_kit/ios/Flutter/flutter_export_environment.sh Updated environment variables for Flutter configuration
packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig Updated FLUTTER_ROOT, FLUTTER_APPLICATION_PATH, FLUTTER_BUILD_NAME, and FLUTTER_BUILD_NUMBER
packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh Updated environment variables for Flutter configuration
examples/wallet_app/macos/Flutter/GeneratedPluginRegistrant.swift Updated registration for the web view plugin to FLTWebViewFlutterPlugin

Sequence Diagram

sequenceDiagram
    participant User
    participant WalletList
    participant WalletProvider
    participant SecureStore

    User->>WalletList: Select Add Account
    WalletList->>WalletProvider: addAccount()
    WalletProvider->>SecureStore: Retrieve Seed Phrase
    alt Successful Retrieval
        WalletProvider-->>WalletList: Account Added
        WalletList->>User: Continue without Navigation
    else Error Occurs
        WalletProvider-->>WalletList: Throw WalletKitError
        WalletList->>User: Display SnackBar with Error
    end
Loading

Poem

🐰 A Rabbit's Ode to Error Handling 🔧
In wallet's realm, where secrets hide,
Errors dance, no more to slide
With WalletKitError's gentle might
We catch the bugs and set things right!
Hop, hop, hurray! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b06699e and c34e7fa.

📒 Files selected for processing (5)
  • packages/secure_store/lib/src/password_store.dart (1 hunks)
  • packages/wallet_kit/lib/errors/index.dart (1 hunks)
  • packages/wallet_kit/lib/errors/wallet_kit_error.dart (1 hunks)
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart (3 hunks)
  • packages/wallet_kit/lib/widgets/wallet_list.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/wallet_kit/lib/errors/index.dart
  • packages/wallet_kit/lib/errors/wallet_kit_error.dart
  • packages/wallet_kit/lib/widgets/wallet_list.dart
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

@Hoossayn Hoossayn requested a review from ptisserand January 13, 2025 15:01
@Hoossayn Hoossayn marked this pull request as ready for review January 13, 2025 15:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)

1-9: Consider enhancing the error class implementation.

The error class could benefit from the following improvements:

  1. Make the class final to prevent inheritance
  2. Add documentation for the message and code fields
  3. Consider adding error codes as constants for common errors
+/// Represents errors that occur during wallet operations.
+/// 
+/// The [message] provides a human-readable description of the error.
+/// The [code] can be used to identify specific error types programmatically.
-class WalletKitError implements Exception {
+final class WalletKitError implements Exception {
   final String message;
+  /// Optional error code for programmatic error handling.
+  /// Positive integers are reserved for system use.
   final int? code;

   WalletKitError(this.message, {this.code});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97c67ed and d770f22.

⛔ Files ignored due to path filters (1)
  • examples/wallet_app/ios/Podfile.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • examples/wallet_app/.gitignore (1 hunks)
  • packages/secure_store/lib/src/password_store.dart (1 hunks)
  • packages/wallet_kit/lib/errors/index.dart (1 hunks)
  • packages/wallet_kit/lib/errors/wallet_kit_error.dart (1 hunks)
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart (3 hunks)
  • packages/wallet_kit/lib/widgets/wallet_list.dart (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/wallet_kit/lib/errors/index.dart
🔇 Additional comments (1)
examples/wallet_app/.gitignore (1)

8-8: LGTM! Appropriate additions for Swift/SPM projects.

The new entries .build/ and .swiftpm/ are standard ignore patterns for Swift and Swift Package Manager projects. These directories contain build artifacts and project-specific metadata that should not be version controlled.

Also applies to: 12-12

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/wallet_kit/lib/errors/wallet_kit_error.dart (2)

3-8: Consider clarifying the purpose and usage of _context and scaffoldKey.
Currently, these fields are declared but not utilized. If you plan to display UI-based error handling (e.g., SnackBars, dialogs), integrate the ScaffoldState or BuildContext in handleError, or remove them if they are not needed.


16-19: Refine logging statement.
The string "WalleeeeetKit Error" appears to contain repeated letters. Consider ensuring consistency before shipping to end users. Also, replace print with debugPrint or a logger package for better debugging control.

- print("WalleeeeetKit Error: $error");
+ debugPrint("WalletKitError: $error");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d770f22 and 2774ec3.

📒 Files selected for processing (9)
  • examples/wallet_app/lib/main.dart (2 hunks)
  • melos_monorepo.iml (1 hunks)
  • packages/wallet_kit/ios/Flutter/Generated.xcconfig (1 hunks)
  • packages/wallet_kit/ios/Flutter/flutter_export_environment.sh (1 hunks)
  • packages/wallet_kit/lib/errors/wallet_kit_error.dart (1 hunks)
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart (3 hunks)
  • packages/wallet_kit/lib/widgets/wallet_list.dart (1 hunks)
  • packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig (1 hunks)
  • packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/wallet_kit/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
  • packages/wallet_kit/ios/Flutter/flutter_export_environment.sh
  • packages/wallet_kit/ios/Flutter/Generated.xcconfig
  • packages/wallet_kit/macos/Flutter/ephemeral/flutter_export_environment.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/wallet_kit/lib/widgets/wallet_list.dart
🔇 Additional comments (4)
melos_monorepo.iml (1)

7-9: LGTM! Standard exclusions for Dart/Flutter projects.

The added exclusions for .dart_tool, .pub, and build directories follow best practices for Dart/Flutter projects. These directories contain generated files and caches that should not be indexed by the IDE.

packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)

22-30: Good introduction of a custom exception class.
The WalletKitError class is straightforward and enables passing both a message and a code. This design simplifies structured error reporting.

packages/wallet_kit/lib/wallet_state/wallet_provider.dart (2)

49-49: Excellent decision to make addAccount asynchronous.
By returning Future<void>, external callers can properly await for its completion and handle related exceptions.


63-79: Enhance error message granularity.
This catch block throws a single “Wrong password” message for all errors. If the issue is that the seed phrase was never created or there's a different decryption error, the user still sees “Wrong password.” Consider passing the original error or differentiating the error cases for more precise feedback.

} catch (e) {
-  final error = WalletKitError("Wrong password");
-  WalletKitErrorHandler().handleError(error);
+  if (e.toString().contains('decrypt')) {
+    WalletKitErrorHandler().handleError(WalletKitError("Wrong password"));
+  } else {
+    WalletKitErrorHandler().handleError(WalletKitError("Failed to add account: ${e.toString()}"));
+  }
}

# Conflicts:
#	examples/wallet_app/lib/main.dart
#	packages/wallet_kit/lib/wallet_state/wallet_provider.dart
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 810c56f and b06699e.

📒 Files selected for processing (5)
  • examples/wallet_app/lib/main.dart (1 hunks)
  • examples/wallet_app/macos/Flutter/GeneratedPluginRegistrant.swift (1 hunks)
  • packages/wallet_kit/lib/errors/wallet_kit_error.dart (1 hunks)
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart (3 hunks)
  • packages/wallet_kit/lib/widgets/wallet_list.dart (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/wallet_kit/lib/widgets/wallet_list.dart
  • examples/wallet_app/lib/main.dart
  • packages/wallet_kit/lib/wallet_state/wallet_provider.dart
🔇 Additional comments (2)
examples/wallet_app/macos/Flutter/GeneratedPluginRegistrant.swift (1)

1-16: Skip reviewing generated file.

This is an auto-generated file that should not be manually edited. The changes appear to be automatically generated, likely due to a plugin update.

packages/wallet_kit/lib/errors/wallet_kit_error.dart (1)

18-26: LGTM! Well-structured error class implementation.

The WalletKitError class is well-designed with:

  • Clear separation of required and optional parameters
  • Clean toString() implementation for error formatting
  • Proper Exception interface implementation

Comment on lines +10 to +15
void handleError(WalletKitError error, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to add account: $error')),
);
Navigator.of(context).pop();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Make error handling more robust and generic.

The current implementation has two issues:

  1. The error message is hardcoded to "Failed to add account", which may not be appropriate for all error scenarios.
  2. Unconditionally popping the navigation stack could crash the app if called from the root route.

Apply this diff to make the error handling more robust:

   void handleError(WalletKitError error, BuildContext context) {
     ScaffoldMessenger.of(context).showSnackBar(
-      SnackBar(content: Text('Failed to add account: $error')),
+      SnackBar(content: Text('$error')),
     );
-    Navigator.of(context).pop();
+    if (Navigator.of(context).canPop()) {
+      Navigator.of(context).pop();
+    }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
void handleError(WalletKitError error, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to add account: $error')),
);
Navigator.of(context).pop();
}
void handleError(WalletKitError error, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('$error')),
);
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}

Copy link
Collaborator

@ptisserand ptisserand left a comment

Choose a reason for hiding this comment

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

Thanks for your contributions!
I really like to have a default error handler but I'm concerned about how a developer can easily customized this behavior without wallet_kit source code modifications.

Why not using notifier instead of a callback ?

Navigator.of(context).pop();
walletId: wallet.id,
getPassword: () => showPasswordModal(context),
context: context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you remove the Navigator.of(context).pop(), the wallet popup will still be displayed after successfully adding an account.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please remove this change

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please remove this change


void handleError(WalletKitError error, BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to add account: $error')),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error message should not be prefixed by 'Failed to add account'

} catch (e) {
final error = WalletKitError("Wrong password");
if (context.mounted) {
WalletKitErrorHandler().handleError(error, context);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How could an application customize error handling in this case ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please remove this change

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please remove this change

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.

2 participants