Skip to content

Commit 6e7a8b7

Browse files
committed
refactor: update TxIntentMismatchError to use undefined
Ticket: WP-6189
1 parent 982f902 commit 6e7a8b7

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
27752775

27762776
// Helper to throw TxIntentMismatchError with consistent context
27772777
const throwTxMismatch = (message: string): never => {
2778-
throw new TxIntentMismatchError(message, '', [txParams], txPrebuild?.txHex || '');
2778+
throw new TxIntentMismatchError(message, undefined, [txParams], txPrebuild?.txHex);
27792779
};
27802780

27812781
if (
@@ -2849,7 +2849,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28492849

28502850
// Helper to throw TxIntentMismatchError with consistent context
28512851
const throwTxMismatch = (message: string): never => {
2852-
throw new TxIntentMismatchError(message, '', [txParams], txPrebuild?.txHex || '');
2852+
throw new TxIntentMismatchError(message, undefined, [txParams], txPrebuild?.txHex);
28532853
};
28542854

28552855
if (!txParams?.recipients || !txPrebuild?.recipients || !wallet) {

modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export async function verifyTransaction(
7878
if (!(tx instanceof utxolib.bitgo.UtxoPsbt)) {
7979
throw new TxIntentMismatchError(
8080
'unexpected transaction type',
81-
params.reqId || '',
81+
params.reqId,
8282
[params.txParams],
83-
params.txPrebuild.txHex || ''
83+
params.txPrebuild.txHex
8484
);
8585
}
8686
assertValidTransaction(tx, descriptorMap, params.txParams.recipients ?? [], tx.network);

modules/abstract-utxo/src/transaction/fixedScript/verifyTransaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function verifyTransaction<TNumber extends bigint | number>(
5151

5252
// Helper to throw TxIntentMismatchError with consistent context
5353
const throwTxMismatch = (message: string): never => {
54-
throw new TxIntentMismatchError(message, reqId || '', [txParams], txPrebuild.txHex || '');
54+
throw new TxIntentMismatchError(message, reqId, [txParams], txPrebuild.txHex);
5555
};
5656

5757
if (!_.isUndefined(verification.disableNetworking) && !_.isBoolean(verification.disableNetworking)) {
@@ -168,7 +168,7 @@ export async function verifyTransaction<TNumber extends bigint | number>(
168168

169169
const allOutputs = parsedTransaction.outputs;
170170
if (!txPrebuild.txHex) {
171-
throw new TxIntentMismatchError(`txPrebuild.txHex not set`, reqId || '', [txParams], '');
171+
throw new TxIntentMismatchError(`txPrebuild.txHex not set`, reqId, [txParams], undefined);
172172
}
173173
const inputs = isPsbt
174174
? getPsbtTxInputs(txPrebuild.txHex, coin.network).map((v) => ({

modules/sdk-core/src/bitgo/errors.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -253,24 +253,29 @@ export interface ContractDataPayload {
253253
*
254254
* @class TxIntentMismatchError
255255
* @extends {BitGoJsError}
256-
* @property {string | IRequestTracer} id - Transaction ID or request tracer for tracking
256+
* @property {string | IRequestTracer | undefined} id - Transaction ID or request tracer for tracking
257257
* @property {TransactionParams[]} txParams - Array of transaction parameters that were analyzed
258-
* @property {string} txHex - The raw transaction in hexadecimal format
258+
* @property {string | undefined} txHex - The raw transaction in hexadecimal format
259259
*/
260260
export class TxIntentMismatchError extends BitGoJsError {
261-
public readonly id: string | IRequestTracer;
261+
public readonly id: string | IRequestTracer | undefined;
262262
public readonly txParams: TransactionParams[];
263-
public readonly txHex: string;
263+
public readonly txHex: string | undefined;
264264

265265
/**
266266
* Creates an instance of TxIntentMismatchError
267267
*
268268
* @param {string} message - Error message describing the intent mismatch
269-
* @param {string | IRequestTracer} id - Transaction ID or request tracer
269+
* @param {string | IRequestTracer | undefined} id - Transaction ID or request tracer
270270
* @param {TransactionParams[]} txParams - Transaction parameters that were analyzed
271-
* @param {string} txHex - Raw transaction hex string
271+
* @param {string | undefined} txHex - Raw transaction hex string
272272
*/
273-
public constructor(message: string, id: string | IRequestTracer, txParams: TransactionParams[], txHex: string) {
273+
public constructor(
274+
message: string,
275+
id: string | IRequestTracer | undefined,
276+
txParams: TransactionParams[],
277+
txHex: string | undefined
278+
) {
274279
super(message);
275280
this.id = id;
276281
this.txParams = txParams;
@@ -295,16 +300,16 @@ export class TxIntentMismatchRecipientError extends TxIntentMismatchError {
295300
* Creates an instance of TxIntentMismatchRecipientError
296301
*
297302
* @param {string} message - Error message describing the recipient intent mismatch
298-
* @param {string | IRequestTracer} id - Transaction ID or request tracer
303+
* @param {string | IRequestTracer | undefined} id - Transaction ID or request tracer
299304
* @param {TransactionParams[]} txParams - Transaction parameters that were analyzed
300-
* @param {string} txHex - Raw transaction hex string
305+
* @param {string | undefined} txHex - Raw transaction hex string
301306
* @param {MismatchedRecipient[]} mismatchedRecipients - Array of recipients that don't match user intent
302307
*/
303308
public constructor(
304309
message: string,
305-
id: string | IRequestTracer,
310+
id: string | IRequestTracer | undefined,
306311
txParams: TransactionParams[],
307-
txHex: string,
312+
txHex: string | undefined,
308313
mismatchedRecipients: MismatchedRecipient[]
309314
) {
310315
super(message, id, txParams, txHex);
@@ -329,16 +334,16 @@ export class TxIntentMismatchContractError extends TxIntentMismatchError {
329334
* Creates an instance of TxIntentMismatchContractError
330335
*
331336
* @param {string} message - Error message describing the contract intent mismatch
332-
* @param {string | IRequestTracer} id - Transaction ID or request tracer
337+
* @param {string | IRequestTracer | undefined} id - Transaction ID or request tracer
333338
* @param {TransactionParams[]} txParams - Transaction parameters that were analyzed
334-
* @param {string} txHex - Raw transaction hex string
339+
* @param {string | undefined} txHex - Raw transaction hex string
335340
* @param {ContractDataPayload} mismatchedDataPayload - The contract interaction data that doesn't match user intent
336341
*/
337342
public constructor(
338343
message: string,
339-
id: string | IRequestTracer,
344+
id: string | IRequestTracer | undefined,
340345
txParams: TransactionParams[],
341-
txHex: string,
346+
txHex: string | undefined,
342347
mismatchedDataPayload: ContractDataPayload
343348
) {
344349
super(message, id, txParams, txHex);
@@ -363,16 +368,16 @@ export class TxIntentMismatchApprovalError extends TxIntentMismatchError {
363368
* Creates an instance of TxIntentMismatchApprovalError
364369
*
365370
* @param {string} message - Error message describing the approval intent mismatch
366-
* @param {string | IRequestTracer} id - Transaction ID or request tracer
371+
* @param {string | IRequestTracer | undefined} id - Transaction ID or request tracer
367372
* @param {TransactionParams[]} txParams - Transaction parameters that were analyzed
368-
* @param {string} txHex - Raw transaction hex string
373+
* @param {string | undefined} txHex - Raw transaction hex string
369374
* @param {TokenApproval} tokenApproval - Details of the token approval that doesn't match user intent
370375
*/
371376
public constructor(
372377
message: string,
373-
id: string | IRequestTracer,
378+
id: string | IRequestTracer | undefined,
374379
txParams: TransactionParams[],
375-
txHex: string,
380+
txHex: string | undefined,
376381
tokenApproval: TokenApproval
377382
) {
378383
super(message, id, txParams, txHex);

0 commit comments

Comments
 (0)