diff --git a/src/app/page.tsx b/src/app/page.tsx index 669ccfa..b99a21a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -10,14 +10,17 @@ import { processMTMPayment } from '../services/paymentService' import { connectWallet, WalletState } from '../services/walletService' import { WalletType } from '../services/types' +const FREE_MODE = process.env.NEXT_PUBLIC_FREE_MODE === 'true' + const Page: React.FC = (): React.ReactElement => { const [walletState, setWalletState] = useState({ - connected: false, + connected: FREE_MODE ? true : false, // Always "connected" in free mode publicKey: null, type: null }) const handleConnect = async (walletType: WalletType): Promise => { + if (FREE_MODE) return try { const newWalletState = await connectWallet(walletType) setWalletState(newWalletState) @@ -33,19 +36,22 @@ const Page: React.FC = (): React.ReactElement => { const handleImageAnalysis = (cost: number) => { return async (imageFile: File): Promise => { - if (!walletState.connected || !walletState.publicKey || !walletState.type) { + // In free mode, skip wallet checks and payment + if (!FREE_MODE && (!walletState.connected || !walletState.publicKey || !walletState.type)) { return { error: 'Wallet not connected' } } - // Process payment first - const paymentResult = await processMTMPayment( - walletState.publicKey, - cost, - walletState.type - ) + // Only process payment if not in free mode + if (!FREE_MODE) { + const paymentResult = await processMTMPayment( + walletState.publicKey!, + cost, + walletState.type! + ) - if (!paymentResult.success) { - return { error: paymentResult.error } + if (!paymentResult.success) { + return { error: paymentResult.error } + } } // Then analyze the image @@ -66,11 +72,13 @@ const Page: React.FC = (): React.ReactElement => {

Go outside and touch grass

- + + {!FREE_MODE && ( + )} {/* Single Analysis Card */} diff --git a/src/components/ImageAnalysisCard.tsx b/src/components/ImageAnalysisCard.tsx index edd35a7..94ffa01 100644 --- a/src/components/ImageAnalysisCard.tsx +++ b/src/components/ImageAnalysisCard.tsx @@ -1,8 +1,11 @@ +// src/components/ImageAnalysisCard.tsx 'use client' import React, { useState, useRef } from 'react' import { Leaf } from 'lucide-react' +const FREE_MODE = process.env.NEXT_PUBLIC_FREE_MODE === 'true' + interface ImageAnalysisCardProps { title: string description: string @@ -48,7 +51,7 @@ const ImageAnalysisCard: React.FC = ({ const handleAnalyze = async () => { const file = fileInputRef.current?.files?.[0] - if (!file || !isWalletConnected) return + if (!file || (!FREE_MODE && !isWalletConnected)) return setAnalysisState({ ...analysisState, @@ -88,7 +91,7 @@ const ImageAnalysisCard: React.FC = ({ } return ( -
+
@@ -98,9 +101,11 @@ const ImageAnalysisCard: React.FC = ({

{description}

-
- Cost: {tokenCost} MTM -
+ {!FREE_MODE && ( +
+ Cost: {tokenCost} MTM +
+ )}
@@ -115,7 +120,7 @@ const ImageAnalysisCard: React.FC = ({ type="file" accept="image/*" onChange={handleFileSelect} - disabled={!isWalletConnected} + disabled={!FREE_MODE && !isWalletConnected} className="absolute inset-0 w-full h-full opacity-0 cursor-pointer disabled:cursor-not-allowed" /> @@ -136,13 +141,13 @@ const ImageAnalysisCard: React.FC = ({
@@ -152,19 +157,12 @@ const ImageAnalysisCard: React.FC = ({
)} - {analysisState.description && ( -
- {analysisState.description.split('\n\n').map((paragraph, index) => ( -

- {paragraph} -

- ))} + {analysisState.description && ( +
+

{analysisState.description}

)} -
+
) }