From 8325cb3577c8c4115b81496c18896a25fe010730 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 15:24:17 +0700 Subject: [PATCH 01/27] feat: Add github actions --- .github/workflows/ci.yml | 10 ++++++++++ .github/workflows/publish.yaml | 35 ++++++++++++++++++++++++++++++++++ Dockerfile | 23 +++++++++++++--------- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..a2ff27f6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,10 @@ +name: ci + +on: + pull_request: + branches: + - '**' + +jobs: + test: + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..23abf95d --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,35 @@ +name: docker_publish + +on: + push: + branches: + - 'hiep/add-github-actions' + # - 'main' + # - 'dev' + # tags: + # - '*' + +jobs: + test: + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + + docker_pipeline: + needs: ["test"] + uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@hiep/add-nodejs-workflows + secrets: inherit + strategy: + matrix: + environment: [devnet, staging] + with: + publish: true + environment: ${{ matrix.environment }} + buildArgs: | + NEXT_PUBLIC_MEMPOOL_API=${{ vars.NEXT_PUBLIC_MEMPOOL_API }} + NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_NETWORK=${{ vars.NEXT_PUBLIC_NETWORK }} + NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${{ vars.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES }} + repoName: "simple-staking-${{ matrix.environment }}" + + + + diff --git a/Dockerfile b/Dockerfile index 08973a98..086a567b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,15 +15,20 @@ COPY tailwind.config.ts . COPY postcss.config.js . COPY docker-entrypoint.sh . -# We replace NEXT_PUBLIC_* variables here with placeholders -# as next.js automatically replaces those during building -# Later the docker-entrypoint.sh script finds such variables and replaces them -# with the docker environment variables we have set -RUN NEXT_PUBLIC_MEMPOOL_API=APP_NEXT_PUBLIC_MEMPOOL_API \ - NEXT_PUBLIC_API_URL=APP_NEXT_PUBLIC_API_URL \ - NEXT_PUBLIC_NETWORK=APP_NEXT_PUBLIC_NETWORK \ - NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=APP_NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES \ - npm run build + +ARG NEXT_PUBLIC_MEMPOOL_API +ENV NEXT_PUBLIC_MEMPOOL_API=${NEXT_PUBLIC_MEMPOOL_API} + +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} + +ARG NEXT_PUBLIC_NETWORK +ENV NEXT_PUBLIC_NETWORK=${NEXT_PUBLIC_NETWORK} + +ARG NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES +ENV NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES} + +RUN npm run build # Step 2. Production image, copy all the files and run next FROM node:22-alpine3.19 AS runner From faf06250ec42f8b2376b8730f7e9a61464618ab6 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 16:06:11 +0700 Subject: [PATCH 02/27] add publish workflow --- .github/workflows/publish.yaml | 111 ++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 23abf95d..77905254 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,23 +12,106 @@ on: jobs: test: uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows - - docker_pipeline: - needs: ["test"] - uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@hiep/add-nodejs-workflows - secrets: inherit + docker_build: + runs-on: ubuntu-22.04 strategy: matrix: environment: [devnet, staging] - with: - publish: true - environment: ${{ matrix.environment }} - buildArgs: | - NEXT_PUBLIC_MEMPOOL_API=${{ vars.NEXT_PUBLIC_MEMPOOL_API }} - NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} - NEXT_PUBLIC_NETWORK=${{ vars.NEXT_PUBLIC_NETWORK }} - NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${{ vars.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES }} - repoName: "simple-staking-${{ matrix.environment }}" + environment: ${{matrix.environment}} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build Docker image + uses: docker/build-push-action@v6 + with: + tags: simple-staking:${{ github.sha }} + outputs: type=docker,dest=/tmp/simple-staking.tar + build-args: | + NEXT_PUBLIC_MEMPOOL_API=${{ vars.NEXT_PUBLIC_MEMPOOL_API }} + NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} + NEXT_PUBLIC_NETWORK=${{ vars.NEXT_PUBLIC_NETWORK }} + NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${{ vars.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES }} + + - name: Upload Docker image to workspace + uses: actions/upload-artifact@v4 + with: + name: simple-staking + path: /tmp/simple-staking.tar + + dockerhub_publish: + runs-on: ubuntu-22.04 + needs: ["docker_build"] + steps: + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking.tar + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + + ecr_publish: + runs-on: ubuntu-22.04 + needs: ["docker_build"] + steps: + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking.tar + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ vars.AWS_ECR_REGION }} + + - name: Login to Amazon ECR Private + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} From e42634dcbe3f47d5ea5de860d9007d12e1518873 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 16:10:47 +0700 Subject: [PATCH 03/27] Update artifact name --- .github/workflows/publish.yaml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 77905254..afbf1df7 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,9 +10,10 @@ on: # - '*' jobs: - test: + lint_test: uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows docker_build: + needs: [lint_test] runs-on: ubuntu-22.04 strategy: matrix: @@ -35,7 +36,7 @@ jobs: uses: docker/build-push-action@v6 with: tags: simple-staking:${{ github.sha }} - outputs: type=docker,dest=/tmp/simple-staking.tar + outputs: type=docker,dest=/tmp/simple-staking-${{ matrix.environment }}.tar build-args: | NEXT_PUBLIC_MEMPOOL_API=${{ vars.NEXT_PUBLIC_MEMPOOL_API }} NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} @@ -46,7 +47,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: simple-staking - path: /tmp/simple-staking.tar + path: /tmp/simple-staking-${{ matrix.environment }}.tar dockerhub_publish: runs-on: ubuntu-22.04 @@ -59,7 +60,7 @@ jobs: path: /tmp/ - name: Load Docker image - run: docker load -i /tmp/simple-staking.tar + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar - name: Login to Docker Hub uses: docker/login-action@v3 @@ -69,7 +70,7 @@ jobs: - name: Push Docker image with SHA run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }} + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - name: Push Docker image with Tag @@ -89,7 +90,7 @@ jobs: path: /tmp/ - name: Load Docker image - run: docker load -i /tmp/simple-staking.tar + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 @@ -104,15 +105,11 @@ jobs: - name: Push Docker image with SHA run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }} + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - name: Push Docker image with Tag if: startsWith(github.ref, 'refs/tags/') run: | docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} - docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} - - - - + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} \ No newline at end of file From 9e2be8f5258a17a7b824d1035cf147f8e7e872c7 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 16:17:54 +0700 Subject: [PATCH 04/27] Fix the artifact name --- .github/workflows/publish.yaml | 117 +++++++++++++++++---------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index afbf1df7..5c4dc035 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,13 +12,14 @@ on: jobs: lint_test: uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + docker_build: needs: [lint_test] runs-on: ubuntu-22.04 strategy: matrix: environment: [devnet, staging] - environment: ${{matrix.environment}} + environment: ${{ matrix.environment }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -42,74 +43,74 @@ jobs: NEXT_PUBLIC_API_URL=${{ vars.NEXT_PUBLIC_API_URL }} NEXT_PUBLIC_NETWORK=${{ vars.NEXT_PUBLIC_NETWORK }} NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=${{ vars.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES }} - + - name: Upload Docker image to workspace uses: actions/upload-artifact@v4 with: - name: simple-staking + name: simple-staking-${{ matrix.environment }} path: /tmp/simple-staking-${{ matrix.environment }}.tar dockerhub_publish: runs-on: ubuntu-22.04 needs: ["docker_build"] steps: - - name: Download Docker image from workspace - uses: actions/download-artifact@v4 - with: - name: simple-staking - path: /tmp/ - - - name: Load Docker image - run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Push Docker image with SHA - run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - - - name: Push Docker image with Tag - if: startsWith(github.ref, 'refs/tags/') - run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} - docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking-${{ matrix.environment }} + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.DOCKERHUB_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} ecr_publish: runs-on: ubuntu-22.04 needs: ["docker_build"] steps: - - name: Download Docker image from workspace - uses: actions/download-artifact@v4 - with: - name: simple-staking - path: /tmp/ - - - name: Load Docker image - run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ vars.AWS_ECR_REGION }} - - - name: Login to Amazon ECR Private - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Push Docker image with SHA - run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} - - - name: Push Docker image with Tag - if: startsWith(github.ref, 'refs/tags/') - run: | - docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} - docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} \ No newline at end of file + - name: Download Docker image from workspace + uses: actions/download-artifact@v4 + with: + name: simple-staking-${{ matrix.environment }} + path: /tmp/ + + - name: Load Docker image + run: docker load -i /tmp/simple-staking-${{ matrix.environment }}.tar + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ vars.AWS_ECR_REGION }} + + - name: Login to Amazon ECR Private + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Push Docker image with SHA + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.sha }}-${{ matrix.environment }} + + - name: Push Docker image with Tag + if: startsWith(github.ref, 'refs/tags/') + run: | + docker tag simple-staking:${{ github.sha }} ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} + docker push ${{ vars.AWS_ECR_REGISTRY_ID }}/simple-staking:${{ github.ref_name }}-${{ matrix.environment }} From 1a538d6a81ac3a42cc9ef13d8b06ecf1f0b5beca Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 16:22:53 +0700 Subject: [PATCH 05/27] Add matrix to dockerhub_publish --- .github/workflows/publish.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5c4dc035..67ef5aa4 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -52,6 +52,9 @@ jobs: dockerhub_publish: runs-on: ubuntu-22.04 + strategy: + matrix: + environment: [devnet, staging] needs: ["docker_build"] steps: - name: Download Docker image from workspace From 5cc88701d28cec59561ddac88c65cfe76204e989 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 16:23:10 +0700 Subject: [PATCH 06/27] Add matrix to dockerhub_publish --- .github/workflows/publish.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 67ef5aa4..4c1884a6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -85,6 +85,9 @@ jobs: ecr_publish: runs-on: ubuntu-22.04 + strategy: + matrix: + environment: [devnet, staging] needs: ["docker_build"] steps: - name: Download Docker image from workspace From d6fd42662afb900bb6a7b89aa8ff63c4586007f2 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 17:18:44 +0700 Subject: [PATCH 07/27] Add mainnet env --- .github/workflows/publish.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4c1884a6..c6de8169 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging] + environment: [devnet, staging, mainnet] environment: ${{ matrix.environment }} steps: - name: Checkout repository @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging] + environment: [devnet, staging, mainnet] needs: ["docker_build"] steps: - name: Download Docker image from workspace @@ -87,7 +87,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging] + environment: [devnet, staging, mainnet] needs: ["docker_build"] steps: - name: Download Docker image from workspace From 165426ee18323740936688d0dbe47711be1ee625 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 17:30:19 +0700 Subject: [PATCH 08/27] Remove docker entry-point --- Dockerfile | 1 - docker-entrypoint.sh | 15 --------------- 2 files changed, 16 deletions(-) delete mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 086a567b..8e58f37e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,6 +51,5 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # Uncomment the following line to disable telemetry at run time ENV NEXT_TELEMETRY_DISABLED 1 -ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["node", "server.js"] STOPSIGNAL SIGTERM diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100755 index f1fc77dd..00000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh -set -Ex - -# This method has been inspired by the comment here: -# https://github.com/vercel/next.js/discussions/17641#discussioncomment-339555 -function apply_path { - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_MEMPOOL_API#$MEMPOOL_API#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_API_URL#$API_URL#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_NETWORK#$NETWORK#g" - find /app/.next \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#APP_NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES#$DISPLAY_TESTING_MESSAGES#g" -} - -apply_path -echo "Starting Nextjs" -exec "$@" From f2cf52495c5f990001311cc42c1da07ca6bc48dc Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 17:36:22 +0700 Subject: [PATCH 09/27] Remove docker entry-point --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e58f37e..12f0c61c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,6 @@ COPY next.config.mjs . COPY tsconfig.json . COPY tailwind.config.ts . COPY postcss.config.js . -COPY docker-entrypoint.sh . - ARG NEXT_PUBLIC_MEMPOOL_API ENV NEXT_PUBLIC_MEMPOOL_API=${NEXT_PUBLIC_MEMPOOL_API} From 7eea32dc97580b0c563bb44de6cb085ed58296fd Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Mon, 5 Aug 2024 17:41:30 +0700 Subject: [PATCH 10/27] Remove docker entry-point --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 12f0c61c..c13ce121 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,6 @@ RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs USER nextjs -COPY --from=builder --chown=nextjs:nodejs /app/docker-entrypoint.sh ./docker-entrypoint.sh COPY --from=builder /app/public ./public # Automatically leverage output traces to reduce image size From d2b35bb1ba84f4df27e9e7c4b97ec9d9b1a008fe Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Tue, 6 Aug 2024 10:08:58 +0700 Subject: [PATCH 11/27] Add all envs --- .github/workflows/publish.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c6de8169..00520a43 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging, mainnet] + environment: [devnet, staging, testnet, mainnet-private, mainnet] environment: ${{ matrix.environment }} steps: - name: Checkout repository @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging, mainnet] + environment: [devnet, staging, testnet, mainnet-private, mainnet] needs: ["docker_build"] steps: - name: Download Docker image from workspace @@ -87,7 +87,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - environment: [devnet, staging, mainnet] + environment: [devnet, staging, testnet, mainnet-private, mainnet] needs: ["docker_build"] steps: - name: Download Docker image from workspace From a40bf5d9b64934a5de838734c4edc733ee873897 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Tue, 6 Aug 2024 11:46:20 +0700 Subject: [PATCH 12/27] Add lint_test inputs --- .github/workflows/ci.yml | 7 +++++-- .github/workflows/publish.yaml | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2ff27f6..aa426b60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,5 +6,8 @@ on: - '**' jobs: - test: - uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows \ No newline at end of file + lint_test: + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + with: + run-build: true + run-unit-tests: true \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 00520a43..e5fe916a 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,6 +12,9 @@ on: jobs: lint_test: uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + with: + run-build: true + run-unit-tests: true docker_build: needs: [lint_test] From 07f848119be2136dd51dd8fbaf2f73c2f90cb384 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Tue, 6 Aug 2024 11:48:39 +0700 Subject: [PATCH 13/27] Trigger condition --- .github/workflows/publish.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index e5fe916a..b672ee62 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -3,11 +3,10 @@ name: docker_publish on: push: branches: - - 'hiep/add-github-actions' - # - 'main' - # - 'dev' - # tags: - # - '*' + - 'main' + - 'dev' + tags: + - '*' jobs: lint_test: From 3219f04e9b47b1786b8e6ed17f6c419d83811686 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Wed, 7 Aug 2024 08:11:05 +0700 Subject: [PATCH 14/27] Add the tag --- .github/workflows/ci.yml | 2 +- .github/workflows/publish.yaml | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa426b60..7083d434 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: lint_test: - uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@v0.3.0 with: run-build: true run-unit-tests: true \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b672ee62..96ed64c2 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -10,7 +10,7 @@ on: jobs: lint_test: - uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@hiep/add-nodejs-workflows + uses: babylonlabs-io/.github/.github/workflows/reusable_node_lint_test.yml@v0.3.0 with: run-build: true run-unit-tests: true @@ -29,12 +29,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build Docker image uses: docker/build-push-action@v6 with: From 570eb9051823dca045258478207696acbe886ab4 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Wed, 7 Aug 2024 08:14:15 +0700 Subject: [PATCH 15/27] Test publish --- .github/workflows/publish.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 96ed64c2..2ab782fb 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -3,8 +3,7 @@ name: docker_publish on: push: branches: - - 'main' - - 'dev' + - "**" tags: - '*' From 8e5f3f164187b9377449864e37dff49dac2d1fc9 Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Wed, 7 Aug 2024 12:35:23 +1000 Subject: [PATCH 16/27] fix: FAQ shall have dynamically injected confirmation depth --- src/app/components/FAQ/FAQ.tsx | 35 ++++++++++++++++++++++-- src/app/components/FAQ/data/questions.ts | 7 +++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/app/components/FAQ/FAQ.tsx b/src/app/components/FAQ/FAQ.tsx index 8beb4265..8cf7f327 100644 --- a/src/app/components/FAQ/FAQ.tsx +++ b/src/app/components/FAQ/FAQ.tsx @@ -1,17 +1,48 @@ +import { useEffect, useState } from "react"; + +import { useGlobalParams } from "@/app/context/api/GlobalParamsProvider"; +import { useBtcHeight } from "@/app/context/mempool/BtcHeightProvider"; import { getNetworkConfig } from "@/config/network.config"; +import { + getCurrentGlobalParamsVersion, + ParamsWithContext, +} from "@/utils/globalParams"; -import { Section } from "./Section"; import { questions } from "./data/questions"; +import { Section } from "./Section"; interface FAQProps {} export const FAQ: React.FC = () => { + const [paramWithCtx, setParamWithCtx] = useState< + ParamsWithContext | undefined + >(); const { coinName } = getNetworkConfig(); + const btcHeight = useBtcHeight(); + const globalParams = useGlobalParams(); + + useEffect(() => { + if (!btcHeight || !globalParams.data) { + return; + } + const paramsWithCtx = getCurrentGlobalParamsVersion( + btcHeight + 1, + globalParams.data, + ); + if (!paramsWithCtx) { + return; + } + setParamWithCtx(paramsWithCtx); + }, [globalParams, btcHeight]); + return (

FAQ

- {questions(coinName).map((question) => ( + {questions( + coinName, + paramWithCtx?.currentVersion?.confirmationDepth, + ).map((question) => (
{ +export const questions = ( + coinName: string, + confirmationDepth?: number, +): Question[] => { const questionList = [ { title: "What is Babylon?", @@ -47,7 +50,7 @@ export const questions = (coinName: string): Question[] => { }, { title: "How long will it take for my stake to become active?", - content: `

A stake’s status demonstrates the current stage of the staking process. All stake starts in a Pending state which denotes that the ${coinName} Staking transaction does not yet have sufficient ${coinName} block confirmations. As soon as it receives 10 ${coinName} block confirmations, the status transitions to Overflow or Active.


+ content: `

A stake’s status demonstrates the current stage of the staking process. All stake starts in a Pending state which denotes that the ${coinName} Staking transaction does not yet have sufficient ${coinName} block confirmations. As soon as it receives ${confirmationDepth || 10} ${coinName} block confirmations, the status transitions to Overflow or Active.


In an amount-based cap, A stake is Overflow if the system has already accumulated the maximum amount of ${coinName} it can accept.


In a time-based cap, where there is a starting block height and ending block height, a stake is overflow if it is included in a ${coinName} block that is newer than the ending block.


From 2f54e9ec5182dc637d67bf47a8ffd71857c8d4de Mon Sep 17 00:00:00 2001 From: jeremy-babylonlabs Date: Tue, 6 Aug 2024 15:03:15 +0800 Subject: [PATCH 17/27] fix tooltip word wrap issue --- src/app/components/Stats/Stats.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/components/Stats/Stats.tsx b/src/app/components/Stats/Stats.tsx index f5d37843..27375b9e 100644 --- a/src/app/components/Stats/Stats.tsx +++ b/src/app/components/Stats/Stats.tsx @@ -197,7 +197,10 @@ export const Stats: React.FC = () => { > - + )}
From 254c7c22b63cb7a8490b27509517b25a228ed621 Mon Sep 17 00:00:00 2001 From: jeremy-babylonlabs Date: Tue, 6 Aug 2024 18:43:10 +0800 Subject: [PATCH 18/27] closes #42 and #45 --- src/app/components/Connect/ConnectSmall.tsx | 2 +- src/app/components/Delegations/Delegation.tsx | 2 +- .../FinalityProviders/FinalityProvider.tsx | 2 +- .../FinalityProviders/FinalityProviders.tsx | 4 ++-- src/app/components/Modals/ConnectModal.tsx | 5 ++++- src/app/components/Stakers/Stakers.tsx | 4 ++-- .../FinalityProviders/FinalityProvider.tsx | 12 +++++++++--- src/app/components/Staking/Staking.tsx | 2 +- src/app/components/Stats/Stats.tsx | 2 +- src/app/components/Summary/Summary.tsx | 17 ++++++++++++++++- src/app/globals.css | 6 ++++++ src/app/page.tsx | 4 ++++ 12 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/app/components/Connect/ConnectSmall.tsx b/src/app/components/Connect/ConnectSmall.tsx index 906e6b38..21d33c78 100644 --- a/src/app/components/Connect/ConnectSmall.tsx +++ b/src/app/components/Connect/ConnectSmall.tsx @@ -54,7 +54,7 @@ export const ConnectSmall: React.FC = ({ > - + ); }; diff --git a/src/app/components/Delegations/Delegation.tsx b/src/app/components/Delegations/Delegation.tsx index 65109f9b..b3ff0dd0 100644 --- a/src/app/components/Delegations/Delegation.tsx +++ b/src/app/components/Delegations/Delegation.tsx @@ -152,7 +152,7 @@ export const Delegation: React.FC = ({ > - +
{generateActionButton()} diff --git a/src/app/components/FinalityProviders/FinalityProvider.tsx b/src/app/components/FinalityProviders/FinalityProvider.tsx index ae38488d..ef88076a 100644 --- a/src/app/components/FinalityProviders/FinalityProvider.tsx +++ b/src/app/components/FinalityProviders/FinalityProvider.tsx @@ -95,7 +95,7 @@ export const FinalityProvider: React.FC = ({ 0 )} - + ); }; diff --git a/src/app/components/FinalityProviders/FinalityProviders.tsx b/src/app/components/FinalityProviders/FinalityProviders.tsx index 0ac6da29..9d8668f1 100644 --- a/src/app/components/FinalityProviders/FinalityProviders.tsx +++ b/src/app/components/FinalityProviders/FinalityProviders.tsx @@ -82,8 +82,8 @@ export const FinalityProviders: React.FC = ({ )} - - + + ); }; diff --git a/src/app/components/Modals/ConnectModal.tsx b/src/app/components/Modals/ConnectModal.tsx index 9c7fefd0..2d7b819a 100644 --- a/src/app/components/Modals/ConnectModal.tsx +++ b/src/app/components/Modals/ConnectModal.tsx @@ -224,7 +224,10 @@ export const ConnectModal: React.FC = ({ > - + )} diff --git a/src/app/components/Stakers/Stakers.tsx b/src/app/components/Stakers/Stakers.tsx index 8ff9954e..d4068422 100644 --- a/src/app/components/Stakers/Stakers.tsx +++ b/src/app/components/Stakers/Stakers.tsx @@ -89,8 +89,8 @@ export const Stakers: React.FC = () => { )} - - + + ); }; diff --git a/src/app/components/Staking/FinalityProviders/FinalityProvider.tsx b/src/app/components/Staking/FinalityProviders/FinalityProvider.tsx index 11b3837c..b576eec5 100644 --- a/src/app/components/Staking/FinalityProviders/FinalityProvider.tsx +++ b/src/app/components/Staking/FinalityProviders/FinalityProvider.tsx @@ -79,7 +79,7 @@ export const FinalityProvider: React.FC = ({ > - + No data provided )} @@ -100,7 +100,10 @@ export const FinalityProvider: React.FC = ({ > - +

Commission:

@@ -115,7 +118,10 @@ export const FinalityProvider: React.FC = ({ > - +
diff --git a/src/app/components/Staking/Staking.tsx b/src/app/components/Staking/Staking.tsx index 50e2e09a..fbab9a12 100644 --- a/src/app/components/Staking/Staking.tsx +++ b/src/app/components/Staking/Staking.tsx @@ -629,7 +629,7 @@ export const Staking: React.FC = ({ > Preview - + {previewReady && ( { )} diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index d8f2ed06..1f0d1500 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -1,4 +1,6 @@ +import { AiOutlineInfoCircle } from "react-icons/ai"; import { FaBitcoin } from "react-icons/fa"; +import { Tooltip } from "react-tooltip"; import { getNetworkConfig } from "@/config/network.config"; import { satoshiToBtc } from "@/utils/btcConversions"; @@ -10,11 +12,13 @@ import { LoadingSmall } from "../Loading/Loading"; interface SummaryProps { totalStakedSat: number; btcWalletBalanceSat?: number; + confirmationDepth?: number; } export const Summary: React.FC = ({ totalStakedSat, btcWalletBalanceSat, + confirmationDepth, }) => { const { coinName } = getNetworkConfig(); const onMainnet = getNetworkConfig().network === Network.MAINNET; @@ -24,7 +28,18 @@ export const Summary: React.FC = ({

Your staking summary

-

Total staked

+
+

Total staked

+ + + + +

diff --git a/src/app/globals.css b/src/app/globals.css index 8e50c77b..3810a469 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -110,3 +110,9 @@ input[type="number"] { body.modal-open { overflow: hidden; } + +.tooltip-wrap { + max-width: 20rem; + white-space: normal; + word-wrap: break-word; +} diff --git a/src/app/page.tsx b/src/app/page.tsx index bcbe380b..d0f0a153 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -401,6 +401,10 @@ const Home: React.FC = () => {

)} Date: Tue, 6 Aug 2024 19:16:08 +0800 Subject: [PATCH 19/27] get confirmation depth in Summary --- src/app/components/Summary/Summary.tsx | 28 +++++++++++++++++++++++--- src/app/page.tsx | 4 ---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index 1f0d1500..eef644b1 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -1,9 +1,16 @@ +import { useMemo, useState } from "react"; import { AiOutlineInfoCircle } from "react-icons/ai"; import { FaBitcoin } from "react-icons/fa"; import { Tooltip } from "react-tooltip"; +import { useGlobalParams } from "@/app/context/api/GlobalParamsProvider"; +import { useBtcHeight } from "@/app/context/mempool/BtcHeightProvider"; import { getNetworkConfig } from "@/config/network.config"; import { satoshiToBtc } from "@/utils/btcConversions"; +import { + getCurrentGlobalParamsVersion, + ParamsWithContext, +} from "@/utils/globalParams"; import { maxDecimals } from "@/utils/maxDecimals"; import { Network } from "@/utils/wallet/wallet_provider"; @@ -12,16 +19,31 @@ import { LoadingSmall } from "../Loading/Loading"; interface SummaryProps { totalStakedSat: number; btcWalletBalanceSat?: number; - confirmationDepth?: number; } export const Summary: React.FC = ({ totalStakedSat, btcWalletBalanceSat, - confirmationDepth, }) => { const { coinName } = getNetworkConfig(); const onMainnet = getNetworkConfig().network === Network.MAINNET; + const [paramWithCtx, setParamWithCtx] = useState< + ParamsWithContext | undefined + >(); + + const btcHeight = useBtcHeight(); + const globalParams = useGlobalParams(); + + useMemo(() => { + if (!btcHeight || !globalParams.data) { + return; + } + const paramCtx = getCurrentGlobalParamsVersion( + btcHeight + 1, + globalParams.data, + ); + setParamWithCtx(paramCtx); + }, [btcHeight, globalParams]); return (
@@ -33,7 +55,7 @@ export const Summary: React.FC = ({ diff --git a/src/app/page.tsx b/src/app/page.tsx index d0f0a153..bcbe380b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -401,10 +401,6 @@ const Home: React.FC = () => { )} Date: Tue, 6 Aug 2024 19:20:10 +0800 Subject: [PATCH 20/27] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 17e1df1f..e5027773 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-staking", - "version": "0.2.30", + "version": "0.2.31", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-staking", - "version": "0.2.30", + "version": "0.2.31", "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", "@keystonehq/animated-qr": "^0.8.6", diff --git a/package.json b/package.json index e3df98c8..b9087f41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-staking", - "version": "0.2.30", + "version": "0.2.31", "private": true, "scripts": { "dev": "next dev", From ca5e0e7a84d68be43ae64828ae904007333f8e22 Mon Sep 17 00:00:00 2001 From: jeremy-babylonlabs Date: Wed, 7 Aug 2024 12:46:17 +0800 Subject: [PATCH 21/27] revert #45 --- src/app/components/Summary/Summary.tsx | 39 +------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/app/components/Summary/Summary.tsx b/src/app/components/Summary/Summary.tsx index eef644b1..d8f2ed06 100644 --- a/src/app/components/Summary/Summary.tsx +++ b/src/app/components/Summary/Summary.tsx @@ -1,16 +1,7 @@ -import { useMemo, useState } from "react"; -import { AiOutlineInfoCircle } from "react-icons/ai"; import { FaBitcoin } from "react-icons/fa"; -import { Tooltip } from "react-tooltip"; -import { useGlobalParams } from "@/app/context/api/GlobalParamsProvider"; -import { useBtcHeight } from "@/app/context/mempool/BtcHeightProvider"; import { getNetworkConfig } from "@/config/network.config"; import { satoshiToBtc } from "@/utils/btcConversions"; -import { - getCurrentGlobalParamsVersion, - ParamsWithContext, -} from "@/utils/globalParams"; import { maxDecimals } from "@/utils/maxDecimals"; import { Network } from "@/utils/wallet/wallet_provider"; @@ -27,41 +18,13 @@ export const Summary: React.FC = ({ }) => { const { coinName } = getNetworkConfig(); const onMainnet = getNetworkConfig().network === Network.MAINNET; - const [paramWithCtx, setParamWithCtx] = useState< - ParamsWithContext | undefined - >(); - - const btcHeight = useBtcHeight(); - const globalParams = useGlobalParams(); - - useMemo(() => { - if (!btcHeight || !globalParams.data) { - return; - } - const paramCtx = getCurrentGlobalParamsVersion( - btcHeight + 1, - globalParams.data, - ); - setParamWithCtx(paramCtx); - }, [btcHeight, globalParams]); return (

Your staking summary

-
-

Total staked

- - - - -
+

Total staked

From dbc2bbb50b00259f97b82b027ac91e95714b7583 Mon Sep 17 00:00:00 2001 From: wjrjerome Date: Wed, 7 Aug 2024 14:22:38 +1000 Subject: [PATCH 22/27] fix: timeout on the wallet getInscriptions method --- src/utils/utxo/index.ts | 18 ++++++++++++++++-- tests/utils/utox/utxo.test.ts | 27 ++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/utils/utxo/index.ts b/src/utils/utxo/index.ts index 7b6cf84a..18fae80b 100644 --- a/src/utils/utxo/index.ts +++ b/src/utils/utxo/index.ts @@ -2,7 +2,8 @@ import { postVerifyUtxoOrdinals, UtxoInfo } from "@/app/api/postFilterOrdinals"; import { InscriptionIdentifier, UTXO } from "../wallet/wallet_provider"; -const LOW_VALUE_UTXO_THRESHOLD = 10000; +export const LOW_VALUE_UTXO_THRESHOLD = 10000; +export const WALLET_FETCH_INSRIPTIONS_TIMEOUT = 3000; // 3 seconds /** * Filters out UTXOs that contain ordinals. @@ -34,7 +35,20 @@ export const filterOrdinals = async ( // try to get the ordinals from the wallet first, if the wallet supports it // otherwise fallback to the Babylon API try { - const inscriptions = await getInscriptionsFromWalletCb(); + const inscriptions = await Promise.race([ + getInscriptionsFromWalletCb(), + new Promise((_, reject) => + setTimeout( + () => + reject( + new Error( + "Request timed out when fetching inscriptions from wallet", + ), + ), + WALLET_FETCH_INSRIPTIONS_TIMEOUT, + ), + ), + ]); // filter out the utxos that contains ordinals return utxos.filter( (utxo) => diff --git a/tests/utils/utox/utxo.test.ts b/tests/utils/utox/utxo.test.ts index 04c0f950..174c4398 100644 --- a/tests/utils/utox/utxo.test.ts +++ b/tests/utils/utox/utxo.test.ts @@ -1,5 +1,5 @@ import { postVerifyUtxoOrdinals } from "@/app/api/postFilterOrdinals"; -import { filterOrdinals } from "@/utils/utxo"; +import { filterOrdinals, WALLET_FETCH_INSRIPTIONS_TIMEOUT } from "@/utils/utxo"; import { InscriptionIdentifier, UTXO } from "@/utils/wallet/wallet_provider"; // Mock the dependencies @@ -109,4 +109,29 @@ describe("filterOrdinals", () => { expect(result).toEqual(mockUtxos); }); + + it("should filter UTXOs using the API fallback when wallet callback times out", async () => { + const mockApiResponse = [ + { txid: "txid1", vout: 0, inscription: true }, + { txid: "txid2", vout: 1, inscription: false }, + { txid: "txid3", vout: 2, inscription: false }, + ]; + const getInscriptionsFromWalletCb = jest.fn().mockImplementation(() => { + return new Promise((resolve) => + setTimeout(resolve, WALLET_FETCH_INSRIPTIONS_TIMEOUT + 1000), + ); + }); + + (postVerifyUtxoOrdinals as jest.Mock).mockResolvedValue(mockApiResponse); + + const result = await filterOrdinals( + mockUtxos, + address, + getInscriptionsFromWalletCb, + ); + + expect(getInscriptionsFromWalletCb).toHaveBeenCalledTimes(1); + expect(postVerifyUtxoOrdinals).toHaveBeenCalledWith(mockUtxos, address); + expect(result).toEqual([mockUtxos[1], mockUtxos[2]]); + }); }); From d0a94085ad25ebacc38b690ca551d4a1379786b9 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Wed, 7 Aug 2024 15:38:36 +0700 Subject: [PATCH 23/27] Revert testing --- .github/workflows/publish.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2ab782fb..96ed64c2 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -3,7 +3,8 @@ name: docker_publish on: push: branches: - - "**" + - 'main' + - 'dev' tags: - '*' From de42e69feb7d59f7a4e211b83f32e3c1c9d8dfb2 Mon Sep 17 00:00:00 2001 From: Hiep Mai Date: Wed, 7 Aug 2024 16:31:29 +0700 Subject: [PATCH 24/27] Remove Circleci --- .circleci/config.yml | 95 -------------------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index ac0f9788..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,95 +0,0 @@ -version: 2.1 - -orbs: - aws-ecr: circleci/aws-ecr@8.2.1 - kubernetes: circleci/kubernetes@1.3.1 - helm: circleci/helm@2.0.1 - node: circleci/node@5.2.0 - -jobs: - build: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - checkout - - node/install: - node-version: "22.3" - - run: - name: Install dependencies - command: | - npm install - - run: - name: Run tests - command: | - npm run test - - run: - name: Build project - command: | - npm run build - - build_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - checkout - - aws-ecr/build-image: - push-image: false - dockerfile: Dockerfile - path: ./ - build-path: ./ - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - repo: "simple-staking" - - run: - name: Save Docker image to export it to workspace - command: | - docker save $(docker image ls --format '{{.Repository}}:{{.Tag}}') > /tmp/simple-staking.tar - - persist_to_workspace: - root: /tmp - paths: - - simple-staking.tar - - push_docker: - machine: - image: ubuntu-2204:2024.01.1 - resource_class: large - steps: - - attach_workspace: - at: /tmp - - run: - name: Load Docker image from workspace - command: | - docker load -i /tmp/simple-staking.tar - - aws-ecr/ecr-login: - aws-access-key-id: AWS_ACCESS_KEY_ID - aws-secret-access-key: AWS_SECRET_ACCESS_KEY - region: "$AWS_REGION" - - aws-ecr/push-image: - registry-id: AWS_ECR_REGISTRY_ID - region: "$AWS_REGION" - repo: "simple-staking" - tag: "$CIRCLE_SHA1,$CIRCLE_TAG" - -workflows: - CICD: - jobs: - - build - - build_docker: - filters: - tags: - only: /.*/ - branches: - only: - - dev - - main - - push_docker: - requires: - - build_docker - filters: - tags: - only: /.*/ - branches: - only: - - dev - - main From 93f5110404a9377d6bc644e3675e017091e73dd9 Mon Sep 17 00:00:00 2001 From: jeremy-babylonlabs Date: Wed, 7 Aug 2024 17:48:38 +0800 Subject: [PATCH 25/27] update comments --- src/app/components/Modals/ConnectModal.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/app/components/Modals/ConnectModal.tsx b/src/app/components/Modals/ConnectModal.tsx index 2d7b819a..7ff42c9f 100644 --- a/src/app/components/Modals/ConnectModal.tsx +++ b/src/app/components/Modals/ConnectModal.tsx @@ -224,10 +224,7 @@ export const ConnectModal: React.FC = ({ > - +

)}
From 63c9a12b6b2ad73de7c9be8741e7dd70dad63248 Mon Sep 17 00:00:00 2001 From: Govard Barkhatov Date: Wed, 7 Aug 2024 16:30:33 +0200 Subject: [PATCH 26/27] fix: App URL (#39) * appUrl is config-based * layout * getNetworkAppUrl * rm image --- src/app/components/Modals/Terms/data/terms.tsx | 11 ++++++----- src/app/layout.tsx | 12 ++++-------- src/config/index.ts | 7 +++++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/components/Modals/Terms/data/terms.tsx b/src/app/components/Modals/Terms/data/terms.tsx index 8b012dfc..c75c045a 100644 --- a/src/app/components/Modals/Terms/data/terms.tsx +++ b/src/app/components/Modals/Terms/data/terms.tsx @@ -1,14 +1,15 @@ +import { getNetworkAppUrl } from "@/config"; + export const Terms = () => { + const url = getNetworkAppUrl(); + return (

Last updated [27 May 2024]


- - https://btcstaking.testnet.babylonchain.io/ + + {url} {" "} is a website-hosted user interface (the{" "} “Interface”).{" "} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3273667a..1883f113 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -3,6 +3,8 @@ import { Inter } from "next/font/google"; import "react-responsive-modal/styles.css"; import "react-tooltip/dist/react-tooltip.css"; +import { getNetworkAppUrl } from "@/config"; + import "./globals.css"; import Providers from "./providers"; @@ -27,17 +29,11 @@ export default function RootLayout({ - + - + diff --git a/src/config/index.ts b/src/config/index.ts index 99ae96e0..88fc21ef 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,3 +5,10 @@ export const shouldDisplayTestingMsg = (): boolean => { process.env.NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES?.toString() !== "false" ); }; + +// getNetworkAppUrl function is used to get the network app url based on the environment +export const getNetworkAppUrl = (): string => { + return shouldDisplayTestingMsg() + ? "https://btcstaking.testnet.babylonchain.io" + : "https://btcstaking.babylonchain.io"; +}; From f32bc641237fcab0924146192c65407cc71d524d Mon Sep 17 00:00:00 2001 From: Crypto Minion <154598612+jrwbabylonlab@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:10:40 +1000 Subject: [PATCH 27/27] chore: improve the msg when staking amount exceeds the available balance (#54) * chore: improve the msg when staking amount exceeds the available balance --- src/app/components/Staking/Form/StakingAmount.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/Staking/Form/StakingAmount.tsx b/src/app/components/Staking/Form/StakingAmount.tsx index 244353d2..a680754b 100644 --- a/src/app/components/Staking/Form/StakingAmount.tsx +++ b/src/app/components/Staking/Form/StakingAmount.tsx @@ -84,7 +84,7 @@ export const StakingAmount: React.FC = ({ }, { valid: satoshis <= btcWalletBalanceSat, - message: `${errorLabel} must be no more than ${satoshiToBtc(btcWalletBalanceSat)} wallet balance.`, + message: `${errorLabel} exceeds your balance (${satoshiToBtc(btcWalletBalanceSat)} ${coinName})!`, }, { valid: validateDecimalPoints(value),