Skip to content

Commit

Permalink
Add actions for fetch accounts blocked/available (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm authored Dec 6, 2024
1 parent f8c0644 commit 3830c23
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 19 deletions.
44 changes: 44 additions & 0 deletions packages/client/src/actions/account.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type {
Account,
AccountAvailable,
AccountBlocked,
AccountFeedsStats,
AccountFeedsStatsRequest,
AccountGraphsFollowStats,
AccountGraphsStatsRequest,
AccountRequest,
AccountStats,
AccountStatsRequest,
AccountsAvailableRequest,
AccountsBlockedRequest,
CreateAccountWithUsernameRequest,
CreateAccountWithUsernameResult,
EnableSignlessResult,
Expand All @@ -20,6 +24,8 @@ import {
AccountGraphsStatsQuery,
AccountQuery,
AccountStatsQuery,
AccountsAvailableQuery,
AccountsBlockedQuery,
CreateAccountWithUsernameMutation,
EnableSignlessMutation,
RemoveSignlessMutation,
Expand Down Expand Up @@ -114,6 +120,44 @@ export function fetchAccountGraphStats(
return client.query(AccountGraphsStatsQuery, { request });
}

/**
* Fetch Accounts Available.
*
* ```ts
* const result = await fetchAccountsAvailable(anyClient, {
* managedBy: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of available accounts.
*/
export function fetchAccountsAvailable(
client: AnyClient,
request: AccountsAvailableRequest,
): ResultAsync<Paginated<AccountAvailable> | null, UnexpectedError> {
return client.query(AccountsAvailableQuery, { request });
}

/**
* Fetch Blocked Accounts.
*
* ```ts
* const result = await fetchAccountsBlocked(sessionClient);
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The query request.
* @returns The list of blocked accounts.
*/
export function fetchAccountsBlocked(
client: SessionClient,
request: AccountsBlockedRequest,
): ResultAsync<Paginated<AccountBlocked> | null, UnexpectedError> {
return client.query(AccountsBlockedQuery, { request });
}

/**
* Search accounts.
*
Expand Down
34 changes: 34 additions & 0 deletions packages/graphql/src/accounts/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { FragmentOf } from 'gql.tada';
import {
Account,
AccountAvailable,
AccountBlocked,
PaginatedResultInfo,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
Expand Down Expand Up @@ -197,3 +199,35 @@ export const AccountGraphsStatsQuery = graphql(
);

export type AccountGraphsStatsRequest = RequestOf<typeof AccountGraphsStatsQuery>;

export const AccountsAvailableQuery = graphql(
`query AccountsAvailable($request: AccountsAvailableRequest!) {
value: accountsAvailable(request: $request) {
items{
...AccountAvailable
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AccountAvailable, PaginatedResultInfo],
);

export type AccountsAvailableRequest = RequestOf<typeof AccountsAvailableQuery>;

export const AccountsBlockedQuery = graphql(
`query AccountsBlocked($request: AccountsBlockedRequest!) {
value: accountsBlocked(request: $request) {
items{
...AccountBlocked
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AccountBlocked, PaginatedResultInfo],
);

export type AccountsBlockedRequest = RequestOf<typeof AccountsBlockedQuery>;
17 changes: 1 addition & 16 deletions packages/graphql/src/accounts/managers.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import type { FragmentOf } from 'gql.tada';
import {
AccountManager,
PaginatedResultInfo,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
} from '../fragments';
import { type RequestOf, graphql } from '../graphql';

const AccountManager = graphql(
`fragment AccountManager on AccountManager {
__typename
addedAt
manager
isLensManager
permissions {
canExecuteTransactions
canSetMetadataUri
canTransferNative
canTransferTokens
}
}`,
);
export type AccountManager = FragmentOf<typeof AccountManager>;

export const AccountManagersQuery = graphql(
`query AccountManagers($request: AccountManagersRequest!) {
value: accountManagers(request: $request) {
Expand Down
69 changes: 69 additions & 0 deletions packages/graphql/src/fragments/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,72 @@ export const FullAccount = graphql(
[AccountMetadata, LoggedInAccountOperations, Username],
);
export type FullAccount = FragmentOf<typeof FullAccount>;

const AccountManagerPermissions = graphql(
`fragment AccountManagerPermissions on AccountManagerPermissions {
__typename
canExecuteTransactions
canSetMetadataUri
canTransferNative
canTransferTokens
}`,
);
export type AccountManagerPermissions = FragmentOf<typeof AccountManagerPermissions>;

export const AccountManager = graphql(
`fragment AccountManager on AccountManager {
__typename
addedAt
manager
isLensManager
permissions {
...AccountManagerPermissions
}
}`,
);
export type AccountManager = FragmentOf<typeof AccountManager>;

const AccountManaged = graphql(
`fragment AccountManaged on AccountManaged {
__typename
addedAt
account {
...Account
}
permissions {
...AccountManagerPermissions
}
}`,
[AccountManagerPermissions, Account],
);
export type AccountManaged = FragmentOf<typeof AccountManaged>;

export const AccountAvailable = graphql(
`fragment AccountAvailable on AccountAvailable {
__typename
... on AccountManaged {
...AccountManaged
}
... on AccountOwned {
__typename
addedAt
account {
...Account
}
}
}`,
[Account, AccountManaged],
);
export type AccountAvailable = FragmentOf<typeof AccountAvailable>;

export const AccountBlocked = graphql(
`fragment AccountBlocked on AccountBlocked {
__typename
blockedAt
account {
...Account
}
}`,
[Account],
);
export type AccountBlocked = FragmentOf<typeof AccountBlocked>;
Loading

0 comments on commit 3830c23

Please sign in to comment.