Skip to content

Commit

Permalink
Refactor isPopupReadyResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMHasperhoven committed Aug 23, 2024
1 parent 3f788eb commit ccd44ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion apps/extension/src/entry/popup-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ chrome.runtime.onMessage.addListener(
if (isTxApprovalRequest(req)) {
void txApprovalSelector(useStore.getState()).acceptRequest(req, responder);
} else if (isOriginApprovalRequest(req)) {
req.request.origin;
originApprovalSelector(useStore.getState()).acceptRequest(req, responder);
} else {
throw new Error('Unknown popup request');
Expand Down
12 changes: 10 additions & 2 deletions apps/extension/src/message/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ export const isPopupRequest = (req: unknown): req is PopupRequest =>
typeof req.type === 'string' &&
req.type in PopupType;

export const isPopupResponse = (res: unknown): res is PopupResponse =>
res != null &&
typeof res === 'object' &&
('data' in res || 'error' in res) &&
'type' in res &&
typeof res.type === 'string' &&
res.type in PopupType;

export const isOriginApprovalRequest = (req: unknown): req is InternalRequest<OriginApproval> =>
isPopupRequest(req) && req.type === PopupType.OriginApproval;

export const isTxApprovalRequest = (req: unknown): req is InternalRequest<TxApproval> =>
isPopupRequest(req) && req.type === PopupType.TxApproval;

export const isPopupReadyResponse = (req: unknown): req is InternalResponse<Ready> =>
isPopupRequest(req) && req.type === PopupType.Ready;
export const isPopupReadyResponse = (res: unknown): res is InternalResponse<Ready> =>
isPopupResponse(res) && res.type === PopupType.Ready;

0 comments on commit ccd44ae

Please sign in to comment.