From 80ab75faae3eb37a0d9f727987b6384a7346e7fa Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 29 Jun 2023 15:22:23 +0700 Subject: [PATCH 1/4] feat: add override api endpoint --- src/env.ts | 3 +++ src/lib/app-provider/hooks/useBaseApiRoute.ts | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/env.ts b/src/env.ts index 36675f879..f9f274035 100644 --- a/src/env.ts +++ b/src/env.ts @@ -18,6 +18,9 @@ export const DEFAULT_SUPPORTED_CHAIN_ID = SUPPORTED_CHAIN_IDS[0]; export const DUMMY_MNEMONIC = process.env.NEXT_PUBLIC_DUMMY_MNEMONIC; +export const OVERRIDE_API_ENDPOINT = + process.env.NEXT_PUBLIC_OVERRIDE_API_ENDPOINT; + // CURRENT THEME CONFIG export const CURR_THEME = (() => { switch (process.env.NEXT_PUBLIC_THEME) { diff --git a/src/lib/app-provider/hooks/useBaseApiRoute.ts b/src/lib/app-provider/hooks/useBaseApiRoute.ts index 404ba37e2..6456f2659 100644 --- a/src/lib/app-provider/hooks/useBaseApiRoute.ts +++ b/src/lib/app-provider/hooks/useBaseApiRoute.ts @@ -1,4 +1,5 @@ import { useCelatoneApp } from "../contexts"; +import { OVERRIDE_API_ENDPOINT } from "env"; export const useBaseApiRoute = ( type: @@ -12,13 +13,17 @@ export const useBaseApiRoute = ( | "rest" ): string => { const { - chainConfig: { chain, api }, + chainConfig: { chain, api: configApi }, currentChainId, } = useCelatoneApp(); - if (!chain || !api || !currentChainId) + + if (!chain || !currentChainId || !configApi) throw new Error( - "Error retrieving chain, api, or currentChainId from chain config." + "Error retrieving chain, api, or currentChainId from chain config." ); + + const api = OVERRIDE_API_ENDPOINT || configApi; + switch (type) { case "txs": return `${api}/txs/${chain}/${currentChainId}`; From 2d569f30f86f89b71b65c35e4ea56fd90109ecb1 Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 29 Jun 2023 15:23:21 +0700 Subject: [PATCH 2/4] docs: add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c49811e73..87f146ad1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features +- [#411](https://github.com/alleslabs/celatone-frontend/pull/411) Add override api endpoint - [#385](https://github.com/alleslabs/celatone-frontend/pull/385) Upgrade cosmos kit major version and replace hooks - [#380](https://github.com/alleslabs/celatone-frontend/pull/380) Support local network - [#363](https://github.com/alleslabs/celatone-frontend/pull/363) Add config not found page and rewrite network logic From a6a8311f01b9cf03e0f5c7d47c94700c329ea801 Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 29 Jun 2023 15:28:24 +0700 Subject: [PATCH 3/4] fix: exceed whitespace --- src/lib/app-provider/hooks/useBaseApiRoute.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/app-provider/hooks/useBaseApiRoute.ts b/src/lib/app-provider/hooks/useBaseApiRoute.ts index 6456f2659..4e986b481 100644 --- a/src/lib/app-provider/hooks/useBaseApiRoute.ts +++ b/src/lib/app-provider/hooks/useBaseApiRoute.ts @@ -19,7 +19,7 @@ export const useBaseApiRoute = ( if (!chain || !currentChainId || !configApi) throw new Error( - "Error retrieving chain, api, or currentChainId from chain config." + "Error retrieving chain, api, or currentChainId from chain config." ); const api = OVERRIDE_API_ENDPOINT || configApi; From 4da2d58cf9f5f49ade86ab4e51b5d3a3f564026c Mon Sep 17 00:00:00 2001 From: evilpeach Date: Thu, 29 Jun 2023 15:31:32 +0700 Subject: [PATCH 4/4] chore: change name --- src/env.ts | 4 ++-- src/lib/app-provider/hooks/useBaseApiRoute.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/env.ts b/src/env.ts index f9f274035..cfce90d6b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -18,8 +18,8 @@ export const DEFAULT_SUPPORTED_CHAIN_ID = SUPPORTED_CHAIN_IDS[0]; export const DUMMY_MNEMONIC = process.env.NEXT_PUBLIC_DUMMY_MNEMONIC; -export const OVERRIDE_API_ENDPOINT = - process.env.NEXT_PUBLIC_OVERRIDE_API_ENDPOINT; +export const CELATONE_API_OVERRIDE = + process.env.NEXT_PUBLIC_CELATONE_API_OVERRIDE; // CURRENT THEME CONFIG export const CURR_THEME = (() => { diff --git a/src/lib/app-provider/hooks/useBaseApiRoute.ts b/src/lib/app-provider/hooks/useBaseApiRoute.ts index 4e986b481..4d9011300 100644 --- a/src/lib/app-provider/hooks/useBaseApiRoute.ts +++ b/src/lib/app-provider/hooks/useBaseApiRoute.ts @@ -1,5 +1,5 @@ import { useCelatoneApp } from "../contexts"; -import { OVERRIDE_API_ENDPOINT } from "env"; +import { CELATONE_API_OVERRIDE } from "env"; export const useBaseApiRoute = ( type: @@ -22,7 +22,7 @@ export const useBaseApiRoute = ( "Error retrieving chain, api, or currentChainId from chain config." ); - const api = OVERRIDE_API_ENDPOINT || configApi; + const api = CELATONE_API_OVERRIDE || configApi; switch (type) { case "txs":