Skip to content
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

chore: fetch wallet images only when modal is open #3760

Merged
merged 19 commits into from
Feb 4, 2025

Conversation

magiziz
Copy link
Contributor

@magiziz magiziz commented Jan 29, 2025

Description

We now fetch wallet images when modal is open instead of fetching them during page load.

Type of change

  • Chore (non-breaking change that addresses non-functional tasks, maintenance, or code quality improvements)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Associated Issues

For Linear issues: Closes APKT-xxx
For GH issues: closes #...

Showcase (Optional)

prefetch.mov

Checklist

  • Code in this PR is covered by automated tests (Unit tests, E2E tests)
  • My changes generate no new warnings
  • I have reviewed my own code
  • I have filled out all required sections
  • I have tested my changes on the preview link
  • Approver of this PR confirms that the changes are tested on the preview link

Copy link

changeset-bot bot commented Jan 29, 2025

🦋 Changeset detected

Latest commit: 0c5bfa5

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

This PR includes changesets to release 19 packages
Name Type
@reown/appkit-scaffold-ui Patch
@reown/appkit-core Patch
@reown/appkit-adapter-bitcoin Patch
@reown/appkit-adapter-ethers Patch
@reown/appkit-adapter-ethers5 Patch
@reown/appkit-adapter-solana Patch
@reown/appkit-adapter-wagmi Patch
@reown/appkit Patch
@reown/appkit-utils Patch
@reown/appkit-cdn Patch
@reown/appkit-cli Patch
@reown/appkit-common Patch
@reown/appkit-experimental Patch
@reown/appkit-polyfills Patch
@reown/appkit-siwe Patch
@reown/appkit-siwx Patch
@reown/appkit-ui Patch
@reown/appkit-wallet Patch
@reown/appkit-wallet-button 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

vercel bot commented Jan 29, 2025

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

Name Status Preview Comments Updated (UTC)
appkit-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 11:33am
appkit-laboratory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 11:33am
9 Skipped Deployments
Name Status Preview Comments Updated (UTC)
appkit-basic-ep ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 11:33am
appkit-basic-ep-example ⬜️ Ignored (Inspect) Feb 4, 2025 11:33am
appkit-basic-example ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 11:33am
appkit-basic-sign-client-example ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 11:33am
appkit-basic-up-example ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 11:33am
appkit-vue-solana ⬜️ Ignored (Inspect) Feb 4, 2025 11:33am
appkit-wagmi-cdn-example ⬜️ Ignored (Inspect) Feb 4, 2025 11:33am
ethereum-provider-wagmi-example ⬜️ Ignored (Inspect) Feb 4, 2025 11:33am
vue-wagmi-example ⬜️ Ignored (Inspect) Feb 4, 2025 11:33am

@magiziz magiziz requested review from tomiir and enesozturk January 29, 2025 14:38
@magiziz magiziz changed the title chore: fetch wallet images when modal is open chore: fetch wallet images only when modal is open Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 68.59% 19863 / 28957
🔵 Statements 68.59% 19863 / 28957
🔵 Functions 59.81% 1740 / 2909
🔵 Branches 80.04% 3558 / 4445
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/controllers/ApiController.ts 92.27% 70.9% 84.61% 92.27% 74-75, 136, 149, 186-187, 274-280, 290-295
packages/core/src/utils/AssetUtil.ts 83.56% 92.5% 86.66% 83.56% 21-22, 34-42, 79-80, 98-99
packages/scaffold-ui/src/modal/w3m-modal/index.ts 90.5% 89.47% 95.23% 90.5% 73-74, 96, 100, 127, 179, 197-205, 228-229
packages/scaffold-ui/src/partials/w3m-account-wallet-features-widget/index.ts 63.47% 62.79% 65% 63.47% 59, 62-70, 80-82, 118, 123, 133-134, 148, 151, 158-159, 169, 180-189, 196-197, 208, 219-227, 249-250, 252-253, 255-256, 263-267, 273-274, 287-288, 291-311, 314-315, 318-329, 307-326
packages/scaffold-ui/src/partials/w3m-connector-list/index.ts 70.76% 16.66% 50% 70.76% 36-37, 49-50, 54-55, 59-60, 69-70, 74-75, 79-80, 84-85, 89-90, 94
packages/scaffold-ui/src/partials/w3m-header/index.ts 78.01% 64.1% 57.89% 78.01% 85, 126, 142-143, 151, 158-160, 163-170, 179-186, 197, 215, 236, 246, 254, 258-262, 265-270, 277, 285-286, 308-319, 323-324
packages/scaffold-ui/src/views/w3m-connect-view/index.ts 83.33% 83.17% 84.21% 83.33% 69, 73, 93, 140-141, 150, 184, 198, 209, 248, 252, 264, 275, 289-290, 293-294, 304, 325-326, 338, 349, 356-357, 362-386, 396-397, 400-401
packages/scaffold-ui/src/views/w3m-networks-view/index.ts 18.18% 100% 0% 18.18% 38-47, 50-51, 55-78, 82-93, 96-97, 104-106, 109-138, 141-155, 158-202
packages/scaffold-ui/src/views/w3m-unsupported-chain-view/index.ts 47.77% 66.66% 50% 47.77% 77, 83-89, 95, 108-109, 116-121, 126-140, 143-164, 110
Generated in workflow #9333 for commit 0c5bfa5 by the Vitest Coverage Report Action

@@ -44,7 +46,7 @@ export class W3mModal extends LitElement {
public constructor() {
super()
this.initializeTheming()
ApiController.prefetch()
ApiController.prefetchAnalyticsConfig()
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this here? @Cali93 can we remove ?

Copy link
Collaborator

@Cali93 Cali93 left a comment

Choose a reason for hiding this comment

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

LGTM, not sure if we need to prefetch the analytics config but if I recall correctly there's was an edge case where we wouldn't sent the first event when analytics isn't specified in the options but analytics is enabled through Cloud.

const promises = [
ApiController.fetchFeaturedWallets(),
ApiController.fetchRecommendedWallets(),
ApiController.fetchNetworkImages(),
ApiController.fetchConnectorImages()
]

state.prefetchPromise = Promise.race([Promise.allSettled(promises)])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need Promise.race ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh seems like it was alwasy there, will remove it 🙏

@enesozturk
Copy link
Contributor

enesozturk commented Jan 30, 2025

@magiziz There is this issue happening that when you don't open the model, the network button doesn't render the network image.

Screenshot 2025-01-30 at 10 37 25

And when I open the networks list, this time it's fetching and updating ETH logo but the other networks are still empty.

Screenshot 2025-01-30 at 10 39 33

I'd propose going with an approach that fetching the network image when the item is visible on the screen. We can achieve this by using the IntersectionOberserver API and fetch the item inside of each network item / image component. This will also help to not fetch images if you don't scroll (if item is not visible on the screen).

I've implemented this on "All Wallets" screen that you can take as a ref. We also have tech doc about it, will share in the channel

@@ -272,17 +272,21 @@ export const ApiController = {
await ApiController.fetchRecommendedWallets()
},

prefetch() {
prefetchWalletImages() {
const promises = [
ApiController.fetchFeaturedWallets(),
ApiController.fetchRecommendedWallets(),
ApiController.fetchNetworkImages(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to be called on init as well else network btton doesn't properly render.
Maybe a cool optimizaton is loading this on the button render/init instead of here

@magiziz
Copy link
Contributor Author

magiziz commented Feb 4, 2025

Marking this PR as draft since it'd break the demo

@magiziz magiziz marked this pull request as ready for review February 4, 2025 10:51
if (OptionsController.state.features?.analytics) {
promises.push(ApiController.fetchAnalyticsConfig())
await ApiController.fetchAnalyticsConfig()
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need to await this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah we don't do await it

@tomiir tomiir merged commit a7590da into main Feb 4, 2025
25 checks passed
@tomiir tomiir deleted the chore/prefetch-wallet-images branch February 4, 2025 11:51
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.

4 participants