Skip to content

Conversation

@0xAlunara
Copy link
Collaborator

@0xAlunara 0xAlunara commented Dec 13, 2025

Depends on #1763

In an effort to removing the user balances store slice and imperative userBalancesMapper usage, I found that aside from quickswap, the biggest user is the gauge reward feature. This PR aims to remove that dependency to rely solely on the new useTokenBalance from token-balance.query.

If you want to test, you can do so by using the 0xE13aDC278c252e04DCBdca8eDced2C973Db994fA address with this pool

(The feature is a bit crap in that sometimes it might detect you as a gauge manager, just refresh with a connected wallet sometimes; out of scope of this PR)

image

@vercel
Copy link

vercel bot commented Dec 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
curve-dapp Ready Ready Preview, Comment Dec 13, 2025 5:19pm
curve-dapp-storybook Ready Ready Preview, Comment Dec 13, 2025 5:19pm

const tokenBalance = userBalancesMapper[rewardTokenId]

if (!tokenBalance) return
enforce(userBalance).condition((userBalance) => ({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried something like userBalance.greaterThan(0) but it didn't show the message. This is a bit more verbose but at least it works

enforce(amount).condition((amount) => ({
pass: +amount < +tokenBalance,
message: t`Amount ${formatNumber(amount, { decimals: 5 })} > wallet balance ${formatNumber(tokenBalance, { decimals: 5 })}`,
pass: +amount <= +userBalance!,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fixes a bug where we used < instead of <=, so if you pressed the 'Max' button it would incorrectly give an error


// Sync userBalance from query into form for validation
useEffect(() => {
methods.setValue('userBalance', userBalance, { shouldValidate: true })
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Initially I looked at vest contexts together with react form hook, but that turned out to be a disaster as contexts aren't reactive. So I applied the same trick as we did for the new borrow form, just make the user balance part of the form values.

type="number"
labelProps={
haveSigner && {
signerAddress && {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We ought to replace InputDebounced with an LTI, but that's out of scope

@0xAlunara 0xAlunara changed the title refactor: remove user balance store dependency in deposit gauge reward validation refactor: remove user balance store dependency in deposit gauge reward feature Dec 13, 2025
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