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

EIP-1193 updates #2856

Merged
merged 5 commits into from
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions packages/web3-providers/src/resolvers/ProviderResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default class ProviderResolver {
return provider;
}

if (provider.host === 'Web3EthereumProvider') {
return provider;
}

if (typeof global.mist !== 'undefined' && provider.constructor.name === 'EthereumProvider') {
return this.providersModuleFactory.createMistEthereumProvider(provider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ProvidersModuleFactory from '../../../src/factories/ProvidersModuleFactor
import HttpProvider from '../../../src/providers/HttpProvider';
import WebsocketProvider from '../../../src/providers/WebsocketProvider';
import IpcProvider from '../../../src/providers/IpcProvider';
import Web3EthereumProvider from '../../../src/providers/Web3EthereumProvider';
import MetamaskProvider from '../../../src/providers/MetamaskProvider';
import CustomProvider from '../../../src/providers/CustomProvider';

Expand All @@ -11,7 +12,6 @@ jest.mock('../../../src/factories/ProvidersModuleFactory');
jest.mock('../../../src/providers/HttpProvider');
jest.mock('../../../src/providers/WebsocketProvider');
jest.mock('../../../src/providers/IpcProvider');
jest.mock('../../../src/providers/Web3EthereumProvider');
jest.mock('../../../src/providers/MetamaskProvider');
jest.mock('../../../src/providers/CustomProvider');

Expand Down Expand Up @@ -85,6 +85,16 @@ describe('ProviderResolverTest', () => {
expect(providersModuleFactoryMock.createWeb3EthereumProvider).toHaveBeenCalledWith(ethereumProviderMock);
});

it('calls resolve with the Web3EthereumProvider', () => {
const ethereumProviderMock = {
isEIP1193: true,
on: () => {}
};
const web3EthereumProvider = new Web3EthereumProvider(ethereumProviderMock);

expect(providerResolver.resolve(web3EthereumProvider)).toBeInstanceOf(Web3EthereumProvider);
});

it('calls resolve with the WebsocketProvider', () => {
new WebsocketProvider({}, 1);
const websocketProviderMock = WebsocketProvider.mock.instances[0];
Expand Down