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
})
const handleConnect = async (walletType: WalletType): Promise<void> => {
const handleConnect = async (walletType: WalletType): Promise<void> => {
try {
const newWalletState = await connectWallet(walletType)
setWalletState(newWalletState)
@ -29,11 +29,13 @@ const Page: React.FC = (): React.ReactElement => {
}
}
const handleFluxGeneration = (modelId: string, cost: number) => {
return async (prompt: string): Promise<FluxGenerationResult> => {
if (!walletState.connected || !walletState.publicKey || !window.solflare) {
return { error: 'Wallet not connected' }
const type = walletState.type;
if (!walletState.connected || !walletState.publicKey ||
(type === 'phantom' && !window.phantom) ||
(type === 'solflare' && !window.solflare)) {
return { error: 'Wallet not connected' }
}
// Process payment first
@ -98,7 +100,6 @@ const Page: React.FC = (): React.ReactElement => {
<span className="text-orange-300 text-sm">TBD</span>
</div>
</div>
<div className="mt-6">
<button
disabled

View File

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