From 62653437b5fb9eb9aec8e1d47405aac6f24b9005 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Thu, 28 Aug 2025 15:16:02 +0400 Subject: [PATCH] added network select feature --- components/SettingsModal.tsx | 71 +++++++++++++++++++++++++++++++++++- config/web3.ts | 22 +++++++++-- providers/Web3Provider.tsx | 20 ++-------- submodules/schedy | 2 +- 4 files changed, 93 insertions(+), 22 deletions(-) diff --git a/components/SettingsModal.tsx b/components/SettingsModal.tsx index f1f96dd..cdf788f 100644 --- a/components/SettingsModal.tsx +++ b/components/SettingsModal.tsx @@ -36,6 +36,10 @@ const defaultSettings: NotificationSettings = { export default function SettingsModal({ open, initial, onClose, onSave }: SettingsModalProps) { const [form, setForm] = useState(initial || defaultSettings); const [testStatus, setTestStatus] = useState(""); + // RPC runtime overrides (stored in localStorage) + const [rpcBase, setRpcBase] = useState(""); + const [rpcArbitrum, setRpcArbitrum] = useState(""); + const [rpcMainnet, setRpcMainnet] = useState(""); useEffect(() => { if (open) { @@ -45,6 +49,16 @@ export default function SettingsModal({ open, initial, onClose, onSave }: Settin if (!merged.ntfyServer) merged.ntfyServer = ENV_NTFY; if (!merged.schedyBaseUrl) merged.schedyBaseUrl = ENV_SCHEDY; setForm(merged); + // Load RPC overrides from localStorage + try { + const ls = typeof window !== 'undefined' ? window.localStorage : undefined; + const b = ls?.getItem('rpc:base') || ''; + const a = ls?.getItem('rpc:arbitrum') || ''; + const m = ls?.getItem('rpc:mainnet') || ''; + setRpcBase(b || 'https://base.llamarpc.com'); + setRpcArbitrum(a || ''); + setRpcMainnet(m || ''); + } catch {} } // eslint-disable-next-line react-hooks/exhaustive-deps }, [open, initial]); @@ -284,6 +298,41 @@ export default function SettingsModal({ open, initial, onClose, onSave }: Settin )} + + {/* RPC settings */} +
+
RPC endpoints (per network)
+
+ + + +
Changes apply immediately after Save without rebuild.
+
+
@@ -307,7 +356,27 @@ export default function SettingsModal({ open, initial, onClose, onSave }: Settin diff --git a/config/web3.ts b/config/web3.ts index e1a2d8b..28b984c 100644 --- a/config/web3.ts +++ b/config/web3.ts @@ -10,16 +10,32 @@ const metadata = { }; // Prefer custom RPCs to avoid public-provider rate limits (429) -const baseRpc = process.env.NEXT_PUBLIC_RPC_BASE; -const arbitrumRpc = process.env.NEXT_PUBLIC_RPC_ARBITRUM; +// Support runtime overrides via localStorage: +// - rpc:base +// - rpc:arbitrum +// - rpc:mainnet +function runtimeRpc(key: string): string | null { + try { + if (typeof window !== 'undefined' && window.localStorage) { + const v = window.localStorage.getItem(key); + return (v && v.trim()) ? v.trim() : null; + } + } catch {} + return null; +} + const enableMainnet = process.env.NEXT_PUBLIC_ENABLE_MAINNET === 'true'; +const baseRpc = runtimeRpc('rpc:base') || process.env.NEXT_PUBLIC_RPC_BASE || 'https://base.llamarpc.com'; +const arbitrumRpc = runtimeRpc('rpc:arbitrum') || process.env.NEXT_PUBLIC_RPC_ARBITRUM || ''; +const mainnetRpc = runtimeRpc('rpc:mainnet') || ''; + export const config = createConfig({ chains: [base, arbitrum, ...(enableMainnet ? [mainnet] : []), sepolia], transports: { [base.id]: baseRpc ? http(baseRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }), [arbitrum.id]: arbitrumRpc ? http(arbitrumRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }), - [mainnet.id]: http(), + [mainnet.id]: mainnetRpc ? http(mainnetRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(), [sepolia.id]: http(), }, ssr: true, diff --git a/providers/Web3Provider.tsx b/providers/Web3Provider.tsx index b2ee7ec..93dceca 100644 --- a/providers/Web3Provider.tsx +++ b/providers/Web3Provider.tsx @@ -1,9 +1,9 @@ 'use client'; -import { WagmiProvider, createConfig, http } from 'wagmi'; -import { mainnet, sepolia, base, arbitrum } from 'wagmi/chains'; +import { WagmiProvider } from 'wagmi'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { PropsWithChildren, useEffect, useState } from 'react'; +import { config } from '../config/web3'; const metadata = { name: 'MortgageFi', @@ -12,21 +12,6 @@ const metadata = { icons: ['https://mortgagefi.app/logo.png'] }; -// Prefer custom RPCs to avoid public-provider rate limits (429) -const baseRpc = process.env.NEXT_PUBLIC_RPC_BASE; -const arbitrumRpc = process.env.NEXT_PUBLIC_RPC_ARBITRUM; - -const config = createConfig({ - chains: [base, arbitrum, mainnet, sepolia], - transports: { - [base.id]: baseRpc ? http(baseRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }), - [arbitrum.id]: arbitrumRpc ? http(arbitrumRpc, { batch: true, retryCount: 2, retryDelay: 250 }) : http(undefined, { batch: true, retryCount: 2, retryDelay: 250 }), - [mainnet.id]: http(), - [sepolia.id]: http(), - }, - ssr: true, -}); - const queryClient = new QueryClient(); export function Web3Provider({ children }: PropsWithChildren) { @@ -44,3 +29,4 @@ export function Web3Provider({ children }: PropsWithChildren) { ); } + diff --git a/submodules/schedy b/submodules/schedy index 595a923..4a5a6a5 160000 --- a/submodules/schedy +++ b/submodules/schedy @@ -1 +1 @@ -Subproject commit 595a9232ccfcf80ca8ad0d552f8fd222ca1b649f +Subproject commit 4a5a6a5aad23d6b380c733599a0aa6dfa5cf9ee5