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

Tweak portfolio UI and add option to show hidden NFTs #19990

Merged
merged 17 commits into from
Sep 6, 2023

Conversation

simoarpe
Copy link
Collaborator

@simoarpe simoarpe commented Sep 5, 2023

Resolves brave/brave-browser#32545

Screenshot_1693913055

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 lint, 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:

  • Open Brave Wallet and navigate to "NFTs" section by tapping on the tab at the top
  • Observe NFTs and Hidden sections are shown
  • Add a new NFT
  • Observe the NFT is shown in the NFTs section
  • Tap on "Edit Visible NFTs"
  • Deselect the NFT and tap on "Save account watchlist"
  • Observe the NFT is shown in the Hidden section

@simoarpe simoarpe added CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-ios Do not run CI builds for iOS CI/skip-windows-x86 CI/skip-windows-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64 labels Sep 5, 2023
@simoarpe simoarpe requested a review from a team as a code owner September 5, 2023 09:12
@simoarpe simoarpe self-assigned this Sep 5, 2023
@@ -384,7 +445,7 @@ private void recordP3AView() {
if (activity instanceof BraveWalletActivity) {
BraveWalletActivity walletActivity = (BraveWalletActivity) activity;
BraveWalletP3a walletP3A = walletActivity.getBraveWalletP3A();
if (walletP3A != null) {
if (walletP3A != null && mNftDataModels != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Improved check as the wallet was crashing here.

Comment on lines 169 to 181
TokenUtils.getUserOrAllTokensFiltered(braveWalletService, blockchainRegistry,
networkInfo, networkInfo.coin, TokenUtils.TokenType.NFTS, true, userAssets -> {
mUserAssets.addAll(Arrays.asList(userAssets));

if (userAssetsCount.incrementAndGet() == totalNetworks) {
mUserAssets.sort(Comparator.comparing(
token -> mAssertSortPriorityPerCoinIndex.get(token.chainId)));
AtomicInteger allAssets = new AtomicInteger();
final List<BlockchainToken> assets = new ArrayList<>();
for (NetworkInfo selectedNetwork : mSelectedNetworks) {
TokenUtils.getUserOrAllTokensFiltered(braveWalletService,
blockchainRegistry, selectedNetwork, selectedNetwork.coin,
TokenUtils.TokenType.NFTS, false, tokens -> {

Choose a reason for hiding this comment

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

TokenUtils.getUserOrAllTokensFiltered with true and false is internally calling braveWalletService.getUserAssets for each networks twice. The result of braveWalletService.getUserAssets can be persisted during the first call and can be reused with with getAllTokensFiltered to reduce latency.

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 417 to 418
LiveDataUtil.observeOnce(getNetworkModel().mCryptoNetworks,
networkList

Choose a reason for hiding this comment

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

PortfolioModel has the mAllNetworkInfos. Add a getter and reuse it than LiveDataUtil.observeOnce(getNetworkModel().mCryptoNetworks,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, right! Nice catch, thank you!

Comment on lines 411 to 420
mPortfolioModel.fetchNfts(
mSelectedNetworkList, (BraveWalletBaseActivity) activity, (portfolioHelper) -> {
if (!AndroidUtils.canUpdateFragmentUi(this)) return;
mPortfolioHelper = portfolioHelper;
List<BlockchainToken> nfts = mPortfolioHelper.getUserAssets();
LiveDataUtil.observeOnce(getNetworkModel().mCryptoNetworks, networkInfos -> {
mPortfolioModel.prepareNftListMetaData(
nfts, networkInfos, mPortfolioHelper);
});
List<BlockchainToken> hiddenNfts = mPortfolioHelper.getHiddenAssets();
LiveDataUtil.observeOnce(getNetworkModel().mCryptoNetworks,
networkList
-> mPortfolioModel.prepareNftListMetaData(
nfts, hiddenNfts, networkList, mPortfolioHelper));
Copy link

@Pavneet-Sing Pavneet-Sing Sep 5, 2023

Choose a reason for hiding this comment

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

nit: We always gonna be needing NFT meta data (can add a new method if not) so fetchNfts can internally call prepareNftListMetaData directly for further processing to remove the back and forth data passing/calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

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++

Copy link

@Pavneet-Sing Pavneet-Sing left a comment

Choose a reason for hiding this comment

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

LGTM, added some comments to improve performance. (can be addressed later if suitable).

Copy link
Member

@SergeyZhukovsky SergeyZhukovsky left a comment

Choose a reason for hiding this comment

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

++

@simoarpe simoarpe merged commit 6f55919 into master Sep 6, 2023
@simoarpe simoarpe deleted the simone/portfolio-ui-tweak branch September 6, 2023 11:43
@github-actions github-actions bot added this to the 1.59.x - Nightly milestone Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-ios Do not run CI builds for iOS CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 feature/web3/wallet unused-CI/skip-linux-x64 Do not run CI builds for Linux x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tweak portfolio UI and add option to show hidden NFTs
4 participants