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