feat: handle URLs with or without trailing slash (#803) (#804)

* feat: handle URLs with or without trailing slash

* tidy: cleanup slashes
This commit is contained in:
Linkie Link 2024-02-14 11:16:06 +01:00 committed by GitHub
parent 3006dbbb21
commit f7f8136b38
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 25 deletions

View File

@ -3,12 +3,12 @@ NEXT_PUBLIC_NETWORK=mainnet
NEXT_PUBLIC_WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x NEXT_PUBLIC_WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x
### Optional Environment Variables ### Optional Environment Variables
NEXT_PUBLIC_OSMOSIS_RPC=https://rpc-osmosis.blockapsis.com/ NEXT_PUBLIC_OSMOSIS_RPC=https://rpc-osmosis.blockapsis.com
NEXT_PUBLIC_OSMOSIS_REST=https://lcd-osmosis.blockapsis.com/ NEXT_PUBLIC_OSMOSIS_REST=https://lcd-osmosis.blockapsis.com
NEXT_PUBLIC_OSMOSIS_TEST_RPC=https://rpc.devnet.osmosis.zone/ NEXT_PUBLIC_OSMOSIS_TEST_RPC=https://rpc.devnet.osmosis.zone
NEXT_PUBLIC_OSMOSIS_TEST_REST=https://lcd.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_RPC=https://rpc-palvus.pion-1.ntrn.tech
NEXT_PUBLIC_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech/ NEXT_PUBLIC_NEUTRON_TEST_REST=https://rest-palvus.pion-1.ntrn.tech
### Enable the following environment variables if you have access to the charting library ### Enable the following environment variables if you have access to the charting library
CHARTING_LIBRARY_USERNAME=git_username CHARTING_LIBRARY_USERNAME=git_username

View File

@ -26,8 +26,8 @@ We allow the use of environment variables to be passed to the Docker container t
| Variable | Description | Default | | Variable | Description | Default |
| ----------------- | ------------------------------------- | ---------------------------------------- | | ----------------- | ------------------------------------- | ---------------------------------------- |
| URL_OSMOSIS_REST | The Osmosis node REST endpoint to use | https://lcd-osmosis.blockapsis.com/ | | URL_OSMOSIS_REST | The Osmosis node REST endpoint to use | https://lcd-osmosis.blockapsis.com |
| URL_OSMOSIS_RPC | The Osmosis node RPC endpoint to use | https://rpc-osmosis.blockapsis.com/ | | URL_OSMOSIS_RPC | The Osmosis node RPC endpoint to use | https://rpc-osmosis.blockapsis.com |
| WALLET_CONNECT_ID | Your projects WalletConnect v2 ID | 0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x | | WALLET_CONNECT_ID | Your projects WalletConnect v2 ID | 0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x |
**Sample Docker run command** **Sample Docker run command**
@ -36,8 +36,8 @@ This command will start the container in interactive mode with port 3000 bound t
```sh ```sh
docker run -it -p 3000:3000 \ docker run -it -p 3000:3000 \
-e URL_OSMOSIS_REST=https://lcd-osmosis.blockapsis.com/ \ -e URL_OSMOSIS_REST=https://lcd-osmosis.blockapsis.com \
-e URL_OSMOSIS_RPC=https://rpc-osmosis.blockapsis.com/ \ -e URL_OSMOSIS_RPC=https://rpc-osmosis.blockapsis.com \
-e WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x marsprotocol/interface:latest -e WALLET_CONNECT_ID=0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x0x marsprotocol/interface:latest
``` ```

View File

@ -33,8 +33,8 @@ const Pion1: ChainConfig = {
}, },
endpoints: { endpoints: {
routes: 'https://app.astroport.fi/api/routes', routes: 'https://app.astroport.fi/api/routes',
rpc: process.env.NEXT_PUBLIC_NEUTRON_TEST_RPC ?? 'https://rpc-palvus.pion-1.ntrn.tech/', rpc: process.env.NEXT_PUBLIC_NEUTRON_TEST_RPC ?? 'https://rpc-palvus.pion-1.ntrn.tech',
rest: process.env.NEXT_PUBLIC_NEUTRON_TEST_REST ?? 'https://rest-palvus.pion-1.ntrn.tech/', rest: process.env.NEXT_PUBLIC_NEUTRON_TEST_REST ?? 'https://rest-palvus.pion-1.ntrn.tech',
swap: 'https://testnet-neutron.astroport.fi/swap', swap: 'https://testnet-neutron.astroport.fi/swap',
pools: '', //TODO: ⛓️ Implement this pools: '', //TODO: ⛓️ Implement this
explorer: 'https://testnet.mintscan.io/neutron-testnet', explorer: 'https://testnet.mintscan.io/neutron-testnet',

View File

@ -9,8 +9,8 @@ const Devnet: ChainConfig = {
name: 'Osmosis Devnet', name: 'Osmosis Devnet',
endpoints: { endpoints: {
...Osmosis1.endpoints, ...Osmosis1.endpoints,
rpc: process.env.NEXT_PUBLIC_OSMOSIS_TEST_RPC ?? 'https://rpc-osmosis.blockapsis.com/', rpc: process.env.NEXT_PUBLIC_OSMOSIS_TEST_RPC ?? 'https://rpc-osmosis.blockapsis.com',
rest: process.env.NEXT_PUBLIC_OSMOSIS_TEST_REST ?? 'https://lcd-osmosis.blockapsis.com/', rest: process.env.NEXT_PUBLIC_OSMOSIS_TEST_REST ?? 'https://lcd-osmosis.blockapsis.com',
swap: 'https://testnet.osmosis.zone', swap: 'https://testnet.osmosis.zone',
}, },
} }

View File

@ -25,6 +25,7 @@ import WETHaxl from 'configs/assets/WETH.xal'
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'
import { getUrl } from 'utils/url'
const ASSETS = [ const ASSETS = [
{ ...OSMO, denom: 'uosmo' }, { ...OSMO, denom: 'uosmo' },
@ -137,15 +138,15 @@ const Osmosis1: ChainConfig = {
}, },
}, },
endpoints: { endpoints: {
rpc: process.env.NEXT_PUBLIC_OSMOSIS_RPC ?? 'https://rpc-osmosis.blockapsis.com/', rpc: process.env.NEXT_PUBLIC_OSMOSIS_RPC ?? 'https://rpc-osmosis.blockapsis.com',
rest: process.env.NEXT_PUBLIC_OSMOSIS_REST ?? 'https://lcd-osmosis.blockapsis.com/', rest: process.env.NEXT_PUBLIC_OSMOSIS_REST ?? 'https://lcd-osmosis.blockapsis.com',
swap: 'https://app.osmosis.zone', swap: 'https://app.osmosis.zone',
explorer: 'https://www.mintscan.io/osmosis/transactions/', explorer: 'https://www.mintscan.io/osmosis/transactions/',
routes: 'https://sqs.osmosis.zone/router', routes: 'https://sqs.osmosis.zone/router',
pools: pools: getUrl(
(process.env.NEXT_PUBLIC_OSMOSIS_REST || process.env.NEXT_PUBLIC_OSMOSIS_REST ?? 'https://lcd-osmosis.blockapsis.com',
'https://osmosis-node.marsprotocol.io/GGSFGSFGFG34/osmosis-lcd-front/') +
'osmosis/gamm/v1beta1/pools/POOL_ID', 'osmosis/gamm/v1beta1/pools/POOL_ID',
),
aprs: { aprs: {
vaults: 'https://api.marsprotocol.io/v1/vaults/osmosis', vaults: 'https://api.marsprotocol.io/v1/vaults/osmosis',
stride: 'https://edge.stride.zone/api/stake-stats', stride: 'https://edge.stride.zone/api/stake-stats',

View File

@ -1,6 +1,7 @@
import useSWR from 'swr' import useSWR from 'swr'
import useChainConfig from 'hooks/useChainConfig' import useChainConfig from 'hooks/useChainConfig'
import { getUrl } from 'utils/url'
export default function useWalletBalances(address?: string) { export default function useWalletBalances(address?: string) {
const chainConfig = useChainConfig() const chainConfig = useChainConfig()
@ -16,13 +17,9 @@ export default function useWalletBalances(address?: string) {
} }
async function getWalletBalances(chainConfig: ChainConfig, address: string): Promise<Coin[]> { async function getWalletBalances(chainConfig: ChainConfig, address: string): Promise<Coin[]> {
const uri = '/cosmos/bank/v1beta1/balances/' const uri = getUrl(chainConfig.endpoints.rest, `cosmos/bank/v1beta1/balances/${address}`)
const response = await fetch( const response = await fetch(uri)
process.env.NEXT_PUBLIC_API_KEY
? `${chainConfig.endpoints.rest}${uri}${address}?x-apikey=${process.env.NEXT_PUBLIC_API_KEY}`
: `${chainConfig.endpoints.rest}${uri}${address}`,
)
if (response.ok) { if (response.ok) {
const data = await response.json() const data = await response.json()

8
src/utils/url.ts Normal file
View File

@ -0,0 +1,8 @@
export const getUrl = (baseUrl: string, path: string): string => {
const url = new URL(baseUrl)
if (process.env.NEXT_PUBLIC_API_KEY)
return `${url.href}${path}?x-apikey=${process.env.NEXT_PUBLIC_API_KEY}`
return url.href + path
}