8e25108701
* chore: [#471] update @vegaprotocol/vegawallet-service-api-client to 0.4.12 * fix: [#471] set up storybook in order-list lib and add tailwind * fix: [#471] organize order list components * chore: [471] pull theme switcher changes * feat: [#471] add cancel order button * feat: [#471] initial impl of use order cancel hook * fix: [#471] fix format of the price in order list * fix: #471 fix static assets issue when merging * fix: #471 refactor order dialog to vega tx dialog * fix: #471 move use cancel order hook in wallet lib * fix: [#471] cancel order dialog and hook refactor * fix: [#471] remove commented code from storybook preview and fix test * fix: [#471] update order-list.tsx * fix: [#471] fix update subscription - show order is cancelled * fix: [#471] fix eslint error * chore: [#471] refactoring and add tests for dialogs and cancel hook * fix: #471 add ref to order list table * fix: #471 add field for cancel fix test * fix: #471 rename vega-order-transaction-dialog, error handiling, open dialog on finalized order * fix: #471 sendTx body mandatory * fix: #471 use BusEventType.Order to check the typename * fix: #471 revert using BusEventType.Order to check the typename * Update libs/wallet/src/order-hooks/use-order-cancel.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * fix: #471 fix order-list refactoring and fixes * fix: #471 generate orders added as a mock in order-list * fix: #471 reset transaction after order updated * fix: #471 remove unused import useEffect * fix: #471 generate mock orders * fix: #471 revert generate mock orders * feat: #463 modify vega dialog to direct you to the block explorer transaction * feat: #463 modify compile-environment.ts * fix: #471 order list price set to display all decimals * fix: #471 generate orders updates * Update apps/trading/.env * fix: #463 add test and remove explorer URL from trading/env.ts * Update apps/trading/lib/config/env.ts * fix: #463 update trading deal ticket * fix: #463 fix test to check href Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
105 lines
2.7 KiB
TypeScript
105 lines
2.7 KiB
TypeScript
import type { RawEnvironment, EnvKey, Environment } from '../types';
|
|
import { Networks, ENV_KEYS } from '../types';
|
|
|
|
declare global {
|
|
interface Window {
|
|
_env_?: Record<string, string>;
|
|
}
|
|
}
|
|
|
|
const isBrowser = typeof window !== 'undefined';
|
|
|
|
const getDefaultEtherumProviderUrl = (env: Networks) => {
|
|
return env === Networks.MAINNET
|
|
? 'https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8'
|
|
: 'https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8';
|
|
};
|
|
|
|
const getDefaultEtherscanUrl = (env: Networks) => {
|
|
return env === Networks.MAINNET
|
|
? 'https://etherscan.io'
|
|
: 'https://ropsten.etherscan.io';
|
|
};
|
|
|
|
const transformValue = (key: EnvKey, value?: string) => {
|
|
switch (key) {
|
|
case 'VEGA_ENV':
|
|
return value as Networks;
|
|
case 'VEGA_NETWORKS': {
|
|
if (value) {
|
|
try {
|
|
return JSON.parse(value);
|
|
} catch (e) {
|
|
console.warn(
|
|
'Error parsing the "NX_VEGA_NETWORKS" environment variable. Make sure it has a valid JSON format.'
|
|
);
|
|
return {};
|
|
}
|
|
}
|
|
return {};
|
|
}
|
|
default:
|
|
return value;
|
|
}
|
|
};
|
|
|
|
const getBundledEnvironmentValue = (key: EnvKey) => {
|
|
switch (key) {
|
|
// need to have these hardcoded so on build time they can be replaced with the relevant environment variable
|
|
case 'VEGA_URL':
|
|
return process.env['NX_VEGA_URL'];
|
|
case 'VEGA_ENV':
|
|
return process.env['NX_VEGA_ENV'];
|
|
case 'VEGA_CONFIG_URL':
|
|
return process.env['NX_VEGA_CONFIG_URL'];
|
|
case 'ETHEREUM_PROVIDER_URL':
|
|
return process.env['NX_ETHEREUM_PROVIDER_URL'];
|
|
case 'ETHERSCAN_URL':
|
|
return process.env['NX_ETHERSCAN_URL'];
|
|
case 'VEGA_NETWORKS':
|
|
return process.env['NX_VEGA_NETWORKS'];
|
|
case 'VEGA_EXPLORER_URL':
|
|
return process.env['NX_VEGA_EXPLORER_URL'];
|
|
}
|
|
};
|
|
|
|
const getValue = (key: EnvKey, definitions: Partial<RawEnvironment> = {}) => {
|
|
if (!isBrowser) {
|
|
return transformValue(
|
|
key,
|
|
definitions[key] ?? getBundledEnvironmentValue(key)
|
|
);
|
|
}
|
|
return transformValue(
|
|
key,
|
|
definitions[key] ?? window._env_?.[key] ?? getBundledEnvironmentValue(key)
|
|
);
|
|
};
|
|
|
|
export const compileEnvironment = (
|
|
definitions?: Partial<RawEnvironment>
|
|
): Environment => {
|
|
const environment = ENV_KEYS.reduce((acc, key) => {
|
|
const value = getValue(key, definitions);
|
|
|
|
if (value) {
|
|
return {
|
|
...acc,
|
|
[key]: value,
|
|
};
|
|
}
|
|
|
|
return acc;
|
|
}, {} as Environment);
|
|
|
|
return {
|
|
// @ts-ignore enable using default object props
|
|
ETHERSCAN_URL: getDefaultEtherscanUrl(environment['VEGA_ENV']),
|
|
// @ts-ignore enable using default object props
|
|
ETHEREUM_PROVIDER_URL: getDefaultEtherumProviderUrl(
|
|
environment['VEGA_ENV']
|
|
),
|
|
...environment,
|
|
};
|
|
};
|