Add check for phantom wallet before throwing error

This commit is contained in:
Adw8 2025-01-27 14:16:09 +05:30
parent 6c9c5a4063
commit 88242a90e6
6 changed files with 35 additions and 28 deletions

5
.env.example Normal file
View File

@ -0,0 +1,5 @@
FAL_AI_KEY=
REACT_APP_MTM_TOKEN_MINT=97RggLo3zV5kFGYW4yoQTxr4Xkz4Vg2WPHzNYXXWpump
REACT_APP_PAYMENT_RECEIVER_ADDRESS=3kKzrJ7KQ67bKZGffcutwK5797hqGA4dAreeBYuXCnad
REACT_APP_SOLANA_RPC_URL=https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4
REACT_APP_SOLANA_WEBSOCKET_URL=wss://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
node_modules
.next
.env

View File

@ -29,10 +29,12 @@ const Page: React.FC = (): React.ReactElement => {
} }
} }
const handleFluxGeneration = (modelId: string, cost: number) => { const handleFluxGeneration = (modelId: string, cost: number) => {
return async (prompt: string): Promise<FluxGenerationResult> => { return async (prompt: string): Promise<FluxGenerationResult> => {
if (!walletState.connected || !walletState.publicKey || !window.solflare) { const type = walletState.type;
if (!walletState.connected || !walletState.publicKey ||
(type === 'phantom' && !window.phantom) ||
(type === 'solflare' && !window.solflare)) {
return { error: 'Wallet not connected' } return { error: 'Wallet not connected' }
} }
@ -63,7 +65,6 @@ const Page: React.FC = (): React.ReactElement => {
<p className="text-gray-400 text-lg mb-8"> <p className="text-gray-400 text-lg mb-8">
Use MTM to generate memes Use MTM to generate memes
</p> </p>
<WalletHeader <WalletHeader
walletState={walletState} walletState={walletState}
onConnect={handleConnect} onConnect={handleConnect}
@ -82,7 +83,6 @@ const Page: React.FC = (): React.ReactElement => {
onGenerate={handleFluxGeneration(model.modelId, model.cost)} onGenerate={handleFluxGeneration(model.modelId, model.cost)}
/> />
))} ))}
{/* Coming Soon Card */} {/* Coming Soon Card */}
<div className="relative bg-gray-800/50 backdrop-blur-lg rounded-2xl shadow-xl border border-gray-700/50 overflow-hidden group"> <div className="relative bg-gray-800/50 backdrop-blur-lg rounded-2xl shadow-xl border border-gray-700/50 overflow-hidden group">
<div className="absolute inset-0 bg-gradient-to-br from-yellow-500/10 to-orange-500/10 opacity-50"></div> <div className="absolute inset-0 bg-gradient-to-br from-yellow-500/10 to-orange-500/10 opacity-50"></div>
@ -98,7 +98,6 @@ const Page: React.FC = (): React.ReactElement => {
<span className="text-orange-300 text-sm">TBD</span> <span className="text-orange-300 text-sm">TBD</span>
</div> </div>
</div> </div>
<div className="mt-6"> <div className="mt-6">
<button <button
disabled disabled

View File

@ -2,16 +2,15 @@ import { Connection, PublicKey, Transaction, SystemProgram } from '@solana/web3.
import { import {
TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID,
createTransferInstruction, createTransferInstruction,
getAssociatedTokenAddress,
createAssociatedTokenAccountInstruction, createAssociatedTokenAccountInstruction,
ASSOCIATED_TOKEN_PROGRAM_ID ASSOCIATED_TOKEN_PROGRAM_ID
} from '@solana/spl-token' } from '@solana/spl-token'
import { WalletType } from './types' import { WalletType } from './types'
const MTM_TOKEN_MINT: string = '97RggLo3zV5kFGYW4yoQTxr4Xkz4Vg2WPHzNYXXWpump' const MTM_TOKEN_MINT = process.env.REACT_APP_MTM_TOKEN_MINT;
const PAYMENT_RECEIVER_ADDRESS: string = 'FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY' const PAYMENT_RECEIVER_ADDRESS = process.env.REACT_APP_PAYMENT_RECEIVER_ADDRESS;
const SOLANA_RPC_URL: string = 'https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4' const SOLANA_RPC_URL = process.env.REACT_APP_SOLANA_RPC_URL;
const SOLANA_WEBSOCKET_URL: string = 'wss://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4' const SOLANA_WEBSOCKET_URL = process.env.REACT_APP_SOLANA_WEBSOCKET_URL;
const connection = new Connection( const connection = new Connection(
SOLANA_RPC_URL, SOLANA_RPC_URL,