From 929ba89e9c74a2e419a942dc9ce23b19f607f3a9 Mon Sep 17 00:00:00 2001 From: 0age <37939117+0age@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:36:41 -0800 Subject: [PATCH] fix fe lint warnings --- .github/workflows/ci.yml | 4 +- frontend/src/App.tsx | 48 ++++++++++++------- frontend/src/components/CreateAllocation.tsx | 2 +- frontend/src/components/DepositForm.tsx | 6 +-- ...onContext.tsx => NotificationProvider.tsx} | 15 +----- frontend/src/context/notification-context.ts | 13 +++++ frontend/src/hooks/useNotification.ts | 2 +- frontend/src/hooks/useSessionPoller.ts | 2 +- 8 files changed, 54 insertions(+), 38 deletions(-) rename frontend/src/context/{NotificationContext.tsx => NotificationProvider.tsx} (61%) create mode 100644 frontend/src/context/notification-context.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 14e18d0..76f6d18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,8 +45,8 @@ jobs: - name: Type check frontend run: cd frontend && pnpm tsc --noEmit -p tsconfig.app.json - - name: Build - run: pnpm build + - name: Build frontend and backend + run: pnpm build:all - name: Check formatting run: pnpm prettier --check "src/**/!(*d).ts" diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 07a6fd4..6803f5c 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,5 +1,15 @@ -import { getDefaultConfig, RainbowKitProvider, darkTheme } from '@rainbow-me/rainbowkit'; -import { mainnet, optimism, optimismGoerli, sepolia, goerli } from 'viem/chains'; +import { + getDefaultConfig, + RainbowKitProvider, + darkTheme, +} from '@rainbow-me/rainbowkit'; +import { + mainnet, + optimism, + optimismGoerli, + sepolia, + goerli, +} from 'viem/chains'; import { WagmiProvider, http } from 'wagmi'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import '@rainbow-me/rainbowkit/styles.css'; @@ -11,7 +21,7 @@ import { BalanceDisplay } from './components/BalanceDisplay'; import { CreateAllocation } from './components/CreateAllocation'; import HealthCheck from './components/HealthCheck'; import { DepositForm } from './components/DepositForm'; -import { NotificationProvider } from './context/NotificationContext'; +import { NotificationProvider } from './context/NotificationProvider'; // Configure supported chains const projectId = 'YOUR_PROJECT_ID'; // Get from WalletConnect Cloud @@ -22,9 +32,7 @@ const config = getDefaultConfig({ appName: 'Smallocator', projectId, chains, - transports: Object.fromEntries( - chains.map((chain) => [chain.id, http()]) - ), + transports: Object.fromEntries(chains.map((chain) => [chain.id, http()])), ssr: true, }); @@ -37,15 +45,19 @@ const customTheme = darkTheme({ function App() { const [sessionToken, setSessionToken] = useState(null); - - const queryClient = useMemo(() => new QueryClient({ - defaultOptions: { - queries: { - staleTime: Infinity, - refetchOnWindowFocus: false, - }, - }, - }), []); + + const queryClient = useMemo( + () => + new QueryClient({ + defaultOptions: { + queries: { + staleTime: Infinity, + refetchOnWindowFocus: false, + }, + }, + }), + [] + ); return ( @@ -82,7 +94,7 @@ function App() { - @@ -109,7 +121,9 @@ function App() { )} {/* Create Allocation Form */} - {sessionToken && } + {sessionToken && ( + + )} diff --git a/frontend/src/components/CreateAllocation.tsx b/frontend/src/components/CreateAllocation.tsx index b645601..37b5f04 100644 --- a/frontend/src/components/CreateAllocation.tsx +++ b/frontend/src/components/CreateAllocation.tsx @@ -177,7 +177,7 @@ export function CreateAllocation({ sessionToken }: CreateAllocationProps) { if (amountBigInt > availableBigInt) { newErrors.amount = 'Amount exceeds available balance'; } - } catch (_err) { + } catch { newErrors.amount = 'Invalid amount'; } } diff --git a/frontend/src/components/DepositForm.tsx b/frontend/src/components/DepositForm.tsx index 027e0c6..4b740ae 100644 --- a/frontend/src/components/DepositForm.tsx +++ b/frontend/src/components/DepositForm.tsx @@ -45,7 +45,7 @@ export function DepositForm() { if (numAmount <= 0) { return { type: 'error', message: 'Amount must be greater than zero' }; } - } catch (_e) { + } catch { return { type: 'error', message: 'Invalid amount format' }; } @@ -78,7 +78,7 @@ export function DepositForm() { return { type: 'warning', message: 'Insufficient Allowance' }; } return null; - } catch (_e) { + } catch { return { type: 'error', message: 'Invalid amount format' }; } } @@ -91,7 +91,7 @@ export function DepositForm() { return { type: 'error', message: 'Insufficient ETH Balance' }; } return null; - } catch (_e) { + } catch { return { type: 'error', message: 'Invalid amount format' }; } } diff --git a/frontend/src/context/NotificationContext.tsx b/frontend/src/context/NotificationProvider.tsx similarity index 61% rename from frontend/src/context/NotificationContext.tsx rename to frontend/src/context/NotificationProvider.tsx index cc9f18a..d6e6405 100644 --- a/frontend/src/context/NotificationContext.tsx +++ b/frontend/src/context/NotificationProvider.tsx @@ -1,16 +1,5 @@ -import { createContext, ReactNode } from 'react'; - -interface NotificationContextType { - showNotification: (notification: { - type: 'success' | 'error' | 'warning' | 'info'; - title: string; - message: string; - }) => void; -} - -export const NotificationContext = createContext< - NotificationContextType | undefined ->(undefined); +import { ReactNode } from 'react'; +import { NotificationContext } from './notification-context'; export function NotificationProvider({ children }: { children: ReactNode }) { const showNotification = (notification: { diff --git a/frontend/src/context/notification-context.ts b/frontend/src/context/notification-context.ts new file mode 100644 index 0000000..1d58807 --- /dev/null +++ b/frontend/src/context/notification-context.ts @@ -0,0 +1,13 @@ +import { createContext } from 'react'; + +interface NotificationContextType { + showNotification: (notification: { + type: 'success' | 'error' | 'warning' | 'info'; + title: string; + message: string; + }) => void; +} + +export const NotificationContext = createContext< + NotificationContextType | undefined +>(undefined); diff --git a/frontend/src/hooks/useNotification.ts b/frontend/src/hooks/useNotification.ts index e7edcc2..d3e18b5 100644 --- a/frontend/src/hooks/useNotification.ts +++ b/frontend/src/hooks/useNotification.ts @@ -1,5 +1,5 @@ import { useContext } from 'react'; -import { NotificationContext } from '../context/NotificationContext'; +import { NotificationContext } from '../context/notification-context'; export function useNotification() { const context = useContext(NotificationContext); diff --git a/frontend/src/hooks/useSessionPoller.ts b/frontend/src/hooks/useSessionPoller.ts index b9b3506..b52cb0a 100644 --- a/frontend/src/hooks/useSessionPoller.ts +++ b/frontend/src/hooks/useSessionPoller.ts @@ -60,7 +60,7 @@ export function useSessionPoller( if (expiryTime < Date.now()) { throw new Error('Session expired'); } - } catch (_error) { + } catch { // On any error, clear the session localStorage.removeItem(`session-${address}`); onSessionUpdate(null);