Skip to content

feat(transaction-pay-controller): add optional getBalance callback for max-amount source-amount calculation - #9802

Draft
matthewwalsh0 wants to merge 4 commits into
mainfrom
feat/pay-get-balance-callback
Draft

feat(transaction-pay-controller): add optional getBalance callback for max-amount source-amount calculation#9802
matthewwalsh0 wants to merge 4 commits into
mainfrom
feat/pay-get-balance-callback

Conversation

@matthewwalsh0

Copy link
Copy Markdown
Member

Explanation

The pay controller's isMaxAmount logic hard-codes a token-balance lookup from paymentToken.balanceHuman/balanceRaw. This works for the standard flow, but alternate transaction types (perps, predict, money-account overrides, post-quote flows) source their balance differently. Previously this forced complex conditional logic to live outside the controller in mobile and other consumers.

This PR adds an optional, synchronous getBalance callback to TransactionPayControllerOptions. When supplied, it is called once per source-amount update (inside the existing immer state-update block) and its return value replaces the built-in token balance in both the standard and post-quote isMaxAmount branches. Returning undefined from the callback (or not providing it at all) falls back to the existing token-balance behaviour, preserving 100% backward compatibility.

The callback must be synchronous because updateSourceAmounts runs inside this.update() — an async version would require a larger refactor and is out of scope.

The PaymentOverride.MoneyAccount guard is preserved; it intentionally bypasses the max branch regardless of any override.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@matthewwalsh0
matthewwalsh0 force-pushed the feat/pay-get-balance-callback branch from ee37727 to bdb9609 Compare August 7, 2026 13:57
@matthewwalsh0
matthewwalsh0 force-pushed the feat/pay-get-balance-callback branch from c72dab9 to 6d62adf Compare August 7, 2026 15:26
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.

1 participant