From 3ad4373395c0568aa41d9df3e7569145a114bcf1 Mon Sep 17 00:00:00 2001 From: Soyuz Date: Sat, 7 Mar 2026 17:55:12 +0800 Subject: [PATCH] Auto-detect STREAM endpoint and remove admin input --- webApp/src/components/App/App.tsx | 45 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/webApp/src/components/App/App.tsx b/webApp/src/components/App/App.tsx index b30b111..3a67f70 100644 --- a/webApp/src/components/App/App.tsx +++ b/webApp/src/components/App/App.tsx @@ -35,7 +35,6 @@ type AidRequest = { type AdminSettings = { fundWallet: string; - streamEndpoint: string; apiToken: string; }; @@ -80,10 +79,27 @@ function normalizeEndpoint(value: string): string { return value.trim(); } +function detectStreamEndpoint(): string { + const configuredEndpoint = normalizeEndpoint(import.meta.env.VITE_STREAM_SENDER_ENDPOINT ?? ''); + if (configuredEndpoint) { + return configuredEndpoint; + } + + if (typeof window !== 'undefined') { + const { hostname, origin, port, protocol } = window.location; + if (port === '3000') { + return `${origin}/stream/send`; + } + return `${protocol}//${hostname}:3000/stream/send`; + } + + return 'http://localhost:3000/stream/send'; +} + function createInterledgerClient(): InterledgerClient { let selfAccount = ''; let targetAccount = ''; - let streamEndpoint = normalizeEndpoint(import.meta.env.VITE_STREAM_SENDER_ENDPOINT ?? ''); + let streamEndpoint = detectStreamEndpoint(); let authToken = (import.meta.env.VITE_INTERLEDGER_API_TOKEN ?? '').trim(); return { @@ -167,11 +183,12 @@ export function App() { const [adminSettings, setAdminSettings] = useState(() => readStoredJson(SETTINGS_STORAGE_KEY, { fundWallet: '', - streamEndpoint: import.meta.env.VITE_STREAM_SENDER_ENDPOINT ?? '', apiToken: import.meta.env.VITE_INTERLEDGER_API_TOKEN ?? '' }) ); + const streamEndpoint = useMemo(() => detectStreamEndpoint(), []); + const [requestForm, setRequestForm] = useState({ requesterName: '', contact: '', @@ -311,16 +328,11 @@ export function App() { return; } - if (!adminSettings.streamEndpoint.trim()) { - setAdminNotice({ kind: 'error', message: 'Set the STREAM sender endpoint in Admin Settings first.' }); - return; - } - setPayingRequestId(request.id); setAdminNotice({ kind: 'idle', message: `Sending payout for ${request.id}...` }); try { - interledgerClient.setStreamEndpoint(adminSettings.streamEndpoint); + interledgerClient.setStreamEndpoint(streamEndpoint); interledgerClient.setAuthToken(adminSettings.apiToken); interledgerClient.setSelfAccount(adminSettings.fundWallet); interledgerClient.setTargetAccount(request.wallet); @@ -565,20 +577,7 @@ export function App() { /> - +

STREAM sender endpoint is auto-detected: {streamEndpoint}