From 0674b126484ab2ca00925eddbe4aff839499797b Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Mon, 9 Dec 2024 12:59:23 +0100 Subject: [PATCH] chore: handle comments --- packages/starknet-snap/src/config.ts | 12 ++++++++++ packages/starknet-snap/src/utils/din.ts | 23 ------------------- .../{din.test.ts => rpc-provider.test.ts} | 2 +- .../starknet-snap/src/utils/rpc-provider.ts | 17 ++++++++++++++ .../starknet-snap/src/utils/starknetUtils.ts | 2 +- 5 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 packages/starknet-snap/src/utils/din.ts rename packages/starknet-snap/src/utils/{din.test.ts => rpc-provider.test.ts} (93%) create mode 100644 packages/starknet-snap/src/utils/rpc-provider.ts diff --git a/packages/starknet-snap/src/config.ts b/packages/starknet-snap/src/config.ts index abe5caa9..b2642ea1 100644 --- a/packages/starknet-snap/src/config.ts +++ b/packages/starknet-snap/src/config.ts @@ -22,6 +22,9 @@ export type SnapConfig = { defaultNetwork: Network; availableNetworks: Network[]; preloadTokens: Erc20Token[]; + rpcEndpoint: { + [key: string]: string; + }; explorer: { [key: string]: string; }; @@ -49,6 +52,15 @@ 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 ?? ''}`, + }, + explorer: { [constants.StarknetChainId.SN_MAIN]: // eslint-disable-next-line no-template-curly-in-string diff --git a/packages/starknet-snap/src/utils/din.ts b/packages/starknet-snap/src/utils/din.ts deleted file mode 100644 index 3717b5a3..00000000 --- a/packages/starknet-snap/src/utils/din.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { constants } from 'starknet'; - -/** - * - * @param chainId - */ -export function getRPCUrl(chainId: string) { - switch (chainId) { - case constants.StarknetChainId.SN_MAIN: - return `https://starknet-mainnet.infura.io/v3/${getRPCCredentials()}`; - default: - case constants.StarknetChainId.SN_SEPOLIA: - return `https://starknet-sepolia.infura.io/v3/${getRPCCredentials()}`; - } -} - -/** - * - */ -export function getRPCCredentials(): string { - // eslint-disable-next-line no-restricted-globals - return process.env.DIN_API_KEY ?? ''; -} diff --git a/packages/starknet-snap/src/utils/din.test.ts b/packages/starknet-snap/src/utils/rpc-provider.test.ts similarity index 93% rename from packages/starknet-snap/src/utils/din.test.ts rename to packages/starknet-snap/src/utils/rpc-provider.test.ts index 926cdeb8..81ba4ef3 100644 --- a/packages/starknet-snap/src/utils/din.test.ts +++ b/packages/starknet-snap/src/utils/rpc-provider.test.ts @@ -1,6 +1,6 @@ import { constants } from 'starknet'; -import { getRPCUrl } from './din'; +import { getRPCUrl } from './rpc-provider'; describe('getRPCUrl', () => { it('returns Mainnet RPC URL if chain id is Mainnet', () => { diff --git a/packages/starknet-snap/src/utils/rpc-provider.ts b/packages/starknet-snap/src/utils/rpc-provider.ts new file mode 100644 index 00000000..a175479d --- /dev/null +++ b/packages/starknet-snap/src/utils/rpc-provider.ts @@ -0,0 +1,17 @@ +import { constants } from 'starknet'; + +import { Config } from '../config'; + +/** + * + * @param chainId + */ +export function getRPCUrl(chainId: string) { + switch (chainId) { + case constants.StarknetChainId.SN_MAIN: + return Config.rpcEndpoint[constants.StarknetChainId.SN_MAIN]; + default: + case constants.StarknetChainId.SN_SEPOLIA: + return Config.rpcEndpoint[constants.StarknetChainId.SN_SEPOLIA]; + } +} diff --git a/packages/starknet-snap/src/utils/starknetUtils.ts b/packages/starknet-snap/src/utils/starknetUtils.ts index 44d8b9f4..39823a96 100644 --- a/packages/starknet-snap/src/utils/starknetUtils.ts +++ b/packages/starknet-snap/src/utils/starknetUtils.ts @@ -69,11 +69,11 @@ import { ETHER_SEPOLIA_TESTNET, BlockIdentifierEnum, } from './constants'; -import { getRPCUrl } from './din'; import { DeployRequiredError, UpgradeRequiredError } from './exceptions'; import { hexToString } from './formatter-utils'; import { getAddressKey } from './keyPair'; import { logger } from './logger'; +import { getRPCUrl } from './rpc-provider'; import { toJson } from './serializer'; import { getAccount,