Skip to content

Commit

Permalink
refactor: Remove usage of deprecated setProviderType
Browse files Browse the repository at this point in the history
All uages of the deprecated `NetworkController` method
`setProviderType` have been removed from this repository. They have
been replaced by calls to `setActiveNetwork`, which now also supports
being given network types, just like `setProviderType` did.
  • Loading branch information
Gudahtt committed Jan 22, 2024
1 parent 028b711 commit 4ef54df
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ describe('AssetsContractController', () => {
);
expect(balances[ERC20_SAI_ADDRESS]).toBeDefined();

await network.setProviderType(NetworkType.sepolia);
await network.setActiveNetwork(NetworkType.sepolia);

const noBalances = await assetsContract.getBalancesInSingleCall(
ERC20_SAI_ADDRESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ const buildMocks = (
mockAddRequest,
);

const mockSetProviderType = jest.fn().mockResolvedValue(true);
messenger.registerActionHandler(
'NetworkController:setProviderType',
mockSetProviderType,
);

const mockSetActiveNetwork = jest.fn().mockResolvedValue(true);
messenger.registerActionHandler(
'NetworkController:setActiveNetwork',
Expand All @@ -111,7 +105,6 @@ const buildMocks = (
enqueueRequest: mockEnqueueRequest,
addRequest: mockAddRequest,
setActiveNetwork: mockSetActiveNetwork,
setProviderType: mockSetProviderType,
setNetworkClientIdForDomain: mockSetNetworkClientIdForDomain,
};
};
Expand Down Expand Up @@ -379,37 +372,7 @@ describe('createQueuedRequestMiddleware', () => {
expect(res.error).toStrictEqual(serializeError(rejected));
});

it('uses setProviderType when the network is an infura one', async () => {
const messenger = buildMessenger();
const middleware = createQueuedRequestMiddleware({
messenger,
useRequestQueue: () => true,
});
const mocks = buildMocks(messenger, {
getProviderConfig: jest.fn().mockReturnValue({
chainId: '0x5',
}),
});

const req = {
...requestDefaults,
method: 'eth_sendTransaction',
};

await new Promise((resolve, reject) =>
middleware(
req,
{} as PendingJsonRpcResponse<typeof req>,
resolve,
reject,
),
);

expect(mocks.setProviderType).toHaveBeenCalled();
expect(mocks.setActiveNetwork).not.toHaveBeenCalled();
});

it('uses setActiveNetwork when the network is a custom one', async () => {
it('switches the current active network', async () => {
const messenger = buildMessenger();
const middleware = createQueuedRequestMiddleware({
messenger,
Expand Down Expand Up @@ -451,7 +414,6 @@ describe('createQueuedRequestMiddleware', () => {
),
);

expect(mocks.setProviderType).not.toHaveBeenCalled();
expect(mocks.setActiveNetwork).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
NetworkControllerGetNetworkClientByIdAction,
NetworkControllerGetStateAction,
NetworkControllerSetActiveNetworkAction,
NetworkControllerSetProviderTypeAction,
} from '@metamask/network-controller';
import { serializeError } from '@metamask/rpc-errors';
import type { SelectedNetworkControllerSetNetworkClientIdForDomainAction } from '@metamask/selected-network-controller';
Expand All @@ -22,7 +21,6 @@ import { QueuedRequestControllerActionTypes } from './QueuedRequestController';
export type MiddlewareAllowedActions =
| NetworkControllerGetStateAction
| NetworkControllerSetActiveNetworkAction
| NetworkControllerSetProviderTypeAction
| NetworkControllerGetNetworkClientByIdAction
| NetworkControllerFindNetworkClientIdByChainIdAction
| SelectedNetworkControllerSetNetworkClientIdForDomainAction
Expand Down Expand Up @@ -155,10 +153,8 @@ export const createQueuedRequestMiddleware = ({
true,
);

const method = isBuiltIn ? 'setProviderType' : 'setActiveNetwork';

await messenger.call(
`NetworkController:${method}`,
`NetworkController:setActiveNetwork`,
networkClientIdForRequest,
);

Expand Down

0 comments on commit 4ef54df

Please sign in to comment.