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

Nj/feat/onBeforeSend #1735

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions packages/app/src/systems/Core/utils/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import type { TransactionRequestLike, TransactionResponse } from 'fuels';
import type {
EstimateTransactionParams,
TransactionRequest,
TransactionRequestLike,
TransactionResponse,
// SendTransactionParams, This should come from fuels
} from 'fuels';
import { WalletLocked, hashMessage, transactionRequestify } from 'fuels';
import { VaultService } from '~/systems/Vault';

interface SendTransactionParams {
skipCustomFee?: boolean;
onBeforeSend?: (txRequest: TransactionRequest) => Promise<TransactionRequest>;
}

export class WalletLockedCustom extends WalletLocked {
/**
* Sign message with wallet instance privateKey
Expand Down Expand Up @@ -39,9 +50,16 @@ export class WalletLockedCustom extends WalletLocked {
}

async sendTransaction(
transactionRequestLike: TransactionRequestLike
transactionRequestLike: TransactionRequestLike,
params?: EstimateTransactionParams & SendTransactionParams
): Promise<TransactionResponse> {
const transactionRequest = transactionRequestify(transactionRequestLike);
let transactionRequest = transactionRequestify(transactionRequestLike);

// Apply onBeforeSend hook if provided
if (params?.onBeforeSend) {
transactionRequest = await params.onBeforeSend(transactionRequest);
}

const txRequestToSend =
await this.populateTransactionWitnessesSignature(transactionRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ export function TransactionRequest() {
errors={errors.simulateTxErrors}
isConfirm
fees={fees}
skipCustomFee={txRequest.input.skipCustomFee}
/>
)}
{shouldShowTxExecuted && (
<TxContent.Info
showDetails
tx={txSummaryExecuted}
txStatus={executedStatus()}
skipCustomFee={txRequest.input.skipCustomFee}
footer={
status('failed') && (
<Button
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/systems/Send/machines/sendMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type MachineContext = {
maxGasLimit?: BN;
input?: TxInputs['createTransfer'];
error?: string;
skipCustomFee?: boolean;
};

type EstimateDefaultTipsReturn = {
Expand All @@ -43,6 +44,7 @@ type CreateTransactionReturn = {
transactionRequest?: TransactionRequest;
providerUrl: string;
address: string;
skipCustomFee?: boolean;
};

type MachineServices = {
Expand Down Expand Up @@ -183,6 +185,7 @@ export const sendMachine = createMachine(
address: ev.data.address,
baseFee: ev.data.baseFee ?? ctx.baseFee,
gasLimit: ev.data.gasLimit ?? ctx.gasLimit,
skipCustomFee: ev.data.skipCustomFee ?? ctx.skipCustomFee,
error: undefined,
})),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type TxContentInfoProps = {
fastTip?: BN;
};
txRequest?: TransactionRequest;
skipCustomFee?: boolean;
};

function TxContentInfo({
Expand All @@ -109,13 +110,15 @@ function TxContentInfo({
errors,
fees,
txRequest,
skipCustomFee,
}: TxContentInfoProps) {
const { getValues } = useFormContext<SendFormValues>();

const status = txStatus || tx?.status || txStatus;
const hasErrors = Boolean(Object.keys(errors || {}).length);
const isExecuted = !!tx?.id;
const txRequestGasLimit = getGasLimitFromTxRequest(txRequest);
const shouldShowFees = !skipCustomFee && showDetails;

const initialAdvanced = useMemo(() => {
if (!fees?.regularTip || !fees?.fastTip) return false;
Expand Down Expand Up @@ -155,9 +158,9 @@ function TxContentInfo({
status={status}
isLoading={isLoading}
/>
{isLoading && !showDetails && <TxFee.Loader />}
{showDetails && !fees && <TxFee fee={tx?.fee} />}
{showDetails &&
{isLoading && !shouldShowFees && <TxFee.Loader />}
{shouldShowFees && !fees && <TxFee fee={tx?.fee} />}
{shouldShowFees &&
fees?.baseFee &&
txRequestGasLimit &&
fees?.regularTip &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export const TxApprove = () => {
isLoading={isLoading}
errors={ctx.errors.simulateTxErrors}
isConfirm
skipCustomFee={ctx.input.skipCustomFee}
/>
)}
{ctx.shouldShowTxExecuted && (
<TxContent.Info
showDetails
tx={ctx.txSummaryExecuted}
txStatus={ctx.executedStatus()}
skipCustomFee={ctx.input.skipCustomFee}
footer={
ctx.status('failed') && (
<Button
Expand Down
Loading