From 7e5b61db0500b7cdf0636bf387fb2a2e72ddfa97 Mon Sep 17 00:00:00 2001 From: Juan Garcia Date: Thu, 28 Nov 2024 14:51:13 +0100 Subject: [PATCH] Implement signless actions --- packages/client/src/actions/account.ts | 49 ++++++++++++++-- packages/client/src/actions/accountManager.ts | 6 -- packages/graphql/schema.graphql | 2 +- packages/graphql/src/accounts/index.ts | 1 + packages/graphql/src/accounts/managers.ts | 2 +- packages/graphql/src/accounts/signless.ts | 58 +++++++++++++++++++ packages/graphql/src/graphql-env.d.ts | 2 +- 7 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 packages/graphql/src/accounts/signless.ts diff --git a/packages/client/src/actions/account.ts b/packages/client/src/actions/account.ts index 114130c16..6bea2fc9f 100644 --- a/packages/client/src/actions/account.ts +++ b/packages/client/src/actions/account.ts @@ -2,17 +2,21 @@ import type { Account, AccountRequest, CreateAccountWithUsernameRequest, + CreateAccountWithUsernameResult, + EnableSignlessResult, SetAccountMetadataRequest, + SetAccountMetadataResult, } from '@lens-protocol/graphql'; import { AccountQuery, CreateAccountWithUsernameMutation, + EnableSignlessMutation, + RemoveSignlessMutation, SetAccountMetadataMutation, } from '@lens-protocol/graphql'; import type { ResultAsync } from '@lens-protocol/types'; -import type { SetAccountMetadataResult } from '@lens-protocol/graphql'; -import type { CreateAccountWithUsernameResult } from '@lens-protocol/graphql'; +import type { RemoveSignlessResult } from '@lens-protocol/graphql'; import type { AnyClient, SessionClient } from '../clients'; import type { UnauthenticatedError, UnexpectedError } from '../errors'; @@ -23,8 +27,6 @@ import type { UnauthenticatedError, UnexpectedError } from '../errors'; * * ```ts * const result = await fetchAccount(anyClient, { - * legacyProfileId?: legacyProfileId('0x01'), - * username?: userNameValue('alice'), * address?: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'), * }); * ``` @@ -65,8 +67,9 @@ export function setAccountMetadata( * * ```ts * const result = await createAccountWithUsername(sessionClient, { - * accountManager: [evmAddress('0x01')], - * localName: 'wagmi', + * username: { + * localname: 'wagmi' + * }, * metadataUri: uri('lens://bafybxiky5jf…'), * }); * ``` @@ -81,3 +84,37 @@ export function createAccountWithUsername( ): ResultAsync { return client.mutation(CreateAccountWithUsernameMutation, { request }); } + +/** + * Get transaction to enable signless. + * + * ```ts + * const result = await enableSignless(sessionClient); + * ``` + * + * @param client - The session client for the authenticated Account. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function enableSignless( + client: SessionClient, +): ResultAsync { + return client.mutation(EnableSignlessMutation, {}); +} + +/** + * Get transaction to remove signless. + * + * ```ts + * const result = await removeSignless(sessionClient); + * ``` + * + * @param client - The session client for the authenticated Account. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function removeSignless( + client: SessionClient, +): ResultAsync { + return client.mutation(RemoveSignlessMutation, {}); +} diff --git a/packages/client/src/actions/accountManager.ts b/packages/client/src/actions/accountManager.ts index ca49c79be..9d387e65c 100644 --- a/packages/client/src/actions/accountManager.ts +++ b/packages/client/src/actions/accountManager.ts @@ -41,12 +41,6 @@ export function fetchAccountManagers( * ```ts * const result = await addAccountManager(sessionClient, { * address: evmAddress("0x90c8c68d0Abfb40D4fCD72316A65e42161520BC3"), - * permissions: { - * canSetMetadataUri: true, - * canTransferNative: true, - * canTransferTokens: true, - * canExecuteTransactions: true, - * }, * }); * ``` * diff --git a/packages/graphql/schema.graphql b/packages/graphql/schema.graphql index b2bab82b5..af41b274d 100644 --- a/packages/graphql/schema.graphql +++ b/packages/graphql/schema.graphql @@ -2279,7 +2279,7 @@ enum ManagedAccountsVisibility { type MeResult { """The logged in account.""" - account: AccountAvailable! + loggedInAs: AccountAvailable! """Whether the account is signless.""" isSignless: Boolean! diff --git a/packages/graphql/src/accounts/index.ts b/packages/graphql/src/accounts/index.ts index 3ac417784..eef25a7a9 100644 --- a/packages/graphql/src/accounts/index.ts +++ b/packages/graphql/src/accounts/index.ts @@ -1,2 +1,3 @@ export * from './account'; export * from './managers'; +export * from './signless'; diff --git a/packages/graphql/src/accounts/managers.ts b/packages/graphql/src/accounts/managers.ts index c59476c28..c653219ce 100644 --- a/packages/graphql/src/accounts/managers.ts +++ b/packages/graphql/src/accounts/managers.ts @@ -11,7 +11,7 @@ const AccountManager = graphql( `fragment AccountManager on AccountManager { __typename addedAt - # address - not possible to query (probably a bug) + manager isLensManager permissions { canExecuteTransactions diff --git a/packages/graphql/src/accounts/signless.ts b/packages/graphql/src/accounts/signless.ts new file mode 100644 index 000000000..ce8d7e681 --- /dev/null +++ b/packages/graphql/src/accounts/signless.ts @@ -0,0 +1,58 @@ +import type { FragmentOf } from 'gql.tada'; + +import { + SelfFundedTransactionRequest, + SponsoredTransactionRequest, + TransactionWillFail, +} from '../fragments'; +import { graphql } from '../graphql'; + +const EnableSignlessResult = graphql( + `fragment EnableSignlessResult on EnableSignlessResult{ + ...on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [SelfFundedTransactionRequest, SponsoredTransactionRequest, TransactionWillFail], +); +export type EnableSignlessResult = FragmentOf; + +export const EnableSignlessMutation = graphql( + `mutation EnableSignless { + value: enableSignless { + ...EnableSignlessResult + } + }`, + [EnableSignlessResult], +); + +const RemoveSignlessResult = graphql( + `fragment RemoveSignlessResult on RemoveSignlessResult{ + ...on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ...on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ...on TransactionWillFail { + ...TransactionWillFail + } + }`, + [SelfFundedTransactionRequest, SponsoredTransactionRequest, TransactionWillFail], +); +export type RemoveSignlessResult = FragmentOf; + +export const RemoveSignlessMutation = graphql( + `mutation RemoveSignless { + value: removeSignless { + ...RemoveSignlessResult + } + }`, + [RemoveSignlessResult], +); diff --git a/packages/graphql/src/graphql-env.d.ts b/packages/graphql/src/graphql-env.d.ts index c2d7435a2..37ce2f3e1 100644 --- a/packages/graphql/src/graphql-env.d.ts +++ b/packages/graphql/src/graphql-env.d.ts @@ -210,7 +210,7 @@ export type introspection_types = { 'LoggedInPostOperations': { kind: 'OBJECT'; name: 'LoggedInPostOperations'; fields: { 'canComment': { name: 'canComment'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'TriStateValue'; ofType: null; }; } }; 'canQuote': { name: 'canQuote'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'TriStateValue'; ofType: null; }; } }; 'canRepost': { name: 'canRepost'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'TriStateValue'; ofType: null; }; } }; 'hasBookmarked': { name: 'hasBookmarked'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'hasCommented': { name: 'hasCommented'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'BooleanValue'; ofType: null; }; } }; 'hasQuoted': { name: 'hasQuoted'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'BooleanValue'; ofType: null; }; } }; 'hasReacted': { name: 'hasReacted'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'hasReported': { name: 'hasReported'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'hasReposted': { name: 'hasReposted'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'BooleanValue'; ofType: null; }; } }; 'id': { name: 'id'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'ID'; ofType: null; }; } }; 'isNotInterested': { name: 'isNotInterested'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; }; }; 'MainContentFocus': { name: 'MainContentFocus'; enumValues: 'ARTICLE' | 'AUDIO' | 'CHECKING_IN' | 'EMBED' | 'EVENT' | 'IMAGE' | 'LINK' | 'LIVESTREAM' | 'MINT' | 'SHORT_VIDEO' | 'SPACE' | 'STORY' | 'TEXT_ONLY' | 'THREE_D' | 'TRANSACTION' | 'VIDEO'; }; 'ManagedAccountsVisibility': { name: 'ManagedAccountsVisibility'; enumValues: 'NONE_HIDDEN' | 'HIDDEN_ONLY' | 'ALL'; }; - 'MeResult': { kind: 'OBJECT'; name: 'MeResult'; fields: { 'account': { name: 'account'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'UNION'; name: 'AccountAvailable'; ofType: null; }; } }; 'appLoggedIn': { name: 'appLoggedIn'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; } }; 'isSignless': { name: 'isSignless'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'isSponsored': { name: 'isSponsored'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'limit': { name: 'limit'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'SponsorshipAllowance'; ofType: null; }; } }; }; }; + 'MeResult': { kind: 'OBJECT'; name: 'MeResult'; fields: { 'appLoggedIn': { name: 'appLoggedIn'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'EvmAddress'; ofType: null; }; } }; 'isSignless': { name: 'isSignless'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'isSponsored': { name: 'isSponsored'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'limit': { name: 'limit'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'SponsorshipAllowance'; ofType: null; }; } }; 'loggedInAs': { name: 'loggedInAs'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'UNION'; name: 'AccountAvailable'; ofType: null; }; } }; }; }; 'MediaAudio': { kind: 'OBJECT'; name: 'MediaAudio'; fields: { 'artist': { name: 'artist'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'attributes': { name: 'attributes'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'LIST'; name: never; ofType: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'MetadataAttribute'; ofType: null; }; }; }; } }; 'cover': { name: 'cover'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'credits': { name: 'credits'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'duration': { name: 'duration'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'genre': { name: 'genre'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'item': { name: 'item'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; }; } }; 'kind': { name: 'kind'; type: { kind: 'ENUM'; name: 'MediaAudioKind'; ofType: null; } }; 'license': { name: 'license'; type: { kind: 'ENUM'; name: 'MetadataLicenseType'; ofType: null; } }; 'lyrics': { name: 'lyrics'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'recordLabel': { name: 'recordLabel'; type: { kind: 'SCALAR'; name: 'Encryptable'; ofType: null; } }; 'type': { name: 'type'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'ENUM'; name: 'MediaAudioType'; ofType: null; }; } }; }; }; 'MediaAudioKind': { name: 'MediaAudioKind'; enumValues: 'MUSIC' | 'PODCAST' | 'AUDIOBOOK' | 'VOICE_NOTE' | 'SOUND' | 'OTHER'; }; 'MediaAudioType': { name: 'MediaAudioType'; enumValues: 'AUDIO_WAV' | 'AUDIO_VND_WAVE' | 'AUDIO_MPEG' | 'AUDIO_OGG' | 'AUDIO_MP_4' | 'AUDIO_AAC' | 'AUDIO_WEBM' | 'AUDIO_FLAC'; };