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

refactor: Remove usage of deprecated setProviderType #3807

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
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
Loading