Skip to content

Commit fdeb173

Browse files
authored
Merge pull request #253 from Agbeleshe/API
Transaction History API and Next.js 15 Build Fixes
2 parents 6cbfffd + 3f081e2 commit fdeb173

File tree

23 files changed

+946
-266
lines changed

23 files changed

+946
-266
lines changed

app/api/remittance/allocate/route.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/api/remittance/emergency/build/route.ts

Lines changed: 0 additions & 206 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { StellarTransactionBuilder } from '../../../../../../services/transaction-builder-service';
3+
import { getSession } from '../../../../../../lib/session';
4+
5+
export const dynamic = 'force-dynamic';
6+
7+
export async function POST(req: NextRequest) {
8+
try {
9+
const session = await getSession();
10+
if (!session?.address) {
11+
return NextResponse.json(
12+
{ error: 'Unauthorized', message: 'Not authenticated' },
13+
{ status: 401 }
14+
);
15+
}
16+
17+
const body = await req.json();
18+
const { destinationAccount, amount, assetCode, assetIssuer, memo } = body;
19+
20+
if (!destinationAccount || !amount) {
21+
return NextResponse.json(
22+
{ error: 'Bad Request', message: 'Missing destinationAccount or amount' },
23+
{ status: 400 }
24+
);
25+
}
26+
27+
const builder = new StellarTransactionBuilder();
28+
const xdr = await builder.buildEmergencyTransfer({
29+
sourceAccount: session.address,
30+
destinationAccount,
31+
amount, // Note: service converts to stroops/XLM as needed
32+
assetCode,
33+
assetIssuer,
34+
memo,
35+
emergency: true,
36+
});
37+
38+
return NextResponse.json({ xdr });
39+
} catch (error: any) {
40+
console.error('Error in emergency build API:', error);
41+
return NextResponse.json(
42+
{ error: 'Internal Server Error', message: error.message },
43+
{ status: 500 }
44+
);
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { getSession } from '../../../../../lib/session';
3+
import { fetchTransactionHistory } from '../../../../../lib/remittance/horizon';
4+
5+
export const dynamic = 'force-dynamic';
6+
7+
/**
8+
* GET /api/remittance/history (protected)
9+
* Returns list of transactions for session user.
10+
*
11+
* Query params:
12+
* - limit: number (default 10, max 200)
13+
* - cursor: string (pagination)
14+
* - status: 'completed' | 'failed' | 'pending'
15+
*/
16+
export async function GET(req: NextRequest) {
17+
try {
18+
const session = await getSession();
19+
if (!session?.address) {
20+
return NextResponse.json(
21+
{ error: 'Unauthorized', message: 'Not authenticated' },
22+
{ status: 401 }
23+
);
24+
}
25+
26+
const { searchParams } = new URL(req.url);
27+
const limitParam = searchParams.get('limit');
28+
const limit = limitParam ? parseInt(limitParam, 10) : 10;
29+
const cursor = searchParams.get('cursor') || undefined;
30+
const status = searchParams.get('status') as 'completed' | 'failed' | 'pending' | null;
31+
32+
const history = await fetchTransactionHistory(session.address, {
33+
limit: Math.min(limit, 200),
34+
cursor,
35+
status: status || undefined,
36+
});
37+
38+
return NextResponse.json(history);
39+
} catch (error: any) {
40+
console.error('Error fetching remittance history:', error);
41+
return NextResponse.json(
42+
{ error: 'Internal Server Error', message: error.message },
43+
{ status: 500 }
44+
);
45+
}
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { NextRequest, NextResponse } from 'next/server';
2+
import { fetchTransactionStatus } from '../../../../../../lib/remittance/horizon';
3+
4+
export const dynamic = 'force-dynamic';
5+
6+
/**
7+
* GET /api/remittance/status/[txHash]
8+
* Returns current status of a single transaction.
9+
*/
10+
export async function GET(
11+
req: NextRequest,
12+
{ params }: { params: Promise<{ txHash: string }> }
13+
) {
14+
try {
15+
const { txHash } = await params;
16+
17+
if (!txHash) {
18+
return NextResponse.json(
19+
{ error: 'Bad Request', message: 'Missing transaction hash' },
20+
{ status: 400 }
21+
);
22+
}
23+
24+
const status = await fetchTransactionStatus(txHash);
25+
26+
return NextResponse.json({ hash: txHash, status });
27+
} catch (error: any) {
28+
console.error('Error fetching transaction status:', error);
29+
return NextResponse.json(
30+
{ error: 'Internal Server Error', message: error.message },
31+
{ status: 500 }
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)