Skip to content

Commit

Permalink
Merge pull request #2856 from LukeSugiura/hotfix/provider-resolver
Browse files Browse the repository at this point in the history
EIP-1193 updates
  • Loading branch information
nivida authored Jun 2, 2019
2 parents 9f95015 + 1814d79 commit caa9410
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit caa9410

Please sign in to comment.