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

feat(wallet): Use Wallet WebUI for Send & Swap on iOS #24328

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

StephenHeaps
Copy link
Collaborator

@StephenHeaps StephenHeaps commented Jun 21, 2024

  • Adds support for using desktop/android wallet WebUI for Send & Swap in native iOS wallet. The send & swap UI will replace the existing native iOS UI when user taps Send / Swap in Portfolio or via tray in Wallet Panel.
  • NFTs are displayed the same as in desktop/android using an iframe to isolate them with chrome-untrusted://nft-display.
  • Creating transactions will continue to dismiss the send & swap modal presented over the native iOS wallet and present the native iOS transaction confirmation panel.

Resolves brave/brave-browser#36968

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:

  1. Open native Brave Wallet and verify Send & Swap both still use the existing native views when feature flag is disabled (default).
  2. Open brave://flags and find Enable WebUI for Brave Wallet iOS feature flag. Enable it & restart the app.
  3. Open native Brave Wallet and verify Send & Swap both use the WebUI seen on desktop (panel) and android.
  4. Test using WebUI on iOS.
    • Creating Send transactions should work the same as on desktop/android. The exact same accounts & networks shown in native iOS wallet should be available for creating transactions.
    • Creating Swap transactions should work the same as on desktop/android. The exact same accounts & networks shown in native iOS wallet should be available in swap
IMG_6660 IMG_6661 IMG_6662 IMG_6663
IMG_6664 IMG_6665 IMG_6666 IMG_6667
Send.WebUI.Demo.MP4
Swap.WebUI.Demo.MP4

@StephenHeaps StephenHeaps self-assigned this Jun 21, 2024
@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet labels Jun 21, 2024
@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from 57c3b89 to ac8e3e5 Compare June 25, 2024 19:36
@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from ac8e3e5 to e797477 Compare June 26, 2024 15:15
@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from e797477 to 863a9f5 Compare June 26, 2024 18:31
@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps marked this pull request as ready for review June 26, 2024 19:57
@StephenHeaps StephenHeaps requested review from a team as code owners June 26, 2024 19:57
@kylehickinson kylehickinson requested a review from a team June 26, 2024 20:00
Copy link
Contributor

@josheleonard josheleonard left a comment

Choose a reason for hiding this comment

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

Approved with nits

@@ -387,4 +394,4 @@ export default class Amount {

return formatter.format(value) + abbreviation
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing EOF new-line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 603c091


return `rgba(${r},${g},${b},0.2)`
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing EOF new line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 603c091

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.

grd++

@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from 603c091 to a4a6bc2 Compare July 2, 2024 16:59
@StephenHeaps StephenHeaps requested a review from nuo-xu July 2, 2024 17:08
@brave-builds
Copy link
Collaborator

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

Copy link
Contributor

@nuo-xu nuo-xu left a comment

Choose a reason for hiding this comment

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

it was very difficult to save Slippage tolerance (or im not sure its saved or not)
sending and swapping work pretty well.
I'm not sure it's my device. it once became pretty hot after I was trying to make tx on webui.

@StephenHeaps StephenHeaps requested a review from a team as a code owner July 9, 2024 02:49
@brave-builds
Copy link
Collaborator

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

@StephenHeaps StephenHeaps requested a review from nuo-xu July 10, 2024 16:44
@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from 72dc3fc to fd4114f Compare July 11, 2024 14:37
@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from 39a3001 to ab0bb0b Compare August 8, 2024 16:11
Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

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

wallet core LGTM (non-iOS code)

@brave-builds
Copy link
Collaborator

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

@brave-builds
Copy link
Collaborator

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

// When isPanel is true, will return:
// "img-src 'self' data: chrome://resources chrome://erc-token-images
// chrome://image chrome://favicon https://assets.cgproxy.brave.com;"
const std::string GetWalletImgSrcCSP(bool isPanel) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: is_panel

Copy link
Collaborator

@supermassive supermassive Aug 9, 2024

Choose a reason for hiding this comment

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

Also no const in return type, just std::string. Same for GetWalletFrameSrcCSP

Comment on lines 119 to 123
frameSrcCSP.append(std::string(" ") +
brave_wallet::mojom::kUntrustedTrezorBridgeURL);
frameSrcCSP.append(std::string(" ") +
brave_wallet::mojom::kUntrustedLedgerBridgeURL);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: brave_wallet::

Copy link
Contributor

github-actions bot commented Aug 9, 2024

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

Description

This PR implements WebUI support for the Brave Wallet on iOS, specifically for the Send and Swap functionality. It adds new files, modifies existing ones, and integrates the Brave Wallet UI into the iOS app architecture.

Changes

Changes

  1. browser/ui/webui/brave_wallet/:

    • Added new files for handling Brave Wallet WebUI on iOS, including brave_wallet_page_ui.h/mm, nft_ui.h/mm, wallet_common_ui.h/mm, wallet_handler.h/mm, and wallet_page_handler.h/mm.
    • These files set up the necessary infrastructure for the Brave Wallet WebUI on iOS.
  2. browser/ui/webui/:

    • Modified brave_web_ui_controller_factory.mm to include the new Brave Wallet WebUI controllers.
    • Added brave_webui_data_source.h/mm to handle WebUI data sources for Brave on iOS.
  3. components/brave_wallet/browser/brave_wallet_constants.cc/h:

    • Added new functions GetWalletFrameSrcCSP() and GetWalletImgSrcCSP() to handle Content Security Policy for the Wallet UI.
  4. components/brave_wallet_ui/:

    • Modified several files to support iOS-specific functionality and adjust imports.
  5. ios/brave-ios/Sources/BraveWallet/:

    • Added new Swift files for the WebUI implementation of Send and Swap functionality.
  6. ios/browser/:

    • Added and modified files to support Brave Wallet features on iOS, including new feature flags.
  7. chromium_src/:

    • Added and modified several files to integrate Brave Wallet functionality into the Chromium base on iOS.

Possible Issues

  1. The implementation adds new untrusted schemes and modifies Content Security Policies, which could potentially introduce security risks if not properly configured.
  2. The changes to the build system (GN files) might affect the build process for other platforms or configurations.

Security Hotspots

  1. The addition of chrome-untrusted scheme in ios/chrome/browser/shared/model/browser_state/chrome_browser_state.mm could potentially be a security risk if not properly restricted.
  2. Modifications to Content Security Policies in various files (e.g., brave_wallet_constants.cc, brave_webui_data_source.mm) should be carefully reviewed to ensure they don't introduce vulnerabilities.

@StephenHeaps StephenHeaps force-pushed the wallet/ios-swap-send-webui branch from ca33759 to bc05824 Compare August 9, 2024 14:21
@brave-builds
Copy link
Collaborator

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

return "frame-src 'none';";
}

std::string URLDataSourceIOS::GetContentSecurityPolicy(
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like a lot of this stuff is copied from URLDataSource which we should not be doing because it's very fragile.

} // namespace

namespace web {
bool URLDataSourceIOS::ShouldAddContentSecurityPolicy() const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we creating our own implementation in the base class instead of URLDataSourceIOSImpl?

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

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

I have serious concerns with this approach of copying code from content WebUIDataSource to ios. We can discuss options in slack.

// On mobile, will return:
// "frame-src chrome-untrusted://nft-display/
// chrome-untrusted://line-chart-display/ chrome-untrusted://market-display/;"
std::string GetWalletFrameSrcCSP() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are these in constants? There are some other methods already in here that don't make sense in a constants.h file, but I would put these in some kind of helper specific to the relevant webui.

@@ -1635,6 +1635,20 @@ const std::string GetAssetRatioBaseURL();
const base::flat_map<std::string, std::string>& GetAnkrBlockchains();
// https://docs.rs/solana-program/1.18.10/src/solana_program/clock.rs.html#129-131
inline constexpr int kSolanaValidBlockHeightThreshold = 150;

inline constexpr char kCSPFrameSrcName[] = "frame-src";
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we creating constants in brave wallet for generic CSP directives?

inline constexpr char kCSPImageSrcName[] = "img-src";
inline constexpr char kCSPSelf[] = "'self'";
inline constexpr char kCSPData[] = "data:";
inline constexpr char kCSPChromeResources[] = "chrome://resources";
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above, a constant for chrome://resources does not belong in brave_wallet_constants

}

bool BraveWebClient::IsAppSpecificURL(const GURL& url) const {
return ChromeWebClient::IsAppSpecificURL(url) || url.SchemeIs(kBraveUIScheme);
return ChromeWebClient::IsAppSpecificURL(url) ||
url.SchemeIs(kBraveUIScheme) || url.SchemeIs(kChromeUIUntrustedScheme);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use WebUI for Send & Swap on iOS