Add check for phantom wallet before throwing error #1

Merged
nabarun merged 2 commits from ag-phantom-support into main 2025-01-27 09:46:41 +00:00
6 changed files with 38 additions and 28 deletions

6
.env.example Normal file
View File

@ -0,0 +1,6 @@
FAL_AI_KEY=
NEXT_PUBLIC_MTM_TOKEN_MINT=97RggLo3zV5kFGYW4yoQTxr4Xkz4Vg2WPHzNYXXWpump
NEXT_PUBLIC_PAYMENT_RECEIVER_ADDRESS=FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY
NEXT_PUBLIC_SOLANA_RPC_URL=https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4
NEXT_PUBLIC_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

@ -15,7 +15,7 @@ const Page: React.FC = (): React.ReactElement => {
type: null type: null
}) })
const handleConnect = async (walletType: WalletType): Promise<void> => { const handleConnect = async (walletType: WalletType): Promise<void> => {
try { try {
const newWalletState = await connectWallet(walletType) const newWalletState = await connectWallet(walletType)
setWalletState(newWalletState) setWalletState(newWalletState)
@ -29,11 +29,13 @@ 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;
return { error: 'Wallet not connected' } if (!walletState.connected || !walletState.publicKey ||
(type === 'phantom' && !window.phantom) ||
(type === 'solflare' && !window.solflare)) {
return { error: 'Wallet not connected' }
} }
// Process payment first // Process payment first
@ -98,7 +100,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.NEXT_PUBLIC_MTM_TOKEN_MINT;
const PAYMENT_RECEIVER_ADDRESS: string = 'FFDx3SdAEeXrp6BTmStB4BDHpctGsaasZq4FFcowRobY' const PAYMENT_RECEIVER_ADDRESS = process.env.NEXT_PUBLIC_PAYMENT_RECEIVER_ADDRESS;
const SOLANA_RPC_URL: string = 'https://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4' const SOLANA_RPC_URL = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;
const SOLANA_WEBSOCKET_URL: string = 'wss://young-radial-orb.solana-mainnet.quiknode.pro/67612b364664616c29514e551bf5de38447ca3d4' const SOLANA_WEBSOCKET_URL = process.env.NEXT_PUBLIC_SOLANA_WEBSOCKET_URL;
const connection = new Connection( const connection = new Connection(
SOLANA_RPC_URL, SOLANA_RPC_URL,