Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actions for fetch accounts blocked/available #994

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires authentication.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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
Loading