Skip to content

Commit 63ce615

Browse files
fix: resolve frontend ESLint issues
1 parent acfb2ab commit 63ce615

7 files changed

Lines changed: 96 additions & 44 deletions

File tree

frontend/src/components/place-bet-form.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { FormEvent, useState } from "react";
3+
import { FormEvent, useEffect, useState } from "react";
44
import clsx from "clsx";
55
import { Market, MarketStatus } from "@/lib/contract/types";
66
import { useWallet } from "@/lib/wallet/use-wallet";
@@ -33,10 +33,13 @@ export function PlaceBetForm({ market, onBetSuccess }: PlaceBetFormProps) {
3333
const [isSubmitting, setIsSubmitting] = useState(false);
3434
const [submitError, setSubmitError] = useState<string | null>(null);
3535
const [successMessage, setSuccessMessage] = useState<string | null>(null);
36+
const [isMarketClosed, setIsMarketClosed] = useState(false);
3637

37-
const now = Math.floor(Date.now() / 1000);
38-
const marketStatus = getMarketStatus(market, now);
39-
const isMarketClosed = marketStatus !== MarketStatus.Active;
38+
useEffect(() => {
39+
const now = Math.floor(Date.now() / 1000);
40+
const marketStatus = getMarketStatus(market, now);
41+
setIsMarketClosed(marketStatus !== MarketStatus.Active);
42+
}, [market]);
4043

4144
const validateForm = (): boolean => {
4245
const newErrors: FormErrors = {};

frontend/src/lib/contract/betting-service.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ export async function getUserBet(
5151
return null;
5252
}
5353

54+
const betData = result as { outcome_index?: number | bigint; amount?: number | bigint };
5455
return {
5556
outcomeIndex:
56-
typeof result.outcome_index === "number"
57-
? result.outcome_index
58-
: Number(result.outcome_index),
57+
typeof betData.outcome_index === "number"
58+
? betData.outcome_index
59+
: Number(betData.outcome_index || 0),
5960
amount:
60-
typeof result.amount === "number"
61-
? result.amount
62-
: Number(result.amount),
61+
typeof betData.amount === "number"
62+
? betData.amount
63+
: Number(betData.amount || 0),
6364
};
6465
} catch (error) {
6566
console.error("Error fetching user bet:", error);

frontend/src/lib/contract/market-service.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function listMarkets(): Promise<Market[]> {
1414
return [];
1515
}
1616

17-
return result.map((market: any) => parseMarketFromContract(market));
17+
return result.map((market: unknown) => parseMarketFromContract(market));
1818
} catch (error) {
1919
console.error("Error fetching markets:", error);
2020
throw error;
@@ -36,16 +36,27 @@ export async function getMarket(marketId: number): Promise<Market> {
3636
}
3737
}
3838

39-
function parseMarketFromContract(data: any): Market {
39+
interface ContractMarketData {
40+
id?: number | bigint;
41+
creator?: string;
42+
title?: string;
43+
description?: string;
44+
end_time?: number | bigint;
45+
outcomes?: string[];
46+
resolved?: boolean;
47+
}
48+
49+
function parseMarketFromContract(data: unknown): Market {
50+
const marketData = data as ContractMarketData;
4051
return {
41-
id: typeof data.id === "bigint" ? Number(data.id) : data.id,
42-
creator: data.creator || "",
43-
title: data.title || "",
44-
description: data.description || "",
52+
id: typeof marketData.id === "bigint" ? Number(marketData.id) : marketData.id || 0,
53+
creator: marketData.creator || "",
54+
title: marketData.title || "",
55+
description: marketData.description || "",
4556
end_time:
46-
typeof data.end_time === "bigint" ? Number(data.end_time) : data.end_time,
47-
outcomes: Array.isArray(data.outcomes) ? data.outcomes : [],
48-
resolved: Boolean(data.resolved),
57+
typeof marketData.end_time === "bigint" ? Number(marketData.end_time) : marketData.end_time || 0,
58+
outcomes: Array.isArray(marketData.outcomes) ? marketData.outcomes : [],
59+
resolved: Boolean(marketData.resolved),
4960
};
5061
}
5162

frontend/src/lib/contract/soroban-client.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
// @ts-nocheck
21
import { STELLAR_NETWORK, CONTRACT_ID } from "@/lib/env";
32

4-
let rpcClient: any = null;
3+
type SorobanRpcServer = {
4+
getAccount: (id: string) => Promise<unknown>;
5+
simulateTransaction: (tx: unknown) => Promise<unknown>;
6+
};
57

6-
export async function getSorobanClient(): Promise<any> {
8+
let rpcClient: SorobanRpcServer | null = null;
9+
10+
export async function getSorobanClient(): Promise<SorobanRpcServer> {
711
if (!rpcClient) {
812
// Dynamic import to avoid TypeScript resolution issues
913
const { SorobanRpc } = await import("@stellar/stellar-sdk");
@@ -25,14 +29,14 @@ export function getContractAddress(): string {
2529

2630
export interface InvokeContractOptions {
2731
method: string;
28-
args?: any[];
29-
signers?: any[];
32+
args?: unknown[];
33+
signers?: unknown[];
3034
}
3135

3236
export async function simulateContractCall(
3337
method: string,
34-
args: any[] = []
35-
): Promise<any> {
38+
args: unknown[] = []
39+
): Promise<unknown> {
3640
const { Address, TransactionBuilder, contract, nativeToScVal, scValToNative, SorobanRpc } = await import(
3741
"@stellar/stellar-sdk"
3842
);
@@ -44,7 +48,7 @@ export async function simulateContractCall(
4448
const source = await client.getAccount(contractId);
4549

4650
// Create a contract invocation with simulated parameters
47-
const params = args.map((arg: any) => {
51+
const params = args.map((arg) => {
4852
if (typeof arg === "string") {
4953
return nativeToScVal(arg, { type: "string" });
5054
}
@@ -70,16 +74,17 @@ export async function simulateContractCall(
7074
const client_tx = await client.simulateTransaction(tx);
7175

7276
if (SorobanRpc.Api.isSimulationSuccess(client_tx)) {
73-
const result = client_tx.result?.retval;
77+
const result = (client_tx as { result?: { retval: unknown } }).result?.retval;
7478
if (result) {
7579
return scValToNative(result);
7680
}
7781
return null;
7882
} else if (SorobanRpc.Api.isSimulationRestore(client_tx)) {
7983
throw new Error("Contract needs restore");
8084
} else if (SorobanRpc.Api.isSimulationError(client_tx)) {
85+
const errorMsg = (client_tx as { error?: { message: string } }).error?.message;
8186
throw new Error(
82-
`Simulation error: ${client_tx.error?.message || "Unknown error"}`
87+
`Simulation error: ${errorMsg || "Unknown error"}`
8388
);
8489
}
8590
} catch (error) {

frontend/src/lib/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export const STELLAR_NETWORK = {
88
// NEXT_PUBLIC_ variables are injected at build time by Next.js
99
export const CONTRACT_ID = (() => {
1010
if (typeof globalThis === "undefined") return "";
11-
const env = (globalThis as any).process?.env;
11+
const env = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env;
1212
return env?.NEXT_PUBLIC_CONTRACT_ID || "";
1313
})();

frontend/src/lib/hooks/use-market.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import { useEffect, useState } from "react";
44
import { Market } from "@/lib/contract/types";
5-
import { getMarket, getMarketPool } from "@/lib/contract/market-service";
5+
import { getMarket } from "@/lib/contract/market-service";
6+
import { getMarketPool } from "@/lib/contract/betting-service";
67

78
interface UseMarketReturn {
89
market: Market | null;
@@ -18,7 +19,29 @@ export function useMarket(marketId: number): UseMarketReturn {
1819
const [isLoading, setIsLoading] = useState(true);
1920
const [error, setError] = useState<string | null>(null);
2021

21-
const fetchMarket = async () => {
22+
useEffect(() => {
23+
const fetchMarket = async () => {
24+
setIsLoading(true);
25+
setError(null);
26+
try {
27+
const marketData = await getMarket(marketId);
28+
setMarket(marketData);
29+
30+
const poolData = await getMarketPool(marketId);
31+
setPool(poolData);
32+
} catch (err) {
33+
const message =
34+
err instanceof Error ? err.message : "Failed to load market";
35+
setError(message);
36+
} finally {
37+
setIsLoading(false);
38+
}
39+
};
40+
41+
void fetchMarket();
42+
}, [marketId]);
43+
44+
const refetch = async () => {
2245
setIsLoading(true);
2346
setError(null);
2447
try {
@@ -36,15 +59,11 @@ export function useMarket(marketId: number): UseMarketReturn {
3659
}
3760
};
3861

39-
useEffect(() => {
40-
void fetchMarket();
41-
}, [marketId]);
42-
4362
return {
4463
market,
4564
pool,
4665
isLoading,
4766
error,
48-
refetch: fetchMarket,
67+
refetch,
4968
};
5069
}

frontend/src/lib/hooks/use-markets.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@ export function useMarkets() {
99
const [isLoading, setIsLoading] = useState(true);
1010
const [error, setError] = useState<string | null>(null);
1111

12-
const fetchMarkets = async () => {
12+
useEffect(() => {
13+
const fetchMarkets = async () => {
14+
setIsLoading(true);
15+
setError(null);
16+
try {
17+
const data = await listMarkets();
18+
setMarkets(data);
19+
} catch (err) {
20+
const message = err instanceof Error ? err.message : "Failed to load markets";
21+
setError(message);
22+
console.error("Error loading markets:", err);
23+
} finally {
24+
setIsLoading(false);
25+
}
26+
};
27+
28+
void fetchMarkets();
29+
}, []);
30+
31+
const refetch = async () => {
1332
setIsLoading(true);
1433
setError(null);
1534
try {
@@ -24,11 +43,5 @@ export function useMarkets() {
2443
}
2544
};
2645

27-
useEffect(() => {
28-
void fetchMarkets();
29-
}, []);
30-
31-
const refetch = () => void fetchMarkets();
32-
3346
return { markets, isLoading, error, refetch };
3447
}

0 commit comments

Comments
 (0)