fix: disable claim button while loading claim data after network switch#630
Open
DrGalio wants to merge 1 commit intoGoodDollar:masterfrom
Open
fix: disable claim button while loading claim data after network switch#630DrGalio wants to merge 1 commit intoGoodDollar:masterfrom
DrGalio wants to merge 1 commit intoGoodDollar:masterfrom
Conversation
When switching networks, the claim data (claimAmount, isWhitelisted) takes time to load from the blockchain. During this window, is set to , causing ClaimButton's internal to evaluate to (falsy), making the button appear clickable. This fix shows a loading spinner while , preventing users from clicking a non-functional button. The ClaimButton reappears once claim data is loaded. Fixes GoodDollar#614
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Using
claimed === undefinedas the loading condition couples UI state to a sentinel value; consider introducing an explicitisClaimLoadingflag (set in theuseEffectthat resetsclaimed) to make the loading state clearer and less fragile to future changes in howclaimedis managed. - Instead of completely swapping the
ClaimButtonfor a centered spinner (which changes layout and removes the primary action from the tree), you might keep the button rendered and leverage any built-inloading/disabledmechanisms onClaimButtonwhile overlaying or embedding a spinner to minimize layout shift and keep the click target location stable.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using `claimed === undefined` as the loading condition couples UI state to a sentinel value; consider introducing an explicit `isClaimLoading` flag (set in the `useEffect` that resets `claimed`) to make the loading state clearer and less fragile to future changes in how `claimed` is managed.
- Instead of completely swapping the `ClaimButton` for a centered spinner (which changes layout and removes the primary action from the tree), you might keep the button rendered and leverage any built-in `loading`/`disabled` mechanisms on `ClaimButton` while overlaying or embedding a spinner to minimize layout shift and keep the click target location stable.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Collaborator
|
Hey, since it's your first time contributing, make sure you are aware of our contribution-guidelines. Its also the practice when working on our repo's that you ask to get assigned a ticket, not randomely push fixes. Thanks in advance! (for now you are assigned) |
Collaborator
|
@DrGalio Hey, I hope you read the contribution guidelines. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When switching networks, the claim button appears clickable (blue, showing "CLAIM NOW") even though claim data hasn't loaded yet. Pressing it does nothing because the underlying blockchain calls haven't completed.
Root cause: In
OldClaim.tsx, when the chain ID changes,claimedis set toundefinedwhile claim data loads:The
ClaimButtoncomponent from@gooddollar/good-designusesdisabled={claimed}. Whenclaimed === undefined, this evaluates todisabled={undefined}(falsy), leaving the button enabled during loading.Solution
Show a loading spinner while
claimed === undefined(data loading state), and render theClaimButtononly when claim data has loaded (claimedistrueorfalse).Changes
Spinnerimport fromnative-baseClaimButtonwith conditional rendering: show spinner when loading, button when readyTesting
Fixes #614
Summary by Sourcery
Bug Fixes: