Skip to content

[SDK] Preload wallet balances on pay embed #7034

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 1 commit into from
May 13, 2025

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 13, 2025

Fixes TOOL-4477


PR-Codex overview

This PR focuses on preloading wallet balances in the BuyScreen component by introducing a new hook, useWalletsAndBalances, which enhances the user experience by fetching wallet balances more efficiently.

Detailed summary

  • Added useWalletsAndBalances hook in fetchBalancesForWallet.tsx.
  • Replaced the previous balance fetching logic in TokenSelectorScreen.tsx with the new hook.
  • Preloaded wallet balances in BuyScreenContent using useWalletsAndBalances.
  • Removed the old balance fetching code and related imports.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented May 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 3:54am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 3:54am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 3:54am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 3:54am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 3:54am

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 13, 2025
Copy link

linear bot commented May 13, 2025

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

github-actions bot commented May 13, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 54.21 KB (-0.02% 🔽) 1.1 s (-0.02% 🔽) 218 ms (+110.05% 🔺) 1.4 s
thirdweb (cjs) 193.92 KB (0%) 3.9 s (0%) 447 ms (+13.27% 🔺) 4.4 s
thirdweb (minimal + tree-shaking) 5.68 KB (0%) 114 ms (0%) 95 ms (+1329.64% 🔺) 208 ms
thirdweb/chains (tree-shaking) 524 B (0%) 11 ms (0%) 19 ms (+719.03% 🔺) 29 ms
thirdweb/react (minimal + tree-shaking) 19.53 KB (0%) 391 ms (0%) 80 ms (+381.01% 🔺) 471 ms

Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: f1a32d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 8.57143% with 64 lines in your changes missing coverage. Please review.

Project coverage is 54.89%. Comparing base (1985de8) to head (f1a32d1).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...Wallet/screens/Buy/swap/fetchBalancesForWallet.tsx 8.92% 51 Missing ⚠️
...act/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx 12.50% 7 Missing ⚠️
...ectWallet/screens/Buy/swap/TokenSelectorScreen.tsx 0.00% 6 Missing ⚠️

❌ Your patch status has failed because the patch coverage (8.57%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7034      +/-   ##
==========================================
- Coverage   54.90%   54.89%   -0.02%     
==========================================
  Files         909      909              
  Lines       58374    58396      +22     
  Branches     4034     4035       +1     
==========================================
+ Hits        32051    32056       +5     
- Misses      26218    26235      +17     
  Partials      105      105              
Flag Coverage Δ
packages 54.89% <8.57%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
...ectWallet/screens/Buy/swap/TokenSelectorScreen.tsx 6.94% <0.00%> (+0.36%) ⬆️
...act/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx 4.77% <12.50%> (+0.07%) ⬆️
...Wallet/screens/Buy/swap/fetchBalancesForWallet.tsx 6.28% <8.92%> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges force-pushed the Preload_wallet_balances_on_pay_embed branch from a9e3693 to f1a32d1 Compare May 13, 2025 03:46
Comment on lines +215 to +217
? !(
mode === "fund_wallet" && account.address === accountAddress
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic for including tokens has been modified when removing the tokenAmount parameter. Previously, tokens were included if their balance exceeded the specified amount, but now they're included regardless of balance when not in fund_wallet mode or when addresses don't match. This change could result in displaying tokens with insufficient balances to users.

Consider whether this behavior change is intentional, as it might affect user experience by showing tokens that can't actually be used for the intended transaction. If this is intentional, perhaps add a comment explaining the rationale for this change.

Suggested change
? !(
mode === "fund_wallet" && account.address === accountAddress
)
? !(
(mode === "fund_wallet" && account.address === accountAddress) ||
token.balance.lte(0) // Only include tokens with positive balances
)

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Member

Choose a reason for hiding this comment

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

Is this right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think it's Worth the tradeoff to not have to reload the entire thing when you change the amount. That way every token has the same behavior: if you have any in your wallet, it shows

Comment on lines +215 to +217
? !(
mode === "fund_wallet" && account.address === accountAddress
)
Copy link
Member

Choose a reason for hiding this comment

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

Is this right?

@joaquim-verges joaquim-verges changed the title Preload wallet balances on pay embed [SDK] Preload wallet balances on pay embed May 13, 2025
@joaquim-verges joaquim-verges merged commit fc65350 into main May 13, 2025
23 of 24 checks passed
@joaquim-verges joaquim-verges deleted the Preload_wallet_balances_on_pay_embed branch May 13, 2025 05:08
@joaquim-verges joaquim-verges mentioned this pull request May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants