Handle additional swapper errors in errorInfoAction#1634
Conversation
Extended errorInfoAction to handle InputAmountError by applying the minimum amount to the input model. Added applyMinAmount helper to update the input field based on the error context.
Summary of ChangesHello @DRadmir, 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 refines the error handling mechanism within the swap feature, particularly for scenarios where the input amount is invalid. By introducing a specific handler for input amount errors and automatically adjusting the input field to a valid minimum, the changes aim to guide users more effectively and prevent common transaction issues, leading to a smoother user experience. 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. 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
|
There was a problem hiding this comment.
Code Review
This pull request extends the errorInfoAction to handle InputAmountError by setting the minimum required amount in the input field. The implementation is straightforward with a new helper function applyMinAmount.
My review includes a suggestion to improve the robustness of this new error handling. By parsing the minAmount string earlier, we can ensure the action is only presented to the user when it's valid, and it also simplifies the new helper function. This will prevent a scenario where the user interacts with the error message but nothing happens.
| case .InputAmountError(let minAmount): | ||
| guard let minAmount, let fromAsset else { return nil } | ||
| return VoidAction { [weak self] in | ||
| self?.applyMinAmount(minAmount, asset: fromAsset.asset) | ||
| } |
There was a problem hiding this comment.
To improve robustness and avoid creating a VoidAction that does nothing if minAmount is not a valid number, it's better to parse minAmount into a BigInt here. This ensures that the action is only available when it's guaranteed to work.
You can then pass the BigInt value directly to applyMinAmount, which simplifies that function as well. I'll leave a corresponding suggestion on applyMinAmount.
| case .InputAmountError(let minAmount): | |
| guard let minAmount, let fromAsset else { return nil } | |
| return VoidAction { [weak self] in | |
| self?.applyMinAmount(minAmount, asset: fromAsset.asset) | |
| } | |
| case .InputAmountError(let minAmount): | |
| guard let minAmount, let value = BigInt(minAmount), let fromAsset else { return nil } | |
| return VoidAction { [weak self] in | |
| self?.applyMinAmount(value, asset: fromAsset.asset) | |
| } |
| private func applyMinAmount(_ minAmount: String, asset: Asset) { | ||
| guard let value = BigInt(minAmount) else { return } | ||
| amountInputModel.text = formatter.format(value: value, decimals: asset.decimals.asInt) | ||
| } |
There was a problem hiding this comment.
Following the suggestion to parse minAmount in errorInfoAction, this function can be simplified to accept a BigInt directly. This makes the function's responsibility clearer and removes the need for failable string parsing within it.
private func applyMinAmount(_ value: BigInt, asset: Asset) {
amountInputModel.text = formatter.format(value: value, decimals: asset.decimals.asInt)
}Introduces a localized 'Use Minimum Amount' button to the swap error section when the input amount is below the minimum. Updates SwapScene and SwapSceneViewModel to support the new action and adds translations for the button in all supported languages.
Extended errorInfoAction to handle InputAmountError by applying the minimum amount to the input model. Added applyMinAmount helper to update the input field based on the error context.