11import type {
22 Address ,
3- AddressesByLookupTableAddress ,
43 Instruction ,
54 Signature ,
5+ SignatureBytes ,
66 TransactionSendingSigner ,
7- TransactionSigner ,
87} from "@solana/kit" ;
98import {
109 compressTransactionMessageUsingAddressLookupTables ,
@@ -16,17 +15,7 @@ import type { GetExplorerLinkFunction } from "../../contexts/grill-context.js";
1615import type { TransactionStatusEvent } from "../../types.js" ;
1716import { getSignatureFromBytes } from "../get-signature-from-bytes.js" ;
1817import { pollConfirmTransaction } from "../poll-confirm-transaction.js" ;
19-
20- export interface SendTXOptions {
21- luts ?: AddressesByLookupTableAddress ;
22- signers ?: TransactionSigner [ ] ;
23- }
24-
25- export type SendTXFunction = (
26- name : string ,
27- ixs : readonly Instruction [ ] ,
28- options ?: SendTXOptions ,
29- ) => Promise < Signature > ;
18+ import type { SendTXFunction , SendTXOptions } from "../types.js" ;
3019
3120export interface CreateSendTXParams {
3221 signer : TransactionSendingSigner | null ;
@@ -77,13 +66,18 @@ export const createSendTX = ({
7766 instructions : [ ...ixs ] ,
7867 latestBlockhash,
7968 // the compute budget values are HIGHLY recommend to be set in order to maximize your transaction landing rate
80- // TODO(igm): make this configurable and/or dynamic based on the instructions
81- computeUnitLimit : 1_400_000 ,
82- computeUnitPrice : 100_000n ,
69+ computeUnitLimit :
70+ options . computeUnitLimit === null
71+ ? undefined
72+ : ( options . computeUnitLimit ?? 1_400_000 ) ,
73+ computeUnitPrice :
74+ options . computeUnitPrice === null
75+ ? undefined
76+ : ( options . computeUnitPrice ?? 100_000n ) ,
8377 } ) ;
8478
8579 // Apply address lookup tables if provided to compress the transaction
86- const addressLookupTables = options . luts ?? { } ;
80+ const addressLookupTables = options . lookupTables ?? { } ;
8781 const finalTransactionMessage =
8882 Object . keys ( addressLookupTables ) . length > 0
8983 ? compressTransactionMessageUsingAddressLookupTables (
@@ -98,9 +92,22 @@ export const createSendTX = ({
9892 } ) ;
9993
10094 // Send transaction using wallet adapter
101- const sigBytes = await signAndSendTransactionMessageWithSigners (
102- finalTransactionMessage ,
103- ) ;
95+ let sigBytes : SignatureBytes ;
96+ try {
97+ sigBytes = await signAndSendTransactionMessageWithSigners (
98+ finalTransactionMessage ,
99+ ) ;
100+ } catch ( error : unknown ) {
101+ const errorMessage =
102+ error instanceof Error ? error . message : "Failed to send transaction" ;
103+ onTransactionStatusEvent ( {
104+ ...baseEvent ,
105+ type : "error-transaction-send-failed" ,
106+ errorMessage,
107+ } ) ;
108+ throw error ;
109+ }
110+
104111 const sig = getSignatureFromBytes ( sigBytes ) ;
105112 const sentTxEvent = {
106113 ...baseEvent ,
@@ -130,7 +137,15 @@ export const createSendTX = ({
130137 . filter ( ( key ) => key . writable )
131138 . map ( ( k ) => k . pubkey ) ;
132139 if ( writableAccounts . length > 0 ) {
133- await refetchAccounts ( writableAccounts ) ;
140+ const waitForAccountRefetch = options . waitForAccountRefetch ?? true ;
141+ if ( waitForAccountRefetch ) {
142+ await refetchAccounts ( writableAccounts ) ;
143+ } else {
144+ // Refetch in background without waiting
145+ refetchAccounts ( writableAccounts ) . catch ( ( error : unknown ) => {
146+ console . warn ( "Failed to refetch accounts in background:" , error ) ;
147+ } ) ;
148+ }
134149 }
135150
136151 if ( result . meta ?. logMessages ) {
0 commit comments