Align wallet SSR with report token-list, dedupe featured v1 tokens, refresh home and wallet snapshots on a 60s cadence, and drive vanilla SPA chain add/watch from API metadata. Add shared pagination/tabs for address, token, and transaction pages, extend token aggregation helpers, and harden stats API with tests and health checks. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
const LOCAL_EXPLORER_API_FALLBACK = 'http://localhost:8080'
|
|
|
|
function normalizeApiBase(value: string | null | undefined): string {
|
|
return (value || '').trim().replace(/\/$/, '')
|
|
}
|
|
|
|
function preferBrowserOriginForSameHost(explicitBase: string, browserOrigin: string): string {
|
|
if (!explicitBase || !browserOrigin) return explicitBase
|
|
|
|
try {
|
|
const explicitUrl = new URL(explicitBase)
|
|
const browserUrl = new URL(browserOrigin)
|
|
if (explicitUrl.hostname === browserUrl.hostname && explicitUrl.protocol !== browserUrl.protocol) {
|
|
return browserOrigin
|
|
}
|
|
} catch {
|
|
return explicitBase
|
|
}
|
|
|
|
return explicitBase
|
|
}
|
|
|
|
export function resolveExplorerApiBase(options: {
|
|
envValue?: string | null
|
|
browserOrigin?: string | null
|
|
serverFallback?: string
|
|
} = {}): string {
|
|
const explicitBase = normalizeApiBase(options.envValue ?? process.env.NEXT_PUBLIC_API_URL ?? '')
|
|
const browserOrigin = normalizeApiBase(
|
|
options.browserOrigin ?? (typeof window !== 'undefined' ? window.location.origin : '')
|
|
)
|
|
if (explicitBase) {
|
|
return preferBrowserOriginForSameHost(explicitBase, browserOrigin)
|
|
}
|
|
|
|
if (browserOrigin) {
|
|
return browserOrigin
|
|
}
|
|
|
|
return normalizeApiBase(options.serverFallback ?? LOCAL_EXPLORER_API_FALLBACK)
|
|
}
|