Skip to content

Commit

Permalink
Added EthereumTransactionEIP1559
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Nov 9, 2021
1 parent 71a304b commit 55db922
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 284 deletions.
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/common/trezor/trezor-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.
import { loadTimeData } from '../../../common/loadTimeData'
import { Unsuccessful, EthereumSignTransaction, CommonParams, Success } from 'trezor-connect'
import { EthereumSignedTx, HDNodeResponse } from 'trezor-connect/lib/typescript/trezor/protobuf'
import { HDNodeResponse } from 'trezor-connect/lib/typescript'
import { EthereumSignedTx } from 'trezor-connect/lib/typescript/networks/ethereum'
export const kTrezorBridgeUrl = loadTimeData.getString('braveWalletTrezorBridgeUrl')

export enum TrezorCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { sendTrezorCommand } from '../../common/trezor/trezor-bridge-transport'
import { getLocale } from '../../../common/locale'
import { hardwareDeviceIdFromAddress } from '../hardwareDeviceIdFromAddress'
import { EthereumSignedTx } from 'trezor-connect/lib/typescript/trezor/protobuf'
import { EthereumSignedTx } from 'trezor-connect/lib/typescript/networks/ethereum'

export default class TrezorBridgeKeyring extends EventEmitter {
constructor () {
Expand Down Expand Up @@ -121,6 +121,30 @@ export default class TrezorBridgeKeyring extends EventEmitter {
}

private prepareTransactionPayload = (path: string, txInfo: TransactionInfo, chainId: string): SignTransactionCommandPayload => {
const isEIP1559Transaction = txInfo.txData.maxPriorityFeePerGas !== '' && txInfo.txData.maxFeePerGas !== ''
if (isEIP1559Transaction) {
return this.createEIP1559TransactionPayload(path, txInfo, chainId)
}
return this.createLegacyTransactionPayload(path, txInfo, chainId)
}

private createEIP1559TransactionPayload = (path: string, txInfo: TransactionInfo, chainId: string): SignTransactionCommandPayload => {
return {
path: path,
transaction: {
to: txInfo.txData.baseData.to,
value: txInfo.txData.baseData.value,
data: bufferToHex(Buffer.from(txInfo.txData.baseData.data)).toString(),
chainId: parseInt(chainId, 16),
nonce: txInfo.txData.baseData.nonce,
gasLimit: txInfo.txData.baseData.gasLimit,
maxFeePerGas: txInfo.txData.maxFeePerGas,
maxPriorityFeePerGas: txInfo.txData.maxPriorityFeePerGas
}
}
}

private createLegacyTransactionPayload = (path: string, txInfo: TransactionInfo, chainId: string): SignTransactionCommandPayload => {
return {
path: path,
transaction: {
Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet_ui/trezor/trezor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you can obtain one at http://mozilla.org/MPL/2.0/.

import TrezorConnect, { Unsuccessful, Success } from 'trezor-connect'
import { EthereumSignedTx } from 'trezor-connect/lib/typescript/trezor/protobuf'
import { EthereumSignedTx } from 'trezor-connect/lib/typescript/networks/ethereum'
import {
TrezorCommand,
UnlockCommand,
Expand Down
Loading

0 comments on commit 55db922

Please sign in to comment.