Skip to content

Commit 2f4bbc2

Browse files
committed
feat: reputation system, stripe integration, swap routes, lightning improvements, and web-wallet updates
1 parent 0d90322 commit 2f4bbc2

File tree

34 files changed

+241
-150
lines changed

34 files changed

+241
-150
lines changed

src/app/api/cron/monitor-payments/route.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ vi.mock('bitcoinjs-lib', () => ({
2424
},
2525
}));
2626

27+
vi.mock('@/lib/blockchain/providers', () => ({
28+
getBlockchainProvider: vi.fn(),
29+
}));
30+
2731
// Mock env before module loads
2832
process.env.NEXT_PUBLIC_SUPABASE_URL = 'https://test.supabase.co';
2933
process.env.SUPABASE_SERVICE_ROLE_KEY = 'test-key';

src/app/api/cron/monitor-payments/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { monitorLightningPayments, syncLnbitsPayments } from './lightning-monito
1818
import { monitorSeries } from './series-monitor';
1919
import { monitorEmails } from './email-monitor';
2020

21-
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
22-
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY!;
21+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co';
22+
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY || 'service-role-key';
2323

2424
/**
2525
* Get cron secret for authentication

src/app/api/lightning/address/route.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { NextRequest, NextResponse } from 'next/server';
33
import { createClient } from '@supabase/supabase-js';
44
import { createPayLink, createUserWallet, getPayLink } from '@/lib/lightning/lnbits';
55

6-
const supabase = createClient(
7-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
8-
process.env.SUPABASE_SERVICE_ROLE_KEY!
9-
);
6+
function getSupabase() {
7+
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
8+
const key = process.env.SUPABASE_SERVICE_ROLE_KEY;
9+
if (!url || !key) {
10+
throw new Error('Missing Supabase server environment variables');
11+
}
12+
return createClient(url, key);
13+
}
1014

1115
const LIGHTNING_USERNAME_REGEX = /^[a-z0-9][a-z0-9._-]{1,30}[a-z0-9]$/;
1216
function isMissingLnbitsWalletError(error: unknown): boolean {
@@ -24,7 +28,7 @@ function isLnbitsAuthError(error: unknown): boolean {
2428
return /api error 401|401 authorization required|unauthorized/i.test(msg);
2529
}
2630

27-
async function ensureLightningAddressBackend(walletId: string, username: string, wallet: {
31+
async function ensureLightningAddressBackend(supabase: ReturnType<typeof getSupabase>, walletId: string, username: string, wallet: {
2832
ln_wallet_adminkey?: string | null;
2933
ln_paylink_id?: number | null;
3034
}) {
@@ -110,6 +114,7 @@ async function ensureLightningAddressBackend(walletId: string, username: string,
110114
*/
111115
export async function POST(request: NextRequest) {
112116
try {
117+
const supabase = getSupabase();
113118
const { wallet_id, username } = await request.json();
114119

115120
if (!wallet_id || !username) {
@@ -187,7 +192,7 @@ export async function POST(request: NextRequest) {
187192
);
188193
}
189194

190-
await ensureLightningAddressBackend(wallet_id, username, {
195+
await ensureLightningAddressBackend(supabase, wallet_id, username, {
191196
ln_wallet_adminkey: wallet.ln_wallet_adminkey ?? null,
192197
ln_paylink_id: wallet.ln_paylink_id ?? null,
193198
});
@@ -224,6 +229,7 @@ export async function POST(request: NextRequest) {
224229
* Get current Lightning Address for a wallet
225230
*/
226231
export async function GET(request: NextRequest) {
232+
const supabase = getSupabase();
227233
const username = request.nextUrl.searchParams.get('username');
228234
if (username) {
229235
const normalized = username.trim().toLowerCase();
@@ -285,7 +291,7 @@ export async function GET(request: NextRequest) {
285291
// Keep Lightning Address restorable after seed imports by self-healing
286292
// stale/missing LNbits wallet or paylink metadata in background.
287293
try {
288-
await ensureLightningAddressBackend(walletId, wallet.ln_username, {
294+
await ensureLightningAddressBackend(supabase, walletId, wallet.ln_username, {
289295
ln_wallet_adminkey: (wallet as any).ln_wallet_adminkey ?? null,
290296
ln_paylink_id: (wallet as any).ln_paylink_id ?? null,
291297
});

src/app/api/lightning/invoices/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { createInvoice as createLnbitsInvoice } from '@/lib/lightning/lnbits';
55
import { createClient } from '@supabase/supabase-js';
66

77
const supabase = createClient(
8-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
9-
process.env.SUPABASE_SERVICE_ROLE_KEY!
8+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
9+
process.env.SUPABASE_SERVICE_ROLE_KEY || 'service-role-key'
1010
);
1111

1212
/**

src/app/api/payments/[id]/check-balance/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { forwardPaymentSecurely } from '@/lib/wallets/secure-forwarding';
55

66
import * as bitcoin from 'bitcoinjs-lib';
77

8-
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
9-
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY!;
8+
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co';
9+
const supabaseServiceKey = process.env.SUPABASE_SERVICE_ROLE_KEY || 'service-role-key';
1010

1111
/**
1212
* CashAddr charset for decoding

src/app/api/reputation/agent/[did]/reputation/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { getAttestationScore } from '@/lib/reputation/mutual-attestation';
77
import { isValidDid } from '@/lib/reputation/crypto';
88

99
const supabase = createClient(
10-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
11-
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
10+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
11+
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'public-anon-key'
1212
);
1313

1414
export async function GET(

src/app/api/reputation/badge/[did]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { computeReputation } from '@/lib/reputation/attestation-engine';
44
import { isValidDid } from '@/lib/reputation/crypto';
55

66
const supabase = createClient(
7-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
8-
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
7+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
8+
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'public-anon-key'
99
);
1010

1111
function generateBadgeSvg(taskCount: number, acceptedRate: number, flagged: boolean): string {

src/app/api/reputation/credential/[id]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
22
import { createClient } from '@supabase/supabase-js';
33

44
const supabase = createClient(
5-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
6-
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
5+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
6+
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'public-anon-key'
77
);
88

99
export async function GET(

src/app/api/reputation/credentials/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { createClient } from '@supabase/supabase-js';
33
import { isValidDid } from '@/lib/reputation/crypto';
44

55
const supabase = createClient(
6-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
7-
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
6+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
7+
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'public-anon-key'
88
);
99

1010
export async function GET(request: NextRequest) {

src/app/api/reputation/issuers/[id]/rotate/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { randomBytes } from 'crypto';
99
import { authenticateRequest, isMerchantAuth } from '@/lib/auth/middleware';
1010

1111
const supabase = createClient(
12-
process.env.NEXT_PUBLIC_SUPABASE_URL!,
13-
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
12+
process.env.NEXT_PUBLIC_SUPABASE_URL || 'https://example.supabase.co',
13+
process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'public-anon-key'
1414
);
1515

1616
export async function POST(

0 commit comments

Comments
 (0)