mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* essential dapps config: switch to concurrent request and and add worker termination * fix rollbar error logging and enable it for server errors * fix for tokens request on address page * update generator script for multichain config * fix hot contracts interval select * update screenshot * update screenshots * pass chainId to trackTransaction for essential dapps * fix vertical alignment in hot contracts table * bump next.js to v15.5.10 --------- Co-authored-by: isstuev <[email protected]> Co-authored-by: Max Alekseenko <[email protected]>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
/* eslint-disable no-restricted-properties */
|
|
import type { MultichainConfig } from 'types/multichain';
|
|
|
|
import config from 'configs/app';
|
|
|
|
function isRunningInDocker() {
|
|
return process.env.HOSTNAME !== undefined;
|
|
}
|
|
|
|
let value: MultichainConfig | undefined = undefined;
|
|
|
|
async function fetchConfig() {
|
|
if (process.env.NEXT_RUNTIME !== 'edge') {
|
|
throw new Error('NEXT_RUNTIME is not edge');
|
|
}
|
|
|
|
// In edge runtime, we need to use absolute URLs
|
|
// When in Docker, use the internal hostname
|
|
const baseUrl = isRunningInDocker() ?
|
|
`http://${ process.env.HOSTNAME }:${ config.app.port || 3000 }` :
|
|
config.app.baseUrl;
|
|
|
|
const url = baseUrl + '/assets/essential-dapps/chains.json';
|
|
const response = await fetch(url);
|
|
if (response.ok) {
|
|
const contentType = response.headers.get('content-type');
|
|
if (contentType?.includes('application/json')) {
|
|
const json = await response.json();
|
|
value = json as MultichainConfig;
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function load() {
|
|
if (!value) {
|
|
return new Promise<MultichainConfig | undefined>((resolve, reject) => {
|
|
fetchConfig()
|
|
.then((value) => {
|
|
resolve(value);
|
|
}).catch((error) => {
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
return Promise.resolve(value);
|
|
}
|
|
|
|
export function getValue() {
|
|
return value;
|
|
}
|