fix: fix getUrl
This commit is contained in:
parent
89d41fa5cf
commit
1a45d64bac
@ -8,6 +8,7 @@ import { MarsParamsQueryClient } from 'types/generated/mars-params/MarsParams.cl
|
|||||||
import { MarsPerpsQueryClient } from 'types/generated/mars-perps/MarsPerps.client'
|
import { MarsPerpsQueryClient } from 'types/generated/mars-perps/MarsPerps.client'
|
||||||
import { MarsRedBankQueryClient } from 'types/generated/mars-red-bank/MarsRedBank.client'
|
import { MarsRedBankQueryClient } from 'types/generated/mars-red-bank/MarsRedBank.client'
|
||||||
import { MarsSwapperOsmosisQueryClient } from 'types/generated/mars-swapper-osmosis/MarsSwapperOsmosis.client'
|
import { MarsSwapperOsmosisQueryClient } from 'types/generated/mars-swapper-osmosis/MarsSwapperOsmosis.client'
|
||||||
|
import { getUrl } from 'utils/url'
|
||||||
|
|
||||||
let _cosmWasmClient: Map<string, CosmWasmClient> = new Map()
|
let _cosmWasmClient: Map<string, CosmWasmClient> = new Map()
|
||||||
let _creditManagerQueryClient: Map<string, MarsCreditManagerQueryClient> = new Map()
|
let _creditManagerQueryClient: Map<string, MarsCreditManagerQueryClient> = new Map()
|
||||||
@ -34,7 +35,7 @@ const getClient = async (rpc: string) => {
|
|||||||
const getCreditManagerQueryClient = async (chainConfig: ChainConfig) => {
|
const getCreditManagerQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.creditManager
|
const contract = chainConfig.contracts.creditManager
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
|
|
||||||
if (!_creditManagerQueryClient.get(key)) {
|
if (!_creditManagerQueryClient.get(key)) {
|
||||||
@ -51,7 +52,7 @@ const getCreditManagerQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
const getParamsQueryClient = async (chainConfig: ChainConfig) => {
|
const getParamsQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.params
|
const contract = chainConfig.contracts.params
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
|
|
||||||
if (!_paramsQueryClient.get(key)) {
|
if (!_paramsQueryClient.get(key)) {
|
||||||
@ -68,7 +69,7 @@ const getParamsQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
const getOracleQueryClient = async (chainConfig: ChainConfig) => {
|
const getOracleQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.oracle
|
const contract = chainConfig.contracts.oracle
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
|
|
||||||
if (!_oracleQueryClient.get(key)) {
|
if (!_oracleQueryClient.get(key)) {
|
||||||
@ -84,7 +85,7 @@ const getOracleQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
|
|
||||||
const getVaultQueryClient = async (chainConfig: ChainConfig, address: string) => {
|
const getVaultQueryClient = async (chainConfig: ChainConfig, address: string) => {
|
||||||
try {
|
try {
|
||||||
const client = await getClient(chainConfig.endpoints.rpc)
|
const client = await getClient(getUrl(chainConfig.endpoints.rpc))
|
||||||
return new MarsMockVaultQueryClient(client, address)
|
return new MarsMockVaultQueryClient(client, address)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error
|
throw error
|
||||||
@ -94,7 +95,7 @@ const getVaultQueryClient = async (chainConfig: ChainConfig, address: string) =>
|
|||||||
const getIncentivesQueryClient = async (chainConfig: ChainConfig) => {
|
const getIncentivesQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.incentives
|
const contract = chainConfig.contracts.incentives
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
if (!_incentivesQueryClient.get(key)) {
|
if (!_incentivesQueryClient.get(key)) {
|
||||||
const client = await getClient(rpc)
|
const client = await getClient(rpc)
|
||||||
@ -110,7 +111,7 @@ const getIncentivesQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
const getSwapperQueryClient = async (chainConfig: ChainConfig) => {
|
const getSwapperQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.swapper
|
const contract = chainConfig.contracts.swapper
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
if (!_swapperOsmosisClient.get(key)) {
|
if (!_swapperOsmosisClient.get(key)) {
|
||||||
const client = await getClient(rpc)
|
const client = await getClient(rpc)
|
||||||
@ -126,7 +127,7 @@ const getSwapperQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
const getPerpsQueryClient = async (chainConfig: ChainConfig) => {
|
const getPerpsQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.perps
|
const contract = chainConfig.contracts.perps
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
if (!_perpsClient.get(key)) {
|
if (!_perpsClient.get(key)) {
|
||||||
const client = await getClient(rpc)
|
const client = await getClient(rpc)
|
||||||
@ -142,7 +143,7 @@ const getPerpsQueryClient = async (chainConfig: ChainConfig) => {
|
|||||||
const getRedBankQueryClient = async (chainConfig: ChainConfig) => {
|
const getRedBankQueryClient = async (chainConfig: ChainConfig) => {
|
||||||
try {
|
try {
|
||||||
const contract = chainConfig.contracts.redBank
|
const contract = chainConfig.contracts.redBank
|
||||||
const rpc = chainConfig.endpoints.rpc
|
const rpc = getUrl(chainConfig.endpoints.rpc)
|
||||||
const key = rpc + contract
|
const key = rpc + contract
|
||||||
|
|
||||||
if (!_redBankQueryClient.get(key)) {
|
if (!_redBankQueryClient.get(key)) {
|
||||||
@ -162,8 +163,8 @@ export {
|
|||||||
getIncentivesQueryClient,
|
getIncentivesQueryClient,
|
||||||
getOracleQueryClient,
|
getOracleQueryClient,
|
||||||
getParamsQueryClient,
|
getParamsQueryClient,
|
||||||
getSwapperQueryClient,
|
|
||||||
getVaultQueryClient,
|
|
||||||
getPerpsQueryClient,
|
getPerpsQueryClient,
|
||||||
getRedBankQueryClient,
|
getRedBankQueryClient,
|
||||||
|
getSwapperQueryClient,
|
||||||
|
getVaultQueryClient,
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import useChainConfig from 'hooks/useChainConfig'
|
|||||||
import useCurrentWallet from 'hooks/useCurrentWallet'
|
import useCurrentWallet from 'hooks/useCurrentWallet'
|
||||||
import useToggle from 'hooks/useToggle'
|
import useToggle from 'hooks/useToggle'
|
||||||
import useStore from 'store'
|
import useStore from 'store'
|
||||||
|
import { getUrl } from 'utils/url'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
providerId?: string
|
providerId?: string
|
||||||
@ -53,7 +54,7 @@ export default function WalletConnecting(props: Props) {
|
|||||||
setIsConnecting(true)
|
setIsConnecting(true)
|
||||||
try {
|
try {
|
||||||
const response = await connect({ extensionProviderId, chainId: chainConfig.id })
|
const response = await connect({ extensionProviderId, chainId: chainConfig.id })
|
||||||
const cosmClient = await CosmWasmClient.connect(chainConfig.endpoints.rpc)
|
const cosmClient = await CosmWasmClient.connect(getUrl(chainConfig.endpoints.rpc))
|
||||||
const walletClient: WalletClient = {
|
const walletClient: WalletClient = {
|
||||||
broadcast,
|
broadcast,
|
||||||
cosmWasmClient: cosmClient,
|
cosmWasmClient: cosmClient,
|
||||||
@ -137,7 +138,7 @@ export default function WalletConnecting(props: Props) {
|
|||||||
setIsConnecting(true)
|
setIsConnecting(true)
|
||||||
try {
|
try {
|
||||||
await mobileConnect({ mobileProviderId, chainId: chainConfig.id })
|
await mobileConnect({ mobileProviderId, chainId: chainConfig.id })
|
||||||
const cosmClient = await CosmWasmClient.connect(chainConfig.endpoints.rpc)
|
const cosmClient = await CosmWasmClient.connect(getUrl(chainConfig.endpoints.rpc))
|
||||||
const walletClient: WalletClient = {
|
const walletClient: WalletClient = {
|
||||||
broadcast,
|
broadcast,
|
||||||
cosmWasmClient: cosmClient,
|
cosmWasmClient: cosmClient,
|
||||||
|
@ -75,7 +75,7 @@ function Content(props: Props) {
|
|||||||
title: (
|
title: (
|
||||||
<FormattedNumber
|
<FormattedNumber
|
||||||
className='text-xl'
|
className='text-xl'
|
||||||
amount={leverage.toNumber()}
|
amount={isNaN(leverage.toNumber()) ? 1 : leverage.toNumber()}
|
||||||
options={{ suffix: 'x' }}
|
options={{ suffix: 'x' }}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
|
@ -11,6 +11,7 @@ import { MarsParamsQueryClient } from 'types/generated/mars-params/MarsParams.cl
|
|||||||
import { MarsPerpsQueryClient } from 'types/generated/mars-perps/MarsPerps.client'
|
import { MarsPerpsQueryClient } from 'types/generated/mars-perps/MarsPerps.client'
|
||||||
import { MarsRedBankQueryClient } from 'types/generated/mars-red-bank/MarsRedBank.client'
|
import { MarsRedBankQueryClient } from 'types/generated/mars-red-bank/MarsRedBank.client'
|
||||||
import { MarsSwapperOsmosisQueryClient } from 'types/generated/mars-swapper-osmosis/MarsSwapperOsmosis.client'
|
import { MarsSwapperOsmosisQueryClient } from 'types/generated/mars-swapper-osmosis/MarsSwapperOsmosis.client'
|
||||||
|
import { getUrl } from 'utils/url'
|
||||||
|
|
||||||
export default function useClients() {
|
export default function useClients() {
|
||||||
const chainConfig = useChainConfig()
|
const chainConfig = useChainConfig()
|
||||||
@ -18,7 +19,7 @@ export default function useClients() {
|
|||||||
const swr = useSWR(
|
const swr = useSWR(
|
||||||
`chains/${chainConfig.id}/clients`,
|
`chains/${chainConfig.id}/clients`,
|
||||||
async () => {
|
async () => {
|
||||||
const client = await CosmWasmClient.connect(chainConfig.endpoints.rpc)
|
const client = await CosmWasmClient.connect(getUrl(chainConfig.endpoints.rpc))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
creditManager: new MarsCreditManagerQueryClient(
|
creditManager: new MarsCreditManagerQueryClient(
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
export const getUrl = (baseUrl: string, path: string): string => {
|
export const getUrl = (baseUrl: string, path?: string): string => {
|
||||||
|
if (!path) path = ''
|
||||||
const isPlaceholder = baseUrl.split('APP_').length > 1
|
const isPlaceholder = baseUrl.split('APP_').length > 1
|
||||||
|
|
||||||
if (isPlaceholder) return baseUrl + '/' + path
|
if (isPlaceholder) return baseUrl + '/' + path
|
||||||
|
|
||||||
const url = new URL(baseUrl)
|
const url = new URL(baseUrl.split('?')[0])
|
||||||
|
|
||||||
if (process.env.NEXT_PUBLIC_API_KEY)
|
if (process.env.NEXT_PUBLIC_API_KEY)
|
||||||
return `${url.href}${path}?x-apikey=${process.env.NEXT_PUBLIC_API_KEY}`
|
return `${url.href}${path}?x-apikey=${process.env.NEXT_PUBLIC_API_KEY}`
|
||||||
|
Loading…
Reference in New Issue
Block a user