Skip to content

Commit

Permalink
Merge pull request #71 from OilerNetwork/fossil-req-server-side
Browse files Browse the repository at this point in the history
Move fossil job status call to the server side
  • Loading branch information
eugenPtr authored Jan 20, 2025
2 parents 61b30fb + 70a6f23 commit 966e72d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 26 deletions.
8 changes: 5 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ NEXT_PUBLIC_VAULT_ADDRESSES=""
NEXT_PUBLIC_ENVIRONMENT=""
NEXT_PUBLIC_RPC_URL_MAINNET=""
NEXT_PUBLIC_RPC_URL_SEPOLIA=""
NEXT_PUBLIC_RPC_URL_DEVNET=""
NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=""
JUNO_DOCKER_HOST=$NEXT_PUBLIC_RPC_URL_JUNO_DEVNET
NEXT_PUBLIC_FOSSIL_API_URL=""
NEXT_PUBLIC_WS_URL=""
FOSSIL_API_KEY=""
FOSSIL_DB_URL=""
PORT=
NEXT_PUBLIC_FOSSIL_USE_MOCK_PRICING_DATA=true

# ⬇️⬇️⬇️ MANDATORY FOR DEVELOPMENT ENVIRONMENT - NOT NEEDED IN PRODUCTION
JUNO_DOCKER_HOST=
NEXT_PUBLIC_RPC_URL_DEVNET=""
NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=""
6 changes: 0 additions & 6 deletions .github/workflows/deploy_pitchlake_ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ env:
NODE_ENV: production
PORT: ${{vars.PORT}}
NEXT_PUBLIC_VAULT_ADDRESSES: ${{vars.VAULT_ADDRESSES}}
NEXT_PUBLIC_API_URL: ${{vars.API_URL}}
NEXT_PUBLIC_ENVIRONMENT: ${{vars.ENVIRONMENT}}
NEXT_PUBLIC_RPC_URL_MAINNET: ${{secrets.RPC_URL_MAINNET}}
NEXT_PUBLIC_RPC_URL_SEPOLIA: ${{secrets.RPC_URL_SEPOLIA}}
NEXT_PUBLIC_RPC_URL_DEVNET: ${{secrets.RPC_URL_DEVNET}}
NEXT_PUBLIC_RPC_URL_JUNO_DEVNET: ${{vars.RPC_URL_JUNO_DEVNET}}
NEXT_PUBLIC_WS_URL: ${{vars.WS_URL}}
FOSSIL_API_KEY: ${{secrets.FOSSIL_API_KEY}}
FOSSIL_DB_URL: ${{secrets.FOSSIL_DB_URL}}
Expand Down Expand Up @@ -73,12 +70,9 @@ jobs:
--platform=linux/amd64 \
--build-arg PORT=${{ env.PORT }} \
--build-arg NEXT_PUBLIC_VAULT_ADDRESSES=${{ env.NEXT_PUBLIC_VAULT_ADDRESSES }} \
--build-arg NEXT_PUBLIC_API_URL=${{ env.NEXT_PUBLIC_API_URL }} \
--build-arg NEXT_PUBLIC_ENVIRONMENT=${{ env.NEXT_PUBLIC_ENVIRONMENT }} \
--build-arg NEXT_PUBLIC_RPC_URL_MAINNET=${{ env.NEXT_PUBLIC_RPC_URL_MAINNET }} \
--build-arg NEXT_PUBLIC_RPC_URL_SEPOLIA=${{ env.NEXT_PUBLIC_RPC_URL_SEPOLIA }} \
--build-arg NEXT_PUBLIC_RPC_URL_DEVNET=${{ env.NEXT_PUBLIC_RPC_URL_DEVNET }} \
--build-arg NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=${{ env.NEXT_PUBLIC_RPC_URL_JUNO_DEVNET }} \
--build-arg NEXT_PUBLIC_WS_URL=${{ env.NEXT_PUBLIC_WS_URL }} \
--build-arg FOSSIL_API_KEY=${{ env.FOSSIL_API_KEY }} \
--build-arg FOSSIL_DB_URL=${{ env.FOSSIL_DB_URL }} \
Expand Down
7 changes: 1 addition & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
FROM node:20-alpine AS builder

ARG NEXT_PUBLIC_VAULT_ADDRESSES
ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_ENVIRONMENT
ARG NEXT_PUBLIC_RPC_URL_MAINNET
ARG NEXT_PUBLIC_RPC_URL_SEPOLIA
ARG NEXT_PUBLIC_RPC_URL_DEVNET
ARG NEXT_PUBLIC_RPC_URL_JUNO_DEVNET
ARG NEXT_PUBLIC_WS_URL
ARG FOSSIL_API_KEY
ARG FOSSIL_DB_URL
ARG NEXT_PUBLIC_FOSSIL_API_URL

ENV NEXT_PUBLIC_VAULT_ADDRESSES=${NEXT_PUBLIC_VAULT_ADDRESSES}
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
ENV NEXT_PUBLIC_ENVIRONMENT=${NEXT_PUBLIC_ENVIRONMENT}
ENV NEXT_PUBLIC_RPC_URL_MAINNET=${NEXT_PUBLIC_RPC_URL_MAINNET}
ENV NEXT_PUBLIC_RPC_URL_SEPOLIA=${NEXT_PUBLIC_RPC_URL_SEPOLIA}
ENV NEXT_PUBLIC_RPC_URL_DEVNET=${NEXT_PUBLIC_RPC_URL_DEVNET}
ENV NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=${NEXT_PUBLIC_RPC_URL_JUNO_DEVNET}
ENV NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
ENV FOSSIL_API_KEY=${FOSSIL_API_KEY}
ENV FOSSIL_DB_URL=${FOSSIL_DB_URL}
Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ services:
- NODE_ENV=production
- PORT= ${PORT}
- NEXT_PUBLIC_VAULT_ADDRESS=${NEXT_PUBLIC_VAULT_ADDRESS}
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
- NEXT_PUBLIC_ENVIRONMENT=${NEXT_PUBLIC_ENVIRONMENT}
- NEXT_PUBLIC_RPC_URL_MAINNET=${NEXT_PUBLIC_RPC_URL_MAINNET}
- NEXT_PUBLIC_RPC_URL_SEPOLIA=${NEXT_PUBLIC_RPC_URL_SEPOLIA}
- NEXT_PUBLIC_RPC_URL_DEVNET=${NEXT_PUBLIC_RPC_URL_DEVNET}
- NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=${NEXT_PUBLIC_RPC_URL_JUNO_DEVNET}
- NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
- FOSSIL_API_KEY=${FOSSIL_API_KEY}
- FOSSIL_DB_URL=${FOSSIL_DB_URL}
- NEXT_PUBLIC_FOSSIL_API_URL=${NEXT_PUBLIC_FOSSIL_API_URL}
- NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
# ⬇️⬇️⬇️ This env var is used only in the devenv. Doesn't need to be set in prod
# ⬇️⬇️⬇️ MANDATORY FOR DEVELOPMENT ENVIRONMENT - NOT NEEDED IN PRODUCTION
- JUNO_DOCKER_HOST=http://juno_plugin:6060
- NEXT_PUBLIC_RPC_URL_DEVNET=${NEXT_PUBLIC_RPC_URL_DEVNET}
- NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=${NEXT_PUBLIC_RPC_URL_JUNO_DEVNET}
3 changes: 3 additions & 0 deletions src/app/api/getHistoricalRoundParams/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export async function GET(request: Request) {
const fromRound = searchParams.get("fromRound");
const toRound = searchParams.get("toRound");
// In the devenv, server side calls to the node need to use the docker host
// This logic does not apply to prod. JUNO_DOCKER_HOST does not need to be set in prod
// TODO: To get rid of this workaround and remove JUNO_DOCKER_HOST from the env, we need to
// all the calls to the node need to be either on the clients side, or on the server side.
let nodeUrl =
searchParams.get("nodeUrl") === process.env.NEXT_PUBLIC_RPC_URL_JUNO_DEVNET
? process.env.JUNO_DOCKER_HOST
Expand Down
19 changes: 19 additions & 0 deletions src/app/api/getJobStatus/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const jobId = searchParams.get('jobId');

if (!jobId) {
return NextResponse.json({ error: 'Missing jobId parameter' }, { status: 400 });
}

try {
const response = await fetch(`${process.env.NEXT_PUBLIC_FOSSIL_API_URL}/job_status/${jobId}`);
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error('Error fetching job status:', error);
return NextResponse.json({ error: 'Failed to fetch job status' }, { status: 500 });
}
}
6 changes: 3 additions & 3 deletions src/components/Vault/Vault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const Vault = () => {
}

return (
<div className="px-6 py-4 bg-faded-black-alt flex-grow flex-box overflow-auto">
<div className="px-6 py-4 pt-[120px] bg-faded-black-alt flex-grow flex-box overflow-auto">
<div className="flex flex-row-reverse text-primary">
<div className="flex flex-row rounded-md border-[1px] border-greyscale-800 ">
<div className="flex flex-row rounded-md border-[1px] border-greyscale-800 h-[55px]">
<div
onClick={() => {
setIsProviderView(true);
Expand All @@ -50,7 +50,7 @@ export const Vault = () => {
setIsProviderView(false);
//setIsEditOpen(false);
}}
className={`flex flex-row items-center m-[1px] hover:cursor-pointer p-4 rounded-md text-[14px] h-[44px] justify-center w-[115px] ${
className={`flex flex-row items-center justify-center m-[1px] hover:cursor-pointer px-4 py-1 rounded-md text-[14px] w-[115px] ${
!isProviderView ? "bg-primary-900" : ""
}`}
>
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/fossil/useFossilStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ const useFossilStatus = () => {
try {

const jobId = createJobId(targetTimestamp, roundDuration);
const response = await fetch(
`${process.env.NEXT_PUBLIC_FOSSIL_API_URL}/job_status/${jobId}`
);

const response = await fetch(`/api/getJobStatus?jobId=${jobId}`);
if (!response.ok) throw new Error("Network response was not ok");

const data = await response.json();
Expand Down
1 change: 1 addition & 0 deletions src/hooks/stateTransition/useRoundState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const getRoundState = ({
if (
fossilError ||
fossilStatus === null ||
fossilStatus.error ||
fossilStatus.status === "Failed"
)
return "FossilReady";
Expand Down

0 comments on commit 966e72d

Please sign in to comment.