Use USDC prices in model map

This commit is contained in:
Adw8 2025-01-28 09:47:11 +05:30
parent fa6a88f297
commit 5d42d281a0
3 changed files with 16 additions and 5 deletions

View File

@ -43,7 +43,7 @@ const Page: React.FC = (): React.ReactElement => {
const handleFluxGeneration = (modelId: string, cost: number) => {
return async (prompt: string): Promise<FluxGenerationResult> => {
const type = walletState.type;
if (!walletState.connected || !walletState.publicKey ||
if (!walletState.connected || !walletState.publicKey || !walletState.type ||
(type === 'phantom' && !window.phantom) ||
(type === 'solflare' && !window.solflare)) {
return { error: 'Wallet not connected' }
@ -53,7 +53,7 @@ const Page: React.FC = (): React.ReactElement => {
const paymentResult = await processMTMPayment(
walletState.publicKey,
cost,
walletState.type
walletState.type
)
if (!paymentResult.success) {
@ -62,6 +62,10 @@ const Page: React.FC = (): React.ReactElement => {
const transactionSignature = paymentResult.transactionSignature;
if (!transactionSignature) {
return { error: 'Transaction signature not found' }
}
// Then generate image with specified model
return generateWithFlux(prompt, modelId, transactionSignature)
}

View File

@ -16,19 +16,19 @@ export const FLUX_MODELS: FluxModelConfig[] = [
modelId: "fal-ai/flux/schnell",
name: "Schnell",
description: "Fast meme generator",
cost: 300
cost: 0.1
},
{
modelId: "fal-ai/recraft-v3",
name: "Recraft",
description: "Advanced meme generator",
cost: 400
cost: 0.15
},
{
modelId: "fal-ai/stable-diffusion-v35-large",
name: "Marquee",
description: "Best meme generator",
cost: 500
cost: 0.2
}
]

View File

@ -1,3 +1,5 @@
import assert from 'assert';
import { Connection, PublicKey, Transaction } from '@solana/web3.js'
import {
TOKEN_PROGRAM_ID,
@ -5,8 +7,13 @@ import {
createAssociatedTokenAccountInstruction,
ASSOCIATED_TOKEN_PROGRAM_ID
} from '@solana/spl-token'
import { WalletType } from './types'
assert(process.env.NEXT_PUBLIC_SOLANA_RPC_URL, 'SOLANA_RPC_URL is required');
assert(process.env.NEXT_PUBLIC_MTM_TOKEN_MINT, 'MTM_TOKEN_MINT is required');
assert(process.env.NEXT_PUBLIC_PAYMENT_RECEIVER_ADDRESS, 'PAYMENT_RECEIVER_ADDRESS is required');
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;