diff --git a/apps/pay/app/lnurlp/[username]/callback/route.ts b/apps/pay/app/lnurlp/[username]/callback/route.ts index 762b918ca2..3955da147c 100644 --- a/apps/pay/app/lnurlp/[username]/callback/route.ts +++ b/apps/pay/app/lnurlp/[username]/callback/route.ts @@ -10,10 +10,10 @@ import Redis from "ioredis" import { env } from "../../../../env" import { - AccountDefaultWalletsDocument, - AccountDefaultWalletsQuery, - LnInvoiceCreateOnBehalfOfRecipientsDocument, - LnInvoiceCreateOnBehalfOfRecipientsMutation, + AccountDefaultWalletDocument, + AccountDefaultWalletQuery, + LnInvoiceCreateOnBehalfOfRecipientDocument, + LnInvoiceCreateOnBehalfOfRecipientMutation, } from "../../../../lib/graphql/generated" import { client } from "../graphql" import { getOriginalRequestInfo } from "../../../../utils/utils" @@ -95,8 +95,8 @@ export async function GET( let walletId: string | null = null try { - const { data } = await client.query({ - query: AccountDefaultWalletsDocument, + const { data } = await client.query({ + query: AccountDefaultWalletDocument, variables: { username, walletCurrency: "BTC" }, context: { "x-real-ip": request.headers.get("x-real-ip"), @@ -144,17 +144,17 @@ export async function GET( descriptionHash = crypto.createHash("sha256").update(metadata).digest("hex") } - const result = await client.mutate({ - mutation: LnInvoiceCreateOnBehalfOfRecipientsDocument, + const result = await client.mutate({ + mutation: LnInvoiceCreateOnBehalfOfRecipientDocument, variables: { - recipientWalletId: walletId, + walletId, amount: amountSats, descriptionHash, }, }) const errors = result.errors - const invoice = result.data?.lnInvoiceCreateOnBehalfOfRecipient?.invoice + const invoice = result.data?.mutationData?.invoice if ((errors && errors.length) || !invoice) { console.log("error getting invoice", errors) diff --git a/apps/pay/codegen.yml b/apps/pay/codegen.yml index 55125a5a3d..b8191642ca 100644 --- a/apps/pay/codegen.yml +++ b/apps/pay/codegen.yml @@ -1,14 +1,11 @@ overwrite: true schema: "https://raw.githubusercontent.com/GaloyMoney/galoy/main/core/api/src/graphql/public/schema.graphql" documents: - - "components/**/*.ts" - - "components/**/*.tsx" - - "lib/**/*.ts" - - "lib/**/*.tsx" - - "pages/**/*.ts" - - "pages/**/*.tsx" - - "hooks/**/*.ts" - - "hooks/**/*.tsx" + - "app/**/*.{ts,tsx}" + - "components/**/*.{ts,tsx}" + - "lib/**/*.{ts,tsx}" + - "pages/**/*.{ts,tsx}" + - "hooks/**/*.{ts,tsx}" generates: lib/graphql/generated.ts: plugins: diff --git a/apps/pay/lib/graphql/generated.ts b/apps/pay/lib/graphql/generated.ts index 8c5b0b55b0..c98ea62fc4 100644 --- a/apps/pay/lib/graphql/generated.ts +++ b/apps/pay/lib/graphql/generated.ts @@ -2043,6 +2043,23 @@ export const WalletCurrency = { } as const; export type WalletCurrency = typeof WalletCurrency[keyof typeof WalletCurrency]; +export type LnInvoiceCreateOnBehalfOfRecipientMutationVariables = Exact<{ + walletId: Scalars['WalletId']; + amount: Scalars['SatAmount']; + descriptionHash: Scalars['Hex32Bytes']; +}>; + + +export type LnInvoiceCreateOnBehalfOfRecipientMutation = { readonly __typename: 'Mutation', readonly mutationData: { readonly __typename: 'LnInvoicePayload', readonly errors: ReadonlyArray<{ readonly __typename: 'GraphQLApplicationError', readonly message: string }>, readonly invoice?: { readonly __typename: 'LnInvoice', readonly paymentRequest: string, readonly paymentHash: string } | null } }; + +export type AccountDefaultWalletQueryVariables = Exact<{ + username: Scalars['Username']; + walletCurrency: WalletCurrency; +}>; + + +export type AccountDefaultWalletQuery = { readonly __typename: 'Query', readonly accountDefaultWallet: { readonly __typename: 'PublicWallet', readonly id: string, readonly walletCurrency: WalletCurrency } }; + export type LnInvoicePaymentStatusSubscriptionVariables = Exact<{ input: LnInvoicePaymentStatusInput; }>; @@ -2112,6 +2129,87 @@ export type NodeIdsQueryVariables = Exact<{ [key: string]: never; }>; export type NodeIdsQuery = { readonly __typename: 'Query', readonly globals?: { readonly __typename: 'Globals', readonly nodesIds: ReadonlyArray } | null }; +export const LnInvoiceCreateOnBehalfOfRecipientDocument = gql` + mutation lnInvoiceCreateOnBehalfOfRecipient($walletId: WalletId!, $amount: SatAmount!, $descriptionHash: Hex32Bytes!) { + mutationData: lnInvoiceCreateOnBehalfOfRecipient( + input: {recipientWalletId: $walletId, amount: $amount, descriptionHash: $descriptionHash} + ) { + errors { + message + } + invoice { + paymentRequest + paymentHash + } + } +} + `; +export type LnInvoiceCreateOnBehalfOfRecipientMutationFn = Apollo.MutationFunction; + +/** + * __useLnInvoiceCreateOnBehalfOfRecipientMutation__ + * + * To run a mutation, you first call `useLnInvoiceCreateOnBehalfOfRecipientMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useLnInvoiceCreateOnBehalfOfRecipientMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [lnInvoiceCreateOnBehalfOfRecipientMutation, { data, loading, error }] = useLnInvoiceCreateOnBehalfOfRecipientMutation({ + * variables: { + * walletId: // value for 'walletId' + * amount: // value for 'amount' + * descriptionHash: // value for 'descriptionHash' + * }, + * }); + */ +export function useLnInvoiceCreateOnBehalfOfRecipientMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(LnInvoiceCreateOnBehalfOfRecipientDocument, options); + } +export type LnInvoiceCreateOnBehalfOfRecipientMutationHookResult = ReturnType; +export type LnInvoiceCreateOnBehalfOfRecipientMutationResult = Apollo.MutationResult; +export type LnInvoiceCreateOnBehalfOfRecipientMutationOptions = Apollo.BaseMutationOptions; +export const AccountDefaultWalletDocument = gql` + query accountDefaultWallet($username: Username!, $walletCurrency: WalletCurrency!) { + accountDefaultWallet(username: $username, walletCurrency: $walletCurrency) { + __typename + id + walletCurrency + } +} + `; + +/** + * __useAccountDefaultWalletQuery__ + * + * To run a query within a React component, call `useAccountDefaultWalletQuery` and pass it any options that fit your needs. + * When your component renders, `useAccountDefaultWalletQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useAccountDefaultWalletQuery({ + * variables: { + * username: // value for 'username' + * walletCurrency: // value for 'walletCurrency' + * }, + * }); + */ +export function useAccountDefaultWalletQuery(baseOptions: Apollo.QueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useQuery(AccountDefaultWalletDocument, options); + } +export function useAccountDefaultWalletLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useLazyQuery(AccountDefaultWalletDocument, options); + } +export type AccountDefaultWalletQueryHookResult = ReturnType; +export type AccountDefaultWalletLazyQueryHookResult = ReturnType; +export type AccountDefaultWalletQueryResult = Apollo.QueryResult; export const LnInvoicePaymentStatusDocument = gql` subscription lnInvoicePaymentStatus($input: LnInvoicePaymentStatusInput!) { lnInvoicePaymentStatus(input: $input) {