1+ /* eslint-disable @typescript-eslint/naming-convention */
2+
13import { ErrorCode , FuelError } from '@fuel-ts/errors' ;
24import type { BN } from '@fuel-ts/math' ;
35import { bn } from '@fuel-ts/math' ;
@@ -115,6 +117,14 @@ export type TransactionResponseJson = {
115117 requestJson ?: string ;
116118} ;
117119
120+ export type TransactionResponseParams = {
121+ transactionRequestOrId : string | TransactionRequest ;
122+ provider : Provider ;
123+ chainId : number ;
124+ abis ?: JsonAbisFromAllCalls ;
125+ submitAndAwaitSubscription ?: SubmitAndAwaitStatusSubscriptionIterable ;
126+ } ;
127+
118128/**
119129 * Represents a response for a transaction.
120130 */
@@ -130,35 +140,85 @@ export class TransactionResponse {
130140 request ?: TransactionRequest ;
131141 status ?: StatusChangeSubscription [ 'statusChange' ] ;
132142 abis ?: JsonAbisFromAllCalls ;
143+ private submitTxSubscription ?: SubmitAndAwaitStatusSubscriptionIterable ;
133144 preConfirmationStatus ?: StatusChangeSubscription [ 'statusChange' ] ;
134145
135146 private waitingForStreamData = false ;
136147 private statusResolvers : Map < StatusType , ( ( ) => void ) [ ] > = new Map ( ) ;
137148
138149 /**
139- * Constructor for ` TransactionResponse` .
150+ * Creates a new TransactionResponse instance .
140151 *
141- * @param tx - The transaction ID or TransactionRequest.
152+ * @param transactionRequestOrId - The transaction ID or TransactionRequest.
142153 * @param provider - The provider.
154+ * @param chainId - The chain ID.
155+ * @param abis - The ABIs.
156+ * @param submitAndAwaitSubscription - The submit and await subscription.
157+ *
158+ * @deprecated Use the object-style constructor instead:
159+ * `new TransactionResponse({ ... })`
143160 */
144161 constructor (
145- tx : string | TransactionRequest ,
162+ transactionRequestOrId : string | TransactionRequest ,
146163 provider : Provider ,
147164 chainId : number ,
148165 abis ?: JsonAbisFromAllCalls ,
149- private submitTxSubscription ?: SubmitAndAwaitStatusSubscriptionIterable
166+ submitAndAwaitSubscription ?: SubmitAndAwaitStatusSubscriptionIterable
167+ ) ;
168+
169+ /**
170+ * Creates a new TransactionResponse instance.
171+ *
172+ * @param constructorParams - The constructor parameters.
173+ */
174+ constructor ( constructorParams : TransactionResponseParams ) ;
175+
176+ /**
177+ * Constructor for `TransactionResponse`.
178+ */
179+ constructor (
180+ constructorParams : string | TransactionRequest | TransactionResponseParams ,
181+ provider ?: Provider ,
182+ chainId ?: number ,
183+ abis ?: JsonAbisFromAllCalls ,
184+ submitTxSubscription ?: SubmitAndAwaitStatusSubscriptionIterable
150185 ) {
186+ let tx : string | TransactionRequest ;
187+ let _provider : Provider ;
188+ let _chainId : number ;
189+ let _abis : JsonAbisFromAllCalls | undefined ;
190+
191+ if (
192+ typeof constructorParams === 'object' &&
193+ 'provider' in constructorParams &&
194+ arguments . length === 1
195+ ) {
196+ // Object-style usage
197+ tx = constructorParams . transactionRequestOrId ;
198+ _provider = constructorParams . provider ;
199+ _chainId = constructorParams . chainId ;
200+ _abis = constructorParams . abis ;
201+ this . submitTxSubscription = constructorParams . submitAndAwaitSubscription ;
202+ } else {
203+ // Deprecated positional usage
204+ tx = constructorParams as string | TransactionRequest ;
205+ _provider = provider as Provider ;
206+ _chainId = chainId as number ;
207+ _abis = abis ;
208+ this . submitTxSubscription = submitTxSubscription ;
209+ }
210+
151211 // Transaction Request was not provided
152212 if ( typeof tx === 'string' ) {
153213 this . id = tx ;
154214 } else {
155215 // Transaction Request was provided
156- this . id = tx . getTransactionId ( chainId ) ;
216+ this . id = tx . getTransactionId ( _chainId ) ;
157217 this . request = tx ;
158218 }
159219
160- this . provider = provider ;
161- this . abis = abis ;
220+ this . provider = _provider ;
221+ this . abis = _abis ;
162222 this . waitForResult = this . waitForResult . bind ( this ) ;
163223 this . waitForPreConfirmation = this . waitForPreConfirmation . bind ( this ) ;
164224 }
0 commit comments