From fd94590ecea1271014f225d9a7f48ef39ed74627 Mon Sep 17 00:00:00 2001 From: Thibaut Sardan <33178835+Tbaut@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:32:22 +0200 Subject: [PATCH] Ability to Reject an authentication request instead of ignoring it (#1453) * Reject instead of ignore * lint --- .../src/background/handlers/Extension.ts | 14 ++++++++++---- packages/extension-base/src/background/types.ts | 2 +- .../extension-ui/src/Popup/Authorize/NoAccount.tsx | 4 ++-- .../extension-ui/src/Popup/Authorize/Request.tsx | 6 +++--- packages/extension-ui/src/messaging.ts | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/extension-base/src/background/handlers/Extension.ts b/packages/extension-base/src/background/handlers/Extension.ts index 9e4cb64fed..bbafe46f95 100644 --- a/packages/extension-base/src/background/handlers/Extension.ts +++ b/packages/extension-base/src/background/handlers/Extension.ts @@ -524,8 +524,14 @@ export default class Extension { return { list: remAuth }; } - private deleteAuthRequest (requestId: string): void { - return this.#state.deleteAuthRequest(requestId); + private rejectAuthRequest (id: string): void { + const queued = this.#state.getAuthRequest(id); + + assert(queued, 'Unable to find request'); + + const { reject } = queued; + + reject(new Error('Rejected')); } private updateCurrentTabs ({ urls }: RequestActiveTabsUrlUpdate) { @@ -549,8 +555,8 @@ export default class Extension { case 'pri(authorize.remove)': return this.removeAuthorization(request as string); - case 'pri(authorize.delete.request)': - return this.deleteAuthRequest(request as string); + case 'pri(authorize.reject)': + return this.rejectAuthRequest(request as string); case 'pri(authorize.requests)': return port && this.authorizeSubscribe(id, port); diff --git a/packages/extension-base/src/background/types.ts b/packages/extension-base/src/background/types.ts index a1467fa461..9e7cc8eedc 100644 --- a/packages/extension-base/src/background/types.ts +++ b/packages/extension-base/src/background/types.ts @@ -96,7 +96,7 @@ export interface RequestSignatures { 'pri(authorize.list)': [null, ResponseAuthorizeList]; 'pri(authorize.requests)': [RequestAuthorizeSubscribe, boolean, AuthorizeRequest[]]; 'pri(authorize.remove)': [string, ResponseAuthorizeList]; - 'pri(authorize.delete.request)': [string, void]; + 'pri(authorize.reject)': [string, void]; 'pri(authorize.update)': [RequestUpdateAuthorizedAccounts, void]; 'pri(activeTabsUrl.update)': [RequestActiveTabsUrlUpdate, void]; 'pri(connectedTabsUrl.get)': [null, ConnectedTabsUrlResponse]; diff --git a/packages/extension-ui/src/Popup/Authorize/NoAccount.tsx b/packages/extension-ui/src/Popup/Authorize/NoAccount.tsx index 669d961176..5d71b446c5 100644 --- a/packages/extension-ui/src/Popup/Authorize/NoAccount.tsx +++ b/packages/extension-ui/src/Popup/Authorize/NoAccount.tsx @@ -6,7 +6,7 @@ import React, { useCallback } from 'react'; import { Trans } from 'react-i18next'; import { Button, Warning } from '../../components/index.js'; -import { deleteAuthRequest } from '../../messaging.js'; +import { rejectAuthRequest } from '../../messaging.js'; import { styled } from '../../styled.js'; interface Props { @@ -16,7 +16,7 @@ interface Props { function NoAccount ({ authId, className }: Props): React.ReactElement { const _onClick = useCallback(() => { - deleteAuthRequest(authId).catch(console.error); + rejectAuthRequest(authId).catch(console.error); }, [authId] ); diff --git a/packages/extension-ui/src/Popup/Authorize/Request.tsx b/packages/extension-ui/src/Popup/Authorize/Request.tsx index 6030f913b9..20dc1c2838 100644 --- a/packages/extension-ui/src/Popup/Authorize/Request.tsx +++ b/packages/extension-ui/src/Popup/Authorize/Request.tsx @@ -7,7 +7,7 @@ import React, { useCallback, useContext, useEffect } from 'react'; import { AccountContext, ActionBar, ActionContext, Button, Link } from '../../components/index.js'; import { useTranslation } from '../../hooks/index.js'; -import { approveAuthRequest, deleteAuthRequest } from '../../messaging.js'; +import { approveAuthRequest, rejectAuthRequest } from '../../messaging.js'; import { AccountSelection } from '../../partials/index.js'; import { styled } from '../../styled.js'; import NoAccount from './NoAccount.js'; @@ -44,7 +44,7 @@ function Request ({ authId, className, isFirst, request: { origin }, url }: Prop const _onClose = useCallback( (): void => { - deleteAuthRequest(authId) + rejectAuthRequest(authId) .then(() => onAction()) .catch((error: Error) => console.error(error)); }, @@ -77,7 +77,7 @@ function Request ({ authId, className, isFirst, request: { origin }, url }: Prop isDanger onClick={_onClose} > - {t('Ask again later')} + {t('Reject')} diff --git a/packages/extension-ui/src/messaging.ts b/packages/extension-ui/src/messaging.ts index 553417e3e7..10ed500e64 100644 --- a/packages/extension-ui/src/messaging.ts +++ b/packages/extension-ui/src/messaging.ts @@ -220,8 +220,8 @@ export async function updateAuthorization (authorizedAccounts: string[], url: st return sendMessage('pri(authorize.update)', { authorizedAccounts, url }); } -export async function deleteAuthRequest (requestId: string): Promise { - return sendMessage('pri(authorize.delete.request)', requestId); +export async function rejectAuthRequest (requestId: string): Promise { + return sendMessage('pri(authorize.reject)', requestId); } export async function subscribeMetadataRequests (cb: (accounts: MetadataRequest[]) => void): Promise {