refactor: extract getBestToken and align Predict payment token selection#28941
Draft
caieu wants to merge 2 commits into
Draft
refactor: extract getBestToken and align Predict payment token selection#28941caieu wants to merge 2 commits into
caieu wants to merge 2 commits into
Conversation
Extract the getBestToken ranking function from useAutomaticTransactionPayToken into a shared utility so usePredictDefaultPaymentToken can reuse the same priority chain (hardware wallet check, feature-flag preferred tokens sorted by success rate, minimum balance threshold) instead of naively picking the first token with any balance. Adds MINIMUM_PREDICT_BALANCE_FOR_BET ($1.05) to account for fees when deciding whether Predict balance suffices.
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Contributor
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - draft PR All E2E tests pre-selected. |
Contributor
|
✅ E2E Fixture Validation — Schema is up to date |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
The
getBestTokentoken-ranking logic was duplicated betweenuseAutomaticTransactionPayToken(confirmations pay flow) andusePredictDefaultPaymentToken(Predict buy screen). The Predict hook had its own inline selection algorithm that filtered by ERC20 standard, testnet status, and fiat balance — diverging from the shared pay flow's feature-flag-aware ranking (preferred tokens, success rates, minimum balance thresholds).This PR:
getBestTokeninto a standalone utility (confirmations/utils/getBestToken.ts) with its own comprehensive test suite (648 lines covering all ranking branches).usePredictDefaultPaymentTokento call the sharedgetBestTokeninstead of reimplementing token selection inline, bringing it in line withuseAutomaticTransactionPayTokenand gaining feature-flag-driven preferred-token ranking, minimum balance checks, and hardware-wallet handling for free.MINIMUM_PREDICT_BALANCE_FOR_BET(1.05) to account for combined fees (~$0.05 on a $1 bet) when deciding whether the Predict balance alone is sufficient.useAutomaticTransactionPayTokentests — token-ranking edge cases now live in thegetBestTokenunit tests, so the hook tests focus on integration behavior (callsgetBestToken, respectsdisable, re-selects on account change).Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist