@@ -5,7 +5,7 @@ import type { ThirdwebClient } from "../../../../client/client.js";
5
5
import { eth_sendRawTransaction } from "../../../../rpc/actions/eth_sendRawTransaction.js" ;
6
6
import { getRpcClient } from "../../../../rpc/rpc.js" ;
7
7
import { getAddress } from "../../../../utils/address.js" ;
8
- import { type Hex , toHex } from "../../../../utils/encoding/hex.js" ;
8
+ import { type Hex , isHex , toHex } from "../../../../utils/encoding/hex.js" ;
9
9
import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js" ;
10
10
import type { Prettify } from "../../../../utils/type-utils.js" ;
11
11
import type {
@@ -141,39 +141,32 @@ export class EnclaveWallet implements IWebWallet {
141
141
const transaction : Record < string , Hex | number | undefined > = {
142
142
to : tx . to ? getAddress ( tx . to ) : undefined ,
143
143
data : tx . data ,
144
- value : typeof tx . value === "bigint" ? toHex ( tx . value ) : undefined ,
145
- gas :
146
- typeof tx . gas === "bigint"
147
- ? toHex ( tx . gas + tx . gas / BigInt ( 10 ) )
148
- : undefined , // Add a 10% buffer to gas
144
+ value : hexlify ( tx . value ) ,
145
+ gas : hexlify ( tx . gas ) ,
149
146
nonce :
150
- typeof tx . nonce === "number"
151
- ? toHex ( tx . nonce )
152
- : toHex (
153
- await import (
154
- "../../../../rpc/actions/eth_getTransactionCount.js"
155
- ) . then ( ( { eth_getTransactionCount } ) =>
156
- eth_getTransactionCount ( rpcRequest , {
157
- address : getAddress ( this . address ) ,
158
- blockTag : "pending" ,
159
- } ) ,
160
- ) ,
161
- ) ,
147
+ hexlify ( tx . nonce ) ||
148
+ toHex (
149
+ await import (
150
+ "../../../../rpc/actions/eth_getTransactionCount.js"
151
+ ) . then ( ( { eth_getTransactionCount } ) =>
152
+ eth_getTransactionCount ( rpcRequest , {
153
+ address : getAddress ( this . address ) ,
154
+ blockTag : "pending" ,
155
+ } ) ,
156
+ ) ,
157
+ ) ,
162
158
chainId : toHex ( tx . chainId ) ,
163
159
} ;
164
160
165
- if ( typeof tx . maxFeePerGas === "bigint" ) {
166
- transaction . maxFeePerGas = toHex ( tx . maxFeePerGas ) ;
167
- transaction . maxPriorityFeePerGas =
168
- typeof tx . maxPriorityFeePerGas === "bigint"
169
- ? toHex ( tx . maxPriorityFeePerGas )
170
- : undefined ;
161
+ if ( hexlify ( tx . maxFeePerGas ) ) {
162
+ transaction . maxFeePerGas = hexlify ( tx . maxFeePerGas ) ;
163
+ transaction . maxPriorityFeePerGas = hexlify ( tx . maxPriorityFeePerGas ) ;
171
164
transaction . type = 2 ;
172
165
} else {
173
- transaction . gasPrice =
174
- typeof tx . gasPrice === "bigint" ? toHex ( tx . gasPrice ) : undefined ;
166
+ transaction . gasPrice = hexlify ( tx . gasPrice ) ;
175
167
transaction . type = 0 ;
176
168
}
169
+
177
170
return signEnclaveTransaction ( {
178
171
client,
179
172
storage,
@@ -253,3 +246,7 @@ export class EnclaveWallet implements IWebWallet {
253
246
} ;
254
247
}
255
248
}
249
+
250
+ function hexlify ( value : string | number | bigint | undefined ) {
251
+ return value === undefined || isHex ( value ) ? value : toHex ( value ) ;
252
+ }
0 commit comments