Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ui-cicd
Browse files Browse the repository at this point in the history
  • Loading branch information
Osinachi-Uro committed Nov 11, 2024
2 parents 93ad87d + 2445cca commit a80aa86
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 32 deletions.
11 changes: 6 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ NEXT_PUBLIC_ENVIRONMENT=""
NEXT_PUBLIC_RPC_URL_MAINNET=""
NEXT_PUBLIC_RPC_URL_SEPOLIA=""
NEXT_PUBLIC_RPC_URL_DEVNET=""
NEXT_PUBLIC_RPC_URL_JUNO_DEVNET=""

# FOSSIL API
FOSSIL_API_KEY=""
NEXT_PUBLIC_FOSSIL_API_URL=""
NEXT_PUBLIC_FOSSIL_API_URL="http://127.0.0.1:3000" # "<replace with hosted URL>"

# FOR DEVNET (PRE FUNDED ACCOUNT)
NEXT_PUBLIC_DEV_ADDRESS=""
NEXT_PUBLIC_DEV_PK=""
NEXT_PUBLIC_WS_URL=""

# FOR VAULTS PAGE
NEXT_PUBLIC_VAULT_ADDRESSES=""
NEXT_PUBLIC_VAULT_ADDRESSES="0x038cfc94b5626c9355910304622f8270eaef77b62cb850e1ca0e38ecedcdee5b,0x2cbdf2381224c850975613fb42848ae1a3a608d91bcd7d7a59dcc2b459d98d4,0x13257401fd2df63db6464035ab3ed13f3ef84ae71a07054f50d7bd20311e0a3,0x8f4e98c8c7f2698ff9a98df855116154f0482b93127dc79b15f05effbe8237"

PORT=
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ COPY --from=builder /app/public ./public
COPY --from=builder /app/node_modules ./node_modules

# Define the command to run the app
CMD ["pnpm", "start", "-p", "${PORT}"]
CMD pnpm start -p ${PORT}
22 changes: 22 additions & 0 deletions Dockerfile.no-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dockerfile used by the pitchlake-launcher

# Use Node.js v20 as the base image
FROM node:20-alpine AS builder

# Set the working directory
WORKDIR /app

# Install pnpm
RUN npm install -g pnpm

# Copy package files first
COPY package.json pnpm-lock.yaml* ./

# Install dependencies
RUN pnpm install --frozen-lockfile

# Copy the rest of the application
COPY . .

# Define the command to run the app
CMD ["pnpm", "run", "build", "&&", "pnpm", "start", "-p", "${PORT}"]
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
build:
context: .
dockerfile: Dockerfile
ports:
- "${PORT}:${PORT}"
environment:
- NODE_ENV=production
- PORT= ${PORT}
Expand All @@ -14,7 +16,10 @@ services:
- 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}
- NEXT_PUBLIC_FOSSIL_API_URL=${NEXT_PUBLIC_FOSSIL_API_URL}
- NEXT_PUBLIC_DEV_ADDRESS=${NEXT_PUBLIC_DEV_ADDRESS}
- NEXT_PUBLIC_DEV_PK=${NEXT_PUBLIC_DEV_PK}
- NEXT_PUBLIC_WS_URL=${NEXT_PUBLIC_WS_URL}
5 changes: 5 additions & 0 deletions src/app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { NextResponse } from 'next/server';

export async function GET() {
return new NextResponse("healthy", { status: 200 });
}
20 changes: 12 additions & 8 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import { useEffect, useRef, useState } from "react";
import VaultCard from "@/components/Vault/VaultCard/VaultCard";

export default function Home() {
const vaults = [
"0x038cfc94b5626c9355910304622f8270eaef77b62cb850e1ca0e38ecedcdee5b",
"0x2cbdf2381224c850975613fb42848ae1a3a608d91bcd7d7a59dcc2b459d98d4",
const vaults = process.env.NEXT_PUBLIC_VAULT_ADDRESSES?.split(",");

// short round
"0x13257401fd2df63db6464035ab3ed13f3ef84ae71a07054f50d7bd20311e0a3",
"0x8f4e98c8c7f2698ff9a98df855116154f0482b93127dc79b15f05effbe8237",
];
// console.log(vaultsRaw);
//
// const vaults = [
// "0x038cfc94b5626c9355910304622f8270eaef77b62cb850e1ca0e38ecedcdee5b",
// "0x2cbdf2381224c850975613fb42848ae1a3a608d91bcd7d7a59dcc2b459d98d4",
//
// // short round
// "0x13257401fd2df63db6464035ab3ed13f3ef84ae71a07054f50d7bd20311e0a3",
// "0x8f4e98c8c7f2698ff9a98df855116154f0482b93127dc79b15f05effbe8237",
// ];

const [isModalVisible, setIsModalVisible] = useState<boolean>();
const handleCreateClick = () => {};
Expand Down Expand Up @@ -61,7 +65,7 @@ export default function Home() {
return (
<div className="flex flex-grow flex-col px-8 mt-6 w-full ">
<p className="my-2 text-base text-white-alt py-2 font-medium">
Popular Vaults - {process.env.NEXT_PUBLIC_VAULT_ADDRESS}
Popular Vaults
</p>
<div className="grid grid-cols-2 w-full pt-6 gap-x-6 gap-y-6">
{vaults?.map((vault: string, index: number) => (
Expand Down
1 change: 0 additions & 1 deletion src/components/Vault/VaultActions/PanelLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { BalanceTooltip } from "@/components/BaseComponents/Tooltip";
import StateTransition from "@/components/Vault/VaultActions/StateTransition";
import { useProvider } from "@starknet-react/core";
import useLatestTimestamp from "@/hooks/chain/useLatestTimestamp";
import useFossilStatus from "@/hooks/fossil/useFossilStatus";

// comment for git

Expand Down
14 changes: 4 additions & 10 deletions src/components/Vault/VaultActions/StateTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ const StateTransition = ({
const { timestamp: timestampRaw } = useLatestTimestamp(provider);
const timestamp = timestampRaw ? timestampRaw : "0";
const { status, error, loading } = useFossilStatus(
createJobId(
selectedRoundState?.optionSettleDate
? selectedRoundState.optionSettleDate.toString()
: "",
),
selectedRoundState?.optionSettleDate?.toString(),
selectedRoundState?.roundId?.toString(),
);
const {
status: statusR1,
error: errorR1,
loading: loadingR1,
} = useFossilStatus(
createJobId(
vaultState?.deploymentDate ? vaultState.deploymentDate.toString() : "",
),
);
} = useFossilStatus(vaultState?.deploymentDate?.toString(), "1");

const [transactionComplete, setTransactionComplete] = useState(false);
// to trigger btn disabled
const [isFossilReqSent, setIsFossilReqSent] = useState<boolean>(false);
Expand Down
29 changes: 27 additions & 2 deletions src/context/StarknetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ import {
} from "@starknet-react/core";
import { Provider } from "starknet";

export const juno = {
id: BigInt("0x1111"),
network: "juno",
name: "Juno Devnet",
nativeCurrency: {
address:
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
name: "Ether",
symbol: "ETH",
decimals: 18,
},
testnet: true,
rpcUrls: {
default: {
http: [],
},
public: {
http: ["http://localhost:6060"],
},
},
} as const satisfies Chain;

export const StarknetProvider = ({
children,
}: {
Expand All @@ -30,6 +52,10 @@ export const StarknetProvider = ({

function rpc(chain: Chain) {
switch (chain.network) {
case "juno":
return {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL_JUNO_DEVNET,
};
case "sepolia":
return {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL_SEPOLIA,
Expand All @@ -38,7 +64,6 @@ export const StarknetProvider = ({
return {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL_MAINNET,
};

case "devnet":
return {
nodeUrl: process.env.NEXT_PUBLIC_RPC_URL_DEVNET,
Expand All @@ -53,7 +78,7 @@ export const StarknetProvider = ({

return (
<StarknetConfig
chains={[sepolia, mainnet, devnet]}
chains={[juno, sepolia, mainnet, devnet]}
provider={provider}
connectors={connectors}
explorer={voyager}
Expand Down
32 changes: 27 additions & 5 deletions src/hooks/fossil/useFossilStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useEffect, useCallback, useState } from "react";
import { createJobId } from "@/lib/utils";
import { OptionRoundStateType } from "@/lib/types";

// Poll a job's status using it's ID
const INTERVAL_MS = 3000;
Expand All @@ -8,15 +10,28 @@ interface StatusData {
error?: string;
}

const useFossilStatus = (jobId: string | undefined) => {
interface FossilStatusParams {
roundId: string | undefined;
targetTimestamp: string | undefined;
isInitialRequest: boolean;
}

//const useFossilStatus = (jobId: string | undefined) => {
//const useFossilStatus = ({ roundId, targetTimestamp }: FossilStatusParams) => {
const useFossilStatus = (
targetTimestamp: string | undefined,
roundId: string | undefined,
) => {
const [status, setStatus] = useState<StatusData | null>(null);
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const fetchStatus = useCallback(async () => {
if (!jobId) return;
if (!targetTimestamp || targetTimestamp === "0") return;
if (!roundId || roundId === "0") return;
setLoading(true);
try {
const jobId = createJobId(targetTimestamp);
const response = await fetch(
`${process.env.NEXT_PUBLIC_FOSSIL_API_URL}/job_status/${jobId}`,
);
Expand All @@ -31,10 +46,17 @@ const useFossilStatus = (jobId: string | undefined) => {
} finally {
setLoading(false);
}
}, [jobId]);
}, [targetTimestamp]);

useEffect(() => {
if (!jobId || status?.status === "Completed" || status?.status === "Failed")
if (
!targetTimestamp ||
targetTimestamp === "0" ||
!roundId ||
roundId === "0" ||
status?.status === "Completed" ||
status?.status === "Failed"
)
return;

const intervalId = setInterval(fetchStatus, INTERVAL_MS);
Expand All @@ -43,7 +65,7 @@ const useFossilStatus = (jobId: string | undefined) => {
return () => {
clearInterval(intervalId);
};
}, [jobId, fetchStatus]);
}, [targetTimestamp, fetchStatus]);

return { status, error, loading };
};
Expand Down
66 changes: 66 additions & 0 deletions src/services/useFossilStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// "use server";
//
// import { useEffect, useCallback, useState } from "react";
// import { createJobId } from "@/lib/utils";
//
// // Poll a job's status using it's ID
// const INTERVAL_MS = 3000;
//
// interface StatusData {
// status?: string;
// error?: string;
// }
//
// const useFossilStatus = (
// targetTimestamp: string | undefined,
// roundId: string | undefined,
// ) => {
// const [status, setStatus] = useState<StatusData | null>(null);
// const [error, setError] = useState<string | null>(null);
// const [loading, setLoading] = useState<boolean>(false);
//
// const fetchStatus = useCallback(async () => {
// if (!targetTimestamp || targetTimestamp === "0") return;
// if (!roundId || roundId === "0") return;
// setLoading(true);
// try {
// const jobId = createJobId(targetTimestamp);
// const response = await fetch(
// `${process.env.FOSSIL_API_URL}/job_status/${jobId}`,
// );
// if (!response.ok) throw new Error("Network response was not ok");
//
// const data = await response.json();
// setStatus(data);
// setError(null);
// } catch (err) {
// setStatus(null);
// setError("Error fetching job status");
// } finally {
// setLoading(false);
// }
// }, [targetTimestamp]);
//
// useEffect(() => {
// if (
// !targetTimestamp ||
// targetTimestamp === "0" ||
// !roundId ||
// roundId === "0" ||
// status?.status === "Completed" ||
// status?.status === "Failed"
// )
// return;
//
// const intervalId = setInterval(fetchStatus, INTERVAL_MS);
// fetchStatus();
//
// return () => {
// clearInterval(intervalId);
// };
// }, [targetTimestamp, fetchStatus]);
//
// return { status, error, loading };
// };
//
// export default useFossilStatus;

0 comments on commit a80aa86

Please sign in to comment.