Skip to content

Commit

Permalink
run on beforeSend
Browse files Browse the repository at this point in the history
  • Loading branch information
nelitow committed Dec 21, 2024
1 parent 0f2c512 commit 5624178
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
13 changes: 13 additions & 0 deletions packages/common/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type EventEmitter from 'node:events';
import type {
BN,
BytesLike,
Predicate as FuelPredicate,
Provider as FuelProvider,
Expand Down Expand Up @@ -53,3 +54,15 @@ export type SignedMessageCustomCurve = {
curve: string;
signature: string;
};

export interface PaymasterParams {
paymasterAddress: string;
maxFeePerGas?: BN;
deadline?: number;
}

export interface SendTransactionParams {
skipCustomFee?: boolean;
onBeforeSend?: (txRequest: TransactionRequest) => Promise<TransactionRequest>;
paymaster?: PaymasterParams;
}
31 changes: 4 additions & 27 deletions packages/fuel-wallet/src/FuelWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,27 +199,13 @@ export class FuelWalletConnector extends FuelConnector {
if (!transaction) {
throw new Error('Transaction is required');
}
let txRequest = transactionRequestify(transaction);

// Log the incoming transaction details
console.log('FuelWalletConnector - Incoming Transaction:', {
inputs: transaction.inputs?.map((input) => ({
type: input.type,
owner: 'owner' in input ? input.owner : undefined,
amount: 'amount' in input ? input.amount?.toString() : undefined,
assetId: 'assetId' in input ? input.assetId : undefined,
})),
outputs: transaction.outputs?.map((output) => ({
type: output.type,
to: 'to' in output ? output.to : undefined,
amount: 'amount' in output ? output.amount?.toString() : undefined,
assetId: 'assetId' in output ? output.assetId : undefined,
})),
witnesses: transaction.witnesses?.length,
params,
});
if (params?.onBeforeSend) {
txRequest = await params.onBeforeSend(txRequest);
}

// Transform transaction object to a transaction request
const txRequest = transactionRequestify(transaction);

/**
* @todo We should remove this once the chainId standard start to be used and chainId is required
Expand All @@ -230,15 +216,6 @@ export class FuelWalletConnector extends FuelConnector {
url: network.url,
};

// Log the final request being sent
console.log('FuelWalletConnector - Sending Request:', {
address,
provider,
skipCustomFee: params?.skipCustomFee,
maxFee: txRequest.maxFee?.toString(),
tip: txRequest.tip?.toString(),
});

return this.client.request('sendTransaction', {
address,
transaction: JSON.stringify(txRequest),
Expand Down

0 comments on commit 5624178

Please sign in to comment.