Skip to content

Commit

Permalink
headless: pay w sol (#347)
Browse files Browse the repository at this point in the history
* save

* save

* save

* save

* save
  • Loading branch information
mPaella authored Feb 18, 2025
1 parent 7637941 commit 38903c9
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 152 deletions.
5 changes: 5 additions & 0 deletions typescript/.changeset/smooth-news-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@goat-sdk/plugin-crossmint-headless-checkout": patch
---

headless: pay w sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@goat-sdk/core": "workspace:*",
"@crossmint/common-sdk-base": "0.3.1",
"@crossmint/client-sdk-base": "1.4.6",
"@crossmint/common-sdk-base": "0.3.1",
"@goat-sdk/core": "workspace:*",
"@goat-sdk/wallet-evm": "workspace:*",
"@goat-sdk/wallet-solana": "workspace:*",
"@solana/web3.js": "catalog:",
"bs58": "^6.0.0",
"viem": "catalog:",
"zod": "catalog:"
},
"peerDependencies": {
"viem": "catalog:",
"@goat-sdk/core": "workspace:*"
"@goat-sdk/core": "workspace:*",
"viem": "catalog:"
},
"homepage": "https://ohmygoat.dev",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Crossmint, CrossmintApiClient, createCrossmint } from "@crossmint/common-sdk-base";
import { Chain, PluginBase, createTool } from "@goat-sdk/core";
import { z } from "zod";
import { type Crossmint, CrossmintApiClient, createCrossmint, isEVMBlockchain } from "@crossmint/common-sdk-base";
import { type Chain, PluginBase, createTool } from "@goat-sdk/core";
import type { z } from "zod";

import { EVMWalletClient } from "@goat-sdk/wallet-evm";
import { SolanaWalletClient } from "@goat-sdk/wallet-solana";

import { Order } from "@crossmint/client-sdk-base";
import type { Order } from "@crossmint/client-sdk-base";
import { Transaction } from "@solana/web3.js";
import base58 from "bs58";
import { parseTransaction } from "viem";
import packageJson from "../package.json";
import { getCreateAndPayOrderParameters } from "./parameters";
Expand Down Expand Up @@ -35,7 +38,7 @@ export class CrossmintHeadlessCheckoutPlugin extends PluginBase {
return true;
}

async getTools(walletClient: EVMWalletClient) {
async getTools(walletClient: EVMWalletClient | SolanaWalletClient) {
const superTools = await super.getTools(walletClient);
return [
...superTools,
Expand Down Expand Up @@ -96,20 +99,40 @@ export class CrossmintHeadlessCheckoutPlugin extends PluginBase {
);
}

const transaction = parseTransaction(serializedTransaction as `0x${string}`);
const paymentMethod = order.payment.method;

if (transaction.to == null) {
throw new Error("Transaction to is null");
if (paymentMethod === "solana") {
if (!(walletClient instanceof SolanaWalletClient)) {
throw new Error(
"Solana wallet client required. Use a solana wallet client, or change the payment method to one supported by your wallet client",
);
}
const transaction = Transaction.from(base58.decode(serializedTransaction));
const sendRes = await walletClient.sendTransaction({
instructions: transaction.instructions,
});
return { order, txId: sendRes.hash };
}
if (isEVMBlockchain(paymentMethod)) {
if (!(walletClient instanceof EVMWalletClient)) {
throw new Error(
"EVM wallet client required. Use an evm wallet client, or change the payment method to one supported by your wallet client",
);
}
const transaction = parseTransaction(serializedTransaction as `0x${string}`);
if (transaction.to == null) {
throw new Error("Transaction to is null");
}
console.log("Paying order:", order.orderId);
const sendRes = await walletClient.sendTransaction({
to: transaction.to,
value: transaction.value || 0n,
data: transaction.data,
});
return { order, txId: sendRes.hash };
}

console.log("Paying order:", order.orderId);

const sendRes = await walletClient.sendTransaction({
to: transaction.to,
value: transaction.value || 0n,
data: transaction.data,
});
return { order, txId: sendRes.hash };
throw new Error(`Unsupported payment method: ${paymentMethod}`);
},
),
];
Expand Down
Loading

0 comments on commit 38903c9

Please sign in to comment.