Skip to content

Commit

Permalink
Warn if using custom and network isn't set, otherwise ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
xbtmatt committed Nov 19, 2024
1 parent d253ad0 commit 9e40dc1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/docker/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ ENV HASH_SEED=$HASH_SEED \
NEXT_PUBLIC_TESTNET_APTOS_API_KEY=$FRONTEND_TESTNET_APTOS_API_KEY \
NEXT_PUBLIC_MAINNET_APTOS_API_KEY=$FRONTEND_MAINNET_APTOS_API_KEY

RUN ["bash", "-c", "pnpm install && pnpm run build:no-checks"]
RUN ["bash", "-c", "pnpm install && pnpm run build:test"]

CMD ["bash", "-c", "pnpm run start -- -H 0.0.0.0"]
13 changes: 10 additions & 3 deletions src/typescript/sdk/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ if (!APTOS_NETWORK) {
}

const allAPIKeys: Record<Network, string | undefined> = {
[Network.LOCAL]: process.env.NEXT_PUBLIC_LOCAL_APTOS_API_KEY ?? "",
[Network.CUSTOM]: process.env.NEXT_PUBLIC_CUSTOM_APTOS_API_KEY ?? "",
[Network.LOCAL]: process.env.NEXT_PUBLIC_LOCAL_APTOS_API_KEY,
[Network.CUSTOM]: process.env.NEXT_PUBLIC_CUSTOM_APTOS_API_KEY,
[Network.DEVNET]: process.env.NEXT_PUBLIC_DEVNET_APTOS_API_KEY,
[Network.TESTNET]: process.env.NEXT_PUBLIC_TESTNET_APTOS_API_KEY,
[Network.MAINNET]: process.env.NEXT_PUBLIC_MAINNET_APTOS_API_KEY,
};

const apiKey = allAPIKeys[APTOS_NETWORK];
if (typeof apiKey === "undefined") {
throw new Error(`Invalid API key set for the network: ${APTOS_NETWORK}: ${apiKey}`);
// Do nothing if we're on a local network, because we don't need an API key for it. For custom,
// warn the developer.
if (APTOS_NETWORK === "custom") {
console.warn(`No API key set. Ignoring because we're on the \`${APTOS_NETWORK}\` network.`);
} else {
throw new Error(`Invalid API key set for the network: ${APTOS_NETWORK}: ${apiKey}`);
}
}
// Select the API key from the list of env API keys. This means we don't have to change the env
// var for API keys when changing environments- we just need to provide them all every time, which
Expand Down
2 changes: 1 addition & 1 deletion src/typescript/sdk/tests/e2e/queries/client/submit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("all submission types for the emojicoin client", () => {
});
const aptos = new Aptos(config);
const emojicoinClient = new EmojicoinClient({ aptos });
expect(aptos.config.clientConfig?.API_KEY).toEqual(undefined);
expect(aptos.config.clientConfig?.API_KEY).toEqual(APTOS_API_KEY);
expect(emojicoinClient.aptos.config.clientConfig?.API_KEY).toEqual(APTOS_API_KEY);
});

Expand Down

0 comments on commit 9e40dc1

Please sign in to comment.