Skip to content

Commit

Permalink
improvement: remove env.js to not to block rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Nov 15, 2023
1 parent 7ce8cc7 commit e93d056
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ stats.html
.yarnrc.yml

.env.analyze
.env.development
.env.production
tsconfig.tsbuildinfo

# Sentry Auth Token
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<link href="/init-loader/style.css" type="text/css" rel="stylesheet">

<script type="module" src="/src/main.tsx"></script>
<script type="text/javascript" src="/env.js"></script>
<!-- <script type="text/javascript" src="/env.js"></script>-->
</head>

<body>
Expand Down
61 changes: 12 additions & 49 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'

Expand Down Expand Up @@ -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 = {
Expand All @@ -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_/, ''),
// )
// }
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,18 @@ const MetamaskZkpSnapContextProvider: FC<HTMLAttributes<HTMLDivElement>> = ({
}, [])

const checkSnapExists = useCallback(async () => {
const _isSnapInstalled = await detectSnapInstalled()
const _isSnapInstalled = await detectSnapInstalled(
'local:http://localhost:8081',
'0.8.0',
)

setIsSnapInstalled(_isSnapInstalled)

return _isSnapInstalled
}, [])

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)
}, [])
Expand Down

0 comments on commit e93d056

Please sign in to comment.