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 NFT visibility in BottomSheet fragment #20361

Merged
merged 15 commits into from
Oct 5, 2023

Conversation

simoarpe
Copy link
Collaborator

@simoarpe simoarpe commented Oct 3, 2023

Resolves brave/brave-browser#31915
Resolves brave/brave-browser#33255

Details

Fixes an issue where NFTs listed in EditVisibleAssetsBottomSheetDialogFragment were always marked as visible.

Screen recording showing the right behavior:

fix-NFT-visibility.mov

⚠️ Notes for Reviewers

The approach used to mark an asset as visible or invisible is going to be rewritten soon.
The new way will leverage a WebUI based on Desktop implementation and will (probably) rely on the same persistency methods if compatible with Android.
Because we don't want to reinvent the wheel, the actual fix is just a simple check on the NFT data model returned from core API and is implemented by the commit 👉 357eaf4
After the transition to a WebUI the state will be handled on the client side and not from core.

Other Notable Changes

  • NetworkUtils#findNetwork has been improved with a new parameter as localhost networks now can belong to FIL, SOL or ETH and on debug builds was returning wrong values.
  • Improved filterTokens method: the filtering now uses Java streams, and it's (roughly) 50% faster as the previous logic was converting to/from array/list multiple times.
  • Added Javadoc to TokenUtils methods.

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 NFT section by tapping on the selector to the right.
  • If not present, add some NFTs by tapping on the plus icon.
  • Tap on "Edit visible NFTs" and deselect all NFTs.
  • Observe the full list is shown in the Hidden section.
  • Tap on "Edit visible NFTs" and deselect all NFTs.
  • Select all the available NFTs.
  • Observe the full list is shown in the NFTs section.
  • Observe the Hidden section is empty.

@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-x64 Do not run CI builds for Windows x64 unused-CI/skip-linux-x64 Do not run CI builds for Linux x64 labels Oct 3, 2023
@simoarpe simoarpe self-assigned this Oct 3, 2023
Comment on lines -81 to -93
} else if (mType == WalletCoinAdapter.AdapterType.SEND_ASSETS_LIST) {
assert mSelectedNetwork != null;
TokenUtils.getUserAssetsFiltered(mBraveWalletService, mSelectedNetwork,
mSelectedNetwork.coin, TokenUtils.TokenType.ALL, tokens -> {
_mAssetsResult.postValue(new AssetsResult(
Arrays.asList(tokens), Collections.emptyList()));
});
} else if (mType == WalletCoinAdapter.AdapterType.BUY_ASSETS_LIST) {
TokenUtils.getBuyTokensFiltered(mBlockchainRegistry, mSelectedNetwork,
TokenUtils.TokenType.ALL, tokens -> {
_mAssetsResult.postValue(new AssetsResult(
Arrays.asList(tokens), Collections.emptyList()));
});
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SEND_ASSETS_LIST and BUY_ASSETS_LIST can be safely removed as they were never accessed: these parts now rely on WebUIs.

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.

++

@Pavneet-Sing
Copy link

Pavneet-Sing commented Oct 5, 2023

The approach used to mark an asset as visible or invisible is going to be rewritten soon.
The new way will leverage a WebUI based on Desktop implementation and will (probably) rely on the same persistency methods if compatible with Android.
Because we don't want to reinvent the wheel, the actual fix is just a simple check on the NFT data model returned from core API and is implemented by the commit 👉 357eaf4
After the transition to a WebUI the state will be handled on the client side and not from core.

We don't need to maintain anything or reinvent(as it is a bug). Token state is definitely handled on the core side, not on client side. This seems like a regression for assets/tokens, but NFT visibility is completely depends on isVisible flag so this is the accurate and only required check to determine NFT visibility.

About tokens visibility issue, It is working as expected for non-native tokens. The issue with native token visibility is that the native token always seems to be added by Stream.concat(Stream.of(nativeAsset), tokenStream); and that's why it is always visible.

assets.webm

Anyway, We will come back to these native changes/issues later if needed after completing webUI issues as priority.

@simoarpe simoarpe merged commit fa85d6a into master Oct 5, 2023
6 checks passed
@simoarpe simoarpe deleted the simone/fix-assets-visibility branch October 5, 2023 12:42
@github-actions github-actions bot added this to the 1.61.x - Nightly milestone Oct 5, 2023
@srirambv
Copy link
Contributor

srirambv commented Oct 6, 2023

Verification passed on Oppo Reno 5 with Android 13 running 1.61.3 x64 Nightly build

  • Verified steps from PR
  • Verified unchecking NFTs moves them into hidden tab
  • Verified checking NFTs moves them back into collected tab
20361.mp4

kjozwiak pushed a commit that referenced this pull request Oct 6, 2023
* Uplift of #20361 (squashed) to beta

* Fix NPE when accessing null network object

---------

Co-authored-by: Simone Arpe <simon.arpe@gmail.com>
kjozwiak pushed a commit that referenced this pull request Oct 6, 2023
* Uplift of #20361 (squashed) to release

* Fix NPE when accessing null network object

---------

Co-authored-by: Simone Arpe <simon.arpe@gmail.com>
@bsclifton bsclifton deleted the simone/fix-assets-visibility branch November 10, 2023 06:21
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.

Hide/unhide NFT doesn't work as expected NFTs stays visible after marked as invisible in edit visible
4 participants