Skip to content

Commit

Permalink
Update stopTransaction to fully support eip1559 transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Jul 13, 2021
1 parent 1e68e2f commit bc89279
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/transaction/TransactionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,14 +723,37 @@ export class TransactionController extends BaseController<
CANCEL_RATE,
);

const txParams = {
from: transactionMeta.transaction.from,
gasLimit: transactionMeta.transaction.gas,
gasPrice,
nonce: transactionMeta.transaction.nonce,
to: transactionMeta.transaction.from,
value: '0x0',
};
const existingMaxFeePerGas = transactionMeta.transaction?.maxFeePerGas;
const existingMaxPriorityFeePerGas =
transactionMeta.transaction?.maxPriorityFeePerGas;

const newMaxFeePerGas =
existingMaxFeePerGas &&
getIncreasedPriceFromExisting(existingMaxFeePerGas, CANCEL_RATE);
const newMaxPriorityFeePerGas =
existingMaxPriorityFeePerGas &&
getIncreasedPriceFromExisting(existingMaxPriorityFeePerGas, CANCEL_RATE);

const txParams =
newMaxFeePerGas && newMaxFeePerGas
? {
from: transactionMeta.transaction.from,
gasLimit: transactionMeta.transaction.gas,
maxFeePerGas: newMaxFeePerGas,
maxPriorityFeePerGas: newMaxPriorityFeePerGas,
type: 2,
nonce: transactionMeta.transaction.nonce,
to: transactionMeta.transaction.from,
value: '0x0',
}
: {
from: transactionMeta.transaction.from,
gasLimit: transactionMeta.transaction.gas,
gasPrice,
nonce: transactionMeta.transaction.nonce,
to: transactionMeta.transaction.from,
value: '0x0',
};

const unsignedEthTx = this.prepareUnsignedEthTx(txParams);

Expand Down

0 comments on commit bc89279

Please sign in to comment.