Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Aug 23, 2023
1 parent 0e9a9e8 commit 6d3a89d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 127 deletions.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
44 changes: 4 additions & 40 deletions app/lnurlp/[username]/callback/route.ts
Original file line number Diff line number Diff line change
@@ -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!
Expand Down
43 changes: 43 additions & 0 deletions app/lnurlp/[username]/graphql.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
`
69 changes: 3 additions & 66 deletions app/lnurlp/[username]/route.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 0 additions & 6 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6d3a89d

Please sign in to comment.