Skip to content

fix: disable claim button while loading claim data after network switch#630

Open
DrGalio wants to merge 1 commit intoGoodDollar:masterfrom
DrGalio:fix/claim-button-loading-state
Open

fix: disable claim button while loading claim data after network switch#630
DrGalio wants to merge 1 commit intoGoodDollar:masterfrom
DrGalio:fix/claim-button-loading-state

Conversation

@DrGalio
Copy link
Copy Markdown

@DrGalio DrGalio commented Mar 25, 2026

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, claimed is set to undefined while claim data loads:

useEffect(() => {
    setClaimed(undefined)
    setRefreshRate('everyBlock')
}, [chainId])

The ClaimButton component from @gooddollar/good-design uses disabled={claimed}. When claimed === undefined, this evaluates to disabled={undefined} (falsy), leaving the button enabled during loading.

Solution

Show a loading spinner while claimed === undefined (data loading state), and render the ClaimButton only when claim data has loaded (claimed is true or false).

Changes

  • Added Spinner import from native-base
  • Wrapped ClaimButton with conditional rendering: show spinner when loading, button when ready

Testing

  1. Connect wallet on one network (e.g., Celo)
  2. Switch to another network (e.g., XDC)
  3. Observe: spinner appears instead of clickable button
  4. Once claim data loads, button appears with correct amount

Fixes #614

Summary by Sourcery

Bug Fixes:

  • Prevent the claim button from appearing clickable while claim data is still loading by showing a spinner until the claimed state is resolved.

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
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@L03TJ3
Copy link
Copy Markdown
Collaborator

L03TJ3 commented Mar 26, 2026

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)
@DrGalio

@L03TJ3
Copy link
Copy Markdown
Collaborator

L03TJ3 commented Mar 30, 2026

@DrGalio Hey, I hope you read the contribution guidelines.
Can you provide a demo-video of it working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: claim button appears clickable while loading claim data

2 participants