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

Fix(wallet): paginate portfolio NFTs page #23816

Merged
merged 5 commits into from
Jun 5, 2024

Conversation

josheleonard
Copy link
Collaborator

@josheleonard josheleonard commented May 23, 2024

Resolves brave/brave-browser#38547
Resolves brave/brave-browser#26782
Resolves brave/brave-browser#38549

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Hide unowned NFTs

  • Create a wallet with many NFTs
  • import an NFT that you do not own
  • view the NFT tab of the portfolio page
  • open the filters modal
  • toggle the "hide unowned NFTs" filter
  • The unowned NFT should appear only if the option is set to not hide unowned NFTs

NFT list pagination

  • Create a wallet with many NFTs
  • import an NFT that you do not own
  • view the NFT tab of the portfolio page
  • scroll to the bottom of the page
  • click the navigation arrows or a page number to change page
  • page number should reset to the first page when searching NFTs or adjusting filters

@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet labels May 23, 2024
@josheleonard josheleonard force-pushed the fix--paginate-portfolio-NFTs-page branch from c354693 to ff57232 Compare May 23, 2024 22:23
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@josheleonard josheleonard force-pushed the fix--paginate-portfolio-NFTs-page branch from ff57232 to 604753c Compare May 24, 2024 14:18
@josheleonard josheleonard marked this pull request as ready for review May 24, 2024 14:23
@josheleonard josheleonard requested review from a team as code owners May 24, 2024 14:23
@josheleonard josheleonard changed the title Fix paginate portfolio nf ts page Fix(wallet): paginate portfolio NFTs page May 24, 2024
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

strings++

@josheleonard josheleonard force-pushed the fix--paginate-portfolio-NFTs-page branch from 604753c to 69eeb0b Compare May 29, 2024 18:41
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Comment on lines +495 to +522

const chainIds = networksRegistry.ids.map(
(network) => networksRegistry.entities[network]!.chainId
)

let currentCursor: string | null = null
const accountSpamNfts = []

do {
const {
tokens,
cursor
}: {
tokens: BraveWallet.BlockchainToken[]
cursor: string | null
} = await braveWalletService.getSimpleHashSpamNFTs(
address,
chainIds,
coin,
currentCursor
)

accountSpamNfts.push(...tokens)
currentCursor = cursor
} while (currentCursor)

this.spamNftsForAccountRegistry[accountId.uniqueKey] = accountSpamNfts
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This just fetches everything with cursor. Should we do that in backend instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could if you would like to take a look are porting this to core

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@supermassive Do we want to handle this in this PR or in a follow-up?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some another PR would be ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines +100 to +102
/** if true, only spam NFT balances will be fetched, if falsey, only user
* token balances will be fetched */
isSpamRegistry?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

It makes sense to be consistent and comment with slashes //

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was purposely commented using doc-comments to allow the comment to be visible when hovering over the variable within a code editor

Copy link
Contributor

@Douglashdaniel Douglashdaniel left a comment

Choose a reason for hiding this comment

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

++

@josheleonard josheleonard force-pushed the fix--paginate-portfolio-NFTs-page branch from 69eeb0b to e529466 Compare June 5, 2024 15:37
Copy link
Contributor

github-actions bot commented Jun 5, 2024

[puLL-Merge] - brave/brave-core@23816

Description

This PR adds several new features and improvements to the Brave Wallet UI:

  • Adds pagination for the NFTs list view to improve performance with large collections
  • Adds a new filter toggle to hide NFTs that are not owned by any of the user's accounts
  • Fetches spam NFT balances separately from user token balances to improve performance
  • Updates routing logic for the NFTs list to handle pagination and tab selection

The motivation for these changes is to improve the user experience and performance of the NFTs list view, especially for users with large collections of NFTs.

Changes

Changes

  • brave_wallet_constants.h: Adds a new localized string for the "Hide not owned NFTs" toggle.

  • base-query-cache.ts:

    • Adds a new spamNftsForAccountRegistry to cache spam NFTs by account.
    • Adds a new getSpamNftsForAccountId method to fetch spam NFTs for a given account from the Simple Hash API.
  • local-storage-keys.ts: Adds new local storage keys for persisting spam token balances and the "Hide not owned NFTs" setting.

  • use-balances-fetcher.tsx: Adds an isSpamRegistry option to the useBalancesFetcher hook to fetch spam NFT balances separately.

  • nfts.endpoints.ts: Updates the getSimpleHashSpamNfts endpoint to optionally fetch spam NFTs for specific accounts.

  • token_balances.endpoints.ts:

    • Adds isSpamRegistry option to GetTokenBalancesRegistryArg to fetch spam or user token balances.
    • Updates persisting of token balances to handle spam registry separately.
  • portfolio-filters-modal.tsx: Adds a new toggle for the "Hide not owned NFTs" setting.

  • nfts.tsx:

    • Adds pagination to the NFTs list view.
    • Fetches spam NFT balances separately.
    • Filters NFTs list by owned/not owned based on setting.
    • Updates routing to handle pagination and tab selection.
  • pagination.tsx: Adds a new Pagination component for handling pagination UI.

  • routes-utils.ts: Adds a new makePortfolioNftsRoute function to generate URLs for the NFTs list view with pagination and tab selection.

Possible Issues

  • The separate fetching of spam NFT balances could lead to some UI flickering or inconsistency if the requests are not properly synchronized. The UI should handle the loading states gracefully.

  • The pagination implementation currently loads all NFTs and then paginates them in the UI. For very large collections, it may be more efficient to paginate the data fetching as well.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@josheleonard josheleonard merged commit 407295f into master Jun 5, 2024
19 checks passed
@josheleonard josheleonard deleted the fix--paginate-portfolio-NFTs-page branch June 5, 2024 19:07
@github-actions github-actions bot added this to the 1.68.x - Nightly milestone Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet/core feature/web3/wallet puLL-Merge
Projects
None yet
5 participants