Skip to content

Conversation

@DukeDeSouth
Copy link

@DukeDeSouth DukeDeSouth commented Feb 9, 2026

Summary

Fixes #614

When switching networks (e.g., from CELO to XDC), the claimed state resets to undefined while new claim data loads from the smart contract. The existing render logic used claimed ? <ClaimBalance> : <ClaimButton>, which treated undefined as falsy — rendering an active, blue "Claim Now" button that does nothing when clicked.

Root Cause

claimed is typed as boolean | undefined. JavaScript's falsy evaluation in the ternary operator doesn't distinguish between false (data loaded, user hasn't claimed) and undefined (data still loading).

Fix

Added an explicit claimed === undefined check before the existing ternary to display a loading Spinner (using the existing variant="page-loader" pattern from the codebase) until claim data is available.

Before:

{claimed ? <ClaimBalance /> : <ClaimButton />}

After:

{claimed === undefined ? <Spinner /> : claimed ? <ClaimBalance /> : <ClaimButton />}

Changes

  • src/pages/gd/Claim/OldClaim.tsx: Added Spinner to native-base import, added loading state guard (6 lines changed)

Test Plan

  • Switch from CELO to XDC network — verify spinner shows instead of clickable button
  • Wait for claim data to load — verify button appears correctly after loading
  • Claim with amount > 0 — verify ClaimButton works
  • Claim with amount = 0 — verify ClaimBalance shows
  • Initial page load — verify spinner shows until data loads
  • After successful claim — verify ClaimBalance shows

Made with Cursor

Summary by Sourcery

Bug Fixes:

  • Prevent an inactive claim button from rendering while claim status is still loading by showing a loading spinner instead.

…ta fetch

When switching networks, `claimed` state resets to `undefined` while new
claim data loads from the smart contract. The existing ternary treated
`undefined` as falsy, rendering an active ClaimButton that does nothing.

Added explicit `claimed === undefined` check to display a loading Spinner
(matching existing codebase pattern) until claim data is available.

Fixes GoodDollar#614

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link

@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:

  • The nested ternary for claimed === undefined ? ... : claimed ? ... : ... is getting a bit hard to read; consider extracting this into a small helper/component or using early returns so each state (loading / claimed / unclaimed) is rendered via clearer conditional blocks.
  • Relying on claimed === undefined as an implicit loading flag couples the data shape to UI state; if possible, consider introducing an explicit isLoadingClaim (or similar) flag from the data-fetching hook to decouple loading from the claimed tri-state.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The nested ternary for `claimed === undefined ? ... : claimed ? ... : ...` is getting a bit hard to read; consider extracting this into a small helper/component or using early returns so each state (loading / claimed / unclaimed) is rendered via clearer conditional blocks.
- Relying on `claimed === undefined` as an implicit loading flag couples the data shape to UI state; if possible, consider introducing an explicit `isLoadingClaim` (or similar) flag from the data-fetching hook to decouple loading from the `claimed` tri-state.

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.

@sirpy
Copy link
Contributor

sirpy commented Feb 11, 2026

@DukeDeSouth please ask for review when you are done
also please submit images or video showing the fix
i've approved the deployment branch

@sirpy sirpy self-requested a review February 11, 2026 14:15
@sirpy
Copy link
Contributor

sirpy commented Feb 11, 2026

@DukeDeSouth also you need to ask to be assigned in #614 so we can assign it to your username

Copy link
Contributor

@sirpy sirpy left a comment

Choose a reason for hiding this comment

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

please provide a video showing how it works
and i'll approve
thanks

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