Skip to content

Commit

Permalink
Merge pull request #133 from multiversx/update-vite-cert
Browse files Browse the repository at this point in the history
Update Vite Config
  • Loading branch information
radumojic authored Oct 23, 2024
2 parents 0a9026c + a7de699 commit 558586a
Show file tree
Hide file tree
Showing 22 changed files with 544 additions and 699 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"@types/ua-parser-js": "0.7.39",
"@typescript-eslint/eslint-plugin": "5.61.0",
"@typescript-eslint/parser": "5.61.0",
"@vitejs/plugin-basic-ssl": "1.1.0",
"@vitejs/plugin-react-swc": "3.3.2",
"cross-env": "7.0.3",
"cypress": "13.1.0",
Expand All @@ -116,8 +117,7 @@
"run-script-os": "1.1.6",
"sass": "1.62.1",
"typescript": "5.1.6",
"vite": "4.4.12",
"vite-plugin-mkcert": "1.16.0",
"vite": "4.5.0",
"vite-plugin-node-polyfills": "0.9.0",
"vite-plugin-svgr": "3.2.0",
"vite-tsconfig-paths": "4.2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/appConstants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './apiFields';

export const BRAND_NAME = process.env.VITE_APP_BRAND_NAME ?? 'MultiversX';
export const BRAND_NAME = import.meta.env.VITE_APP_BRAND_NAME ?? 'MultiversX';

export const METACHAIN_SHARD_ID = 4294967295;
export const MAIN_SHARD_ID = 4294967293;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorElement/ErrorElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { faTimes } from 'icons/regular';

export const ErrorElement = () => {
const { pathname } = useLocation();
const explorerVersion = process.env.VITE_APP_CACHE_BUST;
const explorerVersion = import.meta.env.VITE_APP_CACHE_BUST;
const error = useRouteError();
console.error(error);

Expand Down
13 changes: 8 additions & 5 deletions src/config/helpers/getInternalLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { DEFAULT_HOSTNAME } from 'config';
import { NetworkType, NetworkUrlType } from 'types/network.types';

export const getInternalLinks = (networks: NetworkType[]): NetworkUrlType[] => {
if (
process.env.NODE_ENV === 'production' &&
process.env.VITE_APP_SHARE_PREFIX === 'internal-'
) {
const isInternal =
import.meta.env.NODE_ENV === 'production' &&
import.meta.env.VITE_APP_SHARE_PREFIX === 'internal-';

if (isInternal) {
const internalLinks = networks
.filter(({ id, name, isCustom }) => id && name && !isCustom)
.map(({ id = '', name = '' }) => {
return {
id,
name,
url: `https://${id}.${process.env.VITE_APP_SHARE_PREFIX}${DEFAULT_HOSTNAME}`
url: `https://${id}.${
import.meta.env.VITE_APP_SHARE_PREFIX
}${DEFAULT_HOSTNAME}`
};
});

Expand Down
8 changes: 4 additions & 4 deletions src/config/helpers/getInternalNetworks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NetworkAdapterEnum, NetworkType } from 'types';

export const getInternalNetworks = (): NetworkType[] => {
if (process.env.VITE_APP_INTERNAL_NETWORKS) {
const internalNetworks = import.meta.env.VITE_APP_INTERNAL_NETWORKS;

if (internalNetworks) {
try {
const decodedNetworks = atob(
String(process.env.VITE_APP_INTERNAL_NETWORKS)
);
const decodedNetworks = atob(String(internalNetworks));

const parsedNetworks = JSON.parse(decodedNetworks);
if (parsedNetworks && parsedNetworks.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/config/sharedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ export {
GAS_PRICE
};

export const SHARE_PREFIX = process.env.VITE_APP_SHARE_PREFIX
? process.env.VITE_APP_SHARE_PREFIX.replace('-', '')
: '';
const ENV_PREFIX = import.meta.env.VITE_APP_SHARE_PREFIX;

export const SHARE_PREFIX = ENV_PREFIX ? ENV_PREFIX.replace('-', '') : '';

export const DEFAULT_HOSTNAME =
process.env.VITE_APP_DEFAULT_HOSTNAME ?? 'explorer.multiversx.com';
import.meta.env.VITE_APP_DEFAULT_HOSTNAME ?? 'explorer.multiversx.com';

export const hasExtraNetworks = true;

Expand Down
4 changes: 3 additions & 1 deletion src/helpers/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { DEFAULT_HOSTNAME } from 'config/sharedConfig';

type KeyType = typeof CUSTOM_NETWORK_ID;

const domain = `domain=.${process.env.VITE_APP_SHARE_PREFIX}${DEFAULT_HOSTNAME}`;
const domain = `domain=.${
import.meta.env.VITE_APP_SHARE_PREFIX
}${DEFAULT_HOSTNAME}`;

export const cookie = {
saveToCookies: ({
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/downloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getFileMetadata = (type: DownloadFileType['fileType']) => {
};

export const downloadFile = ({ data, name, fileType }: DownloadFileType) => {
if (data && name && process.env.NODE_ENV !== 'test') {
if (data && name && import.meta.env.NODE_ENV !== 'test') {
const type = getFileMetadata(fileType);
const blob = new Blob([data], { type });

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/fetch/useFetchMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const schema = object({

export const useFetchMarkers = () => {
const dispatch = useDispatch();
const markerUrl = process.env.VITE_APP_MARKERS_API_URL;
const markerUrl = import.meta.env.VITE_APP_MARKERS_API_URL;
const { getMarkers } = useAdapter();
const { isFetched } = useSelector(markersSelector);

Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useCheckVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const useCheckVersion = () => {

const isMainnetExplorer =
window.location.origin === 'https://explorer.multiversx.com';
const explorerVersion = process.env.VITE_APP_CACHE_BUST;
const explorerVersionUrl = process.env.VITE_APP_VERSION_URL;
const explorerVersion = import.meta.env.VITE_APP_CACHE_BUST;
const explorerVersionUrl = import.meta.env.VITE_APP_VERSION_URL;

const withinInterval = moment()
.subtract(refreshRate, 'ms')
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useGetShardText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useGetShardText = () => {
return 'All Shards';
}
if (Number(shard) === 0 && isSovereign) {
return name ?? process.env.VITE_APP_BRAND_NAME ?? 'Sovereign Chain';
return name ?? import.meta.env.VITE_APP_BRAND_NAME ?? 'Sovereign Chain';
}
return `Shard ${shard}`;
};
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Layout/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { faHeart } from 'icons/solid';
import { version } from '../../../../../package.json';

export const Footer = () => {
const explorerVersion = process.env.VITE_APP_CACHE_BUST;
const explorerVersion = import.meta.env.VITE_APP_CACHE_BUST;

return (
<footer
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Layout/components/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const Hero = () => {
<TransactionsStatsCard />
<AccountsStatsCard />
<BlockHeightStatsCard />
{isMainnet && process.env.VITE_APP_MARKERS_API_URL && (
{isMainnet && import.meta.env.VITE_APP_MARKERS_API_URL && (
<ValidatorsStatusCard isSmall />
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const AccountVerifiedContract = ({
return null;
}

const walletConnectV2ProjectId = process.env.VITE_APP_WALLETCONNECT_ID;
const walletConnectV2ProjectId = import.meta.env.VITE_APP_WALLETCONNECT_ID;

const customClassNames = {
cardClassName: 'card card-black',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PageNotFound/PageNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { faTimes } from 'icons/regular';

export const PageNotFound = () => {
const { pathname } = useLocation();
const explorerVersion = process.env.VITE_APP_CACHE_BUST;
const explorerVersion = import.meta.env.VITE_APP_CACHE_BUST;

if (explorerVersion !== undefined) {
analytics.sendEvent({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/slices/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function getInitialInterfaceState(): InterfaceSliceType {
// const media = window.matchMedia('(prefers-color-scheme: dark)')?.matches;
// const systemTheme = media ? ThemesEnum.default : ThemesEnum.default;

// const defaultTheme = Boolean(process.env.VITE_APP_TESTNET)
// const defaultTheme = Boolean(import.meta.env.VITE_APP_TESTNET)
// ? ThemesEnum.testnet
// : systemTheme;

Expand Down
4 changes: 3 additions & 1 deletion src/redux/slices/metaTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const DEFAULT_TITLE = `${BRAND_NAME}${
} Explorer`;
const DEFAULT_DESCRIPTION =
'A highly scalable, fast and secure blockchain platform for distributed apps, enterprise use cases and the new internet economy.';
const DEFAULT_PREVIEW = `https://${process.env.VITE_APP_SHARE_PREFIX}${DEFAULT_HOSTNAME}/${process.env.VITE_APP_SHARE_PREFIX}share.jpg`;
const DEFAULT_PREVIEW = `https://${
import.meta.env.VITE_APP_SHARE_PREFIX
}${DEFAULT_HOSTNAME}/${import.meta.env.VITE_APP_SHARE_PREFIX}share.jpg`;

export const getInitialMetaTagsState = (): MetaTagsType => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/HeroHome/HeroHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const HeroHome = () => {
</div>
<TransactionsStatsCard />
<AccountsStatsCard />
{isMainnet && process.env.VITE_APP_MARKERS_API_URL && (
{isMainnet && import.meta.env.VITE_APP_MARKERS_API_URL && (
<ValidatorsStatusCard isSmall />
)}
</div>
Expand Down
20 changes: 11 additions & 9 deletions src/widgets/ValidatorsStatusCard/components/LargeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export const LargeCard = ({
</div>
<div className='row flex-wrap-reverse'>
<ShardList className='col-md-5' />
{process.env.NODE_ENV !== 'test' && markers.length > 0 && isMainnet && (
<>
<ValidatorMap
markers={markers}
className='col-md-7 position-relative'
/>
<ContinentsRank continentsRank={continentsRank} />
</>
)}
{import.meta.env.NODE_ENV !== 'test' &&
markers.length > 0 &&
isMainnet && (
<>
<ValidatorMap
markers={markers}
className='col-md-7 position-relative'
/>
<ContinentsRank continentsRank={continentsRank} />
</>
)}
<div
className={
isMainnet
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ValidatorsStatusCard/components/SmallCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const SmallCard = ({
{totalValidators ?? ELLIPSIS}
</h2>
</div>
{process.env.NODE_ENV !== 'test' && markers.length > 0 && (
{import.meta.env.NODE_ENV !== 'test' && markers.length > 0 && (
<ValidatorMap markers={markers} />
)}
</div>
Expand Down
11 changes: 3 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import dns from 'dns';
import path from 'path';
import basicSsl from '@vitejs/plugin-basic-ssl';
import react from '@vitejs/plugin-react-swc';
import { defineConfig, loadEnv, splitVendorChunkPlugin } from 'vite';
import mkcert from 'vite-plugin-mkcert';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import svgr from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';

// https://vitejs.dev/config/
(dns as any).setDefaultResultOrder('verbatim');

export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

export default () => {
const shouldUseTSL =
process.env.VITE_APP_USE_HTTPS?.toLowerCase() !== 'false';

Expand All @@ -25,16 +23,13 @@ export default ({ mode }) => {
nodePolyfills({
globals: { Buffer: true, global: true, process: true }
}),
...(shouldUseTSL ? [mkcert()] : [])
...(shouldUseTSL ? [basicSsl()] : [])
],
resolve: {
alias: {
'~bootstrap': path.resolve(__dirname, 'node_modules/bootstrap')
}
},
define: {
'process.env': process.env
},
build: {
outDir: 'build',
cssMinify: true,
Expand Down
Loading

0 comments on commit 558586a

Please sign in to comment.