-
Notifications
You must be signed in to change notification settings - Fork 53
Refactor sheet presentation logic in wallet scene #1026
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
Conversation
Introduced WalletSceneSheetType to unify and simplify sheet presentation state management in WalletSceneViewModel. Updated WalletNavigationStack to use the new enum for presenting sheets, reducing multiple state variables to a single source of truth and improving code maintainability.
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.
Summary of Changes
Hello @gemdev111, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refactors the sheet presentation logic within the Wallet scene. By introducing a new WalletSceneSheetType
enum, the change unifies how different types of sheets are managed and presented, moving from multiple independent state variables to a single, consolidated source of truth. This architectural improvement aims to simplify the codebase, enhance maintainability, and streamline the UI presentation logic for various wallet-related interactions.
Highlights
- Unified Sheet Presentation: Introduced a new
WalletSceneSheetType
enum to centralize and simplify the management of various sheet presentations within the Wallet scene, replacing multiple disparate state variables with a single, unified type. - Code Simplification: Consolidated multiple boolean and optional state variables (e.g.,
isPresentingWallets
,isPresentingSelectAssetType
,isPresentingInfoSheet
,isPresentingUrl
,isPresentingTransferData
,isPresentingPerpetualRecipientData
) inWalletSceneViewModel
into a singleisPresentingSheet: WalletSceneSheetType?
property. - UI Logic Streamlining: Refactored
WalletNavigationStack
to use a single.sheet
modifier that leverages aswitch
statement over theWalletSceneSheetType
enum, reducing redundant sheet modifiers and improving the clarity of UI presentation logic. - Enhanced Maintainability: Provided
Binding
extensions forBinding<WalletSceneSheetType?>
to allow seamless two-way binding with specific sheet data types, ensuring compatibility with existing UI components and improving overall code maintainability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request effectively refactors the sheet presentation logic in WalletSceneViewModel
by consolidating multiple state variables into a single WalletSceneSheetType
enum. This greatly improves maintainability and clarity.
My review has identified a critical compilation issue related to generating an ID for TransferData
, as well as some opportunities to improve the robustness of other sheet IDs and the cross-module visibility of helper properties. I've also suggested using a more type-safe binding helper for presenting the wallets sheet.
case let .selectAssetType(type): "select-asset-type-\(type.id)" | ||
case let .info(type): "info-\(type.id)" | ||
case let .url(url): "url-\(url)" | ||
case let .transferData(data): "transfer-data-\(data.id)" |
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.
The id
for the .transferData
case is constructed using data.id
, but the TransferData
type does not have an id
property and does not conform to Identifiable
. This will result in a compilation error.
Since TransferData
conforms to Hashable
, you can use data.hashValue
to generate a unique identifier. This avoids having to modify the TransferData
struct if that's outside the scope of this PR.
case let .transferData(data): "transfer-data-\(data.id)" | |
case let .transferData(data): "transfer-data-\(data.hashValue)" |
case let .info(type): "info-\(type.id)" | ||
case let .url(url): "url-\(url)" | ||
case let .transferData(data): "transfer-data-\(data.id)" | ||
case let .perpetualRecipientData(data): "perpetual-recipient-data-\(data.asset.id.identifier)" |
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.
The current id
for .perpetualRecipientData
only uses the asset's identifier. This may not be unique if sheets for different recipients can be presented for the same asset. The Identifiable
conformance on PerpetualRecipientData
itself also doesn't include the asset, so data.id
would also be insufficient if the asset is a distinguishing factor.
To ensure a unique ID for all properties of data
, it's safest to use its hash value, as PerpetualRecipientData
is Hashable
. This guarantees a unique ID for each distinct PerpetualRecipientData
value and makes it consistent with the proposed fix for .transferData
.
case let .perpetualRecipientData(data): "perpetual-recipient-data-\(data.asset.id.identifier)" | |
case let .perpetualRecipientData(data): "perpetual-recipient-data-\(data.hashValue)" |
) | ||
} | ||
|
||
var wallets: Binding<Bool> { |
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.
The wallets
computed property provides a convenient and type-safe Binding<Bool>
for the .wallets
sheet case. However, it's declared with internal
access. To be used from WalletNavigationStack
, which appears to be in a different module (Gem
), this property needs to be made public
.
var wallets: Binding<Bool> { | |
public var wallets: Binding<Bool> { |
case let .url(url): | ||
SFSafariView(url: url) | ||
case .wallets: | ||
WalletsNavigationStack(isPresentingWallets: $model.isPresentingSheet.mappedToBool()) |
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.
This code uses a mappedToBool()
function which is not defined in the pull request and is likely a generic conversion. It's safer and clearer to use the dedicated wallets
binding property you've defined on the Binding<WalletSceneSheetType?>
extension. It's specifically designed for this case and provides better type safety.
This change depends on the wallets
property being made public
, which I've commented on separately.
WalletsNavigationStack(isPresentingWallets: $model.isPresentingSheet.mappedToBool()) | |
WalletsNavigationStack(isPresentingWallets: $model.isPresentingSheet.wallets) |
Updated WalletSceneSheetType to use data.id for perpetualRecipientData and made the wallets binding public. Adjusted WalletNavigationStack to use the new wallets binding for presenting WalletsNavigationStack.
Added a new case for setPriceAlert in WalletSceneSheetType and updated related bindings. Refactored WalletSceneViewModel and WalletNavigationStack to use the unified sheet presentation for price alerts, removing the separate isPresentingSetPriceAlert property and sheet. This streamlines sheet management and improves code maintainability.
Introduced WalletSceneSheetType to unify and simplify sheet presentation state management in WalletSceneViewModel. Updated WalletNavigationStack to use the new enum for presenting sheets, reducing multiple state variables to a single source of truth and improving code maintainability.
closes #973