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