Skip to content

Commit e860bba

Browse files
Support hex transaction types in fromTransactionType (#861)
## Changes - Linear: https://linear.app/thirdweb/issue/INF-171/ - Here is the problem being solved. - Here are the changes made. ## How this PR will be tested - [ ] Open the dashboard and click X. Result: A modal should appear. - [ ] Call the /foo/bar API. Result: Returns 200 with "baz" in the response body. ## Output (Example: Screenshot/GIF for UI changes, cURL output for API changes) <!-- start pr-codex --> --- ## PR-Codex overview This PR modifies the `src/shared/utils/sdk.ts` file by enhancing the `fromTransactionType` function and removing the `toTransactionType` function, streamlining transaction type handling. ### Detailed summary - Added `hexToNumber` and `isHex` imports from `thirdweb`. - Updated `fromTransactionType` to convert hex transaction types using `hexToNumber`. - Removed the entire `toTransactionType` function. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent eef9c43 commit e860bba

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

src/shared/utils/sdk.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sha256HexSync } from "@thirdweb-dev/crypto";
2-
import { createThirdwebClient } from "thirdweb";
2+
import { createThirdwebClient, hexToNumber, isHex } from "thirdweb";
33
import type { TransactionReceipt } from "thirdweb/transaction";
44
import { env } from "./env";
55

@@ -27,14 +27,6 @@ export const fromTransactionType = (type: TransactionReceipt["type"]) => {
2727
if (type === "eip2930") return 2;
2828
if (type === "eip4844") return 3;
2929
if (type === "eip7702") return 4;
30+
if (isHex(type)) return hexToNumber(type);
3031
throw new Error(`Unexpected transaction type ${type}`);
3132
};
32-
33-
export const toTransactionType = (value: number) => {
34-
if (value === 0) return "legacy";
35-
if (value === 1) return "eip1559";
36-
if (value === 2) return "eip2930";
37-
if (value === 3) return "eip4844";
38-
if (value === 4) return "eip7702";
39-
throw new Error(`Unexpected transaction type number ${value}`);
40-
};

0 commit comments

Comments
 (0)