Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const compat = new FlatCompat({
baseDirectory: __dirname,
});

const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];

export default eslintConfig;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.2.0",
"@netlify/plugin-nextjs": "^5.15.12",
"@tailwindcss/postcss": "^4.0.0",
"@testing-library/dom": "^10.4.1",
Expand All @@ -32,6 +33,8 @@
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^6.0.4",
"autoprefixer": "^10.4.20",
"eslint": "^9.17.0",
"eslint-config-next": "^15.0.0",
"jsdom": "^29.1.1",
"postcss": "^8.5.0",
"tailwindcss": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/PolicyCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('PolicyCard', () => {

it('displays product name when available', () => {
const html = renderToStaticMarkup(
<PolicyCard policy={makePolicy({ product: { name: 'Crop Insurance' } as any })} />
<PolicyCard policy={makePolicy({ product: { name: 'Crop Insurance' } as unknown as Policy['product'] })} />
);
expect(html).toContain('Crop Insurance');
});
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/ProductCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ProductCard', () => {

it('renders fallback icon for unrecognized category', () => {
const html = renderToStaticMarkup(
<ProductCard product={makeProduct({ category: 'unknown' as any })} />
<ProductCard product={makeProduct({ category: 'unknown' as unknown as Product['category'] })} />
);
expect(html).toContain('🛡️');
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/StatsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface StatsCardProps {
export interface StatsCardProps {
label: string;
value: string;
sublabel?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/components/__tests__/StatsCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@testing-library/react';
import { StatsCard } from '../StatsCard';
import { StatsCard, type StatsCardProps } from '../StatsCard';

describe('StatsCard', () => {
it('renders label, value and sublabel', () => {
Expand All @@ -11,7 +11,7 @@ describe('StatsCard', () => {
expect(screen.getByText('Today')).toBeInTheDocument();
});

it.each([
it.each<[NonNullable<StatsCardProps['trend']>, string, string]>([
['up', '↑', 'text-emerald-400'],
['down', '↓', 'text-red-400'],
['neutral', '→', 'text-gray-400'],
Expand All @@ -20,7 +20,7 @@ describe('StatsCard', () => {
<StatsCard
label="Users"
value="42"
trend={trend as any}
trend={trend}
trendValue="+5%"
/>,
);
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/usePolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function usePolicies(walletAddress: string | null) {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const isFirstLoad = useRef(true);
const refetchController = useRef<AbortController | null>(null);

const load = useCallback(async (signal: AbortSignal) => {
if (!walletAddress) return;
Expand Down Expand Up @@ -59,7 +60,9 @@ export function usePolicies(walletAddress: string | null) {
}, [load, walletAddress]);

const refetch = useCallback(() => {
refetchController.current?.abort();
const controller = new AbortController();
refetchController.current = controller;
return load(controller.signal);
}, [load]);

Expand Down
8 changes: 6 additions & 2 deletions src/hooks/usePools.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
'use client';

import { useState, useEffect, useCallback } from 'react';
import { useState, useEffect, useCallback, useRef } from 'react';
import { fetchPoolStats } from '@/lib/api';
import type { PoolStats } from '@/types';

export function usePools() {
const [pools, setPools] = useState<PoolStats[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const requestId = useRef(0);

const load = useCallback(async () => {
const id = ++requestId.current;
setLoading(true);
setError(null);
try {
const data = await fetchPoolStats();
if (id !== requestId.current) return;
setPools(data);
} catch (err) {
if (id !== requestId.current) return;
setError(err instanceof Error ? err.message : 'Failed to load pool stats');
} finally {
setLoading(false);
if (id === requestId.current) setLoading(false);
}
}, []);

Expand Down
8 changes: 6 additions & 2 deletions src/hooks/useProducts.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
'use client';

import { useState, useEffect, useCallback } from 'react';
import { useState, useEffect, useCallback, useRef } from 'react';
import { fetchProducts } from '@/lib/api';
import type { Product } from '@/types';

export function useProducts() {
const [products, setProducts] = useState<Product[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const requestId = useRef(0);

const load = useCallback(async () => {
const id = ++requestId.current;
setLoading(true);
setError(null);
try {
const data = await fetchProducts();
if (id !== requestId.current) return;
setProducts(data);
} catch (err) {
if (id !== requestId.current) return;
setError(err instanceof Error ? err.message : 'Failed to load products');
} finally {
setLoading(false);
if (id === requestId.current) setLoading(false);
}
}, []);

Expand Down
6 changes: 2 additions & 4 deletions src/lib/__tests__/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import { page, setPostHogReady } from '@/lib/analytics';
vi.mock('posthog-js', () => {
return {
capture: vi.fn(),
} as any;
};
});

declare const window: any;

beforeEach(() => {
// Reset mocks and global state
(posthog.capture as any).mockReset();
vi.mocked(posthog.capture).mockReset();
// Ensure analytics is not ready before each test
setPostHogReady(false);
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ async function waitForConfirmation(hash: string): Promise<string> {
for (let attempt = 0; attempt < TX_POLL_MAX_ATTEMPTS; attempt++) {
await new Promise((r) => setTimeout(r, TX_POLL_INTERVAL_MS));
const status = await rpc.getTransaction(hash);
if (status.status === 'SUCCESS') return hash;
if (status.status === 'FAILED') {
throw new ContractError('Transaction failed on-chain.', hash, (status as any).resultXdr ?? status);
if (status.status === StellarRpc.Api.GetTransactionStatus.SUCCESS) return hash;
if (status.status === StellarRpc.Api.GetTransactionStatus.FAILED) {
throw new ContractError('Transaction failed on-chain.', hash, status.resultXdr ?? status);
}
}
throw new ContractError(`Transaction not confirmed after ${TX_POLL_MAX_ATTEMPTS * TX_POLL_INTERVAL_MS / 1000}s — hash: ${hash}`);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/stellar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ export async function signTransaction(xdrEnvelope: string): Promise<string> {
* signing a minimal Stellar transaction envelope so older wallet extensions
* that only implement `signTransaction` are still supported.
*
* Returns a hex-encoded signature string suitable for sending to the backend
* as `signedChallenge`.
* Returns the signature string exactly as provided by the wallet kit (no
* encoding transformation is applied), for sending to the backend as
* `signedChallenge`. SEP-43 `signMessage` implementations typically return
* this base64-encoded rather than hex-encoded — callers/backends must not
* assume hex.
*/
export async function signAuthMessage(message: string): Promise<string> {
const address = getStoredAddress();
Expand Down
Loading
Loading