Skip to content

Commit

Permalink
fix: imkey supports eip1559 (#2281)
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 authored May 23, 2024
1 parent eed44a2 commit 4845690
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,29 +263,47 @@ export class EthImKeyKeyring extends EventEmitter {
const txChainId = getChainId(transaction.common);
const dataHex = transaction.data.toString('hex');

const txData = {
to: transaction.to!.toString(),
value: convertToBigint(transaction.value),
data: dataHex === '' ? '' : `0x${dataHex}`,
nonce: convertToBigint(transaction.nonce),
gasLimit: convertToBigint(transaction.gasLimit),
gasPrice:
typeof (transaction as Transaction).gasPrice !== 'undefined'
? convertToBigint((transaction as Transaction).gasPrice)
: convertToBigint(
(transaction as FeeMarketEIP1559Transaction).maxFeePerGas
),
chainId: txChainId,
path: accountDetail.hdPath,
};
const txJSON = transaction.toJSON();
const is1559 = is1559Tx(txJSON);

const txData = is1559
? {
data: dataHex === '' ? '' : `0x${dataHex}`,
gasLimit: convertToBigint(transaction.gasLimit),
type: convertToBigint(transaction.type.toString()),
accessList: transaction.accessList,
maxFeePerGas: convertToBigint(transaction.maxFeePerGas),
maxPriorityFeePerGas: convertToBigint(
transaction.maxPriorityFeePerGas
),
nonce: convertToBigint(transaction.nonce),
to: transaction.to!.toString(),
value: convertToBigint(transaction.value),
chainId: txChainId,
path: accountDetail.hdPath,
}
: {
to: transaction.to!.toString(),
value: convertToBigint(transaction.value),
data: dataHex === '' ? '' : `0x${dataHex}`,
nonce: convertToBigint(transaction.nonce),
gasLimit: convertToBigint(transaction.gasLimit),
gasPrice:
typeof (transaction as Transaction).gasPrice !== 'undefined'
? convertToBigint((transaction as Transaction).gasPrice)
: convertToBigint(
(transaction as FeeMarketEIP1559Transaction).maxFeePerGas
),
chainId: txChainId,
path: accountDetail.hdPath,
};

const { signature, txHash } = await this.invokeApp('signTransaction', [
txData,
]);
const txJSON = transaction.toJSON();
let decoded;

if (is1559Tx(txJSON)) {
if (is1559) {
decoded = ethUtil.rlp.decode('0x' + signature.substring(4), true);

txJSON.r = bytesToHex(decoded.data[10]);
Expand Down
2 changes: 2 additions & 0 deletions src/background/service/keyring/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EVENTS } from '@/constant';
import eventBus from '@/eventBus';
import * as Sentry from '@sentry/browser';

export const throwError = (error, method = EVENTS.COMMON_HARDWARE.REJECTED) => {
eventBus.emit(EVENTS.broadcastToUI, {
Expand Down Expand Up @@ -32,6 +33,7 @@ export class SignHelper {
const result = await fn();
resolve(result);
} catch (e) {
Sentry.captureException(e);
throwError(e?.message ?? e, this.errorEventName);
}
};
Expand Down

0 comments on commit 4845690

Please sign in to comment.