diff --git a/README.md b/README.md index a83044dc..6678919f 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,11 @@ With a default installation, Galoy-Pay can be accessed under `pay.domain.com`. Galoy-Pay uses query, mutation, and subscription operations from the Galoy's graphql API endpoints `api.domain.com` as defined in [schema.graphql](https://github.com/GaloyMoney/galoy/blob/main/src/graphql/public/schema.graphql) -## How to run this repo locally? +## How to run this repo locally ? -In the project directory, create a file name `.env.local` and fill it for local dev with +`.env.local` is set with values that works for local dev. -``` -NEXT_PUBLIC_GRAPHQL_URL='http://localhost:4002/graphql' -NEXT_PUBLIC_GRAPHQL_WEBSOCKET_URL='ws://localhost:4002/graphqlws' -GRAPHQL_URL_INTERNAL="http://localhost:4002/graphql" -``` - - -for staging, use +for staging, use `.env.local` with the following properties ``` NEXT_PUBLIC_GRAPHQL_URL='https://api.staging.galoy.io/graphql' diff --git a/app/lnurlp/[username]/callback/route.ts b/app/lnurlp/[username]/callback/route.ts index 851cc60e..d5100f5d 100644 --- a/app/lnurlp/[username]/callback/route.ts +++ b/app/lnurlp/[username]/callback/route.ts @@ -1,57 +1,21 @@ import { NextResponse } from "next/server" import { URL } from "url" +import { gql } from "@apollo/client" import crypto from "crypto" -import { - ApolloClient, - ApolloLink, - concat, - gql, - HttpLink, - InMemoryCache, -} from "@apollo/client" import Redis from "ioredis" -import { GRAPHQL_URL_INTERNAL, NOSTR_PUBKEY } from "../../../../lib/config" +import { URL_HOST_DOMAIN } from "../../../../config/config" +import { NOSTR_PUBKEY } from "../../../../lib/config" import { AccountDefaultWalletDocument, AccountDefaultWalletQuery, LnInvoiceCreateOnBehalfOfRecipientDocument, LnInvoiceCreateOnBehalfOfRecipientMutation, } from "../../../../lib/graphql/generated" -import { URL_HOST_DOMAIN } from "../../../../config/config" - -const ipForwardingMiddleware = new ApolloLink((operation, forward) => { - operation.setContext(({ headers = {} }) => ({ - headers: { - ...headers, - "x-real-ip": operation.getContext()["x-real-ip"], - "x-forwarded-for": operation.getContext()["x-forwarded-for"], - }, - })) - - return forward(operation) -}) - -const client = new ApolloClient({ - link: concat( - ipForwardingMiddleware, - new HttpLink({ - uri: GRAPHQL_URL_INTERNAL, - }), - ), - cache: new InMemoryCache(), -}) +import { client } from "../graphql" gql` - query accountDefaultWallet($username: Username!, $walletCurrency: WalletCurrency!) { - accountDefaultWallet(username: $username, walletCurrency: $walletCurrency) { - __typename - id - walletCurrency - } - } - mutation lnInvoiceCreateOnBehalfOfRecipient( $walletId: WalletId! $amount: SatAmount! diff --git a/app/lnurlp/[username]/graphql.ts b/app/lnurlp/[username]/graphql.ts new file mode 100644 index 00000000..a13ec922 --- /dev/null +++ b/app/lnurlp/[username]/graphql.ts @@ -0,0 +1,43 @@ +import { + ApolloClient, + ApolloLink, + concat, + gql, + HttpLink, + InMemoryCache, +} from "@apollo/client" + +import { GRAPHQL_URL_INTERNAL } from "../../../lib/config" + +const ipForwardingMiddleware = new ApolloLink((operation, forward) => { + operation.setContext(({ headers = {} }) => ({ + headers: { + ...headers, + "x-real-ip": operation.getContext()["x-real-ip"], + "x-forwarded-for": operation.getContext()["x-forwarded-for"], + }, + })) + + return forward(operation) +}) + +export const client = new ApolloClient({ + link: concat( + ipForwardingMiddleware, + new HttpLink({ + uri: GRAPHQL_URL_INTERNAL, + fetchOptions: { cache: "no-store" }, + }), + ), + cache: new InMemoryCache(), +}) + +gql` + query accountDefaultWallet($username: Username!, $walletCurrency: WalletCurrency!) { + accountDefaultWallet(username: $username, walletCurrency: $walletCurrency) { + __typename + id + walletCurrency + } + } +` diff --git a/app/lnurlp/[username]/route.ts b/app/lnurlp/[username]/route.ts index 0c66b1ae..43dd6858 100644 --- a/app/lnurlp/[username]/route.ts +++ b/app/lnurlp/[username]/route.ts @@ -1,77 +1,14 @@ import { NextResponse } from "next/server" -import { - ApolloClient, - ApolloLink, - concat, - gql, - HttpLink, - InMemoryCache, -} from "@apollo/client" - -import { GRAPHQL_URL_INTERNAL, NOSTR_PUBKEY, PAY_SERVER } from "../../../lib/config" +import { URL_HOST_DOMAIN } from "../../../config/config" +import { NOSTR_PUBKEY, PAY_SERVER } from "../../../lib/config" import { AccountDefaultWalletDocument, AccountDefaultWalletQuery, RealtimePriceInitialDocument, RealtimePriceInitialQuery, } from "../../../lib/graphql/generated" -import { URL_HOST_DOMAIN } from "../../../config/config" - -const ipForwardingMiddleware = new ApolloLink((operation, forward) => { - operation.setContext(({ headers = {} }) => ({ - headers: { - ...headers, - "x-real-ip": operation.getContext()["x-real-ip"], - "x-forwarded-for": operation.getContext()["x-forwarded-for"], - }, - })) - - return forward(operation) -}) - -const client = new ApolloClient({ - link: concat( - ipForwardingMiddleware, - new HttpLink({ - uri: GRAPHQL_URL_INTERNAL, - fetchOptions: { cache: "no-store" }, - }), - ), - cache: new InMemoryCache(), -}) - -gql` - query accountDefaultWallet($username: Username!, $walletCurrency: WalletCurrency!) { - accountDefaultWallet(username: $username, walletCurrency: $walletCurrency) { - __typename - id - walletCurrency - } - } - - mutation lnInvoiceCreateOnBehalfOfRecipient( - $walletId: WalletId! - $amount: SatAmount! - $descriptionHash: Hex32Bytes! - ) { - mutationData: lnInvoiceCreateOnBehalfOfRecipient( - input: { - recipientWalletId: $walletId - amount: $amount - descriptionHash: $descriptionHash - } - ) { - errors { - message - } - invoice { - paymentRequest - paymentHash - } - } - } -` +import { client } from "./graphql" const nostrEnabled = !!NOSTR_PUBKEY diff --git a/lib/config.ts b/lib/config.ts index 51d382d1..dbdc8252 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -6,12 +6,6 @@ let GRAPHQL_WEBSOCKET_URL = process.env.NEXT_PUBLIC_GRAPHQL_WEBSOCKET_URL as str // for example: "api.galoy-name-galoy.svc.cluster.local" const GRAPHQL_URL_INTERNAL = process.env.GRAPHQL_URL_INTERNAL -// this one should always be set -// it's possible to always set it because it's not a NEXT_PUBLIC_ variable -if (!GRAPHQL_URL_INTERNAL && typeof window === "undefined") { - throw Error("GRAPHQL_URL_INTERNAL is not defined") -} - // from https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables // Note: After being built, your app will no longer respond to changes to these environment variables. // For instance, if you use a Heroku pipeline to promote slugs built in one environment to another environment, diff --git a/package.json b/package.json index ef3859cc..a72e19d7 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "prettier": "^2.4.1", "react-dev-utils": "^12.0.1", "ts-pnp": "1.2.0", - "typescript": "^4.4.4" + "typescript": "5.1.6" }, "eslintConfig": { "extends": [ diff --git a/yarn.lock b/yarn.lock index 53a33631..d3dbc469 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6798,10 +6798,10 @@ typeforce@^1.11.3, typeforce@^1.11.5: resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== -typescript@^4.4.4: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@5.1.6: + version "5.1.6" + resolved "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274" + integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA== ua-parser-js@^0.7.30: version "0.7.35"