From dfdf050ce43160ce201d376407e240b7caab90e6 Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Wed, 28 Oct 2026 12:28:35 +0000 Subject: [PATCH 1/2] feat(social-controllers): add unblockProfile to SocialService --- .../src/SocialService-method-action-types.ts | 17 +++++ .../src/SocialService.test.ts | 68 +++++++++++++++++++ .../social-controllers/src/SocialService.ts | 33 +++++++++ packages/social-controllers/src/index.ts | 2 + .../src/social-constants.ts | 1 + .../social-controllers/src/social-types.ts | 8 +++ 6 files changed, 129 insertions(+) diff --git a/packages/social-controllers/src/SocialService-method-action-types.ts b/packages/social-controllers/src/SocialService-method-action-types.ts index 086511ed4b9..7eceb2e5a59 100644 --- a/packages/social-controllers/src/SocialService-method-action-types.ts +++ b/packages/social-controllers/src/SocialService-method-action-types.ts @@ -431,6 +431,22 @@ export type SocialServiceBlockAction = { handler: SocialService['block']; }; +/** + * Removes the current user's block on a trader. + * + * Calls `DELETE ${baseUrl}/moderation/blocks/profiles/${profileId}`. + * Unblocking a trader who is not blocked is a no-op. The caller is + * identified server-side from the JWT sub claim carried in the + * Authorization header. + * + * @param options - Options bag. + * @param options.profileId - Profile id (UUID) of the trader to unblock. + */ +export type SocialServiceUnblockProfileAction = { + type: `SocialService:unblockProfile`; + handler: SocialService['unblockProfile']; +}; + /** * Fetches traders the current user has blocked. * @@ -491,5 +507,6 @@ export type SocialServiceMethodActions = | SocialServiceOptInToLeaderboardAction | SocialServiceRefreshNotificationPreferencesCacheAction | SocialServiceBlockAction + | SocialServiceUnblockProfileAction | SocialServiceFetchBlockedProfilesAction | SocialServiceFetchBlockedContentAction; diff --git a/packages/social-controllers/src/SocialService.test.ts b/packages/social-controllers/src/SocialService.test.ts index 9c8065a1cd3..9f7c3e6efa8 100644 --- a/packages/social-controllers/src/SocialService.test.ts +++ b/packages/social-controllers/src/SocialService.test.ts @@ -2932,6 +2932,74 @@ describe('SocialService', () => { }); }); + describe('unblockProfile', () => { + it('sends DELETE to /moderation/blocks/profiles/:profileId', async () => { + mockFetch.mockResolvedValue({ ok: true, status: 204 }); + + const service = createService(); + const result = await service.unblockProfile({ + profileId: mockProfileSummary.profileId, + }); + + expect(result).toBeUndefined(); + expect(mockFetch).toHaveBeenCalledWith( + `${V1_URL}/moderation/blocks/profiles/${mockProfileSummary.profileId}`, + { + method: 'DELETE', + headers: { Authorization: `Bearer ${MOCK_TOKEN}` }, + }, + ); + }); + + it('encodes the profile id in the URL path', async () => { + mockFetch.mockResolvedValue({ ok: true, status: 204 }); + + const service = createService(); + await service.unblockProfile({ profileId: 'a/b c' }); + + expect(mockFetch).toHaveBeenCalledWith( + `${V1_URL}/moderation/blocks/profiles/a%2Fb%20c`, + expect.anything(), + ); + }); + + it('throws HttpError on non-ok response', async () => { + mockFetch.mockResolvedValue({ ok: false, status: 400 }); + + const service = createService(); + + await expect( + service.unblockProfile({ profileId: mockProfileSummary.profileId }), + ).rejects.toThrow( + `${SocialServiceErrorMessage.UNBLOCK_PROFILE_FAILED}: 400`, + ); + }); + + it('always sends the request on repeated calls (staleTime: 0)', async () => { + mockFetch.mockResolvedValue({ ok: true, status: 204 }); + + const service = createService(); + await service.unblockProfile({ profileId: mockProfileSummary.profileId }); + await service.unblockProfile({ profileId: mockProfileSummary.profileId }); + + expect(mockFetch).toHaveBeenCalledTimes(2); + }); + + it('is callable via messenger action', async () => { + mockFetch.mockResolvedValue({ ok: true, status: 204 }); + + const messenger = createMessenger(); + // eslint-disable-next-line no-new + new SocialService({ messenger, baseUrl: BASE_URL }); + + const result = await messenger.call('SocialService:unblockProfile', { + profileId: mockProfileSummary.profileId, + }); + + expect(result).toBeUndefined(); + }); + }); + describe('fetchBlockedProfiles', () => { const mockBlockedProfilesResponse = { items: [ diff --git a/packages/social-controllers/src/SocialService.ts b/packages/social-controllers/src/SocialService.ts index 80e64d9c5bc..d55370dbcc0 100644 --- a/packages/social-controllers/src/SocialService.ts +++ b/packages/social-controllers/src/SocialService.ts @@ -43,6 +43,7 @@ import type { SwapCommentResponse, TranslateCommentOptions, TraderProfileResponse, + UnblockProfileOptions, UnfollowOptions, UnfollowResponse, } from './social-types.js'; @@ -95,6 +96,7 @@ const MESSENGER_EXPOSED_METHODS = [ 'optInToLeaderboard', 'refreshNotificationPreferencesCache', 'block', + 'unblockProfile', 'fetchBlockedProfiles', 'fetchBlockedContent', ] as const; @@ -1176,6 +1178,37 @@ export class SocialService extends BaseDataService< }); } + /** + * Removes the current user's block on a trader. + * + * Calls `DELETE ${baseUrl}/moderation/blocks/profiles/${profileId}`. + * Unblocking a trader who is not blocked is a no-op. The caller is + * identified server-side from the JWT sub claim carried in the + * Authorization header. + * + * @param options - Options bag. + * @param options.profileId - Profile id (UUID) of the trader to unblock. + */ + async unblockProfile({ profileId }: UnblockProfileOptions): Promise { + await this.fetchQuery({ + queryKey: [`${this.name}:unblockProfile`, profileId], + staleTime: 0, + queryFn: async () => { + const url = `${this.#v1Url}/moderation/blocks/profiles/${encodeURIComponent(profileId)}`; + const authHeaders = await this.#getAuthHeaders(); + const response = await fetch(url, { + method: 'DELETE', + headers: authHeaders, + }); + SocialService.#throwIfNotOk( + response, + SocialServiceErrorMessage.UNBLOCK_PROFILE_FAILED, + ); + return null; + }, + }); + } + /** * Fetches traders the current user has blocked. * diff --git a/packages/social-controllers/src/index.ts b/packages/social-controllers/src/index.ts index ddce06a059a..73ed80b4466 100644 --- a/packages/social-controllers/src/index.ts +++ b/packages/social-controllers/src/index.ts @@ -54,6 +54,7 @@ export type { SocialServiceTranslateCommentAction, SocialServiceRefreshNotificationPreferencesCacheAction, SocialServiceRemoveCommentReactionAction, + SocialServiceUnblockProfileAction, SocialServiceUnfollowAction, } from './SocialService-method-action-types.js'; @@ -138,6 +139,7 @@ export type { TraderProfileResponse, TraderRankingTag, TraderStats, + UnblockProfileOptions, UnfollowOptions, UnfollowResponse, } from './social-types.js'; diff --git a/packages/social-controllers/src/social-constants.ts b/packages/social-controllers/src/social-constants.ts index 99db3b15df2..9fe40042828 100644 --- a/packages/social-controllers/src/social-constants.ts +++ b/packages/social-controllers/src/social-constants.ts @@ -68,6 +68,7 @@ export const SocialServiceErrorMessage = { NOTIFICATION_PREFERENCES_CACHE_REFRESH_FAILED: 'SocialService: Notification preferences cache refresh request failed', BLOCK_FAILED: 'SocialService: Block request failed', + UNBLOCK_PROFILE_FAILED: 'SocialService: Unblock profile request failed', FETCH_BLOCKED_PROFILES_FAILED: 'SocialService: Blocked profiles request failed', FETCH_BLOCKED_PROFILES_INVALID_RESPONSE: diff --git a/packages/social-controllers/src/social-types.ts b/packages/social-controllers/src/social-types.ts index 069a036bcfe..5e426a346f3 100644 --- a/packages/social-controllers/src/social-types.ts +++ b/packages/social-controllers/src/social-types.ts @@ -842,6 +842,14 @@ export type BlockOptions = reason?: string; }; +/** + * Options for `DELETE /v1/moderation/blocks/profiles/:profileId`. + */ +export type UnblockProfileOptions = { + /** Profile id (UUID) of the trader to unblock. */ + profileId: string; +}; + /** * Options for the cursor-paginated moderation list endpoints. Omit `cursor` * for the first page. From 26136068906541cb7e50be8fecca9730d436462b Mon Sep 17 00:00:00 2001 From: Antonio Regadas Date: Wed, 28 Oct 2026 12:29:04 +0000 Subject: [PATCH 2/2] chore(social-controllers): update changelog --- packages/social-controllers/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/social-controllers/CHANGELOG.md b/packages/social-controllers/CHANGELOG.md index b4cbfe10f36..e2e990377a1 100644 --- a/packages/social-controllers/CHANGELOG.md +++ b/packages/social-controllers/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `unblockProfile` to `SocialService` (`SocialService:unblockProfile`). Calls `DELETE /v1/moderation/blocks/profiles/:profileId` to remove the current user's block on a trader; unblocking a trader who is not blocked is a no-op. Export `UnblockProfileOptions` and `SocialServiceUnblockProfileAction` ([#11159](https://github.com/MetaMask/core/pull/11159)) + ## [3.13.0] ### Added