Skip to content

Commit

Permalink
fix: properly list network in a map
Browse files Browse the repository at this point in the history
  • Loading branch information
Sekhmet committed Feb 26, 2024
1 parent 47f60de commit b8b0e31
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/mana/src/eth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const jsonRpcRequestSchema = z.object({
});

const handlers = Object.fromEntries(
Object.keys(NETWORKS).map(chainId => [chainId, createNetworkHandler(parseInt(chainId, 10))])
Array.from(NETWORKS.keys()).map(chainId => [chainId, createNetworkHandler(chainId)])
);

const router = express.Router();
Expand Down
2 changes: 1 addition & 1 deletion apps/mana/src/stark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const jsonRpcRequestSchema = z.object({
});

const handlers = Object.fromEntries(
Object.keys(NETWORKS).map(chainId => [chainId, createNetworkHandler(chainId)])
Array.from(NETWORKS.keys()).map(chainId => [chainId, createNetworkHandler(chainId)])
);

const router = express.Router();
Expand Down
12 changes: 6 additions & 6 deletions apps/mana/src/stark/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
import { getProvider, createAccountProxy } from './dependencies';
import { NonceManager } from './nonce-manager';

export const NETWORKS: Record<string, NetworkConfig> = {
[constants.StarknetChainId.SN_MAIN]: starknetMainnet,
[constants.StarknetChainId.SN_GOERLI]: starknetGoerli,
[constants.StarknetChainId.SN_SEPOLIA]: starknetSepolia
};
export const NETWORKS = new Map<string, NetworkConfig>([
[constants.StarknetChainId.SN_MAIN, starknetMainnet],
[constants.StarknetChainId.SN_GOERLI, starknetGoerli],
[constants.StarknetChainId.SN_SEPOLIA, starknetSepolia]
]);

const clientsMap = new Map<
string,
Expand All @@ -34,7 +34,7 @@ export function getClient(chainId: string) {
const client = new clients.StarknetTx({
starkProvider: provider,
ethUrl: process.env.ETH_RPC_URL as string,
networkConfig: NETWORKS[chainId]
networkConfig: NETWORKS.get(chainId)
});

clientsMap.set(chainId, { provider, client, getAccount });
Expand Down
2 changes: 1 addition & 1 deletion apps/mana/src/stark/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as herodotus from './herodotus';
import { rpcError, rpcSuccess } from '../utils';

export const createNetworkHandler = (chainId: string) => {
const networkConfig = NETWORKS[chainId];
const networkConfig = NETWORKS.get(chainId);
if (!networkConfig) throw new Error('Unsupported chainId');

const { client, getAccount } = getClient(chainId);
Expand Down

0 comments on commit b8b0e31

Please sign in to comment.