Cleanup env variables (#713)
* fix: cleaned up env variables and disabled chain selector if there is only one chain * env: update .env.example
This commit is contained in:
parent
1bcf810845
commit
7707586c57
22
.env.example
22
.env.example
@ -1,11 +1,15 @@
|
||||
NEXT_PUBLIC_OSMOSIS1_RPC='https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/'
|
||||
NEXT_PUBLIC_OSMOSIS1_REST='https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/'
|
||||
NEXT_PUBLIC_OSMOSIS_DEVNET_RPC='https://rpc.devnet.osmosis.zone/'
|
||||
NEXT_PUBLIC_OSMOSIS_DEVNET_REST='https://lcd.devnet.osmosis.zone/'
|
||||
NEXT_PUBLIC_PION1_RPC='https://rpc-palvus.pion-1.ntrn.tech/'
|
||||
NEXT_PUBLIC_PION1_REST='https://rest-palvus.pion-1.ntrn.tech/'
|
||||
NEXT_PUBLIC_NETWORK=mainnet
|
||||
|
||||
NEXT_PUBLIC_OSMOSIS_RPC=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/
|
||||
NEXT_PUBLIC_OSMOSIS_REST=https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/
|
||||
NEXT_PUBLIC_OSMOSIS_TEST_RPC=https://rpc.devnet.osmosis.zone/
|
||||
NEXT_PUBLIC_OSMOSIS_TEST_REST=https://lcd.devnet.osmosis.zone/
|
||||
NEXT_PUBLIC_NEUTRON_TEST_RPC=https://rpc-palvus.pion-1.ntrn.tech/
|
||||
NEXT_PUBLIC_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech/
|
||||
|
||||
NEXT_PUBLIC_WALLET_CONNECT_ID=d93fdffb159bae5ec87d8fee4cdbb045
|
||||
CHARTING_LIBRARY_USERNAME="git_username"
|
||||
CHARTING_LIBRARY_ACCESS_TOKEN="access_token"
|
||||
CHARTING_LIBRARY_REPOSITORY="github.com/tradingview/charting_library/"
|
||||
CHARTING_LIBRARY_USERNAME=git_username
|
||||
CHARTING_LIBRARY_ACCESS_TOKEN=access_token
|
||||
CHARTING_LIBRARY_REPOSITORY=github.com/tradingview/charting_library/
|
||||
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import classNames from 'classnames'
|
||||
import { useCallback } from 'react'
|
||||
import { useSWRConfig } from 'swr'
|
||||
import { useCallback, useMemo } from 'react'
|
||||
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
|
||||
import { useSWRConfig } from 'swr'
|
||||
|
||||
import Button from 'components/Button'
|
||||
import ChainLogo from 'components/Chain/ChainLogo'
|
||||
@ -12,6 +12,7 @@ import useCurrentChainId from 'hooks/localStorage/useCurrentChainId'
|
||||
import useChainConfig from 'hooks/useChainConfig'
|
||||
import useToggle from 'hooks/useToggle'
|
||||
import useStore from 'store'
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
import { getPage, getRoute } from 'utils/route'
|
||||
|
||||
export default function ChainSelect() {
|
||||
@ -42,14 +43,23 @@ export default function ChainSelect() {
|
||||
[setCurrentChainId, setShowMenu, mutate, navigate, pathname, searchParams],
|
||||
)
|
||||
|
||||
const currentChains = useMemo(() => {
|
||||
const currentNetworkType = process.env.NEXT_PUBLIC_NETWORK ?? NETWORK.TESTNET
|
||||
|
||||
return Object.entries(chains).filter(([_, chain]) => chain.network === currentNetworkType)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className='relative'>
|
||||
<Button
|
||||
leftIcon={<ChainLogo chainID={chainConfig.id} className='w-4' />}
|
||||
iconClassName='w-5 h-5'
|
||||
color='tertiary'
|
||||
onClick={() => setShowMenu()}
|
||||
className='!p-0 w-8 flex items-center justify-center'
|
||||
onClick={currentChains.length > 1 ? () => setShowMenu() : undefined}
|
||||
className={classNames(
|
||||
'!p-0 w-8 flex items-center justify-center',
|
||||
currentChains.length === 1 && 'pointer-events-none',
|
||||
)}
|
||||
></Button>
|
||||
<Overlay show={showMenu} setShow={setShowMenu} className='right-0 w-[180px] mt-2'>
|
||||
<div
|
||||
@ -63,7 +73,7 @@ export default function ChainSelect() {
|
||||
</Text>
|
||||
</div>
|
||||
<ul className='w-full px-4 py-3 list-none'>
|
||||
{Object.entries(chains).map(([name, chain]) => (
|
||||
{currentChains.map(([name, chain]) => (
|
||||
<li
|
||||
className={classNames(
|
||||
'w-full py-2 flex gap-3 group/chain text-white',
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { defaultSymbolInfo } from 'components/Trade/TradeChart/constants'
|
||||
import { ENV } from 'constants/env'
|
||||
import { MILLISECONDS_PER_MINUTE } from 'constants/math'
|
||||
import { byDenom } from 'utils/array'
|
||||
import {
|
||||
|
@ -43,6 +43,11 @@ function mapChainConfigToChainInfo(chainConfig: ChainConfig): ChainInfo {
|
||||
chainInfo.rest = process.env.NEXT_PUBLIC_OSMOSIS_REST ?? chainInfo.rpc
|
||||
break
|
||||
|
||||
case ChainInfoID.OsmosisDevnet:
|
||||
chainInfo.rpc = process.env.NEXT_PUBLIC_OSMOSIS_TEST_RPC ?? chainInfo.rpc
|
||||
chainInfo.rest = process.env.NEXT_PUBLIC_OSMOSIS_TEST_REST ?? chainInfo.rpc
|
||||
break
|
||||
|
||||
case ChainInfoID.Pion1:
|
||||
chainInfo.rpc = process.env.NEXT_PUBLIC_NEUTRON_TEST_RPC ?? chainInfo.rpc
|
||||
chainInfo.rest = process.env.NEXT_PUBLIC_NEUTRON_TEST_REST ?? chainInfo.rpc
|
||||
|
@ -93,19 +93,7 @@ export default function WalletConnecting(props: Props) {
|
||||
}
|
||||
if (!isConnecting) handleConnectAsync()
|
||||
},
|
||||
[
|
||||
isConnecting,
|
||||
client,
|
||||
setIsConnecting,
|
||||
connect,
|
||||
chainConfig.id,
|
||||
chainConfig.endpoints.rpc,
|
||||
chainConfig.name,
|
||||
broadcast,
|
||||
sign,
|
||||
simulate,
|
||||
recentWallet,
|
||||
],
|
||||
[isConnecting, client, setIsConnecting, connect, chainConfig, broadcast, sign, simulate],
|
||||
)
|
||||
|
||||
const handleMobileConnect = useCallback(
|
||||
@ -172,9 +160,7 @@ export default function WalletConnecting(props: Props) {
|
||||
recentWallet,
|
||||
setIsConnecting,
|
||||
mobileConnect,
|
||||
chainConfig.id,
|
||||
chainConfig.endpoints.rpc,
|
||||
chainConfig.name,
|
||||
chainConfig,
|
||||
broadcast,
|
||||
sign,
|
||||
simulate,
|
||||
|
@ -4,7 +4,7 @@ import ATOM from 'configs/assets/ATOM'
|
||||
import NTRN from 'configs/assets/NTRN'
|
||||
import USDCaxl from 'configs/assets/USDC.axl'
|
||||
import USDollar from 'configs/assets/USDollar'
|
||||
import { ENV } from 'constants/env'
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
import { ChainInfoID } from 'types/enums/wallet'
|
||||
|
||||
const Pion1: ChainConfig = {
|
||||
@ -32,8 +32,8 @@ const Pion1: ChainConfig = {
|
||||
pyth: 'neutron15ldst8t80982akgr8w8ekcytejzkmfpgdkeq4xgtge48qs7435jqp87u3t',
|
||||
},
|
||||
endpoints: {
|
||||
rest: ENV.PION1_REST || 'https://rest-palvus.pion-1.ntrn.tech/',
|
||||
rpc: ENV.PION1_RPC || 'https://rpc-palvus.pion-1.ntrn.tech/',
|
||||
rest: 'https://rest-palvus.pion-1.ntrn.tech/',
|
||||
rpc: 'https://rpc-palvus.pion-1.ntrn.tech/',
|
||||
swap: 'https://testnet-neutron.astroport.fi/swap',
|
||||
pyth: 'https://hermes.pyth.network/api',
|
||||
pythCandles: 'https://benchmarks.pyth.network',
|
||||
@ -44,7 +44,7 @@ const Pion1: ChainConfig = {
|
||||
stride: 'https://edge.stride.zone/api/stake-stats',
|
||||
},
|
||||
},
|
||||
network: 'testnet',
|
||||
network: NETWORK.TESTNET,
|
||||
vaults: [],
|
||||
explorerName: 'Mintscan',
|
||||
bech32Config: Bech32Address.defaultBech32Config('neutron'),
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { ChainInfoID } from 'types/enums/wallet'
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
|
||||
import Osmosis1 from './osmosis-1'
|
||||
|
||||
const Devnet: ChainConfig = {
|
||||
...Osmosis1,
|
||||
id: ChainInfoID.OsmosisDevnet,
|
||||
network: 'devnet',
|
||||
network: NETWORK.TESTNET,
|
||||
name: 'Osmosis Devnet',
|
||||
endpoints: {
|
||||
...Osmosis1.endpoints,
|
||||
|
@ -21,7 +21,6 @@ import USDollar from 'configs/assets/USDollar'
|
||||
import USDT from 'configs/assets/USDT'
|
||||
import WBTCaxl from 'configs/assets/WBTC.axl'
|
||||
import WETHaxl from 'configs/assets/WETH.xal'
|
||||
import { ENV } from 'constants/env'
|
||||
import { VAULTS_META_DATA } from 'constants/vaults'
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
import { ChainInfoID } from 'types/enums/wallet'
|
||||
@ -132,16 +131,15 @@ const Osmosis1: ChainConfig = {
|
||||
},
|
||||
},
|
||||
endpoints: {
|
||||
rpc: ENV.OSMOSIS1_RPC || 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/',
|
||||
rest:
|
||||
ENV.OSMOSIS1_REST || 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/',
|
||||
rpc: 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-rpc-front/',
|
||||
rest: 'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/',
|
||||
swap: 'https://app.osmosis.zone',
|
||||
pyth: 'https://hermes.pyth.network/api',
|
||||
pythCandles: 'https://benchmarks.pyth.network',
|
||||
graphCandles: 'https://osmosis-candles.marsprotocol.io',
|
||||
explorer: 'https://www.mintscan.io/osmosis/transactions/',
|
||||
pools:
|
||||
(ENV.OSMOSIS1_REST ||
|
||||
(process.env.NEXT_PUBLIC_OSMOSIS_REST ||
|
||||
'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/') +
|
||||
'osmosis/gamm/v1beta1/pools/POOL_ID',
|
||||
aprs: {
|
||||
|
@ -1,28 +0,0 @@
|
||||
interface EnvironmentVariables {
|
||||
CANDLES_ENDPOINT_THE_GRAPH: string
|
||||
CANDLES_ENDPOINT_PYTH: string
|
||||
MAINNET_REST_API: string
|
||||
WALLET_CONNECT_ID: string
|
||||
|
||||
OSMOSIS1_REST: string
|
||||
OSMOSIS1_RPC: string
|
||||
OSMOSIS_DEVNET_REST: string
|
||||
OSMOSIS_DEVNET_RPC: string
|
||||
|
||||
PION1_REST: string
|
||||
PION1_RPC: string
|
||||
}
|
||||
|
||||
export const ENV: EnvironmentVariables = {
|
||||
CANDLES_ENDPOINT_THE_GRAPH: process.env.NEXT_PUBLIC_CANDLES_ENDPOINT_THE_GRAPH || '',
|
||||
CANDLES_ENDPOINT_PYTH: process.env.NEXT_PUBLIC_CANDLES_ENDPOINT_PYTH || '',
|
||||
MAINNET_REST_API: process.env.NEXT_PUBLIC_MAINNET_REST || '',
|
||||
WALLET_CONNECT_ID: process.env.NEXT_PUBLIC_WALLET_CONNECT_ID || '',
|
||||
|
||||
OSMOSIS1_REST: process.env.NEXT_PUBLIC_OSMOSIS1_REST || '',
|
||||
OSMOSIS1_RPC: process.env.NEXT_PUBLIC_OSMOSIS1_RPC || '',
|
||||
OSMOSIS_DEVNET_REST: process.env.NEXT_PUBLIC_OSMOSIS_DEVNET_REST || '',
|
||||
OSMOSIS_DEVNET_RPC: process.env.NEXT_PUBLIC_OSMOSIS_DEVNET_RPC || '',
|
||||
PION1_REST: process.env.NEXT_PUBLIC_PION1_REST || '',
|
||||
PION1_RPC: process.env.NEXT_PUBLIC_PION1_RPC || '',
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
export enum NETWORK {
|
||||
MAINNET = 'mainnet',
|
||||
DEVNET = 'devnet',
|
||||
TESTNET = 'testnet',
|
||||
}
|
||||
|
2
src/types/interfaces/chain.d.ts
vendored
2
src/types/interfaces/chain.d.ts
vendored
@ -42,7 +42,7 @@ interface ChainConfig {
|
||||
gasPrice: string
|
||||
id: import('types/enums/wallet').ChainInfoID
|
||||
name: string
|
||||
network: 'mainnet' | 'devnet' | 'testnet'
|
||||
network: 'mainnet' | 'testnet'
|
||||
vaults: VaultMetaData[]
|
||||
hls: boolean
|
||||
perps: boolean
|
||||
|
@ -1,33 +1,51 @@
|
||||
import chains from 'configs/chains'
|
||||
import { LocalStorageKeys } from 'constants/localStorageKeys'
|
||||
import { NETWORK } from 'types/enums/network'
|
||||
import { ChainInfoID } from 'types/enums/wallet'
|
||||
|
||||
export const getCurrentChainId = () => {
|
||||
let chainId = chains[ChainInfoID.Osmosis1].id
|
||||
const currentNetwork = process.env.NEXT_PUBLIC_NETWORK ?? NETWORK.TESTNET
|
||||
const defaultChainId =
|
||||
currentNetwork === NETWORK.MAINNET
|
||||
? chains[ChainInfoID.Osmosis1].id
|
||||
: chains[ChainInfoID.OsmosisDevnet].id
|
||||
let chainId = defaultChainId
|
||||
|
||||
if (window) {
|
||||
const subdomain = window.location.hostname.split('.')[0]
|
||||
|
||||
switch (subdomain) {
|
||||
case 'osmosis':
|
||||
chainId = ChainInfoID.Osmosis1
|
||||
if (currentNetwork === NETWORK.MAINNET) chainId = ChainInfoID.Osmosis1
|
||||
break
|
||||
|
||||
case 'testnet-osmosis':
|
||||
chainId = ChainInfoID.OsmosisDevnet
|
||||
if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.OsmosisDevnet
|
||||
break
|
||||
|
||||
case 'testnet-neutron':
|
||||
chainId = ChainInfoID.Pion1
|
||||
if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.Pion1
|
||||
break
|
||||
}
|
||||
|
||||
if (chainId != chains[ChainInfoID.Osmosis1].id) return chainId
|
||||
if (chainId !== defaultChainId) return chainId
|
||||
}
|
||||
|
||||
const localStorageChainId = localStorage.getItem(LocalStorageKeys.CURRENT_CHAIN_ID)
|
||||
const localStorageChainId = localStorage.getItem(LocalStorageKeys.CURRENT_CHAIN_ID) as ChainInfoID
|
||||
if (localStorageChainId !== null) {
|
||||
if (chains[chainId]) chainId = localStorageChainId as ChainInfoID
|
||||
switch (localStorageChainId) {
|
||||
case ChainInfoID.Osmosis1:
|
||||
if (currentNetwork === NETWORK.MAINNET) chainId = ChainInfoID.Osmosis1
|
||||
break
|
||||
|
||||
case ChainInfoID.OsmosisDevnet:
|
||||
if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.OsmosisDevnet
|
||||
break
|
||||
|
||||
case ChainInfoID.Pion1:
|
||||
if (currentNetwork === NETWORK.TESTNET) chainId = ChainInfoID.Pion1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return chainId
|
||||
|
Loading…
Reference in New Issue
Block a user