Skip to content

Commit

Permalink
NetworkController setProviderType doesn't reset the rpcTarget and nic…
Browse files Browse the repository at this point in the history
…kname (#947)

* set rpcTarget and nickname to undefined when use setProviderType

* updated setProviderType func test cases and removed rinkeby for goerly since rinkeby is deprecated

* added test case for setProviderType after setRpcTarget
  • Loading branch information
tommasini authored Nov 4, 2022
1 parent c027807 commit cf76cbd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/network/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ describe('NetworkController', () => {
messenger,
infuraProjectId: '123',
});
controller.setProviderType('rinkeby' as NetworkType);
expect(controller.state.provider.type).toBe('rinkeby');
expect(controller.state.provider.ticker).toBe('RinkebyETH');
controller.setProviderType('goerli' as NetworkType);
expect(controller.state.provider.type).toBe('goerli');
expect(controller.state.provider.ticker).toBe('GoerliETH');
expect(controller.state.isCustomNetwork).toBe(false);
expect(controller.state.provider.rpcTarget).toBeUndefined();
expect(controller.state.provider.nickname).toBeUndefined();
});

it('should set mainnet provider type', () => {
Expand All @@ -160,6 +162,22 @@ describe('NetworkController', () => {
expect(controller.state.provider.type).toBe('mainnet');
expect(controller.state.provider.ticker).toBe('ETH');
expect(controller.state.isCustomNetwork).toBe(false);
expect(controller.state.provider.rpcTarget).toBeUndefined();
expect(controller.state.provider.nickname).toBeUndefined();
});

it('should set rpcTarget and nickname props to undefined when set a provider type', () => {
const controller = new NetworkController({
messenger,
infuraProjectId: '123',
});
controller.setRpcTarget(RPC_TARGET, NetworksChainId.rpc);
controller.setProviderType('mainnet' as NetworkType);
expect(controller.state.provider.type).toBe('mainnet');
expect(controller.state.provider.ticker).toBe('ETH');
expect(controller.state.isCustomNetwork).toBe(false);
expect(controller.state.provider.rpcTarget).toBeUndefined();
expect(controller.state.provider.nickname).toBeUndefined();
});

it('should throw when setting an unrecognized provider type', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/network/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ export class NetworkController extends BaseController<
state.provider.type = type;
state.provider.ticker = ticker;
state.provider.chainId = NetworksChainId[type];
state.provider.rpcTarget = undefined;
state.provider.nickname = undefined;
});
this.refreshNetwork();
}
Expand Down

0 comments on commit cf76cbd

Please sign in to comment.