Skip to content
Open
Changes from all 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
69 changes: 22 additions & 47 deletions lib/staking/use-apr-metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const APR_API_BASE_URL = (
process.env.NEXT_PUBLIC_SSV_API ??
"https://api.hoodi.ssv.network/api/v4/hoodi/"
).replace(/\/+$/, "");
console.log(APR_API_BASE_URL)

type AprResponse = {
apr?: string | number | null;
aprProjected?: string | number | null;
Expand All @@ -18,56 +18,31 @@ type AprValues = {
};

async function fetchApr(): Promise<AprValues> {
const url = `${APR_API_BASE_URL}/apr/current`;
console.log('🔍 APR Fetch Debug:', {
url,
baseUrl: APR_API_BASE_URL,
envVar: process.env.NEXT_PUBLIC_SSV_API
const response = await fetch(`${APR_API_BASE_URL}/apr/current`, {
cache: "no-store"
});
if (!response.ok) {
return { aprValue: null, potentialAprValue: null };
}
const payload = (await response.json()) as AprResponse;

try {
const response = await fetch(url, {
cache: "no-store"
});

console.log('📡 APR Response:', {
status: response.status,
ok: response.ok,
statusText: response.statusText
});

if (!response.ok) {
console.error('❌ APR Fetch failed:', response.status, response.statusText);
return { aprValue: null, potentialAprValue: null };
const parseMetric = (
value: string | number | null | undefined
): number | null => {
if (typeof value === "number") {
return Number.isFinite(value) ? value : null;
}
if (typeof value === "string") {
const parsed = Number.parseFloat(value);
return Number.isFinite(parsed) ? parsed : null;
}
return null;
};

const payload = (await response.json()) as AprResponse;
console.log('📦 APR Payload:', payload);

const parseMetric = (
value: string | number | null | undefined
): number | null => {
if (typeof value === "number") {
return Number.isFinite(value) ? value : null;
}
if (typeof value === "string") {
const parsed = Number.parseFloat(value);
return Number.isFinite(parsed) ? parsed : null;
}
return null;
};

const result = {
aprValue: parseMetric(payload.apr),
potentialAprValue: parseMetric(payload.aprProjected)
};

console.log('✅ APR Parsed Result:', result);
return result;
} catch (error) {
console.error('💥 APR Fetch Error:', error);
return { aprValue: null, potentialAprValue: null };
}
return {
aprValue: parseMetric(payload.apr),
potentialAprValue: parseMetric(payload.aprProjected)
};
}

export function useAprMetric() {
Expand Down