Skip to content

Commit

Permalink
refactor: remove unnecessary env
Browse files Browse the repository at this point in the history
  • Loading branch information
jstinhw committed Aug 13, 2024
1 parent 51a098a commit 508a11f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
8 changes: 1 addition & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
NEXT_PUBLIC_ZERODEV_BASE_SEPOLIA_PROJECT_ID=

NEXT_PUBLIC_ZERODEV_OP_SEPOLIA_PROJECT_ID=

NEXT_PUBLIC_BASE_SEPOLIA_RPC_URL=

NEXT_PUBLIC_OP_SEPOLIA_RPC_URL=

NEXT_PUBLIC_PIMLICO_API_KEY=
NEXT_PUBLIC_ZERODEV_OP_SEPOLIA_PROJECT_ID=
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 3030",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
5 changes: 2 additions & 3 deletions src/components/Provider/Providers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
import { getPublicRpc } from "@/utils/constants";
import { MantineProvider } from "@mantine/core";
import "@mantine/core/styles.css";
import { Notifications } from "@mantine/notifications";
Expand All @@ -16,8 +15,8 @@ export default function Providers({ children }: { children: ReactNode }) {
const config = createConfig({
chains: [optimismSepolia, baseSepolia],
transports: {
[optimismSepolia.id]: http(getPublicRpc(optimismSepolia.id)),
[baseSepolia.id]: http(getPublicRpc(baseSepolia.id)),
[optimismSepolia.id]: http(),
[baseSepolia.id]: http(),
},
connectors: [wrapEOAConnector(injected())],
multiInjectedProviderDiscovery: false,
Expand Down
34 changes: 5 additions & 29 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { optimismSepolia, baseSepolia } from 'wagmi/chains';
import { type Address } from 'viem';

export const ZERODEV_APP_ID = process.env.NEXT_PUBLIC_ZERODEV_APP_ID || "";
export const zerodevOpSepoliaId = process.env.NEXT_PUBLIC_ZERODEV_OP_SEPOLIA_PROJECT_ID;

export const zerodevOpSepoliaId = process.env.NEXT_PUBLIC_ZERODEV_OP_SEPOLIA_PROJECT_ID || "";
export const zerodevBaseSepoliaId = process.env.NEXT_PUBLIC_ZERODEV_BASE_SEPOLIA_PROJECT_ID;

export const zerodevBaseSepoliaId = process.env.NEXT_PUBLIC_ZERODEV_BASE_SEPOLIA_PROJECT_ID || "";
if (!zerodevOpSepoliaId || !zerodevBaseSepoliaId) {
throw new Error("Please set Zerodev project IDs in .env");
}

export const supportedAccounts = [
"kernel",
Expand All @@ -17,30 +19,20 @@ export const supportedChains = [
logo: "/icons/optimism.svg",
chain: optimismSepolia,
projectId: zerodevOpSepoliaId,
publicRpc: process.env.NEXT_PUBLIC_OP_SEPOLIA_RPC_URL,
isRepay: true,
},
{
id: 84532,
logo: "/icons/base.svg",
chain: baseSepolia,
projectId: zerodevBaseSepoliaId,
publicRpc: process.env.NEXT_PUBLIC_BASE_SEPOLIA_RPC_URL,
isRepay: false,
},
]
if (supportedChains.length !== 2) {
throw new Error("Supported chains not configured correctly");
}

export const getChain = (chainId: number) => {
const chain = supportedChains.find(chain => chain.id === chainId);
if (!chain) {
throw new Error("Unsupported chain");
}
return chain;
};

export const getBundler = (chainId: number) => {
const chain = supportedChains.find(chain => chain.id === chainId);
if (!chain) {
Expand All @@ -49,22 +41,6 @@ export const getBundler = (chainId: number) => {
return `https://rpc.zerodev.app/api/v2/bundler/${chain.projectId}?provider=PIMLICO`;
};

export const getPimlicoRpc = (chainId: number) => {
const chain = supportedChains.find(chain => chain.id === chainId);
if (!chain) {
throw new Error("Unsupported chain");
}
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=${process.env.NEXT_PUBLIC_PIMLICO_API_KEY}`;
}

export const getPublicRpc = (chainId: number) => {
const chain = supportedChains.find(chain => chain.id === chainId);
if (!chain) {
throw new Error("Unsupported chain");
}
return chain.publicRpc;
};

export const getPaymaster = (chainId: number) => {
const chain = supportedChains.find(chain => chain.id === chainId);
if (!chain) {
Expand Down

0 comments on commit 508a11f

Please sign in to comment.