Skip to content

Namadillo: Optimistically updating staking rewards balance #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2024

Conversation

pedrorezende
Copy link
Collaborator

When you claim rewards, the indexer will need to wait for the next block to sync the new amount. This process might take a few seconds, depending on network configuration. This PR sets the available rewards balance to zero as soon as the claim rewards success event gets fired.

Copy link
Collaborator

@euharrison euharrison left a comment

Choose a reason for hiding this comment

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

Nice!

};

useTransactionEventListener("Bond.Success", onBalanceUpdate);
useTransactionEventListener("Unbond.Success", onBalanceUpdate);
useTransactionEventListener("Withdraw.Success", onBalanceUpdate);
useTransactionEventListener("Redelegate.Success", onBalanceUpdate);
useTransactionEventListener("ClaimRewards.Success", onBalanceUpdate);
useTransactionEventListener("ClaimRewards.Success", onBalanceUpdate, [
account,
Copy link
Collaborator

@euharrison euharrison Sep 19, 2024

Choose a reason for hiding this comment

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

nice idea! I'm asking myself if this object changes for whatever reason and if we should use account?.address instead

@@ -159,3 +160,7 @@ export const createClaimAndStakeTx = async (
account.address
);
};

export const clearClaimRewards = (accountAddress: string): void => {
queryClient.setQueryData(["claim-rewards", accountAddress], () => ({}));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you try this as invalidateQueries https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation ? I think this is the "correct way" to clear queries for react-query

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually not. I'm overriding the result of the claim-rewards query, so no rewards are available :) . But maybe I can be more explicit on this. Will make a small change before merging

@pedrorezende pedrorezende merged commit 08a92cb into main Sep 19, 2024
10 checks passed
@pedrorezende pedrorezende deleted the namadillo/optimistic-updates-claims branch September 19, 2024 13:27
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.

2 participants