phatom fix
This commit is contained in:
parent
5e10e2ebc7
commit
6c9c5a4063
@ -8,7 +8,6 @@ import {
|
||||
} from '@solana/spl-token'
|
||||
import { WalletType } from './types'
|
||||
|
||||
// Constants remain the same
|
||||
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'
|
||||
@ -42,13 +41,24 @@ async function findAssociatedTokenAddress(
|
||||
)[0]
|
||||
}
|
||||
|
||||
interface WalletAdapter {
|
||||
signAndSendTransaction(transaction: Transaction): Promise<{ signature: string }>
|
||||
}
|
||||
|
||||
export async function processMTMPayment(
|
||||
walletPublicKey: string,
|
||||
tokenAmount: number,
|
||||
walletType: WalletType
|
||||
): Promise<PaymentResult> {
|
||||
try {
|
||||
const wallet = window[walletType === 'phantom' ? 'phantom.solana' : 'solflare']
|
||||
let wallet: WalletAdapter | null = null;
|
||||
|
||||
if (walletType === 'phantom') {
|
||||
wallet = window.phantom?.solana || null;
|
||||
} else if (walletType === 'solflare') {
|
||||
wallet = window.solflare || null;
|
||||
}
|
||||
|
||||
if (!wallet) {
|
||||
throw new Error(`${walletType} wallet not found`)
|
||||
}
|
||||
@ -63,7 +73,6 @@ export async function processMTMPayment(
|
||||
receiver: receiverPublicKey.toBase58(),
|
||||
})
|
||||
|
||||
// Find ATAs
|
||||
const senderATA = await findAssociatedTokenAddress(
|
||||
senderPublicKey,
|
||||
mintPublicKey
|
||||
@ -81,13 +90,11 @@ export async function processMTMPayment(
|
||||
|
||||
const transaction = new Transaction()
|
||||
|
||||
// Check if accounts exist
|
||||
const [senderATAInfo, receiverATAInfo] = await Promise.all([
|
||||
connection.getAccountInfo(senderATA),
|
||||
connection.getAccountInfo(receiverATA),
|
||||
])
|
||||
|
||||
// Create ATAs if they don't exist
|
||||
if (!receiverATAInfo) {
|
||||
console.log('Creating receiver token account')
|
||||
transaction.add(
|
||||
@ -112,7 +119,6 @@ export async function processMTMPayment(
|
||||
)
|
||||
}
|
||||
|
||||
// Add transfer instruction
|
||||
transaction.add(
|
||||
createTransferInstruction(
|
||||
senderATA,
|
||||
@ -150,4 +156,3 @@ export async function processMTMPayment(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user