vega-frontend-monorepo/apps/trading/lib/use-links.ts
Art 8e5012891c
feat: no markets (#2097)
* feat: no markets

* feat: no markets

* feat: no markets

* feat: no markets

* feat: no markets
2022-11-18 17:08:48 +00:00

25 lines
786 B
TypeScript

import trim from 'lodash/trim';
import { Networks, useEnvironment } from '@vegaprotocol/environment';
import { useCallback } from 'react';
type DApp = 'console' | 'console-fairground' | 'token' | 'explorer';
export const useLinks = (dapp: DApp) => {
const { VEGA_ENV, VEGA_NETWORKS, VEGA_TOKEN_URL, VEGA_EXPLORER_URL } =
useEnvironment();
const urls: { [k in DApp]: string } = {
console: (VEGA_NETWORKS && VEGA_NETWORKS[VEGA_ENV]) || '',
'console-fairground':
(VEGA_NETWORKS && VEGA_NETWORKS[Networks.TESTNET]) || '',
token: VEGA_TOKEN_URL || '',
explorer: VEGA_EXPLORER_URL || '',
};
const baseUrl = trim(urls[dapp], '/');
const link = useCallback(
(url?: string) => `${baseUrl}/${trim(url, '/') || ''}`,
[baseUrl]
);
return link;
};