Skip to content

Commit

Permalink
chore: update getChainByChainId -> getChainByChainIdAsync (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrysaporito authored Jan 11, 2024
1 parent 5479cdf commit 8625cba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/server/utils/chain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Static } from "@sinclair/typebox";
import { allChains, getChainByChainId } from "@thirdweb-dev/chains";
import { allChains, getChainByChainIdAsync } from "@thirdweb-dev/chains";
import { getConfig } from "../../utils/cache/getConfig";
import { networkResponseSchema } from "../../utils/cache/getSdk";

Expand All @@ -26,8 +26,9 @@ export const getChainIdFromChain = async (chain: string): Promise<number> => {
if (!isNaN(parseInt(chain))) {
const unknownChainId = parseInt(chain);
try {
const chain = await getChainByChainIdAsync(unknownChainId);
// If the chain id is for a supported chain, use the chain id
if (getChainByChainId(unknownChainId)) {
if (chain) {
chainId = unknownChainId;
}
} catch {
Expand All @@ -40,7 +41,7 @@ export const getChainIdFromChain = async (chain: string): Promise<number> => {
);
}
}
// If the chain id is unsupported, getChainByChainId will throw
// If the chain id is unsupported, getChainByChainIdAsync will throw
}
} else {
if (config?.chainOverrides) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/utils/wallets/getLocalWallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Static } from "@sinclair/typebox";
import { Chain, getChainByChainId } from "@thirdweb-dev/chains";
import { LocalWallet } from "@thirdweb-dev/wallets";
import { getChainByChainIdAsync } from "@thirdweb-dev/chains";
import { Chain, LocalWallet } from "@thirdweb-dev/wallets";
import { getWalletDetails } from "../../../db/wallets/getWalletDetails";
import { getConfig } from "../../../utils/cache/getConfig";
import { networkResponseSchema } from "../../../utils/cache/getSdk";
Expand All @@ -21,7 +21,7 @@ export const getLocalWallet = async ({
const config = await getConfig();
const CHAIN_OVERRIDES = config.chainOverrides;
try {
chain = getChainByChainId(chainId);
chain = await getChainByChainIdAsync(chainId);
} catch (error) {}

if (CHAIN_OVERRIDES) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/cache/getSdk.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Static, Type } from "@sinclair/typebox";
import { getChainByChainId } from "@thirdweb-dev/chains";
import { getChainByChainIdAsync } from "@thirdweb-dev/chains";
import { NetworkInput, ThirdwebSDK } from "@thirdweb-dev/sdk";
import * as fs from "fs";
import { PrismaTransaction } from "../../schema/prisma";
Expand Down Expand Up @@ -76,7 +76,7 @@ export const getSdk = async ({

let chain: NetworkInput | undefined = undefined;
try {
chain = getChainByChainId(chainId);
chain = await getChainByChainIdAsync(chainId);
} catch (error) {}

if (CHAIN_OVERRIDES) {
Expand Down

0 comments on commit 8625cba

Please sign in to comment.