Skip to content

Commit

Permalink
feat: [GSW-2040] Transaction Rejected handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 17, 2025
1 parent e5daedc commit bef0c3d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/web/src/utils/transaction-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
isContractMessage,
SendTransactionRequestParam,
TransactionMessage,
WalletResponse,
} from "@common/clients/wallet-client/protocols";
import { DEFAULT_CHAIN_ID } from "@constants/environment.constant";
import { DEFAULT_GAS_WANTED } from "@common/values";
Expand Down Expand Up @@ -143,8 +144,8 @@ const generateTransactionDataDocument = async (
export const withTransactionGuard = async <T>(
walletClient: WalletClient | null,
transaction: SendTransactionRequestParam,
executeTransaction: (updatedTransaction?: SendTransactionRequestParam) => Promise<T>,
): Promise<T> => {
executeTransaction: (updatedTransaction?: SendTransactionRequestParam) => Promise<WalletResponse<T>>,
): Promise<WalletResponse<T>> => {
if (!walletClient) {
throw new Error("Wallet client is not initialized");
}
Expand All @@ -154,7 +155,13 @@ export const withTransactionGuard = async <T>(
const approved = await showTransactionApprovalModal(document);

if (approved === false) {
throw new Error("Transaction rejected");
return {
code: 4000,
data: null,
message: "The transaction has been rejected by the user.",
status: "failure",
type: "TRANSACTION_REJECTED",
};
}

const updatedTransaction = {
Expand Down

0 comments on commit bef0c3d

Please sign in to comment.