Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Oct 15, 2024
1 parent b1cc579 commit 3e16ef9
Show file tree
Hide file tree
Showing 18 changed files with 916 additions and 581 deletions.
129 changes: 63 additions & 66 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -1,67 +1,64 @@

You are an expert in Solidity, TypeScript, Node.js, Next.js 14 App Router, React, Vite, Viem v2, Wagmi v2, Shadcn UI, Radix UI, and Tailwind Aria.

Key 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: Avoid using try/catch for expected errors in Server Actions. Use useActionState to manage these errors and return them to the client.
- Use error boundaries for unexpected errors: Implement error boundaries using error.tsx and global-error.tsx files to handle unexpected errors and provide a fallback UI.
- 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.
- 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. Rely on Next.js App Router for state changes.
2. Prioritize Web Vitals (LCP, CLS, FID).
3. 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.

Key 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.

RainbowKit v2 & Wagmi Integration
- Setup RainbowKit v2 with Wagmi v2 using `configureChains` and `createClient` from Wagmi.
- Initialize chains and providers within a `RainbowKitProvider` wrapper.
- Store mnemonics in `expo-secure-store` or other secure storage solutions.
- Use React hooks like `useAccount`, `useConnect`, `useDisconnect` from Wagmi for wallet actions.
- Favor the use of hooks over directly accessing global state.

tRPC v11 Integration
- Use `@trpc/react-query` and define tRPC routers on the server.
- Set up queries and mutations using `trpc.useQuery` and `trpc.useMutation` on the client.
- Use Zod for input validation at both client and server levels.
- Handle optimistic updates in React Query using the `onMutate` and `onSuccess` methods.
- For error handling, ensure tRPC procedures return a consistent error structure.

Key Conventions
1. Rely on Next.js App Router for state changes.
2. Prioritize Web Vitals (LCP, CLS, FID).
3. 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.
12 changes: 6 additions & 6 deletions src/components/contract/ContractFunctions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import {
useWaitForTransactionReceipt,
useWriteContract,
} from "wagmi";
import { Button } from "~/components/ui/button";
import { Input } from "~/components/ui/input";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "../ui/accordion";
import { Label } from "../ui/label";
import { SearchInput } from "../ui/search-input";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
} from "~/components/ui/accordion";
import { Button } from "~/components/ui/button";
import { Input } from "~/components/ui/input";
import { Label } from "~/components/ui/label";
import { SearchInput } from "~/components/ui/search-input";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs";

interface ContractFunctionsProps {
abi: Abi;
Expand Down
71 changes: 71 additions & 0 deletions src/components/deploy-status.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { AlertCircle, CheckIcon } from "lucide-react";
import { Loading } from "./loading";

interface StatusStep {
message: string;
status: "success" | "error" | "loading";
error?: string;
details?: string;
}

interface StatusDisplayProps {
title: string;
steps: StatusStep[];
}

function StatusDisplay({ title, steps }: StatusDisplayProps) {
return (
<div className="p-6">
<h1 className="text-2xl font-bold mb-4 text-center">{title}</h1>
<div className="space-y-1">
{steps.length > 0 ? (
steps.map((step, index) => (
<StatusStep
key={index}
step={step}
isLatest={index === steps.length - 1}
/>
))
) : (
<Loading />
)}
</div>
</div>
);
}

function StatusStep({
step,
isLatest,
}: {
step: StatusStep;
isLatest: boolean;
}) {
const statusIcons = {
success: <CheckIcon className="h-6 w-6 text-green-500" />,
error: <AlertCircle className="h-6 w-6 text-red-500" />,
loading: isLatest ? <Loading /> : null,
};

return (
<div
className={`px-4 py-0 rounded-lg flex items-center space-x-4 transition-opacity duration-500 ease-in-out transform-gpu ${
!isLatest ? "opacity-30" : ""
}`}
style={{ animation: "fadeIn 0.5s" }}
>
{statusIcons[step.status]}
<div>
<p className="font-medium">{step.message}</p>
{step.status === "error" && (
<p className="text-red-500">{step.error}</p>
)}
{step.status === "success" && step.details && (
<p className="text-green-500">{step.details}</p>
)}
</div>
</div>
);
}

export default StatusDisplay;
28 changes: 22 additions & 6 deletions src/components/dialogs/send-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "wagmi";
import { useAuth } from "~/hooks/useAuth";
import { useDebounce } from "~/hooks/useDebounce";
import { trpc } from "~/lib/trpc";
import { cn } from "~/lib/utils";
import { toUserUnits, toUserUnitsString } from "~/utils/units";
import { AddressField } from "../forms/fields/address-field";
Expand All @@ -37,7 +38,6 @@ import {
FormMessage,
} from "../ui/form";
import { Input } from "../ui/input";
import { trpc } from "~/lib/trpc";

const FormSchema = z.object({
voucherAddress: z.string().refine(isAddress, "Invalid voucher address"),
Expand Down Expand Up @@ -83,14 +83,33 @@ const SendForm = (props: {
const debouncedAmount = useDebounce(amount, 500);
const debouncedRecipientAddress = useDebounce(recipientAddress, 500);
const { data: voucherDetails } = useVoucherDetails(voucherAddress);
console.log({
address: voucherAddress,
functionName: "transfer",
args: [
debouncedRecipientAddress,
parseUnits(debouncedAmount?.toString() ?? "", voucherDetails?.decimals ?? 0),
],
query: {
enabled: Boolean(
voucherDetails?.decimals &&
debouncedAmount &&
debouncedRecipientAddress &&
voucherAddress &&
isValid
),
},
gas: 350_000n,
maxFeePerGas: parseGwei("10"),
maxPriorityFeePerGas: 5n,
});
const simulateContract = useSimulateContract({
address: voucherAddress,
abi: erc20Abi,
functionName: "transfer",
args: [
debouncedRecipientAddress,
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
parseUnits(debouncedAmount?.toString() ?? "", voucherDetails?.decimals!),
parseUnits(debouncedAmount?.toString() ?? "", voucherDetails?.decimals),
],
query: {
enabled: Boolean(
Expand Down Expand Up @@ -244,11 +263,8 @@ const SendForm = (props: {
};

export const SendDialog = (props: SendDialogProps) => {
const [open, setOpen] = useState(false);
return (
<ResponsiveModal
open={open}
onOpenChange={setOpen}
button={props.button ?? <PaperPlaneIcon className="m-1" />}
title="Send Voucher"
>
Expand Down
7 changes: 4 additions & 3 deletions src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DrawerTitle,
DrawerTrigger,
} from "./ui/drawer";
import { ScrollArea } from "./ui/scroll-area";

type PopoverProps = ControlledPopoverProps | UnControlledPopoverProps;

Expand Down Expand Up @@ -48,21 +49,21 @@ export const Modal = (props: PopoverProps) => {
</DialogContent>
</Dialog>
);
};
};
export const BottomDrawer = (props: PopoverProps) => {
return (
<Drawer
open={props.open}
onOpenChange={props.onOpenChange}
dismissible={false}
dismissible={true}
>
<DrawerTrigger asChild>{props.button}</DrawerTrigger>
<DrawerContent className="p-2">
<DrawerHeader className="text-left">
<DrawerTitle>{props.title}</DrawerTitle>
<DrawerDescription>{props.description}</DrawerDescription>
</DrawerHeader>
{props.children}
<ScrollArea className="overflow-y-auto">{props.children}</ScrollArea>
</DrawerContent>
</Drawer>
);
Expand Down
56 changes: 0 additions & 56 deletions src/components/pools/create-pool-status.tsx

This file was deleted.

Loading

0 comments on commit 3e16ef9

Please sign in to comment.