Skip to content

Comments

fix: single-sided liquidity max button uses stale balance#4226

Closed
JohnnyWyles wants to merge 2 commits intostagefrom
jw/maxupdate
Closed

fix: single-sided liquidity max button uses stale balance#4226
JohnnyWyles wants to merge 2 commits intostagefrom
jw/maxupdate

Conversation

@JohnnyWyles
Copy link
Collaborator

What is the purpose of the change:

Fixed issue where clicking max button in single-sided liquidity mode would use stale balance value instead of querying fresh balance.

Linear Task

https://linear.app/osmosis/issue/FE-1554/max-button-for-single-sided-add-liquidity-not-displaying-correct-value

Brief Changelog

  • Query current balance from _queryBalances instead of reading config.amount
  • Ensures max button always uses latest balance matching the displayed value

Testing and Verifying

This change has been tested locally by rebuilding the website and verified content and links are expected

Fixed issue where clicking max button in single-sided liquidity mode
would use stale balance value instead of querying fresh balance.

- Query current balance from _queryBalances instead of reading config.amount
- Ensures max button always uses latest balance matching the displayed value

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Nov 19, 2025

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

Project Deployment Preview Comments Updated (UTC)
osmosis-frontend Ready Ready Preview Comment Nov 19, 2025 1:14pm
4 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
osmosis-frontend-datadog Ignored Ignored Nov 19, 2025 1:14pm
osmosis-frontend-dev Ignored Ignored Nov 19, 2025 1:14pm
osmosis-frontend-edgenet Ignored Ignored Nov 19, 2025 1:14pm
osmosis-testnet Ignored Ignored Nov 19, 2025 1:14pm

@JohnnyWyles JohnnyWyles marked this pull request as ready for review November 19, 2025 12:51
@JohnnyWyles
Copy link
Collaborator Author

How to test:

  • Open liquidity add modal in an out of range position cl pool
  • Select max assets
  • In another tab, swap into this asset to increase the balance
  • In the tab with add liquidity, clicking the max should increase the balance in the input box (this previously was not the case)
  • Max displayed in blue should increase in both the current and proposed frontends, assuming the same frontend was used for the swap.

@JohnnyWyles JohnnyWyles requested a review from jasbanza November 19, 2025 12:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

In single-amount-in mode, ObservableAddLiquidityConfig.setMax now fetches a fresh on-chain balance for the sender's selected sendCurrency and uses that balance (via setAmountAt with isMax=true) instead of using the stored config.amount.

Changes

Cohort / File(s) Summary
setMax balance fetching
packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts
Modified setMax to query a fresh on-chain balance for the sender's selected sendCurrency in single-amount-in mode, then call setAmountAt(index, balance.toDec().toString(), { isMax: true }) instead of using config.amount. Mark/unmark max flag flow remains.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Caller (UI)
    participant Config as ObservableAddLiquidityConfig
    participant Balance as BalanceService

    UI->>Config: setMax(index)
    Config->>Config: mark config as max
    alt single-amount-in mode
        Config->>Balance: queryBalance(sender, sendCurrency)
        Balance-->>Config: Balance (bigint/Decimal)
        Config->>Config: format balance -> amountStr
        Config->>Config: setAmountAt(index, amountStr, {isMax: true})
    else other modes
        Config->>Config: use existing flow (no fresh balance)
    end
    Config->>Config: unmark config as max
    Config-->>UI: updated config state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify balance query uses correct account/sender and currency identifiers.
  • Confirm conversion/formatting (e.g., toDec().toString()) matches setAmountAt expectations and preserves precision.
  • Ensure this fresh-balance fetch occurs only in single-amount-in mode and does not introduce race conditions with concurrent state updates.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the max button in single-sided liquidity to use current balance instead of stale balance.
Description check ✅ Passed The description covers all template sections with clear context, including the purpose, linear task link, changelog, and testing verification details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jw/maxupdate

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 006f7cc and 7cd917d.

📒 Files selected for processing (1)
  • packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: staging
  • GitHub Check: wait-for-deployment
  • GitHub Check: test (22.x, bridge)
  • GitHub Check: test (22.x, unit)
  • GitHub Check: test (22.x, tx)
  • GitHub Check: test (22.x, proto-codecs)
  • GitHub Check: test (22.x, web)
  • GitHub Check: test (22.x, pools)
  • GitHub Check: test (22.x, stores)
  • GitHub Check: test (22.x, utils)
  • GitHub Check: test (22.x, web)
  • GitHub Check: test (22.x, bridge)
  • GitHub Check: test (22.x, math)
  • GitHub Check: test (22.x, pools)
  • GitHub Check: test (22.x, stores)
  • GitHub Check: test (22.x, server)
  • GitHub Check: lint-workspace
  • GitHub Check: test (22.x, utils)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Summary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf7ef2c and 006f7cc.

📒 Files selected for processing (1)
  • packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: greg-nagy
Repo: osmosis-labs/osmosis-frontend PR: 3954
File: packages/web/modals/review-order.tsx:132-136
Timestamp: 2024-11-15T10:08:23.742Z
Learning: In `packages/web/modals/review-order.tsx`, the calculation of `wouldExceedSpendLimit` in the `ReviewOrder` component handles optional chaining and null values correctly, and does not require providing default values to avoid potential `NaN` results.
📚 Learning: 2024-11-15T10:08:23.742Z
Learnt from: greg-nagy
Repo: osmosis-labs/osmosis-frontend PR: 3954
File: packages/web/modals/review-order.tsx:132-136
Timestamp: 2024-11-15T10:08:23.742Z
Learning: In `packages/web/modals/review-order.tsx`, the calculation of `wouldExceedSpendLimit` in the `ReviewOrder` component handles optional chaining and null values correctly, and does not require providing default values to avoid potential `NaN` results.

Applied to files:

  • packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts
📚 Learning: 2024-11-23T16:36:41.685Z
Learnt from: greg-nagy
Repo: osmosis-labs/osmosis-frontend PR: 3954
File: packages/web/components/alert/prettify.ts:43-44
Timestamp: 2024-11-23T16:36:41.685Z
Learning: In `packages/web/components/alert/prettify.ts`, when handling overspend error messages related to `uusdc`, assuming 6 decimal places is acceptable because `uusdc` uses 6 decimals.

Applied to files:

  • packages/stores/src/ui-config/manage-liquidity/add-liquidity.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary

@jasbanza
Copy link
Member

  1. So I made an out of range position, using all my available BTC.
  2. Went back to add to position
  3. Then opened another tab to buy more BTC.
  4. switched back to add position tab
  5. saw balance refreshed but clicking didn't fill it in.
  6. Refreshed, still couldn't select max

@JohnnyWyles
Copy link
Collaborator Author

  1. So I made an out of range position, using all my available BTC.
  2. Went back to add to position
  3. Then opened another tab to buy more BTC.
  4. switched back to add position tab
  5. saw balance refreshed but clicking didn't fill it in.
  6. Refreshed, still couldn't select max

Will sync another time on this - I tried doing the same with TON since I have an out of range position again now and it worked fine :/

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