Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions account-kit/react/src/hooks/useSolanaTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export interface SolanaTransaction {
readonly isPending: boolean;
/** The error that occurred */
readonly error: Error | null;
/** The signers that can be used to sign the transaction */
signers: Record<string, PreSend>;
/** The map of transform instructions that can be used to transform the instructions */
mapTransformInstructions: Record<string, TransformInstruction>;
reset(): void;
/** Send the transaction */
sendTransaction(params: SolanaTransactionParams): void;
Expand Down Expand Up @@ -124,7 +120,7 @@ export function useSolanaTransaction(
const mutation = useMutation({
mutationFn: async ({
transactionComponents: {
preSend = signers.fromSigner,
preSend,
transformInstruction = mapTransformInstructions.default,
} = {},
...params
Expand All @@ -144,7 +140,16 @@ export function useSolanaTransaction(
let transaction: VersionedTransaction | Transaction =
await transformInstruction(instructions);

transaction = await preSend(transaction);
transaction = (await preSend?.(transaction)) || transaction;

if (
"message" in transaction &&
transaction.message.staticAccountKeys.find(
(key) => key.toBase58() === signer?.address
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should also check that transaction.message.isSigner(idx) is true

) {
await signer?.addSignature(transaction);
}

const hash = await solanaNetwork.broadcast(
connection || missing("connection"),
Expand All @@ -154,12 +159,6 @@ export function useSolanaTransaction(
},
...opts.mutation,
});
const signers: Record<string, PreSend> = {
async fromSigner(t) {
await signer?.addSignature(t);
return t;
},
};
const signer: null | SolanaSigner = opts?.signer || fallbackSigner;
const connection = opts?.connection || backupConnection?.connection || null;
const policyId =
Expand Down Expand Up @@ -188,8 +187,6 @@ export function useSolanaTransaction(
return {
connection,
signer,
signers,
mapTransformInstructions,
...mutation,
sendTransaction: mutation.mutate,
sendTransactionAsync: mutation.mutateAsync,
Expand Down
4 changes: 2 additions & 2 deletions examples/ui-demo/src/components/small-cards/SolanaNftCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
LAMPORTS_PER_SOL,
PublicKey,
SystemProgram,
TransactionInstruction,

Check warning on line 9 in examples/ui-demo/src/components/small-cards/SolanaNftCard.tsx

View workflow job for this annotation

GitHub Actions / Lint

'TransactionInstruction' is defined but never used
} from "@solana/web3.js";
import { sol } from "@metaplex-foundation/umi";
import {
Expand Down Expand Up @@ -54,7 +55,6 @@
isPending,
connection,
signer: solanaSigner,
signers,
} = useSolanaTransaction();
const [transactionState, setTransactionState] =
useState<TransactionState>("idle");
Expand Down Expand Up @@ -104,7 +104,7 @@
if ("version" in transaction) {
transaction.sign([stakeAccount]);
}
return signers.fromSigner(transaction);
return transaction;
},
},
instructions: [
Expand Down
Loading