Skip to content

Commit c1bcc7d

Browse files
authored
Fix trezor nonce (#1165)
* Prefix nonce if needed * Update version * Fix type problems in trezor package
1 parent fb81fbb commit c1bcc7d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/trezor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/trezor",
3-
"version": "2.1.7-alpha.1",
3+
"version": "2.1.7-alpha.2",
44
"description": "Trezor hardware wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",

packages/trezor/src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function trezor(options: TrezorOptions): WalletInit {
284284
maxFeePerGas: transactionData.maxFeePerGas!,
285285
maxPriorityFeePerGas: transactionData.maxPriorityFeePerGas!,
286286
nonce: transactionData.nonce!,
287-
chainId: parseInt(currentChain.id),
287+
chainId: Number(currentChain.id),
288288
data: transactionData.hasOwnProperty('data')
289289
? transactionData.data
290290
: ''
@@ -296,7 +296,7 @@ function trezor(options: TrezorOptions): WalletInit {
296296
gasPrice: transactionData.gasPrice!,
297297
gasLimit: gasLimit!,
298298
nonce: transactionData.nonce!,
299-
chainId: parseInt(currentChain.id),
299+
chainId: Number(currentChain.id),
300300
data: transactionData.hasOwnProperty('data')
301301
? transactionData.data
302302
: ''
@@ -353,6 +353,15 @@ function trezor(options: TrezorOptions): WalletInit {
353353
) {
354354
populatedTransaction.nonce = populatedTransaction.nonce.toString(16)
355355
}
356+
if (
357+
populatedTransaction.hasOwnProperty('nonce') &&
358+
typeof populatedTransaction.nonce === 'string'
359+
) {
360+
// Adds "0x" to a given `String` if it does not already start with "0x".
361+
populatedTransaction.nonce = ethUtil.addHexPrefix(
362+
populatedTransaction.nonce
363+
)
364+
}
356365

357366
const updateBigNumberFields =
358367
bigNumberFieldsToStrings(populatedTransaction)
@@ -363,7 +372,7 @@ function trezor(options: TrezorOptions): WalletInit {
363372
)
364373

365374
const chainId = currentChain.hasOwnProperty('id')
366-
? Number.parseInt(currentChain.id)
375+
? Number(currentChain.id)
367376
: 1
368377
const common = await getCommon({ customNetwork, chainId })
369378

@@ -386,7 +395,7 @@ function trezor(options: TrezorOptions): WalletInit {
386395

387396
// EIP155 support. check/recalc signature v value.
388397
const rv = parseInt(v, 16)
389-
let cv = parseInt(currentChain.id) * 2 + 35
398+
let cv = Number(currentChain.id) * 2 + 35
390399
if (rv !== cv && (rv & cv) !== rv) {
391400
cv += 1 // add signature v bit.
392401
}
@@ -477,7 +486,7 @@ function trezor(options: TrezorOptions): WalletInit {
477486
? [accounts[0].address]
478487
: [],
479488
eth_chainId: async () =>
480-
currentChain.hasOwnProperty('id') ? currentChain.id : '',
489+
currentChain.hasOwnProperty('id') ? String(currentChain.id) : '',
481490
eth_signTransaction: async ({ params: [transactionObject] }) =>
482491
signTransaction(transactionObject),
483492
eth_sendTransaction: async ({ baseRequest, params }) => {

0 commit comments

Comments
 (0)