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: mustBeMetaMask should not detect brave as MetaMask #87

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
interface MetaMaskEthereumProvider {
isMetaMask?: boolean;
isBraveWallet?: boolean;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Expand Down Expand Up @@ -69,7 +70,7 @@ function detectEthereumProvider<T = MetaMaskEthereumProvider>({

const { ethereum } = window as Window;

if (ethereum && (!mustBeMetaMask || ethereum.isMetaMask)) {
if (ethereum && (!mustBeMetaMask || (ethereum.isMetaMask && !ethereum.isBraveWallet))) {
resolve(ethereum as unknown as T);
} else {

Expand Down
16 changes: 16 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const mockGlobalProps = (ethereum) => {
const providerWithMetaMask = {
isMetaMask: true,
}
const providerWithBrave = {
isMetaMask: true,
isBraveWallet: true,
}

const providerNoMetaMask = {}
const noProvider = null

Expand Down Expand Up @@ -48,6 +53,17 @@ test('detectProvider: mustBeMetamask with ethereum already set', async function
t.end()
})

test('detectProvider: mustBeMetamask with Brave ethereum already set', async function (t) {

mockGlobalProps(providerWithBrave)

const result = await detectProvider({ timeout: 1, mustBeMetaMask: true })
t.equal(result, null, 'promise should have resolved null')
t.ok(window.addEventListener.notCalled, 'addEventListener should not have been called')
t.ok(window.removeEventListener.calledOnce, 'removeEventListener called once')
t.end()
})

test('detectProvider: mustBeMetamask with non-MetaMask ethereum already set', async function (t) {

mockGlobalProps(providerNoMetaMask)
Expand Down