diff --git a/.changeset/sharp-islands-collect.md b/.changeset/sharp-islands-collect.md new file mode 100644 index 00000000000..17c594e15b3 --- /dev/null +++ b/.changeset/sharp-islands-collect.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: added `onBeforeSend` hook to the connector interface diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 6eeca1f3f04..593d7fce145 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: "Release PR to npm" runs-on: ubuntu-latest # comment out if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - name: Checkout diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 60484577999..3c22d3cd8f9 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -646,11 +646,18 @@ export class Account extends AbstractAccount { */ async sendTransaction( transactionRequestLike: TransactionRequestLike, - { estimateTxDependencies = true }: ProviderSendTxParams = {} + { + estimateTxDependencies = true, + onBeforeSend, + skipCustomFee = false + }: ProviderSendTxParams = {} ): Promise { if (this._connector) { return this.provider.getTransactionResponse( - await this._connector.sendTransaction(this.address.toString(), transactionRequestLike) + await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, { + onBeforeSend, + skipCustomFee, + }) ); } const transactionRequest = transactionRequestify(transactionRequestLike); diff --git a/packages/account/src/connectors/fuel-connector.ts b/packages/account/src/connectors/fuel-connector.ts index 92d4346e932..9e004f0f0d2 100644 --- a/packages/account/src/connectors/fuel-connector.ts +++ b/packages/account/src/connectors/fuel-connector.ts @@ -14,6 +14,7 @@ import type { FuelEventArg, Version, SelectNetworkArguments, + SendTransactionParams, } from './types'; interface Connector { @@ -42,7 +43,11 @@ interface Connector { signTransaction(address: string, transaction: TransactionRequestLike): Promise; // #endregion fuel-connector-method-signTransaction // #region fuel-connector-method-sendTransaction - sendTransaction(address: string, transaction: TransactionRequestLike): Promise; + sendTransaction( + address: string, + transaction: TransactionRequestLike, + params?: SendTransactionParams + ): Promise; // #endregion fuel-connector-method-sendTransaction // #region fuel-connector-method-currentAccount currentAccount(): Promise; @@ -193,10 +198,14 @@ export abstract class FuelConnector extends EventEmitter implements Connector { * * @param address - The address to sign the transaction * @param transaction - The transaction to send - * + * @param params - Optional parameters to send the transaction * @returns The transaction id */ - async sendTransaction(_address: string, _transaction: TransactionRequestLike): Promise { + async sendTransaction( + _address: string, + _transaction: TransactionRequestLike, + _params?: SendTransactionParams + ): Promise { throw new FuelError(FuelError.CODES.NOT_IMPLEMENTED, 'Method not implemented.'); } diff --git a/packages/account/src/connectors/types/data-type.ts b/packages/account/src/connectors/types/data-type.ts index 04a63ad028d..77c6458b29f 100644 --- a/packages/account/src/connectors/types/data-type.ts +++ b/packages/account/src/connectors/types/data-type.ts @@ -1,6 +1,8 @@ import type { JsonAbi } from '@fuel-ts/abi-coder'; import type { RequireAtLeastOne } from 'type-fest'; +import type { TransactionRequest } from '../../providers'; + /** * @name Version */ @@ -42,3 +44,8 @@ export type SelectNetworkArguments = RequireAtLeastOne Promise; +}; diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 5f9ffe88f42..70c07e79506 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -363,7 +363,10 @@ export type ProviderCallParams = UTXOValidationParams & EstimateTransactionParam /** * Provider Send transaction params */ -export type ProviderSendTxParams = EstimateTransactionParams; +export type ProviderSendTxParams = EstimateTransactionParams & { + onBeforeSend?: (txRequest: TransactionRequest) => Promise; + skipCustomFee?: boolean; +}; /** * URL - Consensus Params mapping.