-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from balancer/v3-pool-creation
Pool creation for v3
- Loading branch information
Showing
67 changed files
with
3,631 additions
and
366 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Key Principles and Best Practices | ||
|
||
## Expertise Areas | ||
|
||
- Solidity, TypeScript, Node.js, Next.js 14 App Router, React | ||
- Viem v2, Wagmi v2, Shadcn UI, Radix UI, Tailwind Aria | ||
|
||
## General Principles | ||
|
||
- Write concise, technical responses with accurate TypeScript examples | ||
- Use functional, declarative programming; avoid classes | ||
- Prefer iteration and modularization over duplication | ||
- Use descriptive variable names with auxiliary verbs (e.g., isLoading) | ||
- Use lowercase with dashes for directories (e.g., components/auth-wizard) | ||
- Favor named exports for components | ||
- Use the Receive an Object, Return an Object (RORO) pattern | ||
|
||
## JavaScript/TypeScript | ||
|
||
- Use "function" keyword for pure functions; omit semicolons | ||
- Use TypeScript for all code; prefer interfaces over types; avoid enums, use maps | ||
- File structure: Exported component, subcomponents, helpers, static content, types | ||
- Avoid unnecessary curly braces in conditional statements | ||
- For single-line statements in conditionals, omit curly braces | ||
- Use concise, one-line syntax for simple conditional statements (e.g., if (condition) doSomething()) | ||
|
||
## Error Handling and Validation | ||
|
||
- Prioritize error handling and edge cases | ||
- Handle errors and edge cases at the beginning of functions | ||
- Use early returns for error conditions to avoid deeply nested if statements | ||
- Place the happy path last in the function for improved readability | ||
- Avoid unnecessary else statements; use if-return pattern instead | ||
- Use guard clauses to handle preconditions and invalid states early | ||
- Implement proper error logging and user-friendly error messages | ||
- Consider using custom error types or error factories for consistent error handling | ||
|
||
## React/Next.js | ||
|
||
- Use functional components and TypeScript interfaces | ||
- Use declarative JSX | ||
- Use function, not const, for components | ||
- Use Shadcn UI, Radix, and Tailwind Aria for components and styling | ||
- Implement responsive design with Tailwind CSS | ||
- Use mobile-first approach for responsive design | ||
- Place static content and interfaces at file end | ||
- Use content variables for static content outside render functions | ||
- Minimize 'use client', 'useEffect', and 'setState'; favor RSC | ||
- Use Zod for form validation | ||
- Wrap client components in Suspense with fallback | ||
- Use dynamic loading for non-critical components | ||
- Optimize images: WebP format, size data, lazy loading | ||
- Model expected errors as return values | ||
- Use error boundaries for unexpected errors | ||
- Use useActionState with react-hook-form for form validation | ||
- Code in services/ dir always throw user-friendly errors that tanStackQuery can catch and show to the user | ||
|
||
## Server Actions | ||
|
||
- Use next-safe-action for all server actions | ||
- Implement type-safe server actions with proper validation | ||
- Utilize the action function from next-safe-action for creating actions | ||
- Define input schemas using Zod for robust type checking and validation | ||
- Handle errors gracefully and return appropriate responses | ||
- Use import type { ActionResponse } from '@/types/actions' | ||
- Ensure all server actions return the ActionResponse type | ||
- Implement consistent error handling and success responses using ActionResponse | ||
|
||
## Key Conventions | ||
|
||
1. The import syntax for this project is `import {something} from "~~/path" | ||
1. Rely on Next.js App Router for state changes | ||
1. Prioritize Web Vitals (LCP, CLS, FID) | ||
1. Minimize 'use client' usage: | ||
- Prefer server components and Next.js SSR features | ||
- Use 'use client' only for Web API access in small components | ||
- Avoid using 'use client' for data fetching or state management | ||
|
||
Refer to Next.js documentation for Data Fetching, Rendering, and Routing best practices: https://nextjs.org/docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export * from "./StepsDisplay"; | ||
export * from "./PoolCreation"; | ||
export * from "./PoolResetModal"; | ||
export * from "./PoolCreated"; | ||
export * from "./PoolConfiguration"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/nextjs/app/v3/_components/ApproveOnTokenManager.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEffect } from "react"; | ||
import { PERMIT2 } from "@balancer/sdk"; | ||
import { parseUnits } from "viem"; | ||
import { Address } from "viem"; | ||
import { Alert, TransactionButton } from "~~/components/common"; | ||
import { useTargetNetwork } from "~~/hooks/scaffold-eth"; | ||
import { useApproveToken, useReadToken } from "~~/hooks/token"; | ||
import { usePoolCreationStore } from "~~/hooks/v3"; | ||
|
||
type MinimalToken = { address: Address; amount: string; decimals: number; symbol: string }; | ||
|
||
export const ApproveOnTokenManager = ({ token }: { token: MinimalToken }) => { | ||
const { targetNetwork } = useTargetNetwork(); | ||
const { step, updatePool } = usePoolCreationStore(); | ||
const { mutateAsync: approveOnToken, isPending: isApprovePending, error: approveError } = useApproveToken(); | ||
|
||
const rawAmount = parseUnits(token.amount, token.decimals); | ||
const spender = PERMIT2[targetNetwork.id]; | ||
const { allowance, refetchAllowance } = useReadToken(token.address, spender); | ||
|
||
const handleApprove = async () => { | ||
await approveOnToken( | ||
{ token: token.address, spender, rawAmount }, | ||
{ | ||
onSuccess: async () => { | ||
const { data: allowance } = await refetchAllowance(); | ||
if (allowance && allowance >= rawAmount) { | ||
updatePool({ step: step + 1 }); | ||
} | ||
}, | ||
}, | ||
); | ||
}; | ||
|
||
// auto move to next step if allowance is already enough | ||
useEffect(() => { | ||
if (allowance && allowance >= rawAmount) { | ||
updatePool({ step: step + 1 }); | ||
} | ||
}, [allowance, rawAmount, updatePool, step]); | ||
|
||
return ( | ||
<div> | ||
<TransactionButton | ||
title={`Approve ${token.symbol}`} | ||
isDisabled={isApprovePending} | ||
isPending={isApprovePending} | ||
onClick={handleApprove} | ||
/> | ||
{approveError && ( | ||
<div className="max-w-[500px] mt-4"> | ||
<Alert type="error">{approveError.message}</Alert> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.