mars-v2-frontend/src/utils/getCurrentChainId.ts
Linkie Link fb830c08cc
Added chain agnostic v2 (#710)
* update assets config and chains

* make clients dynamic

* feat: formatted ChainSelect

* fix infinite rerender on trade page

* feat: added NTRN icon

* fix: fixed ChainInfoID

* fix: fixed autoLendEnabled for NTRN

* fix: fixed the navigation and dependencies

* fix: fixed the pricefeed id

* fix: fixed the header menu

* fix: fixed the trading charts

* fix: fixed the healthbars

* fix: fixed naming of pion-1

* feast: updated xdefi image

* env: updated contracts

* make localStorage chain agnostic

* fix: made the selected chain persistant

* fix: fixed the wallet providers

* fix: updated auto connect

* fix: fixed auto connecting

* fix: added ChainSelect to focusMode

* store raw strings in localstorage

* 🔥 remnove tests

* update caching keys + disconnect wallet on change chain

* fix: fixed the chain select

* env: bumped version

---------

Co-authored-by: Bob van der Helm <34470358+bobthebuidlr@users.noreply.github.com>
2024-01-03 15:50:38 +01:00

35 lines
883 B
TypeScript

import chains from 'configs/chains'
import { LocalStorageKeys } from 'constants/localStorageKeys'
import { ChainInfoID } from 'types/enums/wallet'
export const getCurrentChainId = () => {
let chainId = chains[ChainInfoID.Osmosis1].id
if (window) {
const subdomain = window.location.hostname.split('.')[0]
switch (subdomain) {
case 'osmosis':
chainId = ChainInfoID.Osmosis1
break
case 'testnet-osmosis':
chainId = ChainInfoID.OsmosisDevnet
break
case 'testnet-neutron':
chainId = ChainInfoID.Pion1
break
}
if (chainId != chains[ChainInfoID.Osmosis1].id) return chainId
}
const localStorageChainId = localStorage.getItem(LocalStorageKeys.CURRENT_CHAIN_ID)
if (localStorageChainId !== null) {
if (chains[chainId]) chainId = localStorageChainId as ChainInfoID
}
return chainId
}