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

Adds event emitter to window.ethereum object #8718

Merged
merged 4 commits into from
May 11, 2021

Conversation

SergeyZhukovsky
Copy link
Member

Resolves brave/brave-browser#15636
Note: actual emit of events, tests and hooking up them to UI will be done in separate 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
  • 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, npm run lint, 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:

@SergeyZhukovsky SergeyZhukovsky requested review from bridiver and bbondy May 5, 2021 19:07
@SergeyZhukovsky SergeyZhukovsky self-assigned this May 5, 2021
resource_name = "brave_wallet_script"
}

pack_web_resources("generated_resources") {
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing with generated_resources for brave_wallet for the panel and the page.
Maybe call it ethereum_provider_generated_resources?

See
https://github.com/brave/brave-core/blob/master/components/brave_wallet_ui/BUILD.gn#L29

Mainly brave_wallet is not specific enough because it is used for a lot of things. We should say what it is specifically. Which is an ethereum provider.

Copy link
Member Author

Choose a reason for hiding this comment

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

corrected

if (!is_android) {
deps += [ "//brave/components/brave_wallet_ui:resources" ]
sources += [
"$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet.pak",
Copy link
Member

Choose a reason for hiding this comment

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

now that we'll have 2 different pak files though I should come back and rename this to brave_wallet_ui.pak

@SergeyZhukovsky
Copy link
Member Author

linux CI randomly fails on diff rewards tests which are not related to the PR, last time it is RewardsNotificationBrowserTest.InsufficientNotificationForACNotEnoughFunds

@SergeyZhukovsky
Copy link
Member Author

ios and macos CI keep aborting

FormProviderErrorResponse(message).c_str()));
}

void BraveWalletJSHandler::ChainChangedEvent(const std::string& chain_id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we want methods for each specific event, we should just have a list of constants for them

Copy link
Member Author

Choose a reason for hiding this comment

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

I will do that in upcoming PRs. As some events will come from browser process via mojo, some will not like connect, on connect we will ask a browser process what chain id is. That place is going to be changed in some kind in the upcoming PRs. Just some things are unknown yet till we investigate how and when exactly we should fire events.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can we also add better error handling in a follow-up PR so the called gets notified if there are any JS errors?

@@ -107,6 +150,9 @@ v8::Local<v8::Promise> BraveWalletJSHandler::Request(
if (!out || !out->is_dict() || !out->GetAsDictionary(&out_dict))
return v8::Local<v8::Promise>();

// Hardcode id to 1 as it is unused
ALLOW_UNUSED_LOCAL(out_dict->SetIntPath("id", 1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

these should probably be consts defined in brave_wallet/common or something

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to do it as consts in that cc as they are not supposed to be used anywhere else

@SergeyZhukovsky SergeyZhukovsky requested a review from a team as a code owner May 7, 2021 18:01
@@ -107,6 +175,9 @@ v8::Local<v8::Promise> BraveWalletJSHandler::Request(
if (!out || !out->is_dict() || !out->GetAsDictionary(&out_dict))
return v8::Local<v8::Promise>();

// Hardcode id to 1 as it is unused
ALLOW_UNUSED_LOCAL(out_dict->SetIntPath("id", kRequestId));
Copy link
Collaborator

Choose a reason for hiding this comment

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

weird that these were needed, I don't see them used in other places, but I guess it's ok because other places also ignore the result


namespace brave_wallet {

BraveWalletJSHandler::BraveWalletJSHandler(content::RenderFrame* render_frame)
: render_frame_(render_frame) {}
: render_frame_(render_frame) {
if (g_provider_script->empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is fine for now, but I don't think we need to store this in a static var. LoadDataResource loads from memory so there's really no benefit to doing this

}

deps += [ "//brave/components/brave_wallet/resources:ethereum_provider_generated_resources" ]
sources += [ "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet_script_generated.pak" ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's no reason to expose additional pak files here, we should repack everything inside brave_wallet into a single output. See https://github.com/brave/brave-core/pull/8703/files#diff-5303bb2b8878c4fce006fc3b8bb18f3d4e0f386dbea78d4c8c37a23323762389R55

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.

please make sure there is browser test coverage before these features are enabled

@SergeyZhukovsky
Copy link
Member Author

post-init CI failed on not related to the PR audits checks
Linux CI failed on not related to the PR rewards tests
macOS CI failed on a known problem AdBlockServiceTest.CnameCloakedRequestsGetBlocked (../../brave/browser/brave_shields/ad_block_service_browsertest.cc:585)

@SergeyZhukovsky SergeyZhukovsky merged commit bd79a49 into master May 11, 2021
@SergeyZhukovsky SergeyZhukovsky deleted the web3_event_emitter branch May 11, 2021 13:36
@SergeyZhukovsky SergeyZhukovsky added this to the 1.26.x - Nightly milestone May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement event emitter for web3 provider
3 participants