From 72e8757ffa2de8af6e2e4a1c8f887e694d24213d Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:49:57 -0700 Subject: [PATCH 1/5] feat: add support for multiple indexer endpoints --- .env.local.example | 4 +++- netlify.toml | 6 ------ src/api/chains/index.ts | 13 ++++++++++--- src/api/chains/regen.ts | 16 ++++++++++++---- src/graphql-request-provider.tsx | 8 ++++---- src/store/chain.store.ts | 7 +++---- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.env.local.example b/.env.local.example index 1138177..dc6a3dc 100644 --- a/.env.local.example +++ b/.env.local.example @@ -1,4 +1,6 @@ VITE_LOCAL_HOSTNAME=http://127.0.0.1 VITE_PROXY_URL_REGEN_MAINNET=http://api.registry.regen.network VITE_PROXY_URL_REGEN_TESTNET=http://api-staging.registry.regen.network -VITE_INDEXER_GRAPHQL_API=http://localhost:5000/indexer/graphql +VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL=http://localhost:5000/indexer/graphql +VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET=https://api.regen.network/indexer/v1/graphql +VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET=https://api-staging.regen.network/indexer/v1/graphql diff --git a/netlify.toml b/netlify.toml index 00f059e..b87b8d3 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,9 +1,3 @@ -[context.production.environment] - VITE_INDEXER_GRAPHQL_API="https://api.registry.regen.network/indexer/graphql" - -[context.deploy-preview.environment] - VITE_INDEXER_GRAPHQL_API="https://api-staging.registry.regen.network/indexer/graphql" - [[redirects]] from = "/*" to = "/index.html" diff --git a/src/api/chains/index.ts b/src/api/chains/index.ts index 87d9fde..75a2132 100644 --- a/src/api/chains/index.ts +++ b/src/api/chains/index.ts @@ -17,13 +17,20 @@ const { import { regenLocal, regenMainnet, regenTestnet } from './regen' -export const mainnetChainsArray: ChainInfo[] = [ +export interface ChainInfoExtended extends ChainInfo { + indexer: string +} + +export const mainnetChainsArray: ChainInfoExtended[] = [ ...(VITE_PROXY_URL_REGEN_MAINNET ? [regenMainnet] : []), ] -export const testnetChainsArray: ChainInfo[] = [ +export const testnetChainsArray: ChainInfoExtended[] = [ ...(VITE_PROXY_URL_REGEN_TESTNET ? [regenTestnet] : []), ...(VITE_LOCAL_HOSTNAME ? [regenLocal] : []), ] -export const allChainsArray: ChainInfo[] = [...mainnetChainsArray, ...testnetChainsArray] +export const allChainsArray: ChainInfoExtended[] = [ + ...mainnetChainsArray, + ...testnetChainsArray, +] diff --git a/src/api/chains/regen.ts b/src/api/chains/regen.ts index 4b90947..d006c09 100644 --- a/src/api/chains/regen.ts +++ b/src/api/chains/regen.ts @@ -1,11 +1,16 @@ -import type { AppCurrency, ChainInfo } from '@keplr-wallet/types' +import type { AppCurrency } from '@keplr-wallet/types' import { Bech32Address } from 'util/bech32' +import { ChainInfoExtended } from './index' + const { VITE_LOCAL_HOSTNAME, VITE_PROXY_URL_REGEN_MAINNET, VITE_PROXY_URL_REGEN_TESTNET, + VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL, + VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET, + VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET, } = import.meta.env const REGEN: AppCurrency = { @@ -22,10 +27,11 @@ const REGEN: AppCurrency = { */ const currencies: AppCurrency[] = [REGEN] -export const regenLocal: ChainInfo = { +export const regenLocal: ChainInfoExtended = { // hardcoded port values based on makefile rpc: `${VITE_LOCAL_HOSTNAME}:26657`, rest: `${VITE_LOCAL_HOSTNAME}:1317`, + indexer: VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL, chainId: 'regen-local', chainName: 'Regen Local', stakeCurrency: REGEN, @@ -40,9 +46,10 @@ export const regenLocal: ChainInfo = { /** * @see https://github.com/cosmos/chain-registry/blob/master/regen/chain.json */ -export const regenMainnet: ChainInfo = { +export const regenMainnet: ChainInfoExtended = { rpc: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger`, rest: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest`, + indexer: VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET, chainId: 'regen-1', chainName: 'Regen', stakeCurrency: REGEN, @@ -54,9 +61,10 @@ export const regenMainnet: ChainInfo = { feeCurrencies: currencies, } -export const regenTestnet: ChainInfo = { +export const regenTestnet: ChainInfoExtended = { rpc: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger`, rest: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest`, + indexer: VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET, chainId: 'regen-redwood-1', chainName: 'Regen Redwood', stakeCurrency: REGEN, diff --git a/src/graphql-request-provider.tsx b/src/graphql-request-provider.tsx index 357986e..03410ae 100644 --- a/src/graphql-request-provider.tsx +++ b/src/graphql-request-provider.tsx @@ -1,16 +1,16 @@ import React, { useState } from 'react' import { GraphQLClient } from 'graphql-request' import { GraphqlRequestContext } from 'graphql-request-context' +import { useSnapshot } from 'valtio' -const { VITE_INDEXER_GRAPHQL_API } = import.meta.env +import { Chain } from './store/chain.store' export const GraphqlProvider = ({ children }: { children?: React.ReactNode }) => { + const { active } = useSnapshot(Chain) const [client, setClient] = useState(undefined) if (!client) { setClient( - new GraphQLClient( - VITE_INDEXER_GRAPHQL_API || 'http://localhost:5000/indexer/graphql', - ), + new GraphQLClient(active.indexer || 'http://localhost:5000/indexer/graphql'), ) } return ( diff --git a/src/store/chain.store.ts b/src/store/chain.store.ts index f2d7ab8..e34d49b 100644 --- a/src/store/chain.store.ts +++ b/src/store/chain.store.ts @@ -1,11 +1,10 @@ import type { StdFee } from '@cosmjs/stargate' -import type { ChainInfo } from '@keplr-wallet/types' import { proxy } from 'valtio' import type { ValidatorSDKType } from 'types' import { isJson } from 'util/validation' -import { allChainsArray } from 'api/chains' +import { allChainsArray, ChainInfoExtended } from 'api/chains' import { bootstrapKeplr } from './wallet.store' @@ -15,8 +14,8 @@ const savedChain = localStorage.getItem(LOCALSTORAGE_CHAIN_KEY) const defaultChain = allChainsArray[0] type ChainStore = { - active: ChainInfo - all: ChainInfo[] + active: ChainInfoExtended + all: ChainInfoExtended[] fee?: StdFee // | 'auto' | number stakeDenom: string validators: ValidatorSDKType[] From da306726f881f6f4d000f6c7c08c299b87b675b4 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:54:54 -0700 Subject: [PATCH 2/5] empty commit From 24234e3062881748dde9c4a1bc5a865018f26203 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:23:17 -0700 Subject: [PATCH 3/5] make envars optional for staging and production --- src/api/chains/regen.ts | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/api/chains/regen.ts b/src/api/chains/regen.ts index d006c09..07f0ce2 100644 --- a/src/api/chains/regen.ts +++ b/src/api/chains/regen.ts @@ -29,9 +29,10 @@ const currencies: AppCurrency[] = [REGEN] export const regenLocal: ChainInfoExtended = { // hardcoded port values based on makefile - rpc: `${VITE_LOCAL_HOSTNAME}:26657`, - rest: `${VITE_LOCAL_HOSTNAME}:1317`, - indexer: VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL, + rpc: VITE_LOCAL_HOSTNAME ? `${VITE_LOCAL_HOSTNAME}:26657` : 'http://127.0.0.1:26657', + rest: VITE_LOCAL_HOSTNAME ? `${VITE_LOCAL_HOSTNAME}:1317` : 'http://127.0.0.1:1317', + indexer: + VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL || 'http://localhost:5000/indexer/graphql', chainId: 'regen-local', chainName: 'Regen Local', stakeCurrency: REGEN, @@ -47,9 +48,15 @@ export const regenLocal: ChainInfoExtended = { * @see https://github.com/cosmos/chain-registry/blob/master/regen/chain.json */ export const regenMainnet: ChainInfoExtended = { - rpc: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger`, - rest: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest`, - indexer: VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET, + rpc: VITE_PROXY_URL_REGEN_MAINNET + ? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger` + : 'https://api.registry.regen.network/ledger', + rest: VITE_PROXY_URL_REGEN_MAINNET + ? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest` + : 'https://api.registry.regen.network/ledger-rest', + indexer: + VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET || + 'https://api.regen.network/indexer/v1/graphql', chainId: 'regen-1', chainName: 'Regen', stakeCurrency: REGEN, @@ -62,9 +69,15 @@ export const regenMainnet: ChainInfoExtended = { } export const regenTestnet: ChainInfoExtended = { - rpc: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger`, - rest: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest`, - indexer: VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET, + rpc: VITE_PROXY_URL_REGEN_TESTNET + ? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger` + : 'https://api-staging.registry.regen.network/ledger', + rest: VITE_PROXY_URL_REGEN_TESTNET + ? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest` + : 'https://api.registry.regen.network/ledger-rest', + indexer: + VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET || + 'https://api-staging.regen.network/indexer/v1/graphql', chainId: 'regen-redwood-1', chainName: 'Regen Redwood', stakeCurrency: REGEN, From 377c4494528fab5986286b72d0e2a6ebfdced9f4 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 15 Aug 2023 08:25:32 -0700 Subject: [PATCH 4/5] update endpoints and local environment --- .env.local.example | 10 +++++----- indexer-codegen.ts | 2 +- src/api/chains/regen.ts | 2 +- src/graphql-request-provider.tsx | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.env.local.example b/.env.local.example index dc6a3dc..8664d0f 100644 --- a/.env.local.example +++ b/.env.local.example @@ -1,6 +1,6 @@ VITE_LOCAL_HOSTNAME=http://127.0.0.1 -VITE_PROXY_URL_REGEN_MAINNET=http://api.registry.regen.network -VITE_PROXY_URL_REGEN_TESTNET=http://api-staging.registry.regen.network -VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL=http://localhost:5000/indexer/graphql -VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET=https://api.regen.network/indexer/v1/graphql -VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET=https://api-staging.regen.network/indexer/v1/graphql +VITE_PROXY_URL_REGEN_MAINNET=http://api.regen.network +VITE_PROXY_URL_REGEN_TESTNET=http://api-staging.regen.network +VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL=http://127.0.0.1:5000/indexer/v1/graphql +VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET=http://127.0.0.1:5000/indexer/v1/graphql +VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET=http://127.0.0.1:5000/indexer/v1/graphql diff --git a/indexer-codegen.ts b/indexer-codegen.ts index ba36f5a..4e5ac0c 100644 --- a/indexer-codegen.ts +++ b/indexer-codegen.ts @@ -2,7 +2,7 @@ import { CodegenConfig } from '@graphql-codegen/cli' const config: CodegenConfig = { overwrite: true, - schema: 'http://localhost:5000/indexer/v1/graphql', + schema: 'http://127.0.0.1:5000/indexer/v1/graphql', documents: ['src/graphql/indexer/**/*.graphql'], generates: { './src/gql/': { diff --git a/src/api/chains/regen.ts b/src/api/chains/regen.ts index 07f0ce2..c28f3b2 100644 --- a/src/api/chains/regen.ts +++ b/src/api/chains/regen.ts @@ -32,7 +32,7 @@ export const regenLocal: ChainInfoExtended = { rpc: VITE_LOCAL_HOSTNAME ? `${VITE_LOCAL_HOSTNAME}:26657` : 'http://127.0.0.1:26657', rest: VITE_LOCAL_HOSTNAME ? `${VITE_LOCAL_HOSTNAME}:1317` : 'http://127.0.0.1:1317', indexer: - VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL || 'http://localhost:5000/indexer/graphql', + VITE_INDEXER_GRAPHQL_API_REGEN_LOCAL || 'http://127.0.0.1:5000/indexer/v1/graphql', chainId: 'regen-local', chainName: 'Regen Local', stakeCurrency: REGEN, diff --git a/src/graphql-request-provider.tsx b/src/graphql-request-provider.tsx index 03410ae..bd932be 100644 --- a/src/graphql-request-provider.tsx +++ b/src/graphql-request-provider.tsx @@ -10,7 +10,7 @@ export const GraphqlProvider = ({ children }: { children?: React.ReactNode }) => const [client, setClient] = useState(undefined) if (!client) { setClient( - new GraphQLClient(active.indexer || 'http://localhost:5000/indexer/graphql'), + new GraphQLClient(active.indexer || 'http://127.0.0.1:5000/indexer/v1/graphql'), ) } return ( From 369453b6d538f61e46edd0354c87c395ddce6f46 Mon Sep 17 00:00:00 2001 From: ryanchristo <12519942+ryanchristo@users.noreply.github.com> Date: Tue, 15 Aug 2023 08:28:24 -0700 Subject: [PATCH 5/5] update endpoints and local environment --- src/api/chains/regen.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/chains/regen.ts b/src/api/chains/regen.ts index c28f3b2..3703fe5 100644 --- a/src/api/chains/regen.ts +++ b/src/api/chains/regen.ts @@ -50,10 +50,10 @@ export const regenLocal: ChainInfoExtended = { export const regenMainnet: ChainInfoExtended = { rpc: VITE_PROXY_URL_REGEN_MAINNET ? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger` - : 'https://api.registry.regen.network/ledger', + : 'https://api.regen.network/ledger', rest: VITE_PROXY_URL_REGEN_MAINNET ? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest` - : 'https://api.registry.regen.network/ledger-rest', + : 'https://api.regen.network/ledger-rest', indexer: VITE_INDEXER_GRAPHQL_API_REGEN_MAINNET || 'https://api.regen.network/indexer/v1/graphql', @@ -71,10 +71,10 @@ export const regenMainnet: ChainInfoExtended = { export const regenTestnet: ChainInfoExtended = { rpc: VITE_PROXY_URL_REGEN_TESTNET ? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger` - : 'https://api-staging.registry.regen.network/ledger', + : 'https://api-staging.regen.network/ledger', rest: VITE_PROXY_URL_REGEN_TESTNET ? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest` - : 'https://api.registry.regen.network/ledger-rest', + : 'https://api.regen.network/ledger-rest', indexer: VITE_INDEXER_GRAPHQL_API_REGEN_TESTNET || 'https://api-staging.regen.network/indexer/v1/graphql',