Add preferred chain ordering for swap receive search results#1805
Add preferred chain ordering for swap receive search results#1805
Conversation
Summary of ChangesHello, 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 enhances the asset selection experience within the swap feature by introducing a mechanism to prioritize search results based on a "preferred chain." When a user initiates a swap, the system will now intelligently suggest receive assets, giving precedence to those residing on the same blockchain as the asset being swapped from. This change aims to streamline the user workflow by presenting more relevant assets upfront, reducing the need for manual filtering or extensive searching. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a preferred chain ordering for swap receive search results. The changes are well-implemented across the view models, request objects, and data store. A preferredChain is now passed down to the AssetsRequest, which uses it to prioritize assets from that chain in search results. The implementation in the database query using a boolean-to-integer sort is clever and efficient. A new test case has been added to verify the basic functionality. My review includes a suggestion to refactor a nested switch for better readability and a recommendation to enhance test coverage for the new ordering logic.
| switch type { | ||
| case .swap(let swapType): | ||
| switch swapType { | ||
| case .receive(_, _, let chain): chain | ||
| case .pay: nil | ||
| } | ||
| case .send, .receive, .buy, .manage, .priceAlert, .deposit, .withdraw: nil | ||
| } |
There was a problem hiding this comment.
| @Test func testSearchPreferredChain() throws { | ||
| let assets: [AssetBasic] = .mock() + [.mock(asset: .mockTronUSDT())] | ||
| let db = DB.mockAssets(assets: assets) | ||
|
|
||
| try db.dbQueue.read { db in | ||
| let result = try AssetsRequest.mock( | ||
| filters: [.search("USDT", hasPriorityAssets: false)], | ||
| preferredChain: .tron | ||
| ).fetch(db) | ||
|
|
||
| #expect(result.first?.asset == .mockTronUSDT()) | ||
| } | ||
| } |
There was a problem hiding this comment.
This test is great for covering the hasPriorityAssets: false scenario. To ensure full coverage of the new logic, it would be beneficial to add another test case for when hasPriorityAssets is true. This would verify that the preferredChain ordering correctly interacts with the existing priority-based sorting, especially in cases where they might conflict.
Close: #1802