Skip to content

Commit

Permalink
fix msg buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
BitHighlander committed Sep 22, 2023
1 parent c02f786 commit c1ca819
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const EIP155SendTransactionConfirmation = () => {
let gasPriceHex = recomendedFeeFromPioneer.data.gasPrice.hex;
let gasPriceInWei = parseInt(gasPriceHex, 16);
let gasPriceInGwei = gasPriceInWei / 1e9;
console.log("pioneer: ", gasPriceInGwei, "gwei")
setGasRecomendedByPioneer(gasPriceInGwei);
setSelectedGasPrice(gasPriceInGwei)

Expand Down Expand Up @@ -328,34 +329,12 @@ export const EIP155SendTransactionConfirmation = () => {
txData.gasPrice = params.request.params[0].gas
delete txData.maxPriorityFeePerGas
delete txData.maxFeePerGas
} else if(selectedGasPriceHex && chainId !== 1){
} else if(selectedGasPriceHex){
console.log("useing selected gas without eip1555 not eth!")
txData.gasPrice = selectedGasPriceHex
console.log("selectedGasPriceHex: ",selectedGasPriceHex)
delete txData.maxPriorityFeePerGas
delete txData.maxFeePerGas
} else if(selectedGasPrice && chainId == 1) {
console.log("Converting selected gas to eip1555");

// Convert selectedGasPrice from Gwei to Wei
const selectedGasPriceInWei = selectedGasPrice * 10**9;

// Calculate 10% of selectedGasPriceInWei as the priority fee (miner tip)
const priorityFee = Math.floor(selectedGasPriceInWei * 0.1);

// Use the selectedGasPriceInWei as the maximum fee
const maxFee = selectedGasPriceInWei;

// Convert integers to Hexadecimal (and pad if necessary)
const maxPriorityFeePerGasHex = "0x" + priorityFee.toString(16).padStart(16, '0');
const maxFeePerGasHex = "0x" + maxFee.toString(16).padStart(16, '0');

// Apply the calculated EIP-1559 compliant fees
txData.maxPriorityFeePerGas = maxPriorityFeePerGasHex;
txData.maxFeePerGas = maxFeePerGasHex;

// Remove the legacy gas price parameter
delete txData.gasPrice;
} else {
throw Error("unable to deturming gas price intent! aborting")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useToast,
VStack,
} from '@chakra-ui/react'
import { Buffer } from 'buffer'
import { formatJsonRpcResult } from '@json-rpc-tools/utils'
import type { BIP32Path } from '@shapeshiftoss/hdwallet-core'
import type { KeepKeyHDWallet } from '@shapeshiftoss/hdwallet-keepkey'
Expand Down Expand Up @@ -48,18 +49,28 @@ export const EIP155SignMessageConfirmation = () => {
const { request } = params
const message = getSignParamsMessage(request.params)

// useEffect(() => {
// if (!wallet) return
// const accounts = (wallet as KeepKeyHDWallet).ethGetAccountPaths({
// coin: 'Ethereum',
// accountIdx: 0,
// })
// setAccountPath(accounts[0].addressNList)
// ;(wallet as KeepKeyHDWallet)
// .ethGetAddress({ addressNList: accounts[0].addressNList, showDisplay: false })
// .then(setAddress)
// }, [wallet])

useEffect(() => {
;(async () => {
if (!wallet) return
// setLoadingAddress(true)
let accountsOptions = [0,1,2,3,4,5]
for(let i=0; i< accountsOptions.length; i++){
const accountPath = wallet.ethGetAccountPaths({ coin: 'Ethereum', accountIdx: i })
let address = await wallet.ethGetAddress({addressNList: accountPath[0].addressNList, showDisplay: false})
if(address.toLowerCase() === params.request.params[1].toLowerCase()){
if(address.toLowerCase() === params.request.params[0].toLowerCase()){
setAddress(address)
setAccountPath(accountPath[0].addressNList)
// setLoadingAddress(false)
return
}
}
Expand All @@ -71,11 +82,7 @@ export const EIP155SignMessageConfirmation = () => {
try {
if (!accountPath || !wallet) return
setLoading(true)

// const message = getSignParamsMessage(request.params)
console.log('request: ', request)
console.log('request.params: ', request.params)
console.log('request.params[1]: ', request.params[1])

let signedMessage
if (
request.method === 'eth_signTypedData' ||
Expand All @@ -87,6 +94,15 @@ export const EIP155SignMessageConfirmation = () => {
typedData: JSON.parse(request.params[1]),
})
} else if (request.method === 'eth_sign' || request.method === 'personal_sign') {
//TODO move this to a util function
const strip0x = (inputHexString: string) =>
inputHexString.startsWith('0x')
? inputHexString.slice(2, inputHexString.length)
: inputHexString

let message = Buffer.from(strip0x(request.params[0]), 'hex')
console.log('message: ', message)

signedMessage = await (wallet as KeepKeyHDWallet).ethSignMessage({
...txData,
addressNList: accountPath,
Expand Down

0 comments on commit c1ca819

Please sign in to comment.