Skip to content

Commit

Permalink
Compat w/ Brave to support multi web3 providers
Browse files Browse the repository at this point in the history
This implements the spec changes needed for better compatibility with Brave:
brave/brave-browser#7503

It makes it so both extensions can co-exist.
  • Loading branch information
bbondy committed Jan 15, 2020
1 parent be08cfe commit cf9d710
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*global chrome*/

import pump from 'pump'
import querystring from 'querystring'
import LocalMessageDuplexStream from 'post-message-stream'
Expand All @@ -21,8 +23,19 @@ const inpageBundle = inpageContent + inpageSuffix
// MetaMask will be much faster loading and performant on Firefox.

if (shouldInjectProvider()) {
injectScript(inpageBundle)
start()
// If this is Brave, it requires coordination to know if we should be the
// web3 provider.
if (chrome.braveWallet && chrome.braveWallet.getWeb3Provider) {
chrome.braveWallet.getWeb3Provider((provider) => {
if (provider === extension.runtime.id) {
injectScript(inpageBundle)
start()
}
})
} else {
injectScript(inpageBundle)
start()
}
}

/**
Expand Down

0 comments on commit cf9d710

Please sign in to comment.