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

(Wallet) Implement NFT asset details screen #16671

Merged
merged 15 commits into from
Jan 24, 2023
Merged

Conversation

simoarpe
Copy link
Collaborator

@simoarpe simoarpe commented Jan 13, 2023

Resolves brave/brave-browser#27276

Implements new NFT asset detail screen supporting GIF, BMP, PNG and JPG images.

demo.mov

Security Review

Requested security review: https://github.com/brave/security/issues/1168.

Light Theme Dark Theme
Android_SDK_built_for_x86_and_Comparing_master___simone_nft-detail-screen_·_brave_brave-core Android_SDK_built_for_x86

Related Issues

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • 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 the wallet section
  • If not already present, add a new NFT selecting "Edit visible assets" > "Add custom assets"
    (E.g 0x59468516a8259058bad1ca5f8f4bff190d30e066, id 183 - Invisible Friends)
  • Tap on the NFT item
  • Observe the new NFT detail screen loads correctly image, title and description.

@simoarpe simoarpe added CI/skip-linux CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-ios Do not run CI builds for iOS labels Jan 13, 2023
@simoarpe simoarpe self-assigned this Jan 13, 2023
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.

check lint, but ++ otherwise

@diracdeltas
Copy link
Member

Is there a security review for this? Particularly SVG support. CC @kdenhartog

@simoarpe
Copy link
Collaborator Author

@diracdeltas, requested a security review: https://github.com/brave/security/issues/1168.

@Pavneet-Sing
Copy link

Pavneet-Sing commented Jan 17, 2023

Is there a security review for this? Particularly SVG support. CC @kdenhartog

We haven't added SVG support with any new lib yet so no security review is needed for now.
It will/should be opened with the implementation of

cc: @diracdeltas @simoarpe

Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

One non blocker from me and I see you've addressed the concern about arbitrary URL file types by limiting this to Network and Data URLs only. LGTM

String networkName = defaultNetwork.chainName;
mNetworkNameView.setText(networkName);
String blockExplorerUrl = defaultNetwork.blockExplorerUrls.length > 0
? defaultNetwork.blockExplorerUrls[0]
Copy link
Member

Choose a reason for hiding this comment

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

Non blocking: is there a reason this needs to be an array if we're just grabbing the first index here always?

Choose a reason for hiding this comment

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

It's a Mojom generated NetworkInfo class to get response data of network as an object from backend so it cannot be changed as it's being used across platforms and since there can be 0,1 or 1+ values so array is the ideal type for this kind of data. Changing this would require changes across platforms, backend and there could be a use case where more than the first url is being used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a very good question!
The blockExplorerUrls is an array because some tokens may have multiple blockchain explorer endpoints, this could be useful in case one endpoint is down. Of course, we should add the required logic on top where we check if an endpoint is down and process the next one if present. (It could be an improvement to implement in the future).

Another constraint to consider is about our current configuration as well: NetworkInfo.java (defaultNetwork) is a Java class generated by the mojo binding generator. So the original type is a struct defined in brave_wallet.mojom here.
Not savvy enough to know how much room we have to modify these mojom files. I'm sure @SergeyZhukovsky could tell us more.

Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

Spotted one blocker to make sure we're disabling support for http. Also one other non blocker for resolving IPFS content which we could do via a gateway if we don't have support for nodes in Android (which I'm pretty sure is the case)

@@ -51,6 +45,6 @@ public static boolean isSvg(String url) {
}

private static boolean isValidImgUrl(String url) {
return !TextUtils.isEmpty(url);
return URLUtil.isDataUrl(url) || URLUtil.isNetworkUrl(url);
Copy link
Member

Choose a reason for hiding this comment

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

Blocker: Just double checked brave-core and noticed that we support only HTTPS here, so going to block to make sure we're not supporting http URLs here.

Choose a reason for hiding this comment

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

In case http, we should

  1. Not load the URL
  2. Try replacing it with https before loading?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I'm going to replace URLUtil.isNetworkUrl(url) with URLUtil.isHttpsUrl(url). Doing so, only HTTPS will be allowed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in this commit 👉 66efe7e (#16671)

Copy link
Member

Choose a reason for hiding this comment

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

Lgtm

@simoarpe
Copy link
Collaborator Author

@kdenhartog security feedback addressed. Re-requesting your review, thanks.

Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

Looks good to me. All security concerns have been addressed

Improve performance and (more importantly) fix serialization as inner classes hold a reference to their outer class when non-static.
@simoarpe simoarpe merged commit 15fd2dc into master Jan 24, 2023
@simoarpe simoarpe deleted the simone/nft-detail-screen branch January 24, 2023 12:37
@github-actions github-actions bot added this to the 1.49.x - Nightly milestone Jan 24, 2023
@simoarpe simoarpe restored the simone/nft-detail-screen branch January 24, 2023 15:10
simoarpe added a commit that referenced this pull request Jan 25, 2023
Implements new NFT asset detail screen supporting GIF, BMP, PNG and JPG images.

(cherry picked from commit 15fd2dc)
@srirambv
Copy link
Contributor

Verification passed on Oppo Reno 5 with Android 13 running 1.49.75 x64 Nighty build

  • Verified NFT asset details view is shown when clicked on the NFT
  • Verified clicking on the Token ID loads the NFT's page on blockexplorer
  • Verified able to view both Solana NFT and Ethereum NFT
16671.mp4

@simoarpe simoarpe deleted the simone/nft-detail-screen branch January 31, 2023 11:43
kjozwiak pushed a commit that referenced this pull request Jan 31, 2023
* (Wallet) Implement NFT asset details screen (#16671)

Implements new NFT asset detail screen supporting GIF, BMP, PNG and JPG images.

(cherry picked from commit 15fd2dc)

* Add missing import
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NFT asset details screen
6 participants