Skip to content

Commit

Permalink
Merge pull request #1002 from lens-protocol/T-23230/js-action-add-mis…
Browse files Browse the repository at this point in the history
…sing-account-mutations

Implement missing mutations for account
  • Loading branch information
cesarenaldi authored Dec 12, 2024
2 parents bb4fbe5 + 33fb8ab commit c6dcb3e
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 89 deletions.
115 changes: 113 additions & 2 deletions packages/client/src/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import type {
AccountStatsRequest,
AccountsAvailableRequest,
AccountsBlockedRequest,
BlockRequest,
BlockResult,
CreateAccountWithUsernameRequest,
CreateAccountWithUsernameResult,
EnableSignlessResult,
MuteRequest,
RecommendAccountRequest,
RemoveSignlessResult,
ReportAccountRequest,
SearchAccountsRequest,
SetAccountMetadataRequest,
SetAccountMetadataResult,
UnblockRequest,
UnblockResult,
UndoRecommendAccountRequest,
UnmuteRequest,
} from '@lens-protocol/graphql';
import {
Expand All @@ -28,12 +35,17 @@ import {
AccountStatsQuery,
AccountsAvailableQuery,
AccountsBlockedQuery,
BlockMutation,
CreateAccountWithUsernameMutation,
EnableSignlessMutation,
MuteAccountMutation,
RecommendAccountMutation,
RemoveSignlessMutation,
ReportAccountMutation,
SearchAccountsQuery,
SetAccountMetadataMutation,
UnblockMutation,
UndoRecommendAccountMutation,
UnmuteAccountMutation,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';
Expand Down Expand Up @@ -264,7 +276,7 @@ export function removeSignless(
*
* ```ts
* const result = await muteAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1");
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
* ```
*
Expand All @@ -284,7 +296,7 @@ export function muteAccount(
*
* ```ts
* const result = await unmuteAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1");
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
* ```
*
Expand All @@ -298,3 +310,102 @@ export function unmuteAccount(
): ResultAsync<void, UnexpectedError | UnauthenticatedError> {
return client.mutation(UnmuteAccountMutation, { request });
}

/**
* Report an account.
*
* ```ts
* const result = await reportAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* reason: AccountReportReason.RepetitiveSpam,
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns void.
*/
export function reportAccount(
client: SessionClient,
request: ReportAccountRequest,
): ResultAsync<void, UnexpectedError | UnauthenticatedError> {
return client.mutation(ReportAccountMutation, { request });
}

/**
* Block an account.
*
* ```ts
* const result = await blockAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function blockAccount(
client: SessionClient,
request: BlockRequest,
): ResultAsync<BlockResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(BlockMutation, { request });
}

/**
* Unblock an account.
*
* ```ts
* const result = await unblockAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function unblockAccount(
client: SessionClient,
request: UnblockRequest,
): ResultAsync<UnblockResult, UnauthenticatedError | UnexpectedError> {
return client.mutation(UnblockMutation, { request });
}

/**
* Recommend an account.
*
* ```ts
* const result = await recommendAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns void.
*/
export function recommendAccount(
client: SessionClient,
request: RecommendAccountRequest,
): ResultAsync<void, UnexpectedError | UnauthenticatedError> {
return client.mutation(RecommendAccountMutation, { request });
}

/**
* Undo recommendation of an account.
*
* ```ts
* const result = await undoRecommendAccount(sessionClient, {
* account: evmAddress("0xe5439696f4057aF073c0FB2dc6e5e755392922e1"),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns void.
*/
export function undoRecommendAccount(
client: SessionClient,
request: UndoRecommendAccountRequest,
): ResultAsync<void, UnexpectedError | UnauthenticatedError> {
return client.mutation(UndoRecommendAccountMutation, { request });
}
23 changes: 23 additions & 0 deletions packages/client/src/actions/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import type {
RefreshResult,
RevokeAuthenticationRequest,
RolloverRefreshRequest,
SwitchAccountRequest,
SwitchAccountResult,
} from '@lens-protocol/graphql';
import {
AuthenticatedSessionsQuery,
CurrentSessionQuery,
LegacyRolloverRefreshMutation,
RefreshMutation,
RevokeAuthenticationMutation,
SwitchAccountMutation,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

Expand Down Expand Up @@ -119,3 +122,23 @@ export function legacyRolloverRefresh(
): ResultAsync<RefreshResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(LegacyRolloverRefreshMutation, { request });
}

/**
* Switch to account managed.
*
* ```ts
* const result = await switchAccount(sessionClient{
* account: evmAddress('0x90c8c68d0Abfb40D4fCD72316A65e42161520BC3'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The query request.
* @returns The authenticated tokens for the switched account.
*/
export function switchAccount(
client: SessionClient,
request: SwitchAccountRequest,
): ResultAsync<SwitchAccountResult, UnauthenticatedError | UnexpectedError> {
return client.query(SwitchAccountMutation, { request });
}
Loading

0 comments on commit c6dcb3e

Please sign in to comment.