Skip to content

Commit

Permalink
fix(core): fix default env for server-side api calls (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
lykalabrada authored Oct 19, 2023
1 parent 7178017 commit 5a23bd7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NetworkConnection } from "@contexts/Environment";
import { getEnvironment, NetworkConnection } from "@contexts/Environment";

export function wrapResponse<T>(res: Response): Promise<T> {
if (!res?.ok) {
Expand All @@ -22,10 +22,12 @@ export const V1_TRANSACTION_URL =
"api?module=transaction&action=gettxinfo&txhash=";

export const getBaseUrl = (network: NetworkConnection) => {
if (network === NetworkConnection.MainNet) {
const defautlEnv = getEnvironment().networks[0];
const currentNetwork = network ?? defautlEnv;
if (currentNetwork === NetworkConnection.MainNet) {
return process.env.NEXT_PUBLIC_RPC_URL_MAINNET;
}
if (network === NetworkConnection.TestNet) {
if (currentNetwork === NetworkConnection.TestNet) {
return process.env.NEXT_PUBLIC_RPC_URL_TESTNET;
}

Expand Down

0 comments on commit 5a23bd7

Please sign in to comment.