Skip to content

Commit

Permalink
chore: fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
khanti42 committed Dec 11, 2024
1 parent 70775c7 commit a94bb1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
14 changes: 3 additions & 11 deletions packages/starknet-snap/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export type SnapConfig = {
defaultNetwork: Network;
availableNetworks: Network[];
preloadTokens: Erc20Token[];
rpcEndpoint: {
[key: string]: string;
};
rpcApiKey: string;
explorer: {
[key: string]: string;
};
Expand Down Expand Up @@ -52,14 +50,8 @@ export const Config: SnapConfig = {
STARKNET_SEPOLIA_TESTNET_NETWORK,
],

rpcEndpoint: {
[constants.StarknetChainId.SN_MAIN]:
// eslint-disable-next-line no-restricted-globals
`https://starknet-mainnet.infura.io/v3/${process.env.DIN_API_KEY ?? ''}`,
[constants.StarknetChainId.SN_SEPOLIA]:
// eslint-disable-next-line no-restricted-globals
`https://starknet-sepolia.infura.io/v3/${process.env.DIN_API_KEY ?? ''}`,
},
// eslint-disable-next-line no-restricted-globals
rpcApiKey: process.env.DIN_API_KEY ?? '',

explorer: {
[constants.StarknetChainId.SN_MAIN]:
Expand Down
8 changes: 5 additions & 3 deletions packages/starknet-snap/src/utils/rpc-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { constants } from 'starknet';

import { Config } from '../config';
import { getRPCUrl } from './rpc-provider';

describe('getRPCUrl', () => {
Config.rpcApiKey = 'test';
it('returns Mainnet RPC URL if chain id is Mainnet', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_MAIN)).toBe(
'https://starknet-mainnet.infura.io/v3/',
`https://starknet-mainnet.infura.io/v3/${Config.rpcApiKey}`,
);
});

it('returns Sepolia RPC URL if chain id is not either Mainnet or Sepolia', () => {
expect(getRPCUrl('0x534e5f474f45524c49')).toBe(
'https://starknet-sepolia.infura.io/v3/',
`https://starknet-sepolia.infura.io/v3/${Config.rpcApiKey}`,
);
});

it('returns Sepolia RPC URL if chain id is Sepolia', () => {
expect(getRPCUrl(constants.StarknetChainId.SN_SEPOLIA)).toBe(
'https://starknet-sepolia.infura.io/v3/',
`https://starknet-sepolia.infura.io/v3/${Config.rpcApiKey}`,
);
});
});
7 changes: 4 additions & 3 deletions packages/starknet-snap/src/utils/rpc-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { constants } from 'starknet';
import { Config } from '../config';

/**
* Gets the rpc URL for a given Chain ID.
*
* @param chainId
* @param chainId - The Chain ID.
*/
export function getRPCUrl(chainId: string) {
switch (chainId) {
case constants.StarknetChainId.SN_MAIN:
return Config.rpcEndpoint[constants.StarknetChainId.SN_MAIN];
return `https://starknet-mainnet.infura.io/v3/${Config.rpcApiKey}`;
default:
case constants.StarknetChainId.SN_SEPOLIA:
return Config.rpcEndpoint[constants.StarknetChainId.SN_SEPOLIA];
return `https://starknet-sepolia.infura.io/v3/${Config.rpcApiKey}`;
}
}

0 comments on commit a94bb1d

Please sign in to comment.