-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Conversation
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. |
WalkthroughThis pull request introduces several changes across the wallet application's codebase, focusing on error handling and project configuration. The modifications include updating the Changes
Sequence DiagramsequenceDiagram
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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- Make the class final to prevent inheritance
- Add documentation for the message and code fields
- 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
⛔ 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
There was a problem hiding this 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
andscaffoldKey
.
Currently, these fields are declared but not utilized. If you plan to display UI-based error handling (e.g., SnackBars, dialogs), integrate theScaffoldState
orBuildContext
inhandleError
, 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, replacedebugPrint
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
📒 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
, andbuild
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.
TheWalletKitError
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 makeaddAccount
asynchronous.
By returningFuture<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
There was a problem hiding this 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
📒 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
void handleError(WalletKitError error, BuildContext context) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('Failed to add account: $error')), | ||
); | ||
Navigator.of(context).pop(); | ||
} |
There was a problem hiding this comment.
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:
- The error message is hardcoded to "Failed to add account", which may not be appropriate for all error scenarios.
- 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.
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(); | |
} | |
} |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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')), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Demo video
https://www.loom.com/share/5f8e866cb9974befab37875340837c0c
Summary by CodeRabbit
Release Notes
New Features
WalletKitError
class for improved error handling.Bug Fixes
Chores
.gitignore
to exclude.build/
and.swiftpm/
directories.0.0.1
to0.0.3
.