citycoins / ui

Basic UI components for interacting with the CityCoin contract. Requires Stacks Wallet for Web.
https://minecitycoins.com
GNU General Public License v3.0
28 stars 13 forks source link

🐞[BUG] mining claim state wrong if API call fails #157

Open whoabuddy opened 1 year ago

whoabuddy commented 1 year ago

Describe the bug

In the logic for claiming mining rewards, the UI checks both is-block-winner and can-claim-mining-reward to determine if the user can claim or not.

https://github.com/citycoins/ui/blob/4b05c7962a615e5bf05a9e45920975eb03394836/src/components/mining/ClaimMiningRewards.js#L95-L128

The related functions used in the citycoins lib for those checks returns undefined if the fetch is unsuccessful. The check for this incorrectly interprets false and undefined as the same state and informs the user they cannot claim when there is an error fetching the data.

https://github.com/citycoins/ui/blob/4b05c7962a615e5bf05a9e45920975eb03394836/src/lib/citycoins.js#L91-L111

To Reproduce

The incorrect state is intermittent depending on if the fetch to the API is successful or not, although it has been reported twice recently through Discord DMs.

Expected behavior

The state should indicate if there is a) a failure in the query or b) if the user is unable to claim.

This could likely be remedied by checking if the value is undefined or false and showing the appropriate state.

Additional context

This may apply to other parts of the logic in this component, and possibly other components.