Skip to content

Commit

Permalink
Merge pull request #1011 from lens-protocol/T-23271/js-actions-refact…
Browse files Browse the repository at this point in the history
…or-all-queries
  • Loading branch information
juangm authored Dec 13, 2024
2 parents 44641e8 + c2d4eb1 commit d36d021
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 173 deletions.
66 changes: 44 additions & 22 deletions packages/client/src/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {
AccountStatsRequest,
AccountsAvailableRequest,
AccountsBlockedRequest,
AccountsBulkRequest,
AccountsRequest,
BlockRequest,
BlockResult,
CreateAccountWithUsernameRequest,
Expand All @@ -21,7 +23,6 @@ import type {
RecommendAccountRequest,
RemoveSignlessResult,
ReportAccountRequest,
SearchAccountsRequest,
SetAccountMetadataRequest,
SetAccountMetadataResult,
UnblockRequest,
Expand All @@ -36,14 +37,15 @@ import {
AccountStatsQuery,
AccountsAvailableQuery,
AccountsBlockedQuery,
AccountsBulkQuery,
AccountsQuery,
BlockMutation,
CreateAccountWithUsernameMutation,
EnableSignlessMutation,
MuteAccountMutation,
RecommendAccountMutation,
RemoveSignlessMutation,
ReportAccountMutation,
SearchAccountsQuery,
SetAccountMetadataMutation,
UnblockMutation,
UndoRecommendAccountMutation,
Expand Down Expand Up @@ -76,6 +78,46 @@ export function fetchAccount(
return client.query(AccountQuery, { request });
}

/**
* Fetch an Accounts.
*
* Using a {@link SessionClient} will yield {@link Account#operations} specific to the authenticated Account.
*
* ```ts
* const result = await fetchAccounts(anyClient);
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts.
*/
export function fetchAccounts(
client: AnyClient,
request: AccountsRequest = {},
): ResultAsync<Paginated<Account> | null, UnexpectedError> {
return client.query(AccountsQuery, { request });
}

/**
* Fetch an Accounts Bulk.
*
* ```ts
* const result = await fetchAccountsBulk(anyClient, {
* addresses: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts.
*/
export function fetchAccountsBulk(
client: AnyClient,
request: AccountsBulkRequest = {},
): ResultAsync<Account[], UnexpectedError> {
return client.query(AccountsBulkQuery, { request });
}

/**
* Fetch an Account Stats.
*
Expand Down Expand Up @@ -174,26 +216,6 @@ export function fetchAccountsBlocked(
return client.query(AccountsBlockedQuery, { request });
}

/**
* Search accounts.
*
* ```ts
* const result = await searchAccounts(anyClient, {
* localName: 'wagmi',
* });
* ```
*
* @param client - Any Lens client.
* @param request - The SearchAccounts query request.
* @returns The list of Account or empty list if it does not find anything.
*/
export function searchAccounts(
client: AnyClient,
request: SearchAccountsRequest,
): ResultAsync<Paginated<Account> | null, UnexpectedError> {
return client.query(SearchAccountsQuery, { request });
}

/**
* Set Account metadata for the authenticated Account.
*
Expand Down
Loading

0 comments on commit d36d021

Please sign in to comment.