Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for multiple indexer endpoints #139

Merged
merged 7 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -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/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
2 changes: 1 addition & 1 deletion indexer-codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/': {
Expand Down
6 changes: 0 additions & 6 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[context.production.environment]
VITE_INDEXER_GRAPHQL_API="https://api.regen.network/indexer/v1/graphql"

[context.deploy-preview.environment]
VITE_INDEXER_GRAPHQL_API="https://api-staging.regen.network/indexer/v1/graphql"

[[redirects]]
from = "/*"
to = "/index.html"
Expand Down
13 changes: 10 additions & 3 deletions src/api/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
41 changes: 31 additions & 10 deletions src/api/chains/regen.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -22,10 +27,12 @@ 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`,
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://127.0.0.1:5000/indexer/v1/graphql',
chainId: 'regen-local',
chainName: 'Regen Local',
stakeCurrency: REGEN,
Expand All @@ -40,9 +47,16 @@ export const regenLocal: ChainInfo = {
/**
* @see https://github.com/cosmos/chain-registry/blob/master/regen/chain.json
*/
export const regenMainnet: ChainInfo = {
rpc: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger`,
rest: `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest`,
export const regenMainnet: ChainInfoExtended = {
rpc: VITE_PROXY_URL_REGEN_MAINNET
? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger`
: 'https://api.regen.network/ledger',
rest: VITE_PROXY_URL_REGEN_MAINNET
? `${VITE_PROXY_URL_REGEN_MAINNET}/ledger-rest`
: 'https://api.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,
Expand All @@ -54,9 +68,16 @@ export const regenMainnet: ChainInfo = {
feeCurrencies: currencies,
}

export const regenTestnet: ChainInfo = {
rpc: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger`,
rest: `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest`,
export const regenTestnet: ChainInfoExtended = {
rpc: VITE_PROXY_URL_REGEN_TESTNET
? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger`
: 'https://api-staging.regen.network/ledger',
rest: VITE_PROXY_URL_REGEN_TESTNET
? `${VITE_PROXY_URL_REGEN_TESTNET}/ledger-rest`
: 'https://api.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,
Expand Down
8 changes: 4 additions & 4 deletions src/graphql-request-provider.tsx
Original file line number Diff line number Diff line change
@@ -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<GraphQLClient | undefined>(undefined)
if (!client) {
setClient(
new GraphQLClient(
VITE_INDEXER_GRAPHQL_API || 'http://localhost:5000/indexer/graphql',
),
new GraphQLClient(active.indexer || 'http://127.0.0.1:5000/indexer/v1/graphql'),
)
}
return (
Expand Down
7 changes: 3 additions & 4 deletions src/store/chain.store.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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[]
Expand Down