diff --git a/src/components/payments/SolanaPay.vue b/src/components/payments/SolanaPay.vue index ca6a1c3e..0de7cb6c 100644 --- a/src/components/payments/SolanaPay.vue +++ b/src/components/payments/SolanaPay.vue @@ -90,23 +90,15 @@ onMounted(async () => { invalidLink.value = "Invalid Link"; } else if (isUrl(requestLink)) { // request link is an url. fetch transaction from url - const result = await parseSolanaPayRequestLink(requestLink, ControllerModule.selectedAddress, ControllerModule.connection); - if (result.transaction.feePayer && result.transaction.recentBlockhash) { - const messageV0 = new TransactionMessage({ - payerKey: result.transaction.feePayer, - instructions: result.transaction.instructions, - recentBlockhash: result.transaction.recentBlockhash, - }).compileToV0Message(); - log.info(result); - transaction.value = new VersionedTransaction(messageV0); - linkParams.value = { - icon: result.icon, - label: result.label, - origin: result.link.origin, - decodedInst: result.decodedInst, - message: result.message || "", - }; - } + const result = await parseSolanaPayRequestLink(requestLink, ControllerModule.selectedAddress); + transaction.value = result.transaction; + linkParams.value = { + icon: result.icon, + label: result.label, + origin: result.link.origin, + decodedInst: result.decodedInst, + message: result.message || "", + }; } else { // check for publickey format, redirect to transfer page try { diff --git a/src/utils/solanaHelpers.ts b/src/utils/solanaHelpers.ts index bddae629..17293698 100644 --- a/src/utils/solanaHelpers.ts +++ b/src/utils/solanaHelpers.ts @@ -19,7 +19,6 @@ import { SimulatedTransactionResponse, SystemInstruction, SystemProgram, - Transaction, TransactionInstruction, TransactionMessage, VersionedMessage, @@ -359,7 +358,7 @@ export async function getEstimateBalanceChange(connection: Connection, tx: Versi // Simulate Transaction with Accounts const instructionAddresses = Array.from(accounts.keys()); const addresses = lookupAddresses?.length ? lookupAddresses : instructionAddresses; - const result = await connection.simulateTransaction(tx, { accounts: { addresses, encoding: "base64" } }); + const result = await connection.simulateTransaction(tx, { accounts: { addresses, encoding: "base64" }, commitment: "confirmed" }); if (result.value.err) { throw new Error(result.value.err.toString()); @@ -435,17 +434,17 @@ export async function parsingTransferAmount( } // SolanaPay -export const validateUrlTransactionSignature = (transaction: Transaction, selectedAddress: string) => { - let signRequired = false; - transaction.signatures.forEach((sig) => { - if (sig.signature === null && sig.publicKey.toBase58() !== selectedAddress) throw new Error("Merchant Signature Verifcation Failed"); - signRequired = signRequired || sig.publicKey.toBase58() === selectedAddress; - }); - if (!signRequired) throw new Error("Wallet Signature Not Required"); - transaction.serialize({ requireAllSignatures: false }); -}; - -export const parseSolanaPayRequestLink = async (request: string, account: string, connection: Connection) => { +// export const validateUrlTransactionSignature = (transaction: VersionedTransaction, selectedAddress: string) => { +// let signRequired = false; +// transaction.signatures.forEach((sig) => { +// if (signature === null && sig.publicKey.toBase58() !== selectedAddress) throw new Error("Merchant Signature Verifcation Failed"); +// signRequired = signRequired || sig.publicKey.toBase58() === selectedAddress; +// }); +// if (!signRequired) throw new Error("Wallet Signature Not Required"); +// transaction.serialize({ requireAllSignatures: false }); +// }; + +export const parseSolanaPayRequestLink = async (request: string, account: string) => { log.info(request); const { label, message, link } = parseURL(request) as TransactionRequestURL; // get link @@ -457,19 +456,22 @@ export const parseSolanaPayRequestLink = async (request: string, account: string // return {"transaction":""} (base64) const postResult = await post<{ transaction: string; message?: string }>(link.toString(), { account }); - const transaction = Transaction.from(Buffer.from(postResult.transaction, "base64")); - const decodedInst = transaction.instructions.map((inst) => decodeInstruction(inst)); + // const transaction = Transaction.from(Buffer.from(postResult.transaction, "base64")); + const transaction = VersionedTransaction.deserialize(Buffer.from(postResult.transaction, "base64")); + const { instructions } = TransactionMessage.decompile(transaction.message); + const decodedInst = instructions.map((inst) => decodeInstruction(inst)); + // assign transaction object - if (transaction.signatures.length === 0) { - log.info("empty signature"); - transaction.feePayer = new PublicKey(account); - const block = await connection.getLatestBlockhash(); - transaction.lastValidBlockHeight = block.lastValidBlockHeight; - transaction.recentBlockhash = block.blockhash; - } else { - validateUrlTransactionSignature(transaction, account); - } + // if (transaction.signatures.length === 0) { + // log.info("empty signature"); + // transaction.feePayer = new PublicKey(account); + // const block = await connection.getLatestBlockhash(); + // transaction.lastValidBlockHeight = block.lastValidBlockHeight; + // transaction.recentBlockhash = block.blockhash; + // } else { + // validateUrlTransactionSignature(transaction, account); + // } return { transaction, decodedInst, message: message || postResult.message, label: label || getResult.label, icon: getResult.icon, link }; };