Skip to content

Commit

Permalink
lint fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ committed Oct 10, 2023
1 parent 9b98ec5 commit f72084e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 124 deletions.
34 changes: 19 additions & 15 deletions packages/queued-request-controller/src/QueuedRequestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const QueuedRequestControllerEventTypes = {
countChanged: `${controllerName}:countChanged` as const,
};

export type QueuedRequestControllerState = {};
export type QueuedRequestControllerState = {
[k: string]: any;
};

export type QueuedRequestControllerStateChangeEvent = {
type: typeof QueuedRequestControllerEventTypes.stateChange;
Expand Down Expand Up @@ -112,20 +114,22 @@ export class QueuedRequestController extends BaseControllerV2<
await this.currentRequest;
}

this.currentRequest = requestNext().then(() => {
this.count -= 1;
this.messagingSystem.publish(
'QueuedRequestController:countChanged',
this.count,
);
}).catch((e) => {
this.count -= 1;
this.messagingSystem.publish(
'QueuedRequestController:countChanged',
this.count,
);
throw e;
});
this.currentRequest = requestNext()
.then(() => {
this.count -= 1;
this.messagingSystem.publish(
'QueuedRequestController:countChanged',
this.count,
);
})
.catch((e) => {
this.count -= 1;
this.messagingSystem.publish(
'QueuedRequestController:countChanged',
this.count,
);
throw e;
});

await this.currentRequest;
}
Expand Down
26 changes: 10 additions & 16 deletions packages/queued-request-controller/src/QueuedRequestMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,9 @@ export const createQueuedRequestMiddleware = (
useRequestQueue: () => boolean,
): JsonRpcMiddleware<any, any> => {
return createAsyncMiddleware(async (req: any, res: any, next) => {
if (!useRequestQueue()) {
// eslint-disable-next-line n/callback-return
return next();
}

if (isConfirmationMethod(req.method)) {
// eslint-disable-next-line n/callback-return
return next();
if (!useRequestQueue() || isConfirmationMethod(req.method)) {
next();
return;
}

const networkClientIdForRequest = req.networkClientId as NetworkClientId;
Expand All @@ -65,21 +60,20 @@ export const createQueuedRequestMiddleware = (

const builtIn =
BUILT_IN_NETWORKS[
networkClientIdForRequest as keyof typeof BUILT_IN_NETWORKS
networkClientIdForRequest as keyof typeof BUILT_IN_NETWORKS
];
const isBuiltIn = builtIn !== undefined && builtIn.chainId;
const networkConfigurationForRequest = isBuiltIn
? builtIn
: messenger.call(
'NetworkController:getNetworkClientById',
networkClientIdForRequest,
).configuration;
'NetworkController:getNetworkClientById',
networkClientIdForRequest,
).configuration;

const currentProviderConfig = messenger.call(
'NetworkController:getState',
).providerConfig;


const currentChainId = currentProviderConfig.chainId;

if (currentChainId === networkConfigurationForRequest.chainId) {
Expand All @@ -97,15 +91,15 @@ export const createQueuedRequestMiddleware = (
};

try {
const approvedRequestData = await messenger.call(
const approvedRequestData = (await messenger.call(
'ApprovalController:addRequest',
{
origin,
type: ApprovalType.SwitchEthereumChain,
requestData,
},
true,
) as any;
)) as any;

if (isBuiltIn) {
await messenger.call(
Expand All @@ -126,7 +120,7 @@ export const createQueuedRequestMiddleware = (
);
} catch (error) {
res.error = error;
return;
return error;
}

// eslint-disable-next-line n/callback-return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ describe('QueuedRequestController', () => {
const controller = new QueuedRequestController(options);

// Mock requestNext function with resolved promises
const resolvedPromise = jest.fn(() => Promise.resolve());

// Use an array to track the order of execution
const executionOrder: string[] = [];

Expand Down
Loading

0 comments on commit f72084e

Please sign in to comment.