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

feat(pay): add galoy pay #3618

Merged
merged 7 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ consent:
- flake.lock
- pnpm-lock.yaml

pay:
- apps/dashboard/*
UncleSamtoshi marked this conversation as resolved.
Show resolved Hide resolved
- flake.lock
- pnpm-lock.yaml

core:
- core/**/*
- flake.lock
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Buck2 build
run: |
nix develop -c buck2 build //core/api //core/api-ws-server \
//core/api-keys //apps/dashboard //apps/consent
//core/api-keys //apps/dashboard //apps/consent //apps/pay
- name: Run bats tests
run: |
nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/**
4 changes: 2 additions & 2 deletions .github/workflows/buck2-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:
${{ toJSON(github.event.pull_request.labels.*.name) }}
EOF

DEFAULT_LABELS=("dashboard" "consent" "core")
DEFAULT_LABELS=("dashboard" "consent" "pay" "core")
LABELS=($(jq -r '.[]' < labels.json))
if [ ${#LABELS[@]} -eq 0 ]; then
LABELS=("${DEFAULT_LABELS[@]}")
fi

for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
dashboard|consent)
dashboard|consent|pay)
ARGS+=" //apps/$LABEL:test-unit"
;;
core)
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ jobs:
${{ toJSON(github.event.pull_request.labels.*.name) }}
EOF

DEFAULT_LABELS=("dashboard" "consent" "core")
DEFAULT_LABELS=("dashboard" "consent" "pay" "core")
LABELS=($(jq -r '.[]' < labels.json))
if [ ${#LABELS[@]} -eq 0 ]; then
LABELS=("${DEFAULT_LABELS[@]}")
fi

for LABEL in "${LABELS[@]}"; do
case "$LABEL" in
dashboard|consent|core)
dashboard|consent|pay|core)
ARGS+=" --test $LABEL"
;;
esac
Expand Down
1 change: 1 addition & 0 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pnpm_workspace(
"//core/api:package.json",
"//apps/consent:package.json",
"//apps/dashboard:package.json",
"//apps/pay:package.json",
"//lib/eslint-config:package.json"
],
visibility = ["PUBLIC"],
Expand Down
3 changes: 3 additions & 0 deletions apps/pay/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"extends": ["next/core-web-vitals", "@galoy/eslint-config/base"]
}
39 changes: 39 additions & 0 deletions apps/pay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts



.env.local
8 changes: 8 additions & 0 deletions apps/pay/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.next/
success-animation.json
tsconfig.json
assetlinks.json

**/*.yaml
**/*.yml
**/*.md
3 changes: 3 additions & 0 deletions apps/pay/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require("@galoy/eslint-config/prettier");

module.exports = baseConfig
93 changes: 93 additions & 0 deletions apps/pay/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
load(
"@toolchains//workspace-pnpm:macros.bzl",
"dev_pnpm_task_binary",
"dev_pnpm_task_test",
"build_node_modules",
"next_build",
"next_build_bin",
"eslint",
"audit",
)

dev_pnpm_task_binary(
name = "dev",
command = "dev",
)

dev_pnpm_task_binary(
name = "lint-fix",
command = "lint:fix",
)

dev_pnpm_task_binary(
name = "cypress-open",
command = "cypress:open",
)

dev_pnpm_task_test(
name = "test-integration",
command = "cypress:run",
)

export_file(
name = "package.json",
visibility = ["PUBLIC"],
)

build_node_modules(
name = "node_modules",
)

filegroup(
name = "src",
srcs = glob([
"app/**",
"theme/**",
"services/**",
"components/**",
"config/**",
"hooks/**",
"lib/**",
"pages/**",
"utils/**",
"public/**",
"next.config.js",
"tsconfig.json",
"*.ts", # env.ts / middleware.ts / instrumentation.ts
"instrumentation.node.ts"
]),
)

next_build(
name = "build",
srcs = [":src"],
)

next_build_bin(
name = "pay",
)

dev_deps_srcs = {
"lib/eslint-config": "//lib/eslint-config:src",
}

audit(
name = "audit",
level = "critical",
)

eslint(
name = "lint",
srcs = [":src"] + glob([".eslint*"]),
extensions = [".ts", ".tsx"],
allow_warnings = True,
dev_deps_srcs = dev_deps_srcs,
)

test_suite(
name = "test-unit",
tests = [
":audit",
":lint",
],
)
42 changes: 42 additions & 0 deletions apps/pay/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Install dependencies only when needed
FROM node:20-alpine AS deps
Copy link
Contributor

@vindard vindard Nov 30, 2023

Choose a reason for hiding this comment

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

This Dockerfile can probably be redone similar to ones in app/dashboard and apps/consent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address in a follow up pr

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat python3 make g++
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn global add node-gyp \
&& yarn install --frozen-lockfile

# Rebuild the source code only when needed
FROM node:20-alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline

# Production image, copy all the files and run next
FROM node:20-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

USER nextjs

EXPOSE 3000

ARG BUILDTIME
ARG COMMITHASH
ENV BUILDTIME ${BUILDTIME}
ENV COMMITHASH ${COMMITHASH}

CMD ["node_modules/.bin/next", "start"]
73 changes: 73 additions & 0 deletions apps/pay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Galoy Pay

## What is it for?

This repo is a web application that can be used to send tips or payments to users.

It's packaged as a docker image, and is automatically installed as part of the Galoy helm charts.

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 ?

`.env.local` is set with values that works for local dev.

for staging, use `.env.local` with the following properties

```
NEXT_PUBLIC_GRAPHQL_URL='https://api.staging.galoy.io/graphql'
NEXT_PUBLIC_GRAPHQL_WEBSOCKET_URL='wss://ws.staging.galoy.io/graphql'
GRAPHQL_URL_INTERNAL="http://api.galoy-staging-galoy.svc.cluster.local"
```

then run

```sh
yarn install
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will automatically reload when you make edits.

You will also see any lint errors in the console.

## How to run this repo in docker?

In your terminal, run

```sh
yarn build:docker
```

then run

```sh
yarn dev:docker
```

This will spin up an instance of a galoy-pay docker container running on <http://localhost:3000>

This will also run the app in production mode.

## How to build for production?

In the project directory, you can run:

```sh
yarn install
yarn build
```

This will build the app for production under a `build` folder. It will bundle React in production mode and optimize the build for the best performance. The build will be minified, and the bundled files will include unique hashes in their names.

## Test lnurlp


This environment variable is needed for getting the lnurlp endpoint working.

curl localhost:3000/.well-known/lnurlp/alice
curl localhost:3000/.well-known/lnurlp/alice?amount=1234
Loading
Loading