From e93d0569ee5b03ac32ce2e5f3b197a2908affaa6 Mon Sep 17 00:00:00 2001 From: lukachi Date: Wed, 15 Nov 2023 15:07:33 +0200 Subject: [PATCH] improvement: remove env.js to not to block rendering --- .gitignore | 2 + index.html | 2 +- src/config.ts | 61 ++++--------------- .../MetamaskZkpSnapContext.tsx | 7 ++- 4 files changed, 20 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 06878b3..6c55c30 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ stats.html .yarnrc.yml .env.analyze +.env.development +.env.production tsconfig.tsbuildinfo # Sentry Auth Token diff --git a/index.html b/index.html index 6c33755..0702421 100644 --- a/index.html +++ b/index.html @@ -33,7 +33,7 @@ - + diff --git a/src/config.ts b/src/config.ts index 2f059c2..7b752d8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,7 @@ import { Chain } from '@distributedlab/w3p' -import mapKeys from 'lodash/mapKeys' -import pickBy from 'lodash/pickBy' +// import mapKeys from 'lodash/mapKeys' +// import pickBy from 'lodash/pickBy' import FALLBACK_SUPPORTED_CHAINS from '@/assets/fallback-supported-chains.json' import packageJson from '../package.json' @@ -16,43 +16,6 @@ type ContractAddresses = { | `LIGHTWEIGHT_STATE_V2_CONTRACT_ADDRESS_${SUPPORTED_CHAINS}`]: string } -export const FALLBACK_CIRCUIT_URLS = { - auth: { - wasm: `${window.location.origin}/circuits/auth/circuit.wasm`, - zkey: `${window.location.origin}/circuits/auth/circuit_final.zkey`, - }, - sigV2OnChain: { - wasm: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm`, - zkey: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey`, - }, - sigV2: { - wasm: `${window.location.origin}/circuits/credentialAtomicQuerySigV2/circuit.wasm`, - zkey: `${window.location.origin}/circuits/credentialAtomicQuerySigV2/circuit_final.zkey`, - }, - mtpV2OnChain: { - wasm: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2OnChain/circuit.wasm`, - zkey: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2OnChain/circuit_final.zkey`, - }, - mtpV2: { - wasm: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2/circuit.wasm`, - zkey: `${window.location.origin}/circuits/credentialAtomicQueryMTPV2/circuit_final.zkey`, - }, -} - -export const META_CIRCUIT_URLS = { - AUTH_WASM_URL: import.meta.env.VITE_AUTH_WASM_URL, - AUTH_ZKEY_URL: import.meta.env.VITE_AUTH_ZKEY_URL, - SIG_V2_ON_CHAIN_WASM_URL: import.meta.env.VITE_SIG_V2_ON_CHAIN_WASM_URL, - SIG_V2_ON_CHAIN_ZKEY_URL: import.meta.env.VITE_SIG_V2_ON_CHAIN_ZKEY_URL, - SIG_V2_WASM_URL: import.meta.env.VITE_SIG_V2_WASM_URL, - SIG_V2_ZKEY_URL: import.meta.env.VITE_SIG_V2_ZKEY_URL, - MTP_V2_ON_CHAIN_WASM_URL: import.meta.env.VITE_MTP_V2_ON_CHAIN_WASM_URL, - MTP_V2_ON_CHAIN_ZKEY_URL: import.meta.env.VITE_MTP_V2_ON_CHAIN_ZKEY_URL, - MTP_V2_WASM_URL: import.meta.env.VITE_MTP_V2_WASM_URL, - MTP_V2_ZKEY_URL: import.meta.env.VITE_MTP_V2_ZKEY_URL, -} -Object.assign(META_CIRCUIT_URLS, _mapEnvCfg(window.document.ENV)) - export type AppConfig = { MODE: 'production' | 'development' @@ -150,8 +113,8 @@ Object.assign(config, { ) as ContractAddresses), }) -Object.assign(config, _mapEnvCfg(import.meta.env)) -Object.assign(config, _mapEnvCfg(window.document.ENV)) +// Object.assign(config, _mapEnvCfg(import.meta.env)) +// Object.assign(config, _mapEnvCfg(window.document.ENV)) if (typeof config.SUPPORTED_CHAINS_DETAILS === 'string') { config.SUPPORTED_CHAINS_DETAILS = { @@ -163,11 +126,11 @@ if (typeof config.SUPPORTED_CHAINS_DETAILS === 'string') { } } -function _mapEnvCfg(env: ImportMetaEnv | typeof window.document.ENV): { - [k: string]: string | boolean | undefined -} { - return mapKeys( - pickBy(env, (v, k) => k.startsWith('VITE_APP_')), - (v, k) => k.replace(/^VITE_APP_/, ''), - ) -} +// function _mapEnvCfg(env: ImportMetaEnv | typeof window.document.ENV): { +// [k: string]: string | boolean | undefined +// } { +// return mapKeys( +// pickBy(env, (v, k) => k.startsWith('VITE_APP_')), +// (v, k) => k.replace(/^VITE_APP_/, ''), +// ) +// } diff --git a/src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx b/src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx index 38a8ca5..9109706 100644 --- a/src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx +++ b/src/contexts/MetamaskZkpSnapContext/MetamaskZkpSnapContext.tsx @@ -124,7 +124,10 @@ const MetamaskZkpSnapContextProvider: FC> = ({ }, []) const checkSnapExists = useCallback(async () => { - const _isSnapInstalled = await detectSnapInstalled() + const _isSnapInstalled = await detectSnapInstalled( + 'local:http://localhost:8081', + '0.8.0', + ) setIsSnapInstalled(_isSnapInstalled) @@ -132,7 +135,7 @@ const MetamaskZkpSnapContextProvider: FC> = ({ }, []) const connectOrInstallSnap = useCallback(async () => { - const snap = await enableSnap() + const snap = await enableSnap('local:http://localhost:8081', '0.8.0') const connector = await snap.getConnector() setConnector(connector) }, [])