Skip to content

Commit a005397

Browse files
authored
feat: support transaction rejected via code
1 parent d56d543 commit a005397

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

lib/__tests__/getParsedEthersError.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,21 @@ describe("getParsedEthersError", () => {
8282
context: message,
8383
});
8484
});
85-
it("should handle transaction rejected", () => {
85+
it("should handle transaction rejected via code", () => {
86+
const message = "User rejected transaction";
87+
88+
const result = getParsedEthersError({
89+
message,
90+
code: ETHERS_ERROR_CODES.ACTION_REJECTED,
91+
action: "sendTransaction",
92+
});
93+
94+
expect(result).toEqual({
95+
errorCode: RETURN_VALUE_ERROR_CODES.REJECTED_TRANSACTION,
96+
context: message,
97+
});
98+
});
99+
it("should handle transaction rejected via error code", () => {
86100
const message = "User rejected transaction";
87101

88102
const result = getParsedEthersError({

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const RETURN_VALUE_ERROR_CODES = {
1515
export const ETHERS_ERROR_CODES = {
1616
NONCE_EXPIRED: "NONCE_EXPIRED",
1717
UNPREDICTABLE_GAS_LIMIT: "UNPREDICTABLE_GAS_LIMIT",
18+
ACTION_REJECTED: "ACTION_REJECTED",
1819
};
1920

2021
export const NESTED_ETHERS_ERROR_CODES = {

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface EthersError {
1616
receipt?: {
1717
gasUsed: BigNumber;
1818
};
19+
action?: string;
1920
}
2021

2122
export interface NestedEthersError {

lib/utils/getTopLevelKnownError.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export function getTopLevelKnownError(
1616
};
1717
}
1818

19+
if (
20+
ethersError.code === ETHERS_ERROR_CODES.ACTION_REJECTED &&
21+
ethersError.action === "sendTransaction"
22+
) {
23+
return {
24+
errorCode: RETURN_VALUE_ERROR_CODES.REJECTED_TRANSACTION,
25+
context: ethersError.message,
26+
};
27+
}
28+
1929
const unpredictableGasLimitError = getUnpredictableGasLimitError(ethersError);
2030
if (unpredictableGasLimitError !== undefined) {
2131
return unpredictableGasLimitError;

0 commit comments

Comments
 (0)