Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: accept before send hook #446

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
run on beforeSend
nelitow committed Dec 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 56241782eec1fc5276b79acc3521f1d7e51487a3
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,
@@ -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
@@ -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
@@ -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),