From 33da8bf22c8cea7ae0e17aae9ba256f07bcbf13e Mon Sep 17 00:00:00 2001 From: MarcoMandar Date: Fri, 9 May 2025 13:31:37 +0300 Subject: [PATCH 1/3] initial Signed-off-by: MarcoMandar --- .../src/components/token-sections/admin.tsx | 2 +- packages/client/src/hooks/use-create-token.ts | 12 +- packages/client/src/pages/create.tsx | 3495 +++-------------- packages/server/src/routes/token.ts | 62 +- packages/server/src/util.ts | 68 +- 5 files changed, 723 insertions(+), 2916 deletions(-) diff --git a/packages/client/src/components/token-sections/admin.tsx b/packages/client/src/components/token-sections/admin.tsx index 7c1e8b5ce..346ccd7b6 100644 --- a/packages/client/src/components/token-sections/admin.tsx +++ b/packages/client/src/components/token-sections/admin.tsx @@ -1,4 +1,4 @@ -import { FormInput } from "@/pages/create"; +import { FormInput } from "@/create/forms/FormInput"; import { isFromDomain } from "@/utils"; import { fetcher } from "@/utils/api"; import { env } from "@/utils/env"; diff --git a/packages/client/src/hooks/use-create-token.ts b/packages/client/src/hooks/use-create-token.ts index 9341dccc6..a5d89b3b0 100644 --- a/packages/client/src/hooks/use-create-token.ts +++ b/packages/client/src/hooks/use-create-token.ts @@ -1,6 +1,8 @@ -import { TokenMetadata } from "@/types/form.type"; +import { TokenMetadata } from "@/create/types"; import { env } from "@/utils/env"; -import { Autofun, SEED_CONFIG, useProgram } from "@/utils/program"; +import { SEED_CONFIG, useProgram } from "@/utils/program"; +import { Autofun } from "@autodotfun/types/types/autofun.ts"; + import { launchAndSwapTx } from "@/utils/swapUtils"; import { BN, Program } from "@coral-xyz/anchor"; import { useConnection, useWallet } from "@solana/wallet-adapter-react"; @@ -127,7 +129,11 @@ const useCreateTokenMutation = () => { "confirmed", ); - return { mintPublicKey: mintKeypair.publicKey, userPublicKey }; + return { + mintPublicKey: mintKeypair.publicKey, + userPublicKey, + signature: txId + }; }, }); }; diff --git a/packages/client/src/pages/create.tsx b/packages/client/src/pages/create.tsx index c7ce4cb4a..56c0f8ca0 100644 --- a/packages/client/src/pages/create.tsx +++ b/packages/client/src/pages/create.tsx @@ -1,694 +1,37 @@ -import { EmptyState } from "@/components/empty-state"; +import { AutoTabContent } from "@/create/components/AutoTabContent"; +import { CreationLoadingModal } from "@/create/components/CreationLoadingModal"; +import { FormSection } from "@/create/components/FormSection"; +import { ImportTabContent } from "@/create/components/ImportTabContent"; +import { TabNavigation } from "@/create/components/TabNavigation"; +import { MAX_INITIAL_SOL, TAB_STATE_KEY } from "@/create/consts"; +import { useWallet } from "@/create/hooks/useWallet"; +import { + FormTab, + PreGeneratedTokenResponse, + TokenMetadata, + TokenSearchData, + UploadImportImageResponse, +} from "@/create/types"; +import { isValidTokenAddress } from "@/create/validators"; + +import { useImageUpload } from "@/create/hooks/useImageUpload"; +import { useTokenCreation } from "@/create/hooks/useTokenCreation"; +import { useTokenForm } from "@/create/hooks/useTokenForm"; +import { useTokenGeneration } from "@/create/hooks/useTokenGeneration"; +import { useVanityAddress } from "@/create/hooks/useVanityAddress"; import useAuthentication from "@/hooks/use-authentication"; -import { useCreateToken } from "@/hooks/use-create-token"; import { useSolBalance } from "@/hooks/use-token-balance"; -import { HomepageTokenSchema } from "@/hooks/use-tokens"; import { getAuthToken } from "@/utils/auth"; -import { env, isDevnet } from "@/utils/env"; -import { getSocket } from "@/utils/socket"; -import { useConnection, useWallet } from "@solana/wallet-adapter-react"; -import { Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js"; +import { env } from "@/utils/env"; +import { useConnection } from "@solana/wallet-adapter-react"; +import { LAMPORTS_PER_SOL } from "@solana/web3.js"; import { useCallback, useEffect, useRef, useState } from "react"; -import { useNavigate } from "react-router"; +import { useNavigate } from "react-router-dom"; import { toast } from "react-toastify"; -import { Icons } from "../components/icons"; -import { TokenMetadata } from "../types/form.type"; -// Import the worker using Vite's ?worker syntax -import InlineVanityWorker from "@/workers/vanityWorker?worker&inline"; // Added import - -const MAX_INITIAL_SOL = isDevnet ? 2.8 : 28; -// Use the token supply and virtual reserves from environment or fallback to defaults -const TOKEN_SUPPLY = Number(env.tokenSupply) || 1000000000; -const VIRTUAL_RESERVES = Number(env.virtualReserves) || 100; - -// Tab types -enum FormTab { - AUTO = "auto", - MANUAL = "manual", - IMPORT = "import", -} - -// LocalStorage key for tab state -const TAB_STATE_KEY = "auto_fun_active_tab"; - -interface UploadResponse { - success: boolean; - imageUrl: string; - metadataUrl: string; -} - -interface GenerateImageResponse { - success: boolean; - mediaUrl: string; - remainingGenerations: number; - resetTime: string; -} - -interface PreGeneratedTokenResponse { - success: boolean; - token: { - id: string; - name: string; - ticker: string; - description: string; - prompt: string; - image?: string; - createdAt: string; - used: number; - }; -} - -interface GenerateMetadataResponse { - success: boolean; - metadata: { - name: string; - symbol: string; - description: string; - prompt: string; - }; -} - -interface UploadImportImageResponse { - success: boolean; - imageUrl: string; -} - -// Define tokenData interface -interface TokenSearchData { - name?: string; - symbol?: string; - description?: string; - creator?: string; - creators?: string[]; - image?: string; - mint: string; - twitter?: string; - telegram?: string; - website?: string; - discord?: string; - metadataUri?: string; - isCreator?: boolean; - updateAuthority?: string; -} - -// Vanity Generator Types (Copied from testing.tsx) -type VanityResult = { - publicKey: string; - secretKey: Keypair; // Store the Keypair object directly -}; -type WorkerMessage = - | { - type: "found"; - workerId: number; - publicKey: string; - secretKey: number[]; // Worker sends array - validated: boolean; - } - | { type: "progress"; workerId: number; count: number } - | { type: "error"; workerId: number; error: string }; - -// Base58 characters -const BASE58_REGEX = /^[1-9A-HJ-NP-Za-km-z]+$/; - -// Form Components -export const FormInput = ({ - label, - isOptional, - error, - leftIndicator, - rightIndicator, - inputTag, - onClick, - isLoading, - ...props -}: { - label?: string; - isOptional?: boolean; - error?: string; - leftIndicator?: React.ReactNode; - rightIndicator?: React.ReactNode; - inputTag?: React.ReactNode; - onClick?: () => void; - isLoading?: boolean; - [key: string]: any; -}) => { - return ( -
-
- {label && ( -
- {label} -
- )} -
-
- {inputTag && ( -
- {inputTag} -
- )} - {leftIndicator && ( -
{leftIndicator}
- )} - - {rightIndicator && ( -
- {rightIndicator} -
- )} -
- {error &&
{error}
} -
- ); -}; - -const FormTextArea = ({ - label, - rightIndicator, - minRows = 3, - maxLength, - onClick, - isLoading, - ...props -}: { - label?: string; - rightIndicator?: React.ReactNode; - minRows?: number; - maxLength?: number; - onClick?: () => void; - isLoading?: boolean; - [key: string]: any; -}) => { - return ( -
-
- {isLoading && ( -
- )} -
-
-